mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Fix PaperTrail::Version#where_object so it works on Ruby19 and Ruby18
This commit is contained in:
parent
d8f846eaa4
commit
e8f88b40c8
2 changed files with 12 additions and 3 deletions
|
@ -70,7 +70,8 @@ module PaperTrail
|
|||
|
||||
# Performs an attribute search on the serialized object by invoking the
|
||||
# identically-named method in the serializer being used.
|
||||
def where_object(**args)
|
||||
def where_object(args = {})
|
||||
raise ArgumentError, 'expected to receive a Hash' unless args.is_a?(Hash)
|
||||
arel_field = arel_table[:object]
|
||||
|
||||
where_conditions = args.map do |field, value|
|
||||
|
|
|
@ -100,9 +100,17 @@ class PaperTrail::VersionTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
context "PaperTrail::Version.where_object" do
|
||||
context "receving something other than a Hash as an argument" do
|
||||
should "raise an error" do
|
||||
assert_raise(ArgumentError) do
|
||||
PaperTrail::Version.where_object(:foo)
|
||||
PaperTrail::Version.where_object([])
|
||||
end
|
||||
end
|
||||
end
|
||||
should "call `where_object` on the serializer" do
|
||||
# Create some args to fake-query on.
|
||||
args = { a: 1, b: "2", c: false, d: nil }
|
||||
args = { :a => 1, :b => '2', :c => false, :d => nil }
|
||||
arel_field = PaperTrail::Version.arel_table[:object]
|
||||
|
||||
# Create a dummy value for us to return for each condition that can be
|
||||
|
@ -120,7 +128,7 @@ class PaperTrail::VersionTest < ActiveSupport::TestCase
|
|||
# Stub out PaperTrail.serializer to return our mock, and then make the
|
||||
# query call.
|
||||
PaperTrail.stub :serializer, serializer do
|
||||
PaperTrail::Version.where_object(**args)
|
||||
PaperTrail::Version.where_object(args)
|
||||
end
|
||||
|
||||
# Verify that our serializer mock received the correct
|
||||
|
|
Loading…
Reference in a new issue