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 8357c21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 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
2 changes: 1 addition & 1 deletion lib/paper_trail/serializers/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def where_object_changes_condition(arel_field, field, value)
arel_field.matches("%\n#{field}:\n- #{value}\n%").
or(arel_field.matches("%\n#{field}:\n-%\n- #{value}\n%"))
else # Syck adds extra spaces into array dumps
arel_field.matches("%\n#{field}: \n%- #{value}\n%").
arel_field.matches("%\n#{field}: \n- #{value}\n%").
or(arel_field.matches("%\n#{field}: \n-%\n- #{value}\n%"))
end
end
Expand Down
13 changes: 7 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,13 @@

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])
puts int
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 +151,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 8357c21

Please sign in to comment.