I'm using shoulda-callback-matchers gem to test my callbacks.
But I have a problem with my after_save
with condition
.
Callback in the model
:
after_save :update_effort_rate, if: -> { saved_change_to_rent? }
My test in my spec
:
context 'callbacks' do
it { is_expected.to callback(:update_effort_rate).after(:save).if :rent_changed? }
end
Rspec
error:
Failure/Error: it { is_expected.to callback(:update_effort_rate).after(:save).if :saved_change_to_rent? }
expected update_effort_rate to be listed as a callback after save if saved_change_to_rent? evaluates to true, but was not
I don't know what i am doing wrong. Any help ? Thanks
CodePudding user response:
Try changing the if clause by just passing in the method name (as opposed to a lambda that calls the method):
after_save :update_effort_rate, if: :saved_change_to_rent?