Add `have_a_version_with_changes` matcher
This commit is contained in:
parent
430239fc1f
commit
920ad9e956
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue