CloudSesame 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +12 -0
  3. data/.gitignore +1 -1
  4. data/Gemfile.lock +13 -13
  5. data/Guardfile +1 -0
  6. data/cloud_sesame.gemspec +2 -2
  7. data/coverage/.last_run.json +1 -1
  8. data/coverage/.resultset.json +679 -591
  9. data/lib/cloud_sesame/config/credential.rb +6 -6
  10. data/lib/cloud_sesame/context.rb +0 -5
  11. data/lib/cloud_sesame/domain/base.rb +147 -128
  12. data/lib/cloud_sesame/domain/client.rb +25 -25
  13. data/lib/cloud_sesame/domain/client_module/caching/base.rb +19 -23
  14. data/lib/cloud_sesame/domain/client_module/caching/no_cache.rb +11 -11
  15. data/lib/cloud_sesame/domain/client_module/caching/rails_cache.rb +32 -28
  16. data/lib/cloud_sesame/domain/client_module/caching.rb +19 -28
  17. data/lib/cloud_sesame/domain/client_module/retry.rb +6 -6
  18. data/lib/cloud_sesame/domain/config.rb +6 -6
  19. data/lib/cloud_sesame/query/ast/abstract/multi_expression_operator.rb +37 -0
  20. data/lib/cloud_sesame/query/ast/abstract/operator.rb +27 -0
  21. data/lib/cloud_sesame/query/ast/abstract/single_expression_operator.rb +39 -0
  22. data/lib/cloud_sesame/query/ast/abstract/value.rb +88 -0
  23. data/lib/cloud_sesame/query/ast/and.rb +1 -1
  24. data/lib/cloud_sesame/query/ast/date_value.rb +19 -3
  25. data/lib/cloud_sesame/query/ast/literal.rb +13 -28
  26. data/lib/cloud_sesame/query/ast/near.rb +4 -4
  27. data/lib/cloud_sesame/query/ast/not.rb +6 -7
  28. data/lib/cloud_sesame/query/ast/numeric_value.rb +20 -12
  29. data/lib/cloud_sesame/query/ast/or.rb +1 -1
  30. data/lib/cloud_sesame/query/ast/phrase.rb +1 -1
  31. data/lib/cloud_sesame/query/ast/prefix.rb +1 -1
  32. data/lib/cloud_sesame/query/ast/range_value.rb +40 -39
  33. data/lib/cloud_sesame/query/ast/root.rb +2 -6
  34. data/lib/cloud_sesame/query/ast/string_value.rb +26 -0
  35. data/lib/cloud_sesame/query/ast/term.rb +1 -1
  36. data/lib/cloud_sesame/query/ast/value.rb +25 -54
  37. data/lib/cloud_sesame/query/builder.rb +83 -54
  38. data/lib/cloud_sesame/query/domain/block.rb +3 -1
  39. data/lib/cloud_sesame/query/dsl/applied_filter_query.rb +14 -23
  40. data/lib/cloud_sesame/query/dsl/field_accessors.rb +25 -22
  41. data/lib/cloud_sesame/query/dsl/field_array_methods.rb +1 -1
  42. data/lib/cloud_sesame/query/dsl/inspect_method.rb +31 -0
  43. data/lib/cloud_sesame/query/dsl/sort_methods.rb +5 -4
  44. data/lib/cloud_sesame/query/node/abstract.rb +1 -2
  45. data/lib/cloud_sesame/query/node/facet.rb +1 -5
  46. data/lib/cloud_sesame/query/node/filter_query.rb +15 -2
  47. data/lib/cloud_sesame/query/node/fuzziness.rb +4 -3
  48. data/lib/cloud_sesame/query/node/page.rb +2 -2
  49. data/lib/cloud_sesame/query/node/query.rb +4 -17
  50. data/lib/cloud_sesame/query/node/query_options.rb +6 -16
  51. data/lib/cloud_sesame/query/node/query_options_field.rb +3 -1
  52. data/lib/cloud_sesame/query/node/query_parser.rb +8 -10
  53. data/lib/cloud_sesame/query/node/request.rb +57 -31
  54. data/lib/cloud_sesame/query/node/sort.rb +25 -11
  55. data/lib/cloud_sesame.rb +15 -12
  56. data/lib/{abstract_object.rb → services/abstract_object.rb} +0 -0
  57. data/lib/services/class_specific.rb +44 -0
  58. data/lib/services/lazy_object.rb +19 -0
  59. data/spec/cloud_sesame/domain/base_spec.rb +26 -11
  60. data/spec/cloud_sesame/domain/client_module/caching/base_spec.rb +2 -1
  61. data/spec/cloud_sesame/domain/client_module/caching/no_cache_spec.rb +2 -3
  62. data/spec/cloud_sesame/domain/client_module/caching/rails_cache_spec.rb +6 -6
  63. data/spec/cloud_sesame/domain/client_module/caching_spec.rb +33 -32
  64. data/spec/cloud_sesame/query/ast/abstract/multi_expression_operator_spec.rb +67 -0
  65. data/spec/cloud_sesame/query/ast/abstract/operator_spec.rb +29 -0
  66. data/spec/cloud_sesame/query/ast/abstract/single_expression_operator_spec.rb +70 -0
  67. data/spec/cloud_sesame/query/ast/abstract/value_spec.rb +118 -0
  68. data/spec/cloud_sesame/query/ast/and_spec.rb +1 -1
  69. data/spec/cloud_sesame/query/ast/or_spec.rb +1 -1
  70. data/spec/cloud_sesame/query/ast/range_value_spec.rb +5 -11
  71. data/spec/cloud_sesame/query/builder_spec.rb +10 -4
  72. data/spec/cloud_sesame/query/domain/block_spec.rb +15 -8
  73. data/spec/cloud_sesame/query/dsl/{block_methods_spec.rb → block_styled_operators_spec.rb} +0 -0
  74. data/spec/cloud_sesame/query/dsl/field_accessors_spec.rb +88 -50
  75. data/spec/cloud_sesame/query/dsl/field_array_methods_spec.rb +0 -2
  76. data/spec/cloud_sesame/query/node/facet_spec.rb +1 -15
  77. data/spec/cloud_sesame/query/node/filter_query_spec.rb +16 -2
  78. data/spec/cloud_sesame/query/node/page_spec.rb +3 -2
  79. data/spec/cloud_sesame/query/node/query_options_spec.rb +1 -1
  80. data/spec/cloud_sesame/query/node/query_parser_spec.rb +1 -7
  81. data/spec/cloud_sesame/query/node/query_spec.rb +10 -28
  82. data/spec/cloud_sesame/query/node/sort_spec.rb +19 -28
  83. data/spec/cloud_sesame_spec.rb +2 -156
  84. data/spec/helpers/benchmark_helper.rb +12 -0
  85. data/spec/integration/filter_query_spec.rb +0 -0
  86. data/spec/profiling_spec.rb +155 -0
  87. data/spec/{abstract_object_spec.rb → services/abstract_object_spec.rb} +0 -0
  88. data/spec/services/class_specific_spec.rb +135 -0
  89. data/spec/spec_helper.rb +3 -0
  90. metadata +32 -22
  91. data/lib/active_support/core_ext/object/deep_dup.rb +0 -53
  92. data/lib/active_support/core_ext/object/duplicable.rb +0 -98
  93. data/lib/cloud_sesame/query/ast/multi_expression_operator.rb +0 -35
  94. data/lib/cloud_sesame/query/ast/operator.rb +0 -25
  95. data/lib/cloud_sesame/query/ast/single_expression_operator.rb +0 -35
  96. data/lib/cloud_sesame/query/scope.rb +0 -21
  97. data/profiler.rb +0 -91
  98. data/spec/cloud_sesame/query/ast/multi_expression_operator_spec.rb +0 -76
  99. data/spec/cloud_sesame/query/ast/operator_spec.rb +0 -29
  100. data/spec/cloud_sesame/query/ast/single_expression_operator_spec.rb +0 -78
  101. data/spec/context_spec.rb +0 -17
