Reputation: 1
When I run the following spec:
require 'spec_helper'
describe User do
before :each do
@user = User.new :email => "[email protected]", :password => "foobar", :password_confirmation => "foobar"
end
it "should be valid" do
@user.should be_valid
end
end
I get this error:
1) User should be valid
Failure/Error: @user = User.new :email => "[email protected]", :password => "foobar", :password_confirmation => "foobar"
ActiveRecord::UnknownAttributeError:
unknown attribute: email
# ./spec/models/user_spec.rb:5:in `new'
However, when I go in to console and run
user = User.new :email => "[email protected]", :password => "foobar", :password_confirmation => "foobar"
user.valid?
It returns true. For some reason, in my test, I am unable to create a User instance, saying that the email attribute is inaccessible.
Upvotes: 0
Views: 151
Reputation: 9000
Console uses the development database, but specs use the test database. Make sure email
is defined in both.
Upvotes: 3