chewy 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -4
  3. data/CHANGELOG.md +16 -0
  4. data/Gemfile +3 -1
  5. data/README.md +2 -10
  6. data/chewy.gemspec +0 -1
  7. data/gemfiles/Gemfile.rails-3.2.active_record +6 -0
  8. data/gemfiles/Gemfile.rails-3.2.active_record.kaminari +7 -0
  9. data/gemfiles/Gemfile.rails-3.2.active_record.will_paginate +7 -0
  10. data/gemfiles/Gemfile.rails-4.0.active_record +6 -0
  11. data/gemfiles/Gemfile.rails-4.0.active_record.kaminari +7 -0
  12. data/gemfiles/Gemfile.rails-4.0.active_record.will_paginate +7 -0
  13. data/gemfiles/Gemfile.rails-4.0.mongoid +6 -0
  14. data/gemfiles/Gemfile.rails-4.0.mongoid.kaminari +7 -0
  15. data/gemfiles/Gemfile.rails-4.0.mongoid.will_paginate +7 -0
  16. data/gemfiles/Gemfile.rails-4.1.active_record +6 -0
  17. data/gemfiles/Gemfile.rails-4.1.active_record.kaminari +7 -0
  18. data/gemfiles/Gemfile.rails-4.1.active_record.will_paginate +7 -0
  19. data/gemfiles/Gemfile.rails-4.1.mongoid +6 -0
  20. data/gemfiles/Gemfile.rails-4.1.mongoid.kaminari +7 -0
  21. data/gemfiles/Gemfile.rails-4.1.mongoid.will_paginate +7 -0
  22. data/gemfiles/Gemfile.rails-4.2.active_record +6 -0
  23. data/gemfiles/Gemfile.rails-4.2.active_record.kaminari +7 -0
  24. data/gemfiles/Gemfile.rails-4.2.active_record.will_paginate +7 -0
  25. data/gemfiles/Gemfile.rails-4.2.mongoid +6 -0
  26. data/gemfiles/Gemfile.rails-4.2.mongoid.kaminari +7 -0
  27. data/gemfiles/Gemfile.rails-4.2.mongoid.will_paginate +7 -0
  28. data/lib/chewy.rb +33 -5
  29. data/lib/chewy/config.rb +1 -0
  30. data/lib/chewy/index/search.rb +6 -3
  31. data/lib/chewy/query.rb +74 -1
  32. data/lib/chewy/query/compose.rb +4 -4
  33. data/lib/chewy/query/pagination.rb +5 -4
  34. data/lib/chewy/query/pagination/kaminari.rb +1 -1
  35. data/lib/chewy/query/pagination/will_paginate.rb +27 -0
  36. data/lib/chewy/type.rb +1 -0
  37. data/lib/chewy/type/adapter/active_record.rb +2 -2
  38. data/lib/chewy/type/adapter/mongoid.rb +147 -0
  39. data/lib/chewy/type/adapter/object.rb +1 -1
  40. data/lib/chewy/type/import.rb +1 -0
  41. data/lib/chewy/type/observe.rb +34 -6
  42. data/lib/chewy/version.rb +1 -1
  43. data/spec/chewy/config_spec.rb +17 -17
  44. data/spec/chewy/fields/base_spec.rb +62 -62
  45. data/spec/chewy/fields/root_spec.rb +5 -5
  46. data/spec/chewy/index/actions_spec.rb +127 -127
  47. data/spec/chewy/index/aliases_spec.rb +9 -9
  48. data/spec/chewy/index/search_spec.rb +4 -4
  49. data/spec/chewy/index/settings_spec.rb +33 -33
  50. data/spec/chewy/index_spec.rb +49 -49
  51. data/spec/chewy/query/criteria_spec.rb +173 -161
  52. data/spec/chewy/query/filters_spec.rb +76 -76
  53. data/spec/chewy/query/loading_spec.rb +54 -23
  54. data/spec/chewy/query/nodes/and_spec.rb +4 -4
  55. data/spec/chewy/query/nodes/bool_spec.rb +8 -8
  56. data/spec/chewy/query/nodes/equal_spec.rb +19 -19
  57. data/spec/chewy/query/nodes/exists_spec.rb +6 -6
  58. data/spec/chewy/query/nodes/has_child_spec.rb +25 -25
  59. data/spec/chewy/query/nodes/has_parent_spec.rb +25 -25
  60. data/spec/chewy/query/nodes/match_all_spec.rb +1 -1
  61. data/spec/chewy/query/nodes/missing_spec.rb +4 -4
  62. data/spec/chewy/query/nodes/not_spec.rb +4 -4
  63. data/spec/chewy/query/nodes/or_spec.rb +4 -4
  64. data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
  65. data/spec/chewy/query/nodes/query_spec.rb +2 -2
  66. data/spec/chewy/query/nodes/range_spec.rb +18 -18
  67. data/spec/chewy/query/nodes/raw_spec.rb +1 -1
  68. data/spec/chewy/query/nodes/regexp_spec.rb +18 -18
  69. data/spec/chewy/query/nodes/script_spec.rb +4 -4
  70. data/spec/chewy/query/pagination/kaminari_spec.rb +41 -39
  71. data/spec/chewy/query/pagination/will_paginage_spec.rb +60 -0
  72. data/spec/chewy/query/pagination_spec.rb +8 -7
  73. data/spec/chewy/query_spec.rb +166 -167
  74. data/spec/chewy/rspec/update_index_spec.rb +1 -1
  75. data/spec/chewy/runtime/version_spec.rb +30 -30
  76. data/spec/chewy/runtime_spec.rb +3 -3
  77. data/spec/chewy/type/actions_spec.rb +3 -3
  78. data/spec/chewy/type/adapter/active_record_spec.rb +143 -143
  79. data/spec/chewy/type/adapter/mongoid_spec.rb +219 -0
  80. data/spec/chewy/type/adapter/object_spec.rb +39 -39
  81. data/spec/chewy/type/import_spec.rb +67 -37
  82. data/spec/chewy/type/mapping_spec.rb +12 -12
  83. data/spec/chewy/type/observe_spec.rb +5 -6
  84. data/spec/chewy/type/wrapper_spec.rb +12 -12
  85. data/spec/chewy_spec.rb +26 -28
  86. data/spec/spec_helper.rb +19 -31
  87. data/spec/support/active_record.rb +52 -0
  88. data/spec/support/class_helpers.rb +0 -4
  89. data/spec/support/mongoid.rb +87 -0
  90. metadata +33 -18
  91. data/gemfiles/Gemfile.rails-3.2 +0 -15
  92. data/gemfiles/Gemfile.rails-4.0 +0 -15
@@ -1,49 +1,49 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Aliases do
4
- before { Chewy.client.indices.delete index: '*' }
4
+ before { Chewy.massacre }
5
5
 
6
6
  before { stub_index :dummies }
7
7
 
8
8
  describe '.indexes' do
9
- specify { DummiesIndex.indexes.should == [] }
9
+ specify { expect(DummiesIndex.indexes).to eq([]) }
10
10
 
11
11
  context do
12
12
  before { DummiesIndex.create! }
13
- specify { DummiesIndex.indexes.should == [] }
13
+ specify { expect(DummiesIndex.indexes).to eq([]) }
14
14
  end
15
15
 
16
16
  context do
