When creating ActiveRecord in rspec, I use instruments for valid records. But when using fxitures in tests, they don't seem to check. In the following example, the employee looks perfectly correct, and yet the related check in the specification says that they are not valid.
class Employee < ActiveRecord::Base
validates_presence_of :email
end
class User < ActiveRecord::Base
validates_associated :employee
end
Employee.find(745185059).errors.count
Employee.find(745185059).errors.full_messages
Employee.find(745185059).valid?
Example:
describe SessionsController do
fixtures :users, :employees
describe "Logging in by cookie" do
def set_remember_token token, time
@user[:remember_token] = token;
@user[:remember_token_expires_at] = time
debugger
@user.save!
end
it 'logs in with cookie' do
stub!(:cookies).and_return({ :auth_token => 'hello!' })
logged_in?.should be_true
end
end
end
Any ideas why I get a validation failure? (Of course, I cut a lot of middle code, it is possible that the error is somewhere else)
source
share