Problem using FactoryGirl with Hobo

32 views
Skip to first unread message

mkar...@gmail.com

unread,
Jul 23, 2012, 7:05:22 AM7/23/12
to hobo...@googlegroups.com
I'm trying to make a Hobo app with a REST api and test it with RSpec with FactoryGirl fixtures.

my user fields look like:
  fields do
    name          :string, :required, :unique
    email_address :email_address, :login => true
    administrator :boolean, :default => false
    api_key       :string, :default=>""
    timestamps
  end

And I have a user factory which looks like:

FactoryGirl.define do
  factory :user do 
    name "Joe Blow"
    email_address "j...@blow.com"
    administrator false
    api_key "nil value"
  end
end

Right at the start of my first spec file I do

  let(:user) {  FactoryGirl.create(:user) }


And the failure I get is:

  Failure/Error: let(:user) {  FactoryGirl.create(:user) }
     NoMethodError:
       undefined method `api_key=' for #<User:0x00000103ccf098>

In development mode, the api_key can be populated (by an observer)
and generally works as expected.

Can anyone please give me a hint why this is an unknown attribute when
trying to run rspec?

Thanks in advance.

Mike K




Matt Jones

unread,
Jul 23, 2012, 7:29:46 AM7/23/12
to hobo...@googlegroups.com

On Jul 23, 2012, at 7:05 AM, mkar...@gmail.com wrote:
>
> And the failure I get is:
>
> Failure/Error: let(:user) { FactoryGirl.create(:user) }
> NoMethodError:
> undefined method `api_key=' for #<User:0x00000103ccf098>
>
> In development mode, the api_key can be populated (by an observer)
> and generally works as expected.
>
> Can anyone please give me a hint why this is an unknown attribute when
> trying to run rspec?

This is going to sound like a silly question, but are you running specs with the rspec command line tool? If you are, you may want to do:

rake db:test:prepare

as it looks like your test DB is missing the api_key column...

--Matt Jones

mkar...@gmail.com

unread,
Jul 23, 2012, 10:28:39 AM7/23/12
to hobo...@googlegroups.com
Not silly at all. In fact, quite the point.
Ah, well, <blush>... RTFM

Thank you.


Mike
Reply all
Reply to author
Forward
0 new messages