17
17
  before { DummiesIndex.create! }
18
18
  before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2013' }
19
- specify { DummiesIndex.indexes.should == [] }
19
+ specify { expect(DummiesIndex.indexes).to eq([]) }
20
20
  end
21
21
 
22
22
  context do
23
23
  before { DummiesIndex.create! '2013' }
24
24
  before { DummiesIndex.create! '2014' }
25
- specify { DummiesIndex.indexes.should =~ ['dummies_2013', 'dummies_2014'] }
25
+ specify { expect(DummiesIndex.indexes).to match_array(['dummies_2013', 'dummies_2014']) }
26
26
  end
27
27
  end
28
28
 
29
29
  describe '.aliases' do
30
- specify { DummiesIndex.aliases.should == [] }
30
+ specify { expect(DummiesIndex.aliases).to eq([]) }
31
31
 
32
32
  context do
33
33
  before { DummiesIndex.create! }
34
- specify { DummiesIndex.aliases.should == [] }
34
+ specify { expect(DummiesIndex.aliases).to eq([]) }
35
35
  end
36
36
 
37
37
  context do
38
38
  before { DummiesIndex.create! }
39
39
  before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2013' }
40
40
  before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2014' }
41
- specify { DummiesIndex.aliases.should =~ ['dummies_2013', 'dummies_2014'] }
41
+ specify { expect(DummiesIndex.aliases).to match_array(['dummies_2013', 'dummies_2014']) }
42
42
  end
43
43
 
44
44
  context do
45
45
  before { DummiesIndex.create! '2013' }
46
- specify { DummiesIndex.aliases.should == [] }
46
+ specify { expect(DummiesIndex.aliases).to eq([]) }
47
47
  end
48
48
  end
49
49
  end
@@ -35,12 +35,12 @@ describe Chewy::Index::Search do
35
35
  end
36
36
 
37
37
  describe '.search_index' do
38
- specify { ProductsIndex.search_index.should == ProductsIndex }
39
- specify { product.search_index.should == ProductsIndex }
38
+ specify { expect(ProductsIndex.search_index).to eq(ProductsIndex) }
39
+ specify { expect(product.search_index).to eq(ProductsIndex) }
40
40
  end
41
41
 
42
42
  describe '.search_type' do
43
- specify { ProductsIndex.search_type.should == ['product', 'product2'] }
44
- specify { product.search_type.should == 'product' }
43
+ specify { expect(ProductsIndex.search_type).to eq(['product', 'product2']) }
44
+ specify { expect(product.search_type).to eq('product') }
45
45
  end
46
46
  end
@@ -2,35 +2,35 @@ require 'spec_helper'
2
2
 
3
3
  describe Chewy::Index::Settings do
4
4
  describe '#to_hash' do
5
- before { Chewy.stub(config: Chewy::Config.send(:new)) }
5
+ before { allow(Chewy).to receive_messages(config: Chewy::Config.send(:new)) }
6
6
 
7
- specify { described_class.new.to_hash.should == {} }
8
- specify { described_class.new(number_of_nodes: 3).to_hash.should == {settings: {number_of_nodes: 3}} }
9
- specify { described_class.new(number_of_nodes: 3, analysis: {}).to_hash
10
- .should == {settings: {number_of_nodes: 3, analysis: {}}} }
11
- specify { described_class.new(number_of_nodes: 3, analysis: {filter: {filter1: {}}}).to_hash
12
- .should == {settings: {number_of_nodes: 3, analysis: {filter: {filter1: {}}}}} }
13
- specify { described_class.new(number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}).to_hash
14
- .should == {settings: {number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}}} }
15
- specify { described_class.new(number_of_nodes: 3, analysis: {
7
+ specify { expect(described_class.new.to_hash).to eq({}) }
8
+ specify { expect(described_class.new(number_of_nodes: 3).to_hash).to eq({settings: {number_of_nodes: 3}}) }
9
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {}).to_hash)
10
+ .to eq({settings: {number_of_nodes: 3, analysis: {}}}) }
11
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {filter: {filter1: {}}}).to_hash)
12
+ .to eq({settings: {number_of_nodes: 3, analysis: {filter: {filter1: {}}}}}) }
13
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}).to_hash)
14
+ .to eq({settings: {number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}}}) }
15
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {
16
16
  analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}}
17
- }).to_hash
18
- .should == {settings: {number_of_nodes: 3, analysis: {
17
+ }).to_hash)
18
+ .to eq({settings: {number_of_nodes: 3, analysis: {
19
19
  analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}}
20
- }}} }
21
- specify { described_class.new(number_of_nodes: 3, analysis: {analyser: ['analyzer1']}).to_hash
22
- .should == {settings: {number_of_nodes: 3, analysis: {}}} }
20
+ }}}) }
21
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {analyser: ['analyzer1']}).to_hash)
22
+ .to eq({settings: {number_of_nodes: 3, analysis: {}}}) }
23
23
 
24
24
  context do
25
25
  before { Chewy.tokenizer :tokenizer1, {options: 42} }
26
26
 
27
- specify { described_class.new(number_of_nodes: 3, analysis: {
27
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {
28
28
  analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}}
29
- }).to_hash
30
- .should == {settings: {number_of_nodes: 3, analysis: {
29
+ }).to_hash)
30
+ .to eq({settings: {number_of_nodes: 3, analysis: {
31
31
  analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}},
32
32
  tokenizer: {tokenizer1: {options: 42}}
33
- }}} }
33
+ }}}) }
34
34
  end
35
35
 
36
36
  context do
@@ -40,14 +40,14 @@ describe Chewy::Index::Settings do
40
40
  Chewy.filter :filter5, {options: 44}
41
41
  end
42
42
 
43
- specify { described_class.new(number_of_nodes: 3, analysis: {
43
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {
44
44
  analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}},
45
45
  filter: ['filter3', {filter4: {options: 45}}]
46
- }).to_hash
47
- .should == {settings: {number_of_nodes: 3, analysis: {
46
+ }).to_hash)
47
+ .to eq({settings: {number_of_nodes: 3, analysis: {
48
48
  analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}},
49
49
  filter: {filter2: {options: 42}, filter3: {options: 43}, filter4: {options: 45}}
50
- }}} }
50
+ }}}) }
51
51
  end
52
52
 
53
53
  context do
@@ -56,26 +56,26 @@ describe Chewy::Index::Settings do
56
56
  Chewy.tokenizer :tokenizer1, {options: 43}
57
57
  end
58
58
 
59
- specify { described_class.new(number_of_nodes: 3, analysis: {
59
+ specify { expect(described_class.new(number_of_nodes: 3, analysis: {
60
60
  analyzer: ['analyzer1', {analyzer2: {options: 44}}]
61
- }).to_hash
62
- .should == {settings: {number_of_nodes: 3, analysis: {
61
+ }).to_hash)
62
+ .to eq({settings: {number_of_nodes: 3, analysis: {
63
63
  analyzer: {analyzer1: {options: 42, tokenizer: 'tokenizer1'}, analyzer2: {options: 44}},
64
64
  tokenizer: {tokenizer1: {options: 43}}
65
- }}} }
65
+ }}}) }
66
66
  end
67
67
 
68
68
  context ':index' do
