Module: ElabsMatchers::Matchers::Rspec::Orm
- Defined in:
- lib/elabs_matchers/matchers/rspec/orm.rb
Instance Method Summary (collapse)
-
- (Object) persist
Asserts if an assigned value persistes in the database.
Instance Method Details
- (Object) persist
Asserts if an assigned value persistes in the database.
Example: post.should persist(:title, "Blog post")
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/elabs_matchers/matchers/rspec/orm.rb', line 15 RSpec::Matchers.define :persist do |attribute, value| match do |actual| actual.send(:#{attribute}=", value) actual.save! actual = actual.class.find(actual.id) @final_value = actual.send(attribute) @final_value == value end { |actual| "Expected #{attribute} to be persisted and retain its value of #{value.inspect} but the value was #{@final_value.inspect}" } { |actual| "Expected #{attribute} not to be persisted and retain its value of #{value.inspect} but it did." } end |