thoughtbot/factory_girl — Issue #277: NoMethodError: undefined method `attributes'
Author: sekrett
Created: 2012-01-20 12:19:38+00:00
State: open

Hello!

I have a `Contact` model:

class Contact
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming

validates :name, :contact, :question, :presence => true

attr_accessor :name, :contact, :subject, :question

def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end

def persisted?
false
end
end

A factory:

Factory.define :contact do |f|
f.name 'my name'
f.contact 'my contact'
f.subject 'my subject'
f.question 'my question'
end

And then I do:

Loading test environment (Rails 3.1.3)
>> Factory.build(:contact).attributes
NoMethodError: undefined method `attributes' for #
from (irb):1
from /Users/sekrett/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/sekrett/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/sekrett/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'
>>

It works when using old `attributes_for` method.