69
- specify { described_class.new(index: {number_of_shards: 3}).to_hash
70
- .should == {settings: {index: {number_of_shards: 3}}} }
69
+ specify { expect(described_class.new(index: {number_of_shards: 3}).to_hash)
70
+ .to eq({settings: {index: {number_of_shards: 3}}}) }
71
71
 
72
72
  context do
73
73
  before { Chewy.configuration = {index: {number_of_shards: 7, number_of_replicas: 2}} }
74
74
 
75
- specify { described_class.new.to_hash
76
- .should == {settings: {index: {number_of_shards: 7, number_of_replicas: 2}}} }
77
- specify { described_class.new(index: {number_of_shards: 3}).to_hash
78
- .should == {settings: {index: {number_of_shards: 3, number_of_replicas: 2}}} }
75
+ specify { expect(described_class.new.to_hash)
76
+ .to eq({settings: {index: {number_of_shards: 7, number_of_replicas: 2}}}) }
77
+ specify { expect(described_class.new(index: {number_of_shards: 3}).to_hash)
78
+ .to eq({settings: {index: {number_of_shards: 3, number_of_replicas: 2}}}) }
79
79
  end
80
80
  end
81
81
  end
@@ -8,7 +8,7 @@ describe Chewy::Index do
8
8
  end
9
9
 
10
10
  describe '.client' do
11
- specify { stub_index(:dummies1).client.should == stub_index(:dummies2).client }
11
+ specify { expect(stub_index(:dummies1).client).to eq(stub_index(:dummies2).client) }
12
12
 
13
13
  context do
14
14
  before do
@@ -16,13 +16,13 @@ describe Chewy::Index do
16
16
  stub_index(:dummies2, Dummies1Index)
17
17
  end
18
18
 
19
- specify { Dummies1Index.client.should == Dummies2Index.client }
19
+ specify { expect(Dummies1Index.client).to eq(Dummies2Index.client) }
20
20
  end
21
21
  end
22
22
 
23
23
  describe '.settings' do
24
24
  before do
25
- Chewy.stub(config: Chewy::Config.send(:new))
25
+ allow(Chewy).to receive_messages(config: Chewy::Config.send(:new))
26
26
 
27
27
  Chewy.analyzer :name, filter: ['lowercase', 'icu_folding', 'names_nysiis']
28
28
  Chewy.analyzer :phone, tokenizer: 'ngram', char_filter: ['phone']
@@ -34,34 +34,34 @@ describe Chewy::Index do
34
34
  let(:documents) { stub_index(:documents) { settings analysis: {analyzer: [:name, :phone, {sorted: {option: :baz}}]} } }
35
35
 
36
36
  specify { expect { documents.settings_hash }.to_not change(documents._settings, :inspect) }
37
- specify { documents.settings_hash.should == {settings: {analysis: {
37
+ specify { expect(documents.settings_hash).to eq({settings: {analysis: {
38
38
  analyzer: {name: {filter: ['lowercase', 'icu_folding', 'names_nysiis']},
39
39
  phone: {tokenizer: 'ngram', char_filter: ['phone']},
40
40
  sorted: {option: :baz}},
41
41
  tokenizer: {ngram: {type: 'nGram', min_gram: 3, max_gram: 3}},
42
42
  char_filter: {phone: {type: 'pattern_replace', pattern: '[^\d]', replacement: ''}},
43
43
  filter: {names_nysiis: {type: 'phonetic', encoder: 'nysiis', replace: false}}
44
- }}} }
44
+ }}}) }
45
45
  end
46
46
 
47
47
  describe '.define_type' do
48
- specify { DummiesIndex.type_hash['dummy'].should == DummiesIndex::Dummy }
48
+ specify { expect(DummiesIndex.type_hash['dummy']).to eq(DummiesIndex::Dummy) }
49
49
 
50
50
  context do
51
51
  before { stub_index(:dummies) { define_type :dummy, name: :borogoves } }
52
- specify { DummiesIndex.type_hash['borogoves'].should == DummiesIndex::Borogoves }
52
+ specify { expect(DummiesIndex.type_hash['borogoves']).to eq(DummiesIndex::Borogoves) }
53
53
  end
54
54
 
55
55
  context do
56
- before { stub_model(:city) }
56
+ before { stub_class(:city) }
57
57
  before { stub_index(:dummies) { define_type City, name: :country } }
58
- specify { DummiesIndex.type_hash['country'].should == DummiesIndex::Country }
58
+ specify { expect(DummiesIndex.type_hash['country']).to eq(DummiesIndex::Country) }
59
59
  end
60
60
 
61
61
 
62
62
  context do
63
- before { stub_model('City') }
64
- before { stub_model('City::District', City) }
63
+ before { stub_class('City') }
64
+ before { stub_class('City::District', City) }
65
65
 
66
66
  specify do
67
67
  expect {
@@ -88,85 +88,85 @@ describe Chewy::Index do
88
88
  end
89
89
 
90
90
  describe '.type_hash' do
91
- specify { DummiesIndex.type_hash['dummy'].should == DummiesIndex::Dummy }
92
- specify { DummiesIndex.type_hash.should have_key 'dummy' }
93
- specify { DummiesIndex.type_hash['dummy'].should be < Chewy::Type }
94
- specify { DummiesIndex.type_hash['dummy'].type_name.should == 'dummy' }
91
+ specify { expect(DummiesIndex.type_hash['dummy']).to eq(DummiesIndex::Dummy) }
92
+ specify { expect(DummiesIndex.type_hash).to have_key 'dummy' }
93
+ specify { expect(DummiesIndex.type_hash['dummy']).to be < Chewy::Type }
94
+ specify { expect(DummiesIndex.type_hash['dummy'].type_name).to eq('dummy') }
95
95
  end
96
96
 
97
- specify { DummiesIndex.type_names.should == DummiesIndex.type_hash.keys }
97
+ specify { expect(DummiesIndex.type_names).to eq(DummiesIndex.type_hash.keys) }
98
98
 
99
99
  describe '.types' do
100
- specify { DummiesIndex.types.should == DummiesIndex.type_hash.values }
101
- specify { DummiesIndex.types(:dummy).should be_a Chewy::Query }
102
- specify { DummiesIndex.types(:user).should be_a Chewy::Query }
100
+ specify { expect(DummiesIndex.types).to eq(DummiesIndex.type_hash.values) }
101
+ specify { expect(DummiesIndex.types(:dummy)).to be_a Chewy::Query }
102
+ specify { expect(DummiesIndex.types(:user)).to be_a Chewy::Query }
103
103
  end
104
104
 
105
105
  describe '.index_name' do
106
106
  specify { expect { Class.new(Chewy::Index).index_name }.to raise_error Chewy::UndefinedIndex }
107
- specify { Class.new(Chewy::Index) { index_name :myindex }.index_name.should == 'myindex' }
108
- specify { stub_const('DeveloperIndex', Class.new(Chewy::Index)).index_name.should == 'developer' }
109
- specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name.should == 'developers' }
107
+ specify { expect(Class.new(Chewy::Index) { index_name :myindex }.index_name).to eq('myindex') }
108
+ specify { expect(stub_const('DeveloperIndex', Class.new(Chewy::Index)).index_name).to eq('developer') }
109
+ specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name).to eq('developers') }
110
110
 
111
111
  context do
