当我在 rspec 或 cucumber 中进行测试时,每次更新属性时,我都必须再次“重新加载”变量:
@answer.update_attributes(notified: false)
@answer = Answer.find(@answer)
否则 @answer 不会更新。这似乎效率低下。这是正确的吗?我做错了什么还是这就是它应该工作的方式?
编辑:完整规格
describe "notify method" do
before (:each) do
@user = FactoryGirl.create(:user)
friend = generate_friend_for_user(@user)
@answer = FactoryGirl.create(:answer, user: friend, contact: @user.service)
@answer.update_attributes(notified: false)
@answer = Answer.find(@answer)
end
it "should send an email and update last_email field" do
@user.update_attributes(last_email: 25.hours.ago)
@answer.notify.should == true
@user = User.find(@user)
@user.last_email.should > 1.minute.ago
end