Skip to content

Commit 3273a67

Browse files
authored
Merge pull request #338 from ChrisBr/feature/implement_hash
Implement eql and hash for Builder class
2 parents 23c337e + 86543f2 commit 3273a67

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- [#338](https://github.com/JsonApiClient/json_api_client/pull/338) - implement hash and eql? for builder class
56
- [#351](https://github.com/JsonApiClient/json_api_client/pull/351) - Remove rudimental `last_result_set` relationship from serializer
67

78
## 1.13.0

lib/json_api_client/query/builder.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ def method_missing(method_name, *args, &block)
109109
to_a.send(method_name, *args, &block)
110110
end
111111

112+
def hash
113+
[
114+
klass,
115+
params
116+
].hash
117+
end
118+
119+
def ==(other)
120+
return false unless other.is_a?(self.class)
121+
122+
hash == other.hash
123+
end
124+
alias_method :eql?, :==
125+
112126
protected
113127

114128
def _fetch

test/unit/query_builder_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,24 @@ def test_build_propagate_only_path_params
312312
assert_equal '123', record.author_id
313313
assert_equal [], record.relationships.changed
314314
end
315+
316+
def test_build_hash_sum
317+
a = ArticleNested.where(author_id: '123', name: 'John')
318+
b = ArticleNested.where(author_id: '123', name: 'John')
319+
c = ArticleNested.where(author_id: '123')
320+
d = Article.where(author_id: '123', name: 'John')
321+
assert(a.hash == b.hash)
322+
assert_equal(false, a.hash == c.hash)
323+
assert_equal(false, a.hash == d.hash)
324+
end
325+
326+
def test_build_eql
327+
a = ArticleNested.where(author_id: '123', name: 'John')
328+
b = ArticleNested.where(author_id: '123', name: 'John')
329+
c = ArticleNested.where(author_id: '123')
330+
d = Article.where(author_id: '123', name: 'John')
331+
assert(a == b)
332+
assert_equal(false, a == c)
333+
assert_equal(false, a == d)
334+
end
315335
end

0 commit comments

Comments
 (0)