112
- before { Chewy.stub(configuration: {prefix: 'testing'}) }
113
- specify { DummiesIndex.index_name.should == 'testing_dummies' }
114
- specify { stub_index(:dummies) { index_name :users }.index_name.should == 'testing_users' }
112
+ before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
113
+ specify { expect(DummiesIndex.index_name).to eq('testing_dummies') }
114
+ specify { expect(stub_index(:dummies) { index_name :users }.index_name).to eq('testing_users') }
115
115
  end
116
116
  end
117
117
 
118
118
  describe '.build_index_name' do
119
- specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(suffix: '').should == 'developers' }
120
- specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(suffix: '2013').should == 'developers_2013' }
121
- specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(prefix: '').should == 'developers' }
122
- specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(prefix: 'test').should == 'test_developers' }
123
- specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(:users, prefix: 'test', suffix: '2013').should == 'test_users_2013' }
119
+ specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(suffix: '')).to eq('developers') }
120
+ specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(suffix: '2013')).to eq('developers_2013') }
121
+ specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(prefix: '')).to eq('developers') }
122
+ specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(prefix: 'test')).to eq('test_developers') }
123
+ specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).build_index_name(:users, prefix: 'test', suffix: '2013')).to eq('test_users_2013') }
124
124
  end
125
125
 
126
126
  describe '.index_params' do
127
- before { Chewy.stub(config: Chewy::Config.send(:new)) }
127
+ before { allow(Chewy).to receive_messages(config: Chewy::Config.send(:new)) }
128
128
 
129
- specify { stub_index(:documents).index_params.should == {} }
130
- specify { stub_index(:documents) { settings number_of_shards: 1 }.index_params.keys.should == [:settings] }
131
- specify { stub_index(:documents) do
129
+ specify { expect(stub_index(:documents).index_params).to eq({}) }
130
+ specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.index_params.keys).to eq([:settings]) }
131
+ specify { expect(stub_index(:documents) do
132
132
  define_type :document do
133
133
  field :name, type: 'string'
134
134
  end
135
- end.index_params.keys.should == [:mappings] }
136
- specify { stub_index(:documents) do
135
+ end.index_params.keys).to eq([:mappings]) }
136
+ specify { expect(stub_index(:documents) do
137
137
  settings number_of_shards: 1
138
138
  define_type :document do
139
139
  field :name, type: 'string'
140
140
  end
141
- end.index_params.keys.should =~ [:mappings, :settings] }
141
+ end.index_params.keys).to match_array([:mappings, :settings]) }
142
142
  end
143
143
 
144
144
  describe '.settings_hash' do
145
- before { Chewy.stub(config: Chewy::Config.send(:new)) }
145
+ before { allow(Chewy).to receive_messages(config: Chewy::Config.send(:new)) }
146
146
 
147
- specify { stub_index(:documents).settings_hash.should == {} }
148
- specify { stub_index(:documents) { settings number_of_shards: 1 }.settings_hash.should == {settings: {number_of_shards: 1}} }
147
+ specify { expect(stub_index(:documents).settings_hash).to eq({}) }
148
+ specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.settings_hash).to eq({settings: {number_of_shards: 1}}) }
149
149
  end
150
150
 
151
151
  describe '.mappings_hash' do
152
- specify { stub_index(:documents).mappings_hash.should == {} }
153
- specify { stub_index(:documents) { define_type :document }.mappings_hash.should == {} }
154
- specify { stub_index(:documents) do
152
+ specify { expect(stub_index(:documents).mappings_hash).to eq({}) }
153
+ specify { expect(stub_index(:documents) { define_type :document }.mappings_hash).to eq({}) }
154
+ specify { expect(stub_index(:documents) do
155
155
  define_type :document do
156
156
  field :name, type: 'string'
157
157
  end
158
- end.mappings_hash.should == {mappings: {document: {properties: {name: {type: 'string'}}}}} }
159
- specify { stub_index(:documents) do
158
+ end.mappings_hash).to eq({mappings: {document: {properties: {name: {type: 'string'}}}}}) }
159
+ specify { expect(stub_index(:documents) do
160
160
  define_type :document do
161
161
  field :name, type: 'string'
162
162
  end
163
163
  define_type :document2 do
164
164
  field :name, type: 'string'
165
165
  end
166
- end.mappings_hash[:mappings].keys.should =~ [:document, :document2] }
166
+ end.mappings_hash[:mappings].keys).to match_array([:document, :document2]) }
167
167
  end
168
168
 
169
- describe '.import' do
169
+ describe '.import', :orm do
170
170
  before do
171
171
  stub_model(:city)
172
172
  stub_model(:country)
@@ -177,8 +177,8 @@ describe Chewy::Index do
177
177
  end
178
178
  end
179
179
 
180
- let!(:cities) { 2.times.map { City.create! } }
181
- let!(:countries) { 2.times.map { Country.create! } }
180
+ let!(:cities) { 2.times.map { |i| City.create! id: i + 1 } }
181
+ let!(:countries) { 2.times.map { |i| Country.create! id: i + 1 } }
182
182
 
183
183
  specify do
184
184
  expect { PlacesIndex.import }.to update_index(PlacesIndex::City).and_reindex(cities)
@@ -123,59 +123,59 @@ describe Chewy::Query::Criteria do
123
123
  describe '#merge' do
124
124
  let(:criteria) { described_class.new }
125
125
 