@@ -0,0 +1,70 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ module Abstract
5
+ describe SingleExpressionOperator do
6
+
7
+ let(:context) { {} }
8
+ let(:options) { {} }
9
+ let(:block) { Proc.new {} }
10
+
11
+ subject { SingleExpressionOperator.new(context, options, &block) }
12
+
13
+ it 'should be a type of operator' do
14
+ expect(MultiExpressionOperator.ancestors).to include(Operator)
15
+ end
16
+
17
+ describe '#child' do
18
+ it 'should be nil by default' do
19
+ expect(subject.child).to be_nil
20
+ end
21
+ end
22
+
23
+ describe '#is_for' do
24
+ it 'should forward the field and field options to it\'s child' do
25
+ subject.child = OpenStruct.new is_for: ""
26
+ expect(subject.child).to receive(:is_for).with(:test, :options)
27
+ subject.is_for :test, :options
28
+ end
29
+ end
30
+
31
+ describe '#<<' do
32
+ it 'should set the object as child' do
33
+ child = OpenStruct.new()
34
+ expect { subject << child }.to change{ subject.child }.from(nil).to(child)
35
+ end
36
+ end
37
+
38
+ describe '#compile' do
39
+ before {
40
+ subject.child = OpenStruct.new compile: ""
41
+ allow(subject.child).to receive(:compile).and_return(" ")
42
+ }
43
+ it 'should compile it\'s child and detailed set to false' do
44
+ expect(subject.child).to receive(:compile).with(SingleExpressionOperator::DETAILED)
45
+ subject.compile
46
+ end
47
+ context 'when theres boost options' do
48
+ it 'should include boost value in the compiled value' do
49
+ subject.options[:boost] = 1
50
+ expect(subject.compile).to include("boost=1")
51
+ end
52
+ end
53
+ context 'when theres no boost options' do
54
+ it 'should not include boost value in the compiled value' do
55
+ expect(subject.compile).to_not include("boost=")
56
+ end
57
+ end
58
+ context 'when theres a symbol' do
59
+ before { SingleExpressionOperator::SYMBOL = "test_symbol"}
60
+ it 'should include the symbol in the compiled value' do
61
+ expect(subject.compile).to include "(test_symbol"
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,118 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ module Abstract
5
+ describe Value do
6
+
7
+ subject { Value.new(raw_value) }
8
+
9
+ describe 'initialize' do
10
+ context 'given the value is not nil' do
11
+ let(:raw_value) { 1 }
12
+ it 'should accept and store a value' do
13
+ expect(subject.value).to eq raw_value
14
+ end
15
+ it 'should default changed to true' do
16
+ expect(subject.changed).to be_truthy
17
+ end
18
+ end
19
+ context 'given the value is nil' do
20
+ let(:raw_value) { nil }
21
+ it 'should accept and store a value' do
22
+ expect(subject.value).to eq raw_value
23
+ end
24
+ it 'should default changed to false' do
25
+ expect(subject.changed).to be_falsey
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#value setter' do
31
+ context 'given a different value' do
32
+ let(:raw_value) { 2 }
33
+ let(:new_value) { 1 }
34
+ before { subject.compile }
35
+ it 'should set changed to true' do
36
+ expect{ subject.value = new_value }.to change{ subject.changed }.from(be_falsey).to(be_truthy)
37
+ end
38
+ it 'should set the value' do
39
+ expect{ subject.value = new_value }.to change{ subject.value }.from(raw_value).to(new_value)
40
+ end
41
+ end
42
+ context 'given the same value' do
43
+ let(:raw_value) { 2 }
44
+ let(:new_value) { 2 }
45
+ before { subject.compile }
46
+ it 'should not set changed to true' do
47
+ expect{ subject.value = new_value }.to_not change{ subject.changed }.from(be_falsey)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#compile' do
53
+ let(:raw_value) { 2 }
54
+ context 'the value is changed' do
55
+ it 'should compile the value' do
56
+ expect(subject).to receive(:recompile).with(raw_value)
57
+ subject.compile
58
+ end
59
+ it 'should update the compiled value' do
60
+ expect{ subject.compile }.to change{ subject.compiled }.to(raw_value)
61
+ end
62
+ it 'should toggle the changed status to false' do
63
+ expect{ subject.compile }.to change{ subject.changed }.from(true).to(false)
64
+ end
65
+ end
66
+ context 'the value is the same' do
67
+ before { subject.compile }
68
+ it 'should not recompile' do
69
+ expect(subject).to_not receive(:recompile)
70
+ subject.compile
71
+ end
72
+ it 'should not change the compiled value' do
73
+ expect{ subject.compile }.to_not change{ subject.compiled }
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '#to_s' do
79
+ let(:raw_value) { 2 }
80
+ it 'should return the value in string format' do
81
+ expect(subject.to_s).to eq raw_value.to_s
82
+ end
83
+ end
84
+
85
+ describe '#==' do
86
+ context 'given a Value object' do
87
+ let(:raw_value) { 1 }
88
+ let(:value) { Value.new(raw_value) }
89
+ it 'should compare values based on their compiled value' do
90
+ expect(value).to receive(:compile).and_call_original
91
+ subject == value
92
+ end
93
+ it 'should return true if compiled values are the same' do
94
+ expect(subject == value).to be_truthy
95
+ end
96
+ end
97
+ context 'given a raw value' do
98
+ let(:raw_value) { double(:string) }
99
+ let(:value) { 1 }
100
+ it 'should compare the value with the raw value' do
101
+ expect(subject.value).to receive(:==).and_return(true)
102
+ subject == value
103
+ end
104
+ it 'should compare the value with the compiled value if raw value is different' do
105
+ response = double(:compiled_value)
106
+ expect(subject).to receive(:compile).and_return(response)
107
+ expect(response).to receive(:==)
108
+ subject == value
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -4,7 +4,7 @@ module CloudSesame
4
4
  describe And do
