Skip to content

Commit 3669654

Browse files
committed
fix: condition explicitly uses attribute values and not public_send
Using public_send caused an issue when attribute names shadowed method names. Closes #280
1 parent 7a07bcc commit 3669654

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/active_hash/condition.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def matches?(record)
1919
expectation_method = inverted ? :any? : :all?
2020

2121
constraints.send(expectation_method) do |attribute, expected|
22-
value = record.public_send(attribute)
22+
value = record[attribute]
2323

2424
matches_value?(value, expected)
2525
end
@@ -41,4 +41,4 @@ def matches_value?(value, comparison)
4141
def normalize(value)
4242
value.respond_to?(:to_s) ? value.to_s : value
4343
end
44-
end
44+
end

spec/active_hash/relation_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,24 @@
5050
expect(array.size).to eq(2)
5151
end
5252
end
53+
54+
describe "colliding methods" do
55+
it "should handle attributes named after existing methods" do
56+
klass = Class.new(ActiveHash::Base) do
57+
self.data = [
58+
{
59+
id: 1,
60+
name: "Aaa",
61+
display: true,
62+
},
63+
{
64+
id: 2,
65+
name: "Bbb",
66+
display: false,
67+
},
68+
]
69+
end
70+
expect(klass.where(display: true).length).to eq(1)
71+
end
72+
end
5373
end

0 commit comments

Comments
 (0)