126
- specify { subject.merge(criteria).should_not be_equal subject }
127
- specify { subject.merge(criteria).should_not be_equal criteria }
128
-
129
- specify { subject.tap { |c| c.update_options(opt1: 'hello') }
130
- .merge(criteria.tap { |c| c.update_options(opt2: 'hello') }).options.should include(opt1: 'hello', opt2: 'hello') }
131
- specify { subject.tap { |c| c.update_request_options(opt1: 'hello') }
132
- .merge(criteria.tap { |c| c.update_request_options(opt2: 'hello') }).request_options.should include(opt1: 'hello', opt2: 'hello') }
133
- specify { subject.tap { |c| c.update_facets(field1: 'hello') }
134
- .merge(criteria.tap { |c| c.update_facets(field1: 'hello') }).facets.should == {field1: 'hello', field1: 'hello'} }
135
- specify { subject.tap { |c| c.update_scores(script: 'hello') }
136
- .merge(criteria.tap { |c| c.update_scores(script: 'foobar') }).scores.should == [{script: 'hello'}, { script: 'foobar' } ] }
137
- specify { subject.tap { |c| c.update_aggregations(field1: 'hello') }
138
- .merge(criteria.tap { |c| c.update_aggregations(field1: 'hello') }).aggregations.should == {field1: 'hello', field1: 'hello'} }
139
- specify { subject.tap { |c| c.update_queries(field1: 'hello') }
140
- .merge(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries.should == [{field1: 'hello'}, {field2: 'hello'}] }
141
- specify { subject.tap { |c| c.update_filters(field1: 'hello') }
142
- .merge(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters.should == [{field1: 'hello'}, {field2: 'hello'}] }
143
- specify { subject.tap { |c| c.update_post_filters(field1: 'hello') }
144
- .merge(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters.should == [{field1: 'hello'}, {field2: 'hello'}] }
145
- specify { subject.tap { |c| c.update_sort(:field1) }
146
- .merge(criteria.tap { |c| c.update_sort(:field2) }).sort.should == [:field1, :field2] }
147
- specify { subject.tap { |c| c.update_fields(:field1) }
148
- .merge(criteria.tap { |c| c.update_fields(:field2) }).fields.should == ['field1', 'field2'] }
149
- specify { subject.tap { |c| c.update_types(:type1) }
150
- .merge(criteria.tap { |c| c.update_types(:type2) }).types.should == ['type1', 'type2'] }
126
+ specify { expect(subject.merge(criteria)).not_to be_equal subject }
127
+ specify { expect(subject.merge(criteria)).not_to be_equal criteria }
128
+
129
+ specify { expect(subject.tap { |c| c.update_options(opt1: 'hello') }
130
+ .merge(criteria.tap { |c| c.update_options(opt2: 'hello') }).options).to include(opt1: 'hello', opt2: 'hello') }
131
+ specify { expect(subject.tap { |c| c.update_request_options(opt1: 'hello') }
132
+ .merge(criteria.tap { |c| c.update_request_options(opt2: 'hello') }).request_options).to include(opt1: 'hello', opt2: 'hello') }
133
+ specify { expect(subject.tap { |c| c.update_facets(field1: 'hello') }
134
+ .merge(criteria.tap { |c| c.update_facets(field1: 'hello') }).facets).to eq({field1: 'hello', field1: 'hello'}) }
135
+ specify { expect(subject.tap { |c| c.update_scores(script: 'hello') }
136
+ .merge(criteria.tap { |c| c.update_scores(script: 'foobar') }).scores).to eq([{script: 'hello'}, { script: 'foobar' } ]) }
137
+ specify { expect(subject.tap { |c| c.update_aggregations(field1: 'hello') }
138
+ .merge(criteria.tap { |c| c.update_aggregations(field1: 'hello') }).aggregations).to eq({field1: 'hello', field1: 'hello'}) }
139
+ specify { expect(subject.tap { |c| c.update_queries(field1: 'hello') }
140
+ .merge(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
141
+ specify { expect(subject.tap { |c| c.update_filters(field1: 'hello') }
142
+ .merge(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
143
+ specify { expect(subject.tap { |c| c.update_post_filters(field1: 'hello') }
144
+ .merge(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
145
+ specify { expect(subject.tap { |c| c.update_sort(:field1) }
146
+ .merge(criteria.tap { |c| c.update_sort(:field2) }).sort).to eq([:field1, :field2]) }
147
+ specify { expect(subject.tap { |c| c.update_fields(:field1) }
148
+ .merge(criteria.tap { |c| c.update_fields(:field2) }).fields).to eq(['field1', 'field2']) }
149
+ specify { expect(subject.tap { |c| c.update_types(:type1) }
150
+ .merge(criteria.tap { |c| c.update_types(:type2) }).types).to eq(['type1', 'type2']) }
151
151
  end
152
152
 
153
153
  describe '#merge!' do
154
154
  let(:criteria) { described_class.new }
155
155
 
156
- specify { subject.merge!(criteria).should be_equal subject }
157
- specify { subject.merge!(criteria).should_not be_equal criteria }
158
-
159
- specify { subject.tap { |c| c.update_options(opt1: 'hello') }
160
- .merge!(criteria.tap { |c| c.update_options(opt2: 'hello') }).options.should include(opt1: 'hello', opt2: 'hello') }
161
- specify { subject.tap { |c| c.update_request_options(opt1: 'hello') }
162
- .merge!(criteria.tap { |c| c.update_request_options(opt2: 'hello') }).request_options.should include(opt1: 'hello', opt2: 'hello') }
163
- specify { subject.tap { |c| c.update_facets(field1: 'hello') }
164
- .merge!(criteria.tap { |c| c.update_facets(field1: 'hello') }).facets.should == {field1: 'hello', field1: 'hello'} }
165
- specify { subject.tap { |c| c.update_aggregations(field1: 'hello') }
166
- .merge!(criteria.tap { |c| c.update_aggregations(field1: 'hello') }).aggregations.should == {field1: 'hello', field1: 'hello'} }
167
- specify { subject.tap { |c| c.update_queries(field1: 'hello') }
168
- .merge!(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries.should == [{field1: 'hello'}, {field2: 'hello'}] }
169
- specify { subject.tap { |c| c.update_filters(field1: 'hello') }
170
- .merge!(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters.should == [{field1: 'hello'}, {field2: 'hello'}] }
171
- specify { subject.tap { |c| c.update_post_filters(field1: 'hello') }
172
- .merge!(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters.should == [{field1: 'hello'}, {field2: 'hello'}] }
173
- specify { subject.tap { |c| c.update_sort(:field1) }
174
- .merge!(criteria.tap { |c| c.update_sort(:field2) }).sort.should == [:field1, :field2] }
175
- specify { subject.tap { |c| c.update_fields(:field1) }
176
- .merge!(criteria.tap { |c| c.update_fields(:field2) }).fields.should == ['field1', 'field2'] }
177
- specify { subject.tap { |c| c.update_types(:type1) }
178
- .merge!(criteria.tap { |c| c.update_types(:type2) }).types.should == ['type1', 'type2'] }
156
+ specify { expect(subject.merge!(criteria)).to be_equal subject }
157
+ specify { expect(subject.merge!(criteria)).not_to be_equal criteria }
158
+
159
+ specify { expect(subject.tap { |c| c.update_options(opt1: 'hello') }
160
+ .merge!(criteria.tap { |c| c.update_options(opt2: 'hello') }).options).to include(opt1: 'hello', opt2: 'hello') }
161
+ specify { expect(subject.tap { |c| c.update_request_options(opt1: 'hello') }
162
+ .merge!(criteria.tap { |c| c.update_request_options(opt2: 'hello') }).request_options).to include(opt1: 'hello', opt2: 'hello') }
163
+ specify { expect(subject.tap { |c| c.update_facets(field1: 'hello') }
164
+ .merge!(criteria.tap { |c| c.update_facets(field1: 'hello') }).facets).to eq({field1: 'hello', field1: 'hello'}) }
165
+ specify { expect(subject.tap { |c| c.update_aggregations(field1: 'hello') }
166
+ .merge!(criteria.tap { |c| c.update_aggregations(field1: 'hello') }).aggregations).to eq({field1: 'hello', field1: 'hello'}) }
167
+ specify { expect(subject.tap { |c| c.update_queries(field1: 'hello') }
168
+ .merge!(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
169
+ specify { expect(subject.tap { |c| c.update_filters(field1: 'hello') }
170
+ .merge!(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
171
+ specify { expect(subject.tap { |c| c.update_post_filters(field1: 'hello') }
172
+ .merge!(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters).to eq([{field1: 'hello'}, {field2: 'hello'}]) }
173
+ specify { expect(subject.tap { |c| c.update_sort(:field1) }
174
+ .merge!(criteria.tap { |c| c.update_sort(:field2) }).sort).to eq([:field1, :field2]) }
175
+ specify { expect(subject.tap { |c| c.update_fields(:field1) }
176
+ .merge!(criteria.tap { |c| c.update_fields(:field2) }).fields).to eq(['field1', 'field2']) }
177
+ specify { expect(subject.tap { |c| c.update_types(:type1) }
178
+ .merge!(criteria.tap { |c| c.update_types(:type2) }).types).to eq(['type1', 'type2']) }
179
179
  end
180
180
 
181
181
  describe '#request_body' do
@@ -184,20 +184,20 @@ describe Chewy::Query::Criteria do
184
184
  subject.request_body
185
185
  end
186
186
 
187
- specify { request_body.should == {body: {}} }
188
- specify { request_body { update_request_options(size: 10) }.should == {body: {size: 10}} }
189
- specify { request_body { update_request_options(from: 10) }.should == {body: {from: 10}} }
190
- specify { request_body { update_request_options(explain: true) }.should == {body: {explain: true}} }
191
- specify { request_body { update_queries(:query) }.should == {body: {query: :query}} }
192
- specify { request_body {
187
+ specify { expect(request_body).to eq({body: {}}) }
188
+ specify { expect(request_body { update_request_options(size: 10) }).to eq({body: {size: 10}}) }
189
+ specify { expect(request_body { update_request_options(from: 10) }).to eq({body: {from: 10}}) }
190
+ specify { expect(request_body { update_request_options(explain: true) }).to eq({body: {explain: true}}) }
191
+ specify { expect(request_body { update_queries(:query) }).to eq({body: {query: :query}}) }
192
+ specify { expect(request_body {
193
193
  update_scores(script_score: { script: '_score'})
194
- }.should == {body: {query: { function_score: { functions: [{ script_score: {script: '_score' }}] }}}} }
195
- specify { request_body {
194
+ }).to eq({body: {query: { function_score: { functions: [{ script_score: {script: '_score' }}] }}}}) }
195
+ specify { expect(request_body {
196
196
  update_scores(script_score: { script: "boost_me" })
197
197
  update_queries(:query)
198
198
  update_options(boost_mode: :add)
199
199
  update_options(score_mode: :avg)
200
- }.should == {body: {query: {
200
+ }).to eq({body: {query: {
201
201
  function_score: {
202
202
  functions: [{
203
203
  script_score: {script: 'boost_me' }
@@ -205,18 +205,18 @@ describe Chewy::Query::Criteria do
205
205
  query: :query,
206
206
  boost_mode: :add,
207
207
  score_mode: :avg
208
- }}}}
208
+ }}}})
209
209
  }
210
- specify { request_body {
210
+ specify { expect(request_body {
211
211
  update_request_options(from: 10); update_sort(:field); update_fields(:field); update_queries(:query)
212
- }.should == {body: {query: :query, from: 10, sort: [:field], _source: ['field']}} }
212
+ }).to eq({body: {query: :query, from: 10, sort: [:field], _source: ['field']}}) }
213
213
 
214
- specify { request_body {
214
+ specify { expect(request_body {
215
215
  update_queries(:query); update_filters(:filters);
216
- }.should == {body: {query: {filtered: {query: :query, filter: :filters}}}} }
217
- specify { request_body {
216
+ }).to eq({body: {query: {filtered: {query: :query, filter: :filters}}}}) }
217
+ specify { expect(request_body {
218
218
  update_queries(:query); update_post_filters(:post_filter);
219
- }.should == {body: {query: :query, post_filter: :post_filter}} }
219
+ }).to eq({body: {query: :query, post_filter: :post_filter}}) }
220
220
  end
221
221
 
222
222
  describe '#_filtered_query' do
@@ -225,59 +225,59 @@ describe Chewy::Query::Criteria do
225
225
  subject.send(:_filtered_query, subject.send(:_request_query), subject.send(:_request_filter), options)
226
226
  end
227
227
 
228
- specify { _filtered_query.should == {} }
229
- specify { _filtered_query { update_queries(:query) }.should == {query: :query} }
230
- specify { _filtered_query(strategy: 'query_first') { update_queries(:query) }.should == {query: :query} }
231
- specify { _filtered_query { update_queries([:query1, :query2]) }
232
- .should == {query: {bool: {must: [:query1, :query2]}}} }
233
- specify { _filtered_query { update_options(query_mode: :should); update_queries([:query1, :query2]) }
234
- .should == {query: {bool: {should: [:query1, :query2]}}} }
235
- specify { _filtered_query { update_options(query_mode: :dis_max); update_queries([:query1, :query2]) }
236
- .should == {query: {dis_max: {queries: [:query1, :query2]}}} }
237
-
238
- specify { _filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]) }
239
- .should == {query: {filtered: {query: {match_all: {}}, filter: {and: [:filter1, :filter2]}, strategy: 'query_first'}}} }
240
- specify { _filtered_query { update_filters([:filter1, :filter2]) }
241
- .should == {query: {filtered: {query: {match_all: {}}, filter: {and: [:filter1, :filter2]}}}} }
242
-
243
- specify { _filtered_query { update_filters([:filter1, :filter2]); update_queries([:query1, :query2]) }
244
- .should == {query: {filtered: {
228
+ specify { expect(_filtered_query).to eq({}) }
229
+ specify { expect(_filtered_query { update_queries(:query) }).to eq({query: :query}) }
230
+ specify { expect(_filtered_query(strategy: 'query_first') { update_queries(:query) }).to eq({query: :query}) }
231
+ specify { expect(_filtered_query { update_queries([:query1, :query2]) })
232
+ .to eq({query: {bool: {must: [:query1, :query2]}}}) }
233
+ specify { expect(_filtered_query { update_options(query_mode: :should); update_queries([:query1, :query2]) })
234
+ .to eq({query: {bool: {should: [:query1, :query2]}}}) }
235
+ specify { expect(_filtered_query { update_options(query_mode: :dis_max); update_queries([:query1, :query2]) })
236
+ .to eq({query: {dis_max: {queries: [:query1, :query2]}}}) }
237
+
238
+ specify { expect(_filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]) })
239
+ .to eq({query: {filtered: {query: {match_all: {}}, filter: {and: [:filter1, :filter2]}, strategy: 'query_first'}}}) }
240
+ specify { expect(_filtered_query { update_filters([:filter1, :filter2]) })
241
+ .to eq({query: {filtered: {query: {match_all: {}}, filter: {and: [:filter1, :filter2]}}}}) }
242
+
243
+ specify { expect(_filtered_query { update_filters([:filter1, :filter2]); update_queries([:query1, :query2]) })
244
+ .to eq({query: {filtered: {
245
245
  query: {bool: {must: [:query1, :query2]}},
246
246
  filter: {and: [:filter1, :filter2]}
247
- }}}
247
+ }}})
248
248
  }
249
- specify { _filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]); update_queries([:query1, :query2]) }
250
- .should == {query: {filtered: {
249
+ specify { expect(_filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]); update_queries([:query1, :query2]) })
250
+ .to eq({query: {filtered: {
251
251
  query: {bool: {must: [:query1, :query2]}},
252
252
  filter: {and: [:filter1, :filter2]},
253
253
  strategy: 'query_first'
254
- }}}
254
+ }}})
255
255
  }
256
- specify { _filtered_query {
256
+ specify { expect(_filtered_query {
257
257
  update_options(query_mode: :should); update_options(filter_mode: :or);
258
258
  update_filters([:filter1, :filter2]); update_queries([:query1, :query2])
259
- }.should == {query: {filtered: {
259
+ }).to eq({query: {filtered: {
260
260
  query: {bool: {should: [:query1, :query2]}},
261
261
  filter: {or: [:filter1, :filter2]}
262
- }}}
262
+ }}})
263
263
  }
264
264
  end
265
265
 
266
266
  describe "#_boost_query" do
267
- specify { subject.send(:_boost_query, query: :query).should eq(query: :query) }
267
+ specify { expect(subject.send(:_boost_query, query: :query)).to eq(query: :query) }
268
268
  specify {
269
269
  subject.update_scores({ boost_factor: 5 })
270
- subject.send(:_boost_query, query: :query).should eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query } })
270
+ expect(subject.send(:_boost_query, query: :query)).to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query } })
271
271
  }
272
272
  specify {
273
273
  subject.update_scores({ boost_factor: 5 })
274
274
  subject.update_options(boost_mode: :multiply)
275
275
  subject.update_options(score_mode: :add)
276
- subject.send(:_boost_query, query: :query).should eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query, boost_mode: :multiply, score_mode: :add } })
276
+ expect(subject.send(:_boost_query, query: :query)).to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query, boost_mode: :multiply, score_mode: :add } })
277
277
  }
278
278
  specify {
279
279
  subject.update_scores({ boost_factor: 5 })
280
- subject.send(:_boost_query, query: :query, filter: :filter).should eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: { filtered: { query: :query, filter: :filter } } } })
280
+ expect(subject.send(:_boost_query, query: :query, filter: :filter)).to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: { filtered: { query: :query, filter: :filter } } } })
281
281
  }
