Reputation: 99
I am using Factory Girl to help in creating records for testing. The problem I am having isn that on of the fields in a table is named 'alias', which is a reserved ruby keyword. This is what I am trying to do:
factory :time_zone do
id 4
name "Eastern"
abbreviation "EST"
utc "-5"
alias "America/New_York"
end
I get an error when running tests.
When I tried using self.alias "America/New_York", This is the error that I get.
Failure/Error: FactoryGirl.create(:time_zone, id: 4 , name:"Eastern" , utc:"-5") NoMethodError: undefined method `alias=' for #<TimeZone id: 4, name: "Eastern", abbreviation: "EST", utc: -5>
Note: The self.alias does work on my local machine, but the test is failing using jenkins service for monitoring tests.
How do I make this work?
Thanks
Upvotes: 2
Views: 987
Reputation: 696
As others have commented, your life will be easier it you use a different name for that column, however if you want to stick with it, you can make factory_girl work by using add_attribute
. Your factory would then look like:
factory :time_zone do
id 4
name "Eastern"
abbreviation "EST"
utc "-5"
add_attribute :alias, "America/New_York"
end
Upvotes: 4