5
5
 
6
6
  it 'should be a type of operator' do
7
- expect(And.ancestors).to include(MultiExpressionOperator)
7
+ expect(And.ancestors).to include(Abstract::MultiExpressionOperator)
8
8
  end
9
9
 
10
10
  it 'should have symbol :and' do
@@ -4,7 +4,7 @@ module CloudSesame
4
4
  describe Or do
5
5
 
6
6
  it 'should be a type of operator' do
7
- expect(Or.ancestors).to include(MultiExpressionOperator)
7
+ expect(Or.ancestors).to include(Abstract::MultiExpressionOperator)
8
8
  end
9
9
 
10
10
  it 'should have symbol :or' do
@@ -6,19 +6,13 @@ module CloudSesame
6
6
  describe 'initialize' do
7
7
  shared_examples 'initialize with initial value' do
8
8
  it 'should be an array' do
9
- expect(subject.data).to be_kind_of(Array)
9
+ expect(subject.value).to be_kind_of(Array)
10
10
  end
11
11
  it 'should not be empty' do
12
- expect(subject.data).to_not be_empty
12
+ expect(subject.value).to_not be_empty
13
13
  end
14
14
  it 'should capture the range information' do
15
- expect(subject.data).to eq data
16
- end
17
- context 'when begin and end value exists' do
18
- it 'should convert begin and end value to Value' do
19
- expect(subject.data[1]).to be_kind_of(Value) if data[1]
20
- expect(subject.data[2]).to be_kind_of(Value) if data[2]
21
- end
15
+ expect(subject.value).to eq data
22
16
  end
