7-31-工作琐事

1. Get a mail from a colleague this morning

When you commit code, make sure you do it with your real name, and a proper email address (your scilearn address). You can set your name like this, in the repo:

1
2
$ git config user.name "Hot Day"
$ git config user.email "hday@hotday.com.cn"

You can also do it globally, for all repos:

1
2
$ git config --global user.name "Hot Day"
$ git config --global user.email "hday@hotday.com.cn"

and check the current name and email of a repo:

1
2
$ git config --get user.name
$ git config --get user.email

Thanks!


2. factory_girl and mysql

truncate 清空的表 id 会从新记录, 而 delete 清空的表则不会从新记录 会继续原数据记录,当然这里 id 为自增长。

When I am writing the cucucmber features for our new project, we meet an issue:

the snippet below will not work.

1
2
3
Given the following posts exist
| id | name | description | user_id |
| 1 | a post | This is a post | 1 |

If everything is ok, the Given will find the step in pickle_step.rb:

1
2
3
4
# create models from a table
Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
create_models_from_table(plural_factory, table)
end

And the code will call the factory which defined before using factory_girl.
Then it will save a post in database sure enough.

But it says

Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails

Obviously, we have something wrong with the user_id field. And more obviously, we have not generate a user.

I thought before the factory_girl will take care of the association object if there is no record in database.
Actually, if we feed the factory attributes, factory_girl will take these values and create a post object rather than create a association record.

So here, it won’t create a user with id 1. The Given will be interpreted to a sql at last:

1
INSERT INTO `posts` ( `created_at`, `description`, `id`, `name`, `updated_at`, `user_id`) VALUES ('2013-07-31 06:12:41', 'This is a post', 1, 'a post', 1, '2013-07-31 06:12:41', 1)

And we have a foreign key constraint on user_id, of course it will fail.

###Solutions:

  1. Given a user with name: “Test”
  2. Prepare a user before test.
  3. If the user does not matter, just remove user_id, let factory_girl take care of user.

3. Capybara get the native css value

element.native.css_value("text-overflow")

  1. element is the capybara element
  2. native is used to get the selenium-webdriver element
  3. css_value is used to get the computed style.
文章目录
  1. 1. 1. Get a mail from a colleague this morning
  2. 2. 2. factory_girl and mysql
  3. 3. 3. Capybara get the native css value
|