282
282
  end
283
283
 
@@ -287,29 +287,33 @@ describe Chewy::Query::Criteria do
287
287
  subject.send(:_request_filter)
288
288
  end
289
289
 
290
- specify { _request_filter.should be_nil }
291
-
292
- specify { _request_filter { update_types(:type) }.should == {type: {value: 'type'}} }
293
- specify { _request_filter { update_types([:type1, :type2]) }
294
- .should == {or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]} }
295
-
296
- specify { _request_filter { update_filters([:filter1, :filter2]) }
297
- .should == {and: [:filter1, :filter2]} }
298
- specify { _request_filter { update_options(filter_mode: :or); update_filters([:filter1, :filter2]) }
299
- .should == {or: [:filter1, :filter2]} }
300
- specify { _request_filter { update_options(filter_mode: :must); update_filters([:filter1, :filter2]) }
301
- .should == {bool: {must: [:filter1, :filter2]}} }
302
- specify { _request_filter { update_options(filter_mode: :should); update_filters([:filter1, :filter2]) }
303
- .should == {bool: {should: [:filter1, :filter2]}} }
304
-
305
- specify { _request_filter { update_types([:type1, :type2]); update_filters([:filter1, :filter2]) }
306
- .should == {and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, :filter1, :filter2]} }
307
- specify { _request_filter { update_options(filter_mode: :or); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) }
308
- .should == {and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {or: [:filter1, :filter2]}]} }
309
- specify { _request_filter { update_options(filter_mode: :must); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) }
310
- .should == {and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must: [:filter1, :filter2]}}]} }
311
- specify { _request_filter { update_options(filter_mode: :should); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) }
312
- .should == {and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {should: [:filter1, :filter2]}}]} }
290
+ specify { expect(_request_filter).to be_nil }
291
+
292
+ specify { expect(_request_filter { update_types(:type) }).to eq({type: {value: 'type'}}) }
293
+ specify { expect(_request_filter { update_types([:type1, :type2]) })
294
+ .to eq({or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}) }
295
+
296
+ specify { expect(_request_filter { update_filters([:filter1, :filter2]) })
297
+ .to eq({and: [:filter1, :filter2]}) }
298
+ specify { expect(_request_filter { update_options(filter_mode: :or); update_filters([:filter1, :filter2]) })
299
+ .to eq({or: [:filter1, :filter2]}) }
300
+ specify { expect(_request_filter { update_options(filter_mode: :must); update_filters([:filter1, :filter2]) })
301
+ .to eq({bool: {must: [:filter1, :filter2]}}) }
302
+ specify { expect(_request_filter { update_options(filter_mode: :should); update_filters([:filter1, :filter2]) })
303
+ .to eq({bool: {should: [:filter1, :filter2]}}) }
304
+ specify { expect(_request_filter { update_options(filter_mode: :must_not); update_filters([:filter1, :filter2]) })
305
+ .to eq({bool: {must_not: [:filter1, :filter2]}}) }
306
+
307
+ specify { expect(_request_filter { update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
308
+ .to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, :filter1, :filter2]}) }
309
+ specify { expect(_request_filter { update_options(filter_mode: :or); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
310
+ .to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {or: [:filter1, :filter2]}]}) }
311
+ specify { expect(_request_filter { update_options(filter_mode: :must); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
312
+ .to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must: [:filter1, :filter2]}}]}) }
313
+ specify { expect(_request_filter { update_options(filter_mode: :should); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
314
+ .to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {should: [:filter1, :filter2]}}]}) }
315
+ specify { expect(_request_filter { update_options(filter_mode: :must_not); update_types([:type1, :type2]); update_filters([:filter1, :filter2]) })
316
+ .to eq({and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must_not: [:filter1, :filter2]}}]}) }
313
317
  end
