每当我在RSpec或Cucumber中进行测试时,每次更新属性时,我都需要再次“重新加载”变量:
否则 @answer 不会更新。这似乎效率不高。我是错了还是这就是它应该工作的方式?
编辑:完整规范
@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