I want to check if no attributes on an ActiveRecord object have been modified. Currently I'm doing this:
prev_attr = obj.attributes
<- this will give me back a Hash with attr name and attr value
And then, later, I grab the attributes again and compare the 2 hashes. Is there another way?
There is another way indeed. You can do it like this :
it "should not change sth" do
expect {
# some action
}.to_not change{subject.attribute}
end
See https://www.relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/expect-change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With