Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# active_hash Changelog

## next - unreleased

- Fix relation matching when attribute name collides with a method. [#281](https://github.com/active-hash/active_hash/pull/281) @flavorjones


## Version [3.2.0] - <sub><sup>2022-07-14</sup></sub>

- Add Ruby 3.2 to the CI matrix [#275](https://github.com/active-hash/active_hash/pull/275) @petergoldstein
Expand Down
4 changes: 2 additions & 2 deletions lib/active_hash/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def matches?(record)
expectation_method = inverted ? :any? : :all?

constraints.send(expectation_method) do |attribute, expected|
value = record.public_send(attribute)
value = record.read_attribute(attribute)

matches_value?(value, expected)
end
Expand All @@ -41,4 +41,4 @@ def matches_value?(value, comparison)
def normalize(value)
value.respond_to?(:to_s) ? value.to_s : value
end
end
end
21 changes: 21 additions & 0 deletions spec/active_hash/relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,25 @@
expect(array.size).to eq(2)
end
end

describe "colliding methods https://github.com/active-hash/active_hash/issues/280" do
it "should handle attributes named after existing methods" do
klass = Class.new(ActiveHash::Base) do
self.data = [
{
id: 1,
name: "Aaa",
display: true,
},
{
id: 2,
name: "Bbb",
display: false,
},
]
end

expect(klass.where(display: true).length).to eq(1)
end
end
end