Merge pull request #881 from aried3r/ar/have_version_with_changes_matcher
Add `have_a_version_with_changes` matcher
This commit is contained in:
commit
5a2e709e2e
|
@ -18,7 +18,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- None
|
- [#881](https://github.com/airblade/paper_trail/pull/881) - Add RSpec matcher
|
||||||
|
`have_a_version_with_changes` for easier testing.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
|
@ -1392,7 +1392,8 @@ end
|
||||||
```
|
```
|
||||||
|
|
||||||
It is also possible to do assertions on the versions using `have_a_version_with`
|
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
|
```ruby
|
||||||
describe '`have_a_version_with` matcher' do
|
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
|
# check if the model has a version with the specified attributes
|
||||||
match { |actual| actual.versions.where_object(attributes).any? }
|
match { |actual| actual.versions.where_object(attributes).any? }
|
||||||
end
|
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
|
||||||
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
|
describe "versioning option" do
|
||||||
context "enabled", versioning: true do
|
context "enabled", versioning: true do
|
||||||
it "should enable versioning" do
|
it "should enable versioning" do
|
||||||
|
|
Loading…
Reference in New Issue