ruby on rails - RSpec changing model attribute name -
not value, name of attribute. yes, real. don't know hell going on.
the migration:
class createfolders < activerecord::migration def change create_table :folders |t| t.string :name, null: false t.timestamps end change_table :bookmarks |t| t.belongs_to :folder end end end
the schema:
activerecord::schema.define(version: 20140424065045) # these extensions must enabled in order support database enable_extension "plpgsql" create_table "bookmarks", force: true |t| t.string "name", null: false t.string "url", null: false t.datetime "created_at" t.datetime "updated_at" t.integer "folder_id" end create_table "folders", force: true |t| t.string "name", null: false t.datetime "created_at" t.datetime "updated_at" end end
what shows inside of rails c
:
[3] pry(main)> bookmark => bookmark(id: integer, name: string, url: string, created_at: datetime, updated_at: datetime, folder_id: integer)
and now, our huge glaring problem:
[3] pry(#<rspec::core::examplegroup::nested_2::nested_1>)> bookmark => bookmark(id: integer, name: string, url: string, created_at: datetime, updated_at: datetime, folders_id: integer)
notice name of last attribute there: folders_id
does know in hell ever cause this?
finally found issue was, , damn bizarre.
so brand new in rails 4, activerecord::migration.maintain_test_schema!
. convenient little tool pretty nice, only updates test schema on creation of new migration. in process, if migration wrong first time, , update later, you'll find inconsistencies this.
to fix problem, run rake db:test:prepare
. you'll deprecation warning, ignore it. when check inside of rspec again should work fine.
Comments
Post a Comment