Merge pull request #881 from aried3r/ar/have_version_with_changes_matcher

Add `have_a_version_with_changes` matcher
This commit is contained in:
Jared Beck 2016-10-18 13:13:16 -04:00 committed by GitHub
commit 5a2e709e2e
4 changed files with 23 additions and 2 deletions

View File

@ -18,7 +18,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
### Added
- None
- [#881](https://github.com/airblade/paper_trail/pull/881) - Add RSpec matcher
`have_a_version_with_changes` for easier testing.
### Fixed

View File

@ -1392,7 +1392,8 @@ end
```
It is also possible to do assertions on the versions using `have_a_version_with`
matcher
and `have_a_version_with_changes` matchers. For more examples, see the
[Widget spec](https://github.com/airblade/paper_trail/blob/master/spec/models/widget_spec.rb)
```ruby
describe '`have_a_version_with` matcher' do

View File

@ -27,3 +27,8 @@ RSpec::Matchers.define :have_a_version_with do |attributes|
# check if the model has a version with the specified attributes
match { |actual| actual.versions.where_object(attributes).any? }
end
RSpec::Matchers.define :have_a_version_with_changes do |attributes|
# check if the model has a version changes with the specified attributes
match { |actual| actual.versions.where_object_changes(attributes).any? }
end

View File

@ -21,6 +21,20 @@ describe Widget, type: :model do
end
end
describe "`have_a_version_with_changes` matcher", versioning: true do
before do
widget.update_attributes!(name: "Leonard", an_integer: 2)
widget.update_attributes!(name: "Tom")
widget.update_attributes!(name: "Bob")
end
it "is possible to do assertions on versions" do
expect(widget).to have_a_version_with_changes name: "Leonard", an_integer: 2
expect(widget).to have_a_version_with_changes an_integer: 2
expect(widget).to have_a_version_with_changes name: "Tom"
end
end
describe "versioning option" do
context "enabled", versioning: true do
it "should enable versioning" do