314
318
 
315
319
  describe '#_request_post_filter' do
@@ -318,22 +322,22 @@ describe Chewy::Query::Criteria do
318
322
  subject.send(:_request_post_filter)
319
323
  end
320
324
 
321
- specify { _request_post_filter.should be_nil }
325
+ specify { expect(_request_post_filter).to be_nil }
322
326
 
323
- specify { _request_post_filter { update_post_filters([:post_filter1, :post_filter2]) }
324
- .should == {and: [:post_filter1, :post_filter2]} }
325
- specify { _request_post_filter { update_options(post_filter_mode: :or); update_post_filters([:post_filter1, :post_filter2]) }
326
- .should == {or: [:post_filter1, :post_filter2]} }
327
- specify { _request_post_filter { update_options(post_filter_mode: :must); update_post_filters([:post_filter1, :post_filter2]) }
328
- .should == {bool: {must: [:post_filter1, :post_filter2]}} }
329
- specify { _request_post_filter { update_options(post_filter_mode: :should); update_post_filters([:post_filter1, :post_filter2]) }
330
- .should == {bool: {should: [:post_filter1, :post_filter2]}} }
327
+ specify { expect(_request_post_filter { update_post_filters([:post_filter1, :post_filter2]) })
328
+ .to eq({and: [:post_filter1, :post_filter2]}) }
329
+ specify { expect(_request_post_filter { update_options(post_filter_mode: :or); update_post_filters([:post_filter1, :post_filter2]) })
330
+ .to eq({or: [:post_filter1, :post_filter2]}) }
331
+ specify { expect(_request_post_filter { update_options(post_filter_mode: :must); update_post_filters([:post_filter1, :post_filter2]) })
332
+ .to eq({bool: {must: [:post_filter1, :post_filter2]}}) }
333
+ specify { expect(_request_post_filter { update_options(post_filter_mode: :should); update_post_filters([:post_filter1, :post_filter2]) })
334
+ .to eq({bool: {should: [:post_filter1, :post_filter2]}}) }
331
335
 
332
336
  context do
333
- before { Chewy.stub(filter_mode: :or) }
337
+ before { allow(Chewy).to receive_messages(filter_mode: :or) }
334
338
 
