开发者

Why gives FactoryGirl such large ID's in my testcases?

开发者 https://www.devze.com 2023-04-09 03:43 出处:网络
I am using a Rails 2.3.x and Ruby 1.8.7 environment with FactoryGirl 1.3.3 (edit: version of FG has no influence as far as I can see)

I am using a Rails 2.3.x and Ruby 1.8.7 environment with FactoryGirl 1.3.3 (edit: version of FG has no influence as far as I can see)

In my console, when I do:

Factory(:user_activity)

I get:

#<Use开发者_开发技巧rActivity id: 25, user_id: 1, resource_id: nil, ... >

However when I do in my testcase:

@ua = Factory(:user_activity)

I get:

#<UserActivity id: 980190963, user_id: 298486374, resource_id: nil,  ... >

Where are these large IDs coming from? How can I setup my testcases to use the expected IDs as seen in the console?


I suppose that the IDs are calculated in the same or an equivalent way as when using ActiveRecord fixtures (AR fixtures hashes the fixture label).

I don't know why using Factory in console will give you more normal IDs however.

Do you really need to know the ID in order to test? Or can you use your @ua variable to get the ID if you need it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号