I am working through the (excellent) railstutorial.org site have have a basic question about rspec.
When I run the below test on a new user model, I get an "unknown attribute: username" message and a failed test.
before(:each) do
@attr = { :lname_e => "User", :fname_e => "Test", :email => "[email protected]", :username => "testUser" }
end
it "should create a new instance given valid attributes" do
User.create!(@attr)
end
Error syntax is
Failures:
1) User should create a new instance given valid attributes
Failure/Error: User.create!(@attr)
unknown attribute: username
# ./spec/models/user_spec.rb:11:in `block (2 levels) in <top (required)>'
The field is in the users table (string), it's in the model as attr_accessible and in the console I can create a user with exactly the same syntax in the test. This "username" field was added via a migration after creating the initial table, is there some other file I need to update here?
Thanks,
Did you run rake db:test:prepare
?
The field may be missing from your test database, but present in your development database (which is why the console is working).
Try making sure your migrations are all up to date and then update the test database:
rake db:migrate
rake db:test:prepare
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With