335
- specify { _request_post_filter { update_post_filters([:post_filter1, :post_filter2]) }
336
- .should == {or: [:post_filter1, :post_filter2]} }
339
+ specify { expect(_request_post_filter { update_post_filters([:post_filter1, :post_filter2]) })
340
+ .to eq({or: [:post_filter1, :post_filter2]}) }
337
341
  end
338
342
  end
339
343
 
@@ -343,10 +347,10 @@ describe Chewy::Query::Criteria do
343
347
  subject.send(:_request_types)
344
348
  end
345
349
 
346
- specify { _request_types.should be_nil }
347
- specify { _request_types { update_types(:type1) }.should == {type: {value: 'type1'}} }
348
- specify { _request_types { update_types([:type1, :type2]) }
349
- .should == {or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]} }
350
+ specify { expect(_request_types).to be_nil }
351
+ specify { expect(_request_types { update_types(:type1) }).to eq({type: {value: 'type1'}}) }
352
+ specify { expect(_request_types { update_types([:type1, :type2]) })
353
+ .to eq({or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}) }
350
354
  end
351
355
 
352
356
  describe '#_queries_join' do
@@ -356,25 +360,29 @@ describe Chewy::Query::Criteria do
356
360
 
357
361
  let(:query) { {term: {field: 'value'}} }
358
362
 
359
- specify { _queries_join([], :dis_max).should be_nil }
360
- specify { _queries_join([query], :dis_max).should == query }
361
- specify { _queries_join([query, query], :dis_max).should == {dis_max: {queries: [query, query]}} }
363
+ specify { expect(_queries_join([], :dis_max)).to be_nil }
364
+ specify { expect(_queries_join([query], :dis_max)).to eq(query) }
365
+ specify { expect(_queries_join([query, query], :dis_max)).to eq({dis_max: {queries: [query, query]}}) }
362
366
 
363
- specify { _queries_join([], 0.7).should be_nil }
364
- specify { _queries_join([query], 0.7).should == query }
365
- specify { _queries_join([query, query], 0.7).should == {dis_max: {queries: [query, query], tie_breaker: 0.7}} }
367
+ specify { expect(_queries_join([], 0.7)).to be_nil }
368
+ specify { expect(_queries_join([query], 0.7)).to eq(query) }
369
+ specify { expect(_queries_join([query, query], 0.7)).to eq({dis_max: {queries: [query, query], tie_breaker: 0.7}}) }
366
370
 
367
- specify { _queries_join([], :must).should be_nil }
368
- specify { _queries_join([query], :must).should == query }
369
- specify { _queries_join([query, query], :must).should == {bool: {must: [query, query]}} }
371
+ specify { expect(_queries_join([], :must)).to be_nil }
372
+ specify { expect(_queries_join([query], :must)).to eq(query) }
373
+ specify { expect(_queries_join([query, query], :must)).to eq({bool: {must: [query, query]}}) }
370
374
 
371
- specify { _queries_join([], :should).should be_nil }
372
- specify { _queries_join([query], :should).should == query }
373
- specify { _queries_join([query, query], :should).should == {bool: {should: [query, query]}} }
375
+ specify { expect(_queries_join([], :should)).to be_nil }
376
+ specify { expect(_queries_join([query], :should)).to eq(query) }
377
+ specify { expect(_queries_join([query, query], :should)).to eq({bool: {should: [query, query]}}) }
374
378
 
375
- specify { _queries_join([], '25%').should be_nil }
376
- specify { _queries_join([query], '25%').should == query }
377
- specify { _queries_join([query, query], '25%').should == {bool: {should: [query, query], minimum_should_match: '25%'}} }
379
+ specify { expect(_queries_join([], :must_not)).to be_nil }
380
+ specify { expect(_queries_join([query], :must_not)).to eq({bool: {must_not: [query]}}) }
381
+ specify { expect(_queries_join([query, query], :must_not)).to eq({bool: {must_not: [query, query]}}) }
382
+
383
+ specify { expect(_queries_join([], '25%')).to be_nil }
384
+ specify { expect(_queries_join([query], '25%')).to eq(query) }
385
+ specify { expect(_queries_join([query, query], '25%')).to eq({bool: {should: [query, query], minimum_should_match: '25%'}}) }
378
386
  end
379
387
 
380
388
  describe '#_filters_join' do
@@ -384,24 +392,28 @@ describe Chewy::Query::Criteria do
384
392
 
385
393
  let(:filter) { {term: {field: 'value'}} }
386
394
 
387
- specify { _filters_join([], :and).should be_nil }
388
- specify { _filters_join([filter], :and).should == filter }
389
- specify { _filters_join([filter, filter], :and).should == {and: [filter, filter]} }
395
+ specify { expect(_filters_join([], :and)).to be_nil }
396
+ specify { expect(_filters_join([filter], :and)).to eq(filter) }
397
+ specify { expect(_filters_join([filter, filter], :and)).to eq({and: [filter, filter]}) }
398
+
399
+ specify { expect(_filters_join([], :or)).to be_nil }
400
+ specify { expect(_filters_join([filter], :or)).to eq(filter) }
401
+ specify { expect(_filters_join([filter, filter], :or)).to eq({or: [filter, filter]}) }
390
402
 
391
- specify { _filters_join([], :or).should be_nil }
392
- specify { _filters_join([filter], :or).should == filter }
393
- specify { _filters_join([filter, filter], :or).should == {or: [filter, filter]} }
403
+ specify { expect(_filters_join([], :must)).to be_nil }
404
+ specify { expect(_filters_join([filter], :must)).to eq(filter) }
405
+ specify { expect(_filters_join([filter, filter], :must)).to eq({bool: {must: [filter, filter]}}) }
394
406
 
395
- specify { _filters_join([], :must).should be_nil }
396
- specify { _filters_join([filter], :must).should == filter }
397
- specify { _filters_join([filter, filter], :must).should == {bool: {must: [filter, filter]}} }
407
+ specify { expect(_filters_join([], :should)).to be_nil }
408
+ specify { expect(_filters_join([filter], :should)).to eq(filter) }
409
+ specify { expect(_filters_join([filter, filter], :should)).to eq({bool: {should: [filter, filter]}}) }
398
410
 
399
- specify { _filters_join([], :should).should be_nil }
400
- specify { _filters_join([filter], :should).should == filter }
401
- specify { _filters_join([filter, filter], :should).should == {bool: {should: [filter, filter]}} }
411
+ specify { expect(_filters_join([], :must_not)).to be_nil }
412
+ specify { expect(_filters_join([filter], :must_not)).to eq({bool: {must_not: [filter]}}) }
413
+ specify { expect(_filters_join([filter, filter], :must_not)).to eq({bool: {must_not: [filter, filter]}}) }
402
414
 
403
- specify { _filters_join([], '25%').should be_nil }
404
- specify { _filters_join([filter], '25%').should == filter }
405
- specify { _filters_join([filter, filter], '25%').should == {bool: {should: [filter, filter], minimum_should_match: '25%'}} }
415
+ specify { expect(_filters_join([], '25%')).to be_nil }
416
+ specify { expect(_filters_join([filter], '25%')).to eq(filter) }
417
+ specify { expect(_filters_join([filter, filter], '25%')).to eq({bool: {should: [filter, filter], minimum_should_match: '25%'}}) }
406
418
  end
407
419
  end