CloudSesame 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,6 @@ module CloudSesame
5
5
 
6
6
  def_delegators :client, :config, :caching_with
7
7
 
8
- attr_accessor :_caller
9
8
  attr_reader :searchable
10
9
 
11
10
  def self.definitions
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  module CloudSesame
2
4
  module Domain
3
5
  module ClientModule
@@ -11,10 +11,15 @@ module CloudSesame
11
11
 
12
12
  def compile
13
13
  if query && !query.empty?
14
- compiled = ["(#{ query })"]
15
- compiled << fuzziness.compile(query) if fuzziness
16
- compiled << sloppiness.compile(query) if sloppiness
17
- { query: compiled.compact.join('|') }
14
+ compiled = "(#{ query })"
15
+
16
+ [fuzziness, sloppiness].each do |parser|
17
+ if parser && (parsed = parser.compile(query))
18
+ compiled << "|" << parsed
19
+ end
20
+ end
21
+
22
+ { query: compiled }
18
23
  end
19
24
  end
20
25
 
@@ -49,19 +49,25 @@ module CloudSesame
49
49
  end
50
50
 
51
51
  describe 'executor getter' do
52
+ it 'should return an Caching::NoCache executor by default' do
53
+ expect(subject.executor).to be_kind_of(Caching::NoCache)
54
+ end
52
55
  it 'should default to Caching::NoCache' do
53
56
  expect(Caching::NoCache).to receive(:new).with(subject.searchable) do |_, &lazy_client|
54
- expect(lazy_client.call).to eq subject.client
55
- end.and_call_original
56
- expect(subject.executor).to be_kind_of Caching::NoCache
57
+ expect(lazy_client.call).to eq subject.aws_client
58
+ end
59
+ subject.executor
57
60
  end
58
61
  end
59
62
 
60
63
  describe 'executor setter' do
61
64
  it 'should accept a caching module' do
62
65
  expect(Caching::GoodCache).to receive(:new).with(subject.searchable) do |_, &lazy_client|
63
- expect(lazy_client.call).to eq subject.client
64
- end.and_call_original
66
+ expect(lazy_client.call).to eq subject.aws_client
67
+ end
68
+ subject.executor = Caching::GoodCache
69
+ end
70
+ it 'should return a Caching::GoodCache instance' do
65
71
  subject.executor = Caching::GoodCache
66
72
  expect(subject.executor).to be_kind_of Caching::GoodCache
67
73
  end
@@ -35,12 +35,6 @@ module CloudSesame
35
35
  subject.is_excluded
36
36
  end
37
37
  end
38
- context 'when child not exist' do
39
- it 'should call #is_excluded on it\'s child' do
40
- expect(subject.child).to_not receive(:is_excluded)
41
- subject.is_excluded
42
- end
43
- end
44
38
  end
45
39
 
46
40
  describe '#<<' do
@@ -4,56 +4,100 @@ module CloudSesame
4
4
  module Query
5
5
  module Node
6
6
  describe Query do
7
- let(:arguments) {{ }}
8
- let(:node) { Query.new(arguments) }
7
+ let(:context) {{ }}
8
+ let(:node) { Query.new(context) }
9
+ subject { Query.new(context) }
9
10
 
10
- describe '#initialize' do
11
- context 'when arguments passed in' do
12
- let(:arguments) {{ query: "" }}
13
- it 'should initalize an empty string if query is empty' do
14
- expect(node.query).to eq ""
15
- end
16
- it 'should accept query as args and initialize query' do
17
- arguments[:query] = "hello world"
18
- expect(node.query).to eq "hello world"
11
+ describe '#query' do
12
+ context 'when context include query on initialize' do
13
+ let(:query_string) { "hello world" }
14
+ let(:context) { { query: query_string }}
15
+ it 'should set query to context query' do
16
+ expect(subject.query).to eq query_string
19
17
  end
20
18
  end
21
- context 'when arguments not passed in' do
22
- it 'should initialize an empty terms' do
23
- expect(node.query).to eq nil
19
+ context 'when context does not include query on initialize' do
20
+ it 'should just return nil' do
21
+ expect(subject.query).to eq nil
24
22
  end
25
23
  end
26
24
  end
27
25
 
