Skip to content

Commit 483f846

Browse files
stephenpraterkarmi
authored andcommitted
[DSL] Added correct implementation of Sort#empty?
Closes #317
1 parent 062de55 commit 483f846

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: lib/elasticsearch/dsl/search/sort.rb

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def to_hash
4444
@hash = @value.flatten
4545
@hash
4646
end
47+
48+
def empty?
49+
@value.empty? && @args.empty?
50+
end
4751
end
4852
end
4953
end

Diff for: test/unit/search_sort_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ class SearchSortTest < ::Test::Unit::TestCase
2222
assert_equal( [ { foo: { order: 'desc', mode: 'avg' } } ], subject.to_hash )
2323
end
2424

25+
context "when the search is empty" do
26+
should "respond with true to empty?" do
27+
subject = Elasticsearch::DSL::Search::Sort.new
28+
assert_equal subject.empty?, true
29+
end
30+
end
31+
32+
context "when search is not empty" do
33+
should "respond with false to empty?" do
34+
subject = Elasticsearch::DSL::Search::Sort.new foo: { order: 'desc' }
35+
assert_equal subject.empty?, false
36+
end
37+
end
38+
39+
2540
should "add fields with the DSL method" do
2641
subject = Elasticsearch::DSL::Search::Sort.new do
2742
by :foo

0 commit comments

Comments
 (0)