23
17
  end
24
18
 
@@ -37,7 +31,7 @@ module CloudSesame
37
31
  context 'when given a range value in string format' do
38
32
  {
39
33
  "[0, nil}" => ['[', 0, nil, '}'],
40
- "{, 100]" => ['{', nil, 100, ']'],
34
+ "{, 100]" => ['{', '', '100', ']'],
41
35
  }.each do |before_value, after_value|
42
36
  subject { RangeValue.new(before_value) }
43
37
  let(:data) { after_value }
@@ -49,7 +43,7 @@ module CloudSesame
49
43
  subject { RangeValue.new }
50
44
  let(:data) { [] }
51
45
  it 'should set the data to the default value' do
52
- expect(subject.data).to eq ['{', nil, nil, '}']
46
+ expect(subject.value).to eq ['{', nil, nil, '}']
53
47
  end
54
48
  end
55
49
  end
@@ -1,11 +1,17 @@
1
- require 'spec_helper'
1
+ require_relative 'dsl/field_accessors_spec'
2
2
 
3
3
  module CloudSesame
4
4
  module Query
5
5
  describe Builder do
6
- let(:client) { {} }
7
- let(:searchable_class) { "Test" }
8
- subject { Builder.new(client, searchable_class) }
6
+
7
+ it_behaves_like 'FieldAccessors' do
8
+ subject { Builder.new({}, "Searchable") }
9
+ before {
10
+ Builder.send(:include, DSL::FieldAccessors)
11
+ Domain::Block.send(:include, DSL::FieldAccessors)
12
+ allow(_scope).to receive(:context).and_return(context)
13
+ }
14
+ end
9
15
 
10
16
  end
11
17
  end
@@ -1,8 +1,23 @@
1
+ require_relative '../dsl/field_accessors_spec'
2
+
1
3
  module CloudSesame
2
4
  module Query
3
5
  module Domain
4
6
  describe Block do
5
7
 
8
+ # Module Specs
9
+ # =======================================
10
+ it_behaves_like 'FieldAccessors' do
11
+ let(:scope) { AST::Root.new(context, {}) }
12
+ subject { Block.new(self, context) }
13
+ before do
14
+ Block.send(:include, DSL::FieldAccessors)
15
+ subject.instance_variable_set(:@_scopes, [scope])
16
+ end
17
+ end
18
+
19
+ # Class Specs
20
+ # =======================================
6
21
  class Caller
7
22
 
8
23
  def initialize
@@ -18,7 +33,6 @@ module CloudSesame
18
33
 
19
34
  [
20
35
  DSL::BlockStyledOperators,
21
- DSL::FieldAccessors,
22
36
  DSL::ScopeAccessors,
23
37
  DSL::Operators,
24
38
  DSL::BindCaller
@@ -63,13 +77,6 @@ module CloudSesame
63
77
  end
64
78
  end
65
79
 
66
- # def _eval(node, _scope, _return = _scope, &block)
67
- # _scopes.push node
68
- # instance_eval &block
69
- # _scope << node
70
- # _scopes.pop
71
- # _scope.is_a?(AST::Root) ? _return : node
72
- # end
73
80
  describe '#_eval' do
74
81
 
75
82
  let(:node) { AST::And.new({}, {}) }
@@ -1,52 +1,90 @@
1
- require 'spec_helper'
2
-
3
1
  module CloudSesame
4
- module Query
5
- module DSL
6
- describe FieldAccessors do
7
-
8
- # Setup Test Class
9
- class Product
10
- include CloudSesame
11
- define_cloudsearch {
12
- field :name
13
- field :tags
14
- }
15
- end
16
-
17
- subject(:cloudsearch) { Product.cloudsearch.builder }
18
-
19
- context 'when field is registered' do
20
- it 'should create a literal node' do
21
- expect(AST::Literal).to receive(:new).with(:name, "my name", {})
22
- subject.name "my name"
23
- end
24
- it 'should belong to the dsl context' do
25
- expect{ subject.name "name" }.to change{ subject.request.filter_query.root.children.size }.by(1)
26
- end
27
- it 'should return the dsl scope if called from the root' do
28
- expect(subject.tags "men").to eq subject
29
- end
30
- it 'should return the field array if called from inside a block' do
31
- array = nil
32
- subject.and { array = tags("men") }
33
- expect(array).to be_kind_of(AST::FieldArray)
34
- expect(array).to include(AST::Literal)
35
- end
36
- it 'shoudl set the field array#field' do
37
- array = nil
38
- subject.and { array = tags("men") }
39
- expect(array.field).to eq :tags
40
- end
41
- end
42
-
43
- context 'when field is not registered' do
44
- it 'should raise an error' do
45
- expect{ subject.description("description") }.to raise_error NoMethodError
46
- end
47
- end
48
-
49
- end
50
- end
51
- end
2
+ module Query
3
+ module DSL
4
+ shared_examples_for 'FieldAccessors' do
5
+ let(:field_name) { :test_field_name }
6
+ let(:_scope) { subject.send(:_scope) }
7
+ let(:context) { { fields: { field_name => {} } } }
8
+ let(:_return) { subject.send(:_return) }
9
+ let(:options) { context[:fields][field_name] }
10
+
11
+ describe '#literal' do
12
+
13
+ it 'should tell the scope children what field is it for' do
14
+ expect(subject.send(:_scope).children).to receive(:field=).with(field_name)
15
+ subject.literal(field_name)
16
+ end
17
+
18
+ it 'should tell the scope children what to return' do
19
+ allow(subject).to receive(:_return).and_return(_return)
20
+ expect(subject.send(:_scope).children).to receive(:_return=).with(_return)
21
+ subject.literal(field_name)
22
+ end
23
+
24
+ it 'should insert all the values into the children' do
25
+ values = [1, 2, 3, 4, 5]
26
+ expect(subject.send(:_scope).children).to receive(:insert).with(values)
27
+ subject.literal(field_name, *values)
28
+ end
29
+
30
+ context 'given a block' do
31
+ let(:block) { Proc.new { "1" } }
32
+ let(:caller) { self }
33
+
34
+ it 'should evalute the block with Domain::Literal' do
35
+ domain = Domain::Literal.new(field_name, options, caller)
36
+ expect(Domain::Literal).to receive(:new).with(field_name, options, self).and_return(domain)
37
+ expect(domain).to receive(:_eval) do |&received_block|
38
+ received_block == block
39
+ end
40
+ subject.literal(field_name, &block)
41
+ end
42
+
43
+ it 'should add the evaluated value to values' do
44
+ expect(subject.send(:_scope).children).to receive(:insert).with(include(AST::Literal))
45
+ subject.literal(field_name, &block)
46
+
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ context 'when field is registered' do
53
+ let(:value) { "value" }
54
+ before { DSL::FieldAccessors.__define_accessor__(field_name) }
55
+ it 'should create a literal node' do
56
+ expect(AST::Literal).to receive(:new).with(field_name, value, options)
57
+ subject.send(field_name, value)
58
+ end
59
+ it 'should belong to the scope object' do
60
+ expect{ subject.send(field_name, value) }.to change{ subject.send(:_scope).children.size }.by(1)
61
+ end
62
+ it 'should return the dsl scope if called from the root' do
63
+ if subject.send(:_scope).is_a?(Builder)
64
+ expect(subject.send(field_name, value)).to eq subject
65
+ end
66
+ end
67
+
68
+ it 'should return the field array if called from inside a block' do
69
+ array = nil
70
+ subject.and { array = send(field_name, value) }
71
+ expect(array).to be_kind_of(AST::FieldArray)
72
+ expect(array).to include(AST::Literal)
73
+ end
74
+ it 'should set the field array#field' do
75
+ array = nil
76
+ subject.and { array = send(field_name, value) }
77
+ expect(array.field).to eq field_name
78
+ end
79
+ end
80
+
81
+ context 'when field is not registered' do
82
+ it 'should raise an error' do
83
+ expect{ subject.unregistered("description") }.to raise_error NoMethodError
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
52
90
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  module CloudSesame
4
2
  module Query
5
3
  module DSL
@@ -5,26 +5,12 @@ module CloudSesame
5
5
  module Node
6
6
  describe Facet do
7
7
  let(:facet) { Facet.new(facet_options) }
8
- describe '#facet' do
9
- context 'when default facet is defined' do
10
- let(:facet_options) { { price: { size: 100 } } }
11
- it 'should return the default facet options' do
12
- expect(facet_options).to include(facet_options)
13
- end
14
- end
15
- context 'when default facet is not defined' do
16
- let(:facet_options) { {} }
17
- it 'should return an empty facet options' do
18
- expect(facet_options).to include(facet_options)
19
- end
20
- end
21
- end
22
8
 
23
9
  describe '#compile' do
24
10
  context 'when facet is not empty' do
25
11
  let(:facet_options) { { price: { size: 100 } } }
26
12
  it 'should return stringified JSON facet' do
27
- expect(facet.compile).to include facet: JSON.dump(facet_options)
13
+ expect(facet.compile).to eq JSON.dump(facet_options)
28
14
  end
29
15
  end
30
16
  context 'when facet is empty' do
@@ -11,8 +11,22 @@ module CloudSesame
11
11
  expect(subject.root).to receive(:compile)
12
12
  subject.compile
13
13
  end
14
- it 'should return an hash with filter query' do
15
- expect(subject.compile).to include(filter_query: subject.root.compile )
14
+ context 'when compiled value is nil' do
15
+ it 'should return nil' do
16
+ expect(subject.compile).to be_nil
17
+ end
18
+ end
19
+ context 'when compiled value is empty' do
20
+ it 'should return nil' do
21
+ expect(subject.compile).to be_nil
22
+ end
23
+ end
24
+ context 'when compiled value is not empty' do
25
+ let(:value) { "compiled value" }
26
+ it 'should return the compiled value' do
27
+ allow(subject.root).to receive(:compile).and_return(value)
28
+ expect(subject.compile).to eq value
29
+ end
16
30
  end
17
31
  end
18
32
 
@@ -10,7 +10,7 @@ module CloudSesame
10
10
  context 'when arguments passed in' do
11
11
  let(:arguments) { { page: 2, size: 13 } }
12
12
  it 'should initialize the page with the page argument' do
13
- expect(node.page).to eq 2
13
+ expect(node.page).to eq 1
14
14
  end
15
15
  it 'should initialize the size with the size argument' do
16
16
  expect(node.size).to eq 13
@@ -36,7 +36,8 @@ module CloudSesame
36
36
  page: 3, size: 13, expect_start: 26
37
37
  }].each do |arguments|
38
38
  it 'should calculate and return the starting point' do
39
- node = Page.new arguments
39
+ node = Page.new(size: arguments[:size])
40
+ node.page = arguments[:page]
40
41
  expect(node.start).to eq arguments[:expect_start]
41
42
  end
42
43
  end
@@ -45,7 +45,7 @@ module CloudSesame
45
45
  let(:context) { {fields: { description: { weight: 2 }, name: {} } } }
46
46
  it 'should return a hash with query_options and fields as JSON' do
47
47
  expected_result = { fields: ['description^2', 'name'] }
48
- expect(query_options.compile).to include(query_options: JSON.dump(expected_result))
48
+ expect(query_options.compile).to eq JSON.dump(expected_result)
49
49
  end
50
50
  end
51
51
  end
@@ -17,17 +17,11 @@ module CloudSesame
17
17
  it 'should default to simple if not passed in from context' do
18
18
  expect(subject.type).to eq('simple')
19
19
  end
20
- context 'when default context passed in' do
21
- let(:context) { {query_parser: 'structured'} }
22
- it 'should default to the context value' do
23
- expect(subject.type).to eq('structured')
24
- end
25
- end
26
20
  end
27
21
 
28
22
  describe '#compile' do
29
23
  it 'should return a hash with query_parser type' do