28
- describe '#query' do
29
- it 'should return the query string' do
30
- node.query = ["term1", "term2", "term3", "-term4"].join(' ')
31
- expect(node.query).to eq "term1 term2 term3 -term4"
32
- end
33
- end
34
-
35
26
  describe '#compile' do
36
- context 'when fuzziness is defined' do
37
- it 'should parse with fuzziness' do
38
- fuzziness = Fuzziness.new
39
- node = Query.new(fuzziness: fuzziness)
40
- node.query = ["term1", "someterm2", "verylongterm3", "-excluded_term4"].join(' ')
41
- expect(fuzziness).to receive(:compile).with(node.query).and_call_original
42
- expect(node.compile).to eq(query: "(term1 someterm2 verylongterm3 -excluded_term4)|(term1+someterm2~2+verylongterm3~2+-excluded_term4)")
27
+
28
+ shared_examples 'common query compile actions' do
29
+ context 'and query is nil' do
30
+ let(:query_string) { nil }
31
+ it 'should return nil' do
32
+ expect(subject.compile).to eq nil
33
+ end
34
+ end
35
+ context 'and query is empty' do
36
+ let(:query_string) { "" }
37
+ it 'should return nil' do
38
+ expect(subject.compile).to eq nil
39
+ end
40
+ end
41
+ context 'and query contains one word' do
42
+ let(:query_string) { "oneword" }
43
+ it 'should include the original string inside parenthesis' do
44
+ expect(subject.compile[:query]).to include("(#{ query_string })")
45
+ end
46
+ end
47
+ context 'and query contains multiple words' do
48
+ let(:query_string) { "one three fourty longword" }
49
+ it 'should include the original string inside parenthesis' do
50
+ expect(subject.compile[:query]).to include("(#{ query_string })")
51
+ end
43
52
  end
44
53
  end
45
- context 'when sloppiness is defined' do
46
- it 'should parse with sloppiness' do
47
- sloppiness = Sloppiness.new(4)
48
- node = Query.new(sloppiness: sloppiness)
49
- node.query = ["term1", "term2", "term3", "-term4"].join(' ')
50
- expect(sloppiness).to receive(:compile).with(node.query).and_call_original
51
- expect(node.compile).to eq(query: "(term1 term2 term3 -term4)|\"term1 term2 term3 -term4\"~4")
54
+
55
+ shared_examples 'with additional parser defined' do |parser_name|
56
+ context 'and query string is nil' do
57
+ let(:query_string) { nil }
58
+ it "should not trigger #{ parser_name }" do
59
+ expect(parser).to_not receive(:compile)
60
+ subject.compile
61
+ end
62
+ end
63
+ context 'and query string is empty' do
64
+ let(:query_string) { "" }
65
+ it "should not trigger #{ parser_name }" do
66
+ expect(parser).to_not receive(:compile)
67
+ subject.compile
68
+ end
69
+ end
70
+ context 'and query string exist and not empty' do
71
+ let(:query_string) { "not empty" }
72
+ it "should trigger #{ parser_name }" do
73
+ result = parser.compile(query_string)
74
+ expect(parser).to receive(:compile).with(query_string).and_call_original
75
+ expect(subject.compile[:query]).to include(result)
76
+ end
52
77
  end
53
78
  end
54
- it 'should return a serialized hash contains query string' do
55
- node.query = ["term1", "term2", "term3", "-term4"].join(' ')
56
- expect(node.compile).to eq({ query: "(term1 term2 term3 -term4)" })
79
+
80
+ context 'when both fuzziness and sloppiness are not defined' do
81
+ let(:context) {{ query: query_string }}
82
+ include_examples 'common query compile actions'
83
+ end
84
+ context 'when fuzziness is defined' do
85
+ let(:parser) { Fuzziness.new }
86
+ let(:context) {{
87
+ query: query_string,
88
+ fuzziness: parser
89
+ }}
90
+ include_examples 'common query compile actions'
91
+ include_examples 'with additional parser defined', "fuzziness"
92
+ end
93
+ context 'when sloppiness is defined' do
94
+ let(:parser) { Sloppiness.new(3) }
95
+ let(:context) {{
96
+ query: query_string,
97
+ sloppiness: parser
98
+ }}
99
+ include_examples 'common query compile actions'
100
+ include_examples 'with additional parser defined', "sloppiness"
57
101
  end
58
102
  end
59
103
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CloudSesame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu