daedal 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTEzNTlhZTlmYjZkY2U0ZGY3YzhhZmNiYjdjZjljOThmM2U2MGI4Mg==
4
+ NTNjNjRlYjhmYTA1MzVlNmM4OTRiNGEwM2Q0OTI5YzIwOGI3MzFhZQ==
5
5
  data.tar.gz: !binary |-
6
- NTRkNGMyYjc1ZTRmYzQyZTM0ZTUzMDg4N2Y2NzI2YWYzNzQ1YzljNA==
6
+ ZjViZDYxOWY4Mjg4ZTlmZDIxMmMxMWU0MmVlYzIyMDNhNjdlZGYwYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTk5MjRmMWYyMjcyZjEzYWIyM2M4MGViYTVkYTFhNDI5NjM5OWNiMzg3MmU3
10
- MTZhOTg3NzAxZWUyMTAyYTM2NzFkMWViMmY1NmU2MDE1NTdhZGM4Njg2MmVi
11
- NDQyOGRlNjdkMjdjYTk0ZjVmMzBkMzI0ZDRiN2UxNzU5YTUyZjg=
9
+ Y2M2MTRhNTk3ZmNkMmRlZjUwNjI3Zjg1NTc0Zjc0ZDY4ODVjOWNhMDUwN2Q0
10
+ MDYyYjRjYTI0MTNlOTIyZDRkZTQ2M2IwOTBkMDEyNzY5NWMwMGIyNjBlNTRj
11
+ ZTg5MjU0MDZiZmQ1ZjdmNGMxOThkZDkyNTNkZGFhOTRlNjMzYWM=
12
12
  data.tar.gz: !binary |-
13
- MzA5MzBiNmU5ZWY3YTQ2YTIwMzU4ZGNlZWU0NmQ1NzA1ZTZmOTc5OTllZDZh
14
- ZDI3MzBiNTdjNzY2YTQ1YWNkOTEyMmM0N2Q0Yzk4YTc5M2U5YWNhMzM5MjU5
15
- MzhkNjk0MWEyOTkxZDgzNGIzOThjYzI0ZWJkNjU3Y2Q3NDM5YWQ=
13
+ Y2E4MmFjYWQ1ZGI5MzMyMzcwYmQ2NTY5NGYzZTM5MDczODc3ZWExMDdjNjQ4
14
+ ZGEyZTlmODQxMWU0YTQ3NTFhYjJhZjMyYTkyZjNjNWYxZjYzZGI2NGI0NGQ5
15
+ ZWE1NWRkZDc4ZTliYWZiYWNiYjI2ODFhZDU0Mjc5NzdmYjQ3ODA=
@@ -0,0 +1,23 @@
1
+ module Daedal
2
+ module Filters
3
+ """Class for the nested filter"""
4
+ class NestedFilter < Filter
5
+
6
+ # required attributes
7
+ attribute :path, Daedal::Attributes::Field
8
+ attribute :filter, Daedal::Attributes::Filter
9
+
10
+ # non required attributes
11
+ attribute :cache, Boolean, required: false
12
+ attribute :name, Symbol, required: false
13
+
14
+ def to_hash
15
+ result = {nested: {path: path, filter: filter.to_hash}}
16
+ options = {_name: name, _cache: cache}.select { |k,v| !v.nil? }
17
+ result[:nested].merge! options
18
+
19
+ result
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Daedal
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Filters::NestedFilter do
4
+
5
+ subject do
6
+ Daedal::Filters::NestedFilter
7
+ end
8
+
9
+ let(:term_filter) do
10
+ Daedal::Filters::TermFilter.new field: 'foo', term: 'bar'
11
+ end
12
+
13
+ context 'with no path specified' do
14
+ it 'will raise an error' do
15
+ expect{subject.new(filter: term_filter)}.to raise_error(Virtus::CoercionError)
16
+ end
17
+ end
18
+
19
+ context 'with no filter specified' do
20
+ it 'will raise an error' do
21
+ expect{subject.new(path: 'foo')}.to raise_error(Virtus::CoercionError)
22
+ end
23
+ end
24
+
25
+ context 'with an invalid filter specified' do
26
+ it 'will raise an error' do
27
+ expect{subject.new(filter: :foo)}.to raise_error(Virtus::CoercionError)
28
+ end
29
+ end
30
+
31
+ context 'with a filter and a path specified' do
32
+ let(:filter) do
33
+ subject.new filter: term_filter, path: :foo
34
+ end
35
+ let(:hash_filter) do
36
+ {nested: {path: :foo, filter: term_filter.to_hash}}
37
+ end
38
+
39
+ it 'will create a nested filter with the appropriate fields' do
40
+ expect(filter.filter).to eq term_filter
41
+ expect(filter.path).to eq :foo
42
+ end
43
+
44
+ it 'will have the correct hash representation' do
45
+ expect(filter.to_hash).to eq hash_filter
46
+ end
47
+
48
+ it 'will have the correct json representation' do
49
+ expect(filter.to_json).to eq hash_filter.to_json
50
+ end
51
+ end
52
+
53
+ context 'with cache set to true' do
54
+ let(:filter) do
55
+ subject.new filter: term_filter, path: :foo, cache: true
56
+ end
57
+ it 'will set _cache to true' do
58
+ expect(filter.cache).to eq true
59
+ expect(filter.to_hash[:nested][:_cache]).to eq true
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daedal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Schuch
@@ -58,6 +58,7 @@ files:
58
58
  - lib/daedal/filters/bool_filter.rb
59
59
  - lib/daedal/filters/filter.rb
60
60
  - lib/daedal/filters/geo_distance_filter.rb
61
+ - lib/daedal/filters/nested_filter.rb
61
62
  - lib/daedal/filters/or_filter.rb
62
63
  - lib/daedal/filters/range_filter.rb
63
64
  - lib/daedal/filters/term_filter.rb
@@ -79,6 +80,7 @@ files:
79
80
  - spec/unit/daedal/filters/and_filter_spec.rb
80
81
  - spec/unit/daedal/filters/bool_filter_spec.rb
81
82
  - spec/unit/daedal/filters/geo_distance_filter_spec.rb
83
+ - spec/unit/daedal/filters/nested_filter_spec.rb
82
84
  - spec/unit/daedal/filters/or_filter_spec.rb
83
85
  - spec/unit/daedal/filters/range_filter_spec.rb
84
86
  - spec/unit/daedal/filters/term_filter_spec.rb