Skip to content

Commit

Permalink
Adjust specs regarding #where_object_changes to prevent possible coin…
Browse files Browse the repository at this point in the history
…cidental errors; also acknowledge inconsistent nature of fixnum value args
  • Loading branch information
batter committed Jan 14, 2015
1 parent cd7c09e commit 1ad7838
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ version.event
# Query versions objects by attributes.
PaperTrail::Version.where_object(attr1: val1, attr2: val2)

# Query versions object_changes field by attributes (requires [`object_changes`](https://github.com/airblade/paper_trail#diffing-versions) column on versions table)
# Query versions object_changes field by attributes (requires [`object_changes`](https://github.com/airblade/paper_trail#diffing-versions) column on versions table). Also can't guarantee consistent results for values of type Fixnum due to limitations of wildcard matchers against the column.
PaperTrail::Version.where_object_changes(attr1: val1)
```

Expand Down
12 changes: 6 additions & 6 deletions spec/models/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
context "valid arguments", :versioning => true do
let(:widget) { Widget.new }
let(:name) { Faker::Name.first_name }
let(:int) { rand(10) + 1 }
let(:int) { rand(5) + 2 }

before do
widget.update_attributes!(:name => name, :an_integer => 0)
widget.update_attributes!(:name => 'foobar', :an_integer => 100)
widget.update_attributes!(:name => 'foobar', :an_integer => 77)
widget.update_attributes!(:name => Faker::Name.last_name, :an_integer => int)
end

Expand All @@ -135,12 +135,12 @@

it "should be able to locate versions according to their `object_changes` contents" do
expect(widget.versions.where_object_changes(:name => name)).to eq(widget.versions[0..1])
expect(widget.versions.where_object_changes(:an_integer => 100)).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => 77)).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => int)).to eq([widget.versions.last])
end

it "should be able to handle queries for multiple attributes" do
expect(widget.versions.where_object_changes(:an_integer => 100, :name => 'foobar')).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')).to eq(widget.versions[1..2])
end
end

Expand All @@ -150,12 +150,12 @@

it "should be able to locate versions according to their `object_changes` contents" do
expect(widget.versions.where_object_changes(:name => name)).to eq(widget.versions[0..1])
expect(widget.versions.where_object_changes(:an_integer => 100)).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => 77)).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => int)).to eq([widget.versions.last])
end

it "should be able to handle queries for multiple attributes" do
expect(widget.versions.where_object_changes(:an_integer => 100, :name => 'foobar')).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')).to eq(widget.versions[1..2])
end

after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
Expand Down

0 comments on commit 1ad7838

Please sign in to comment.