2

I've got a cucumber step that is trying to populate objects, including a new column that was just added via a migration. The column is named is_active, and the error is:

      unknown attribute: is_active (ActiveRecord::UnknownAttributeError)

which is raised as a result of this line:

    city = City.find_or_create_by_name_and_state(:name => attributes['City'], :state => attributes['State'], :icao_code => attributes['ICAO'], :display_order => attributes['Order'], :is_active => attributes['Active'], :current_temperature => attributes['Current'])

The odd thing is that earlier today, I added column display_order, which is working fine.

If I remove the :is_active assignment from the step and add a "puts city.attributes" after the city assignment, is_active is not listed among the attributes. But if I do "City.new.attributes" from the rails console, the is_active attribute is there.

It appears that the cucumber test is not executing in the proper environment, although it is able to see the recent display_order attribute, which is defined only in the dev environment, as is the most recent is_active attribute.

Any ideas how I get cucumber to see the attribute?

Thanks,

Phil

POOCH
  • 33
  • 3
  • what environment are you running your cucumber tests in? have you run rake db:test:prepare ? – kclair Mar 16 '12 at 21:20

1 Answers1

2
rake db:migrate
rake db:test:prepare

The test environment does not use the same database used in development. You have to run the command rake db:test:prepare to recreate it after every migration you make that actually changes the database structure.

That command simply creates the test database based on the schema.rb file (or the structure.sql, it depends on the project's configurations), that are created/updated when you run a migration.

Check the info from the rails guides

Castilho
  • 3,147
  • 16
  • 15
  • That was it. The db:test:prepare is what I had missed. Thanks very much! – POOCH Mar 16 '12 at 22:55
  • 1
    `rake db:test:prepare` is deprecated for Rails 4. ```WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.``` see http://stackoverflow.com/questions/23351783/when-i-ran-bundle-exec-rake-testprepare-it-errored-out-but-bundle-exec-rake – kittyminky Feb 11 '15 at 04:12