30
- expect(subject.compile).to eq({query_parser: 'simple'})
24
+ expect(subject.compile).to eq 'simple'
31
25
  end
32
26
  end
33
27
 
@@ -5,27 +5,12 @@ module CloudSesame
5
5
  module Node
6
6
  describe Query do
7
7
  let(:context) {{ }}
8
- let(:node) { Query.new(context) }
9
8
  subject { Query.new(context) }
10
9
 
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
17
- end
18
- end
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
22
- end
23
- end
24
- end
25
-
26
10
  describe '#compile' do
27
11
 
28
12
  shared_examples 'common query compile actions' do
13
+ before { subject.query = query_string }
29
14
  context 'and query is nil' do
30
15
  let(:query_string) { nil }
31
16
  it 'should return nil' do
@@ -41,18 +26,20 @@ module CloudSesame
41
26
  context 'and query contains one word' do
42
27
  let(:query_string) { "oneword" }
43
28
  it 'should include the original string inside parenthesis' do
44
- expect(subject.compile[:query]).to include("(#{ query_string })")
29
+ expect(subject.compile).to include("(#{ query_string })")
45
30
  end
46
31
  end
47
32
  context 'and query contains multiple words' do
48
33
  let(:query_string) { "one three fourty longword" }
49
34
  it 'should include the original string inside parenthesis' do
50
- expect(subject.compile[:query]).to include("(#{ query_string })")
35
+ expect(subject.compile).to include("(#{ query_string })")
51
36
  end
52
37
  end
53
38
  end
54
39
 
55
40
  shared_examples 'with additional parser defined' do |parser_name|
41
+ before { subject.query = query_string }
42
+
56
43
  context 'and query string is nil' do
57
44
  let(:query_string) { nil }
58
45
  it "should not trigger #{ parser_name }" do
@@ -72,30 +59,25 @@ module CloudSesame
72
59
  it "should trigger #{ parser_name }" do
73
60
  result = parser.compile(query_string)
74
61
  expect(parser).to receive(:compile).with(query_string).and_call_original
75
- expect(subject.compile[:query]).to include(result)
62
+ expect(subject.compile).to include(result)
76
63
  end
77
64
  end
78
65
  end
79
66
 
80
67
  context 'when both fuzziness and sloppiness are not defined' do
81
- let(:context) {{ query: query_string }}
68
+ let(:context) {{ }}
69
+
82
70
  include_examples 'common query compile actions'
83
71
  end
84
72
  context 'when fuzziness is defined' do
85
73
  let(:parser) { Fuzziness.new }
86
- let(:context) {{
87
- query: query_string,
88
- fuzziness: parser
89
- }}
74
+ let(:context) {{ fuzziness: parser }}
90
75
  include_examples 'common query compile actions'
91
76
  include_examples 'with additional parser defined', "fuzziness"
92
77
  end
93
78
  context 'when sloppiness is defined' do
94
79
  let(:parser) { Sloppiness.new(3) }
95
- let(:context) {{
96
- query: query_string,
97
- sloppiness: parser
98
- }}
80
+ let(:context) {{ sloppiness: parser }}
99
81
  include_examples 'common query compile actions'
100
82
  include_examples 'with additional parser defined', "sloppiness"
101
83
  end