thoughtbot/factory_girl — Issue #275: FactoryGirl::AttributeDefinitionError - strange error message
Author: JoelQ
Created: 2012-01-18 18:06:31+00:00
State: open

When building a factory with an association that does not have a factory, for example:

```ruby
factory :degree_consultation do
student
degree_consultant
sequence(:start_time) { |n| Random.new.rand(3..10).days.from_now }
sequence(:end_time) { |n| Random.new.rand(11..12).days.from_now }
next_action ["Call Student", "Called Student"].sample
degree
transfer_credit { "http://"+Faker::Internet.domain_name }
end
```
which does not have a `degree` factory, I receive this error message:

12) Admin::DegreeConsultationActionsController DELETE destroy should redirect to the index
Failure/Error: let! (:dc) {create :degree_consultation }
FactoryGirl::AttributeDefinitionError:
Attribute already defined: student
# ./spec/controllers/admin/degree_consultation_actions_controller_spec.rb:7:in `block (2 levels) in '

This error message was completely misleading. It took over a day to realize that the missing degree factory was the root cause of the problem. Any ideas?