chewy 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +26 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +3 -1
- data/README.md +2 -10
- data/chewy.gemspec +0 -1
- data/gemfiles/Gemfile.rails-3.2.active_record +6 -0
- data/gemfiles/Gemfile.rails-3.2.active_record.kaminari +7 -0
- data/gemfiles/Gemfile.rails-3.2.active_record.will_paginate +7 -0
- data/gemfiles/Gemfile.rails-4.0.active_record +6 -0
- data/gemfiles/Gemfile.rails-4.0.active_record.kaminari +7 -0
- data/gemfiles/Gemfile.rails-4.0.active_record.will_paginate +7 -0
- data/gemfiles/Gemfile.rails-4.0.mongoid +6 -0
- data/gemfiles/Gemfile.rails-4.0.mongoid.kaminari +7 -0
- data/gemfiles/Gemfile.rails-4.0.mongoid.will_paginate +7 -0
- data/gemfiles/Gemfile.rails-4.1.active_record +6 -0
- data/gemfiles/Gemfile.rails-4.1.active_record.kaminari +7 -0
- data/gemfiles/Gemfile.rails-4.1.active_record.will_paginate +7 -0
- data/gemfiles/Gemfile.rails-4.1.mongoid +6 -0
- data/gemfiles/Gemfile.rails-4.1.mongoid.kaminari +7 -0
- data/gemfiles/Gemfile.rails-4.1.mongoid.will_paginate +7 -0
- data/gemfiles/Gemfile.rails-4.2.active_record +6 -0
- data/gemfiles/Gemfile.rails-4.2.active_record.kaminari +7 -0
- data/gemfiles/Gemfile.rails-4.2.active_record.will_paginate +7 -0
- data/gemfiles/Gemfile.rails-4.2.mongoid +6 -0
- data/gemfiles/Gemfile.rails-4.2.mongoid.kaminari +7 -0
- data/gemfiles/Gemfile.rails-4.2.mongoid.will_paginate +7 -0
- data/lib/chewy.rb +33 -5
- data/lib/chewy/config.rb +1 -0
- data/lib/chewy/index/search.rb +6 -3
- data/lib/chewy/query.rb +74 -1
- data/lib/chewy/query/compose.rb +4 -4
- data/lib/chewy/query/pagination.rb +5 -4
- data/lib/chewy/query/pagination/kaminari.rb +1 -1
- data/lib/chewy/query/pagination/will_paginate.rb +27 -0
- data/lib/chewy/type.rb +1 -0
- data/lib/chewy/type/adapter/active_record.rb +2 -2
- data/lib/chewy/type/adapter/mongoid.rb +147 -0
- data/lib/chewy/type/adapter/object.rb +1 -1
- data/lib/chewy/type/import.rb +1 -0
- data/lib/chewy/type/observe.rb +34 -6
- data/lib/chewy/version.rb +1 -1
- data/spec/chewy/config_spec.rb +17 -17
- data/spec/chewy/fields/base_spec.rb +62 -62
- data/spec/chewy/fields/root_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +127 -127
- data/spec/chewy/index/aliases_spec.rb +9 -9
- data/spec/chewy/index/search_spec.rb +4 -4
- data/spec/chewy/index/settings_spec.rb +33 -33
- data/spec/chewy/index_spec.rb +49 -49
- data/spec/chewy/query/criteria_spec.rb +173 -161
- data/spec/chewy/query/filters_spec.rb +76 -76
- data/spec/chewy/query/loading_spec.rb +54 -23
- data/spec/chewy/query/nodes/and_spec.rb +4 -4
- data/spec/chewy/query/nodes/bool_spec.rb +8 -8
- data/spec/chewy/query/nodes/equal_spec.rb +19 -19
- data/spec/chewy/query/nodes/exists_spec.rb +6 -6
- data/spec/chewy/query/nodes/has_child_spec.rb +25 -25
- data/spec/chewy/query/nodes/has_parent_spec.rb +25 -25
- data/spec/chewy/query/nodes/match_all_spec.rb +1 -1
- data/spec/chewy/query/nodes/missing_spec.rb +4 -4
- data/spec/chewy/query/nodes/not_spec.rb +4 -4
- data/spec/chewy/query/nodes/or_spec.rb +4 -4
- data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
- data/spec/chewy/query/nodes/query_spec.rb +2 -2
- data/spec/chewy/query/nodes/range_spec.rb +18 -18
- data/spec/chewy/query/nodes/raw_spec.rb +1 -1
- data/spec/chewy/query/nodes/regexp_spec.rb +18 -18
- data/spec/chewy/query/nodes/script_spec.rb +4 -4
- data/spec/chewy/query/pagination/kaminari_spec.rb +41 -39
- data/spec/chewy/query/pagination/will_paginage_spec.rb +60 -0
- data/spec/chewy/query/pagination_spec.rb +8 -7
- data/spec/chewy/query_spec.rb +166 -167
- data/spec/chewy/rspec/update_index_spec.rb +1 -1
- data/spec/chewy/runtime/version_spec.rb +30 -30
- data/spec/chewy/runtime_spec.rb +3 -3
- data/spec/chewy/type/actions_spec.rb +3 -3
- data/spec/chewy/type/adapter/active_record_spec.rb +143 -143
- data/spec/chewy/type/adapter/mongoid_spec.rb +219 -0
- data/spec/chewy/type/adapter/object_spec.rb +39 -39
- data/spec/chewy/type/import_spec.rb +67 -37
- data/spec/chewy/type/mapping_spec.rb +12 -12
- data/spec/chewy/type/observe_spec.rb +5 -6
- data/spec/chewy/type/wrapper_spec.rb +12 -12
- data/spec/chewy_spec.rb +26 -28
- data/spec/spec_helper.rb +19 -31
- data/spec/support/active_record.rb +52 -0
- data/spec/support/class_helpers.rb +0 -4
- data/spec/support/mongoid.rb +87 -0
- metadata +33 -18
- data/gemfiles/Gemfile.rails-3.2 +0 -15
- data/gemfiles/Gemfile.rails-4.0 +0 -15
@@ -2,47 +2,47 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chewy::Runtime::Version do
|
4
4
|
describe '#major' do
|
5
|
-
specify { described_class.new('1.2.3').major.
|
6
|
-
specify { described_class.new('1.2').major.
|
7
|
-
specify { described_class.new(1.2).major.
|
8
|
-
specify { described_class.new('1').major.
|
9
|
-
specify { described_class.new('').major.
|
5
|
+
specify { expect(described_class.new('1.2.3').major).to eq(1) }
|
6
|
+
specify { expect(described_class.new('1.2').major).to eq(1) }
|
7
|
+
specify { expect(described_class.new(1.2).major).to eq(1) }
|
8
|
+
specify { expect(described_class.new('1').major).to eq(1) }
|
9
|
+
specify { expect(described_class.new('').major).to eq(0) }
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '#minor' do
|
13
|
-
specify { described_class.new('1.2.3').minor.
|
14
|
-
specify { described_class.new('1.2').minor.
|
15
|
-
specify { described_class.new(1.2).minor.
|
16
|
-
specify { described_class.new('1').minor.
|
13
|
+
specify { expect(described_class.new('1.2.3').minor).to eq(2) }
|
14
|
+
specify { expect(described_class.new('1.2').minor).to eq(2) }
|
15
|
+
specify { expect(described_class.new(1.2).minor).to eq(2) }
|
16
|
+
specify { expect(described_class.new('1').minor).to eq(0) }
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '#patch' do
|
20
|
-
specify { described_class.new('1.2.3').patch.
|
21
|
-
specify { described_class.new('1.2.3.pre1').patch.
|
22
|
-
specify { described_class.new('1.2').patch.
|
23
|
-
specify { described_class.new(1.2).patch.
|
20
|
+
specify { expect(described_class.new('1.2.3').patch).to eq(3) }
|
21
|
+
specify { expect(described_class.new('1.2.3.pre1').patch).to eq(3) }
|
22
|
+
specify { expect(described_class.new('1.2').patch).to eq(0) }
|
23
|
+
specify { expect(described_class.new(1.2).patch).to eq(0) }
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#to_s' do
|
27
|
-
specify { described_class.new('1.2.3').to_s.
|
28
|
-
specify { described_class.new('1.2.3.pre1').to_s.
|
29
|
-
specify { described_class.new('1.2').to_s.
|
30
|
-
specify { described_class.new(1.2).to_s.
|
31
|
-
specify { described_class.new('1').to_s.
|
32
|
-
specify { described_class.new('').to_s.
|
27
|
+
specify { expect(described_class.new('1.2.3').to_s).to eq('1.2.3') }
|
28
|
+
specify { expect(described_class.new('1.2.3.pre1').to_s).to eq('1.2.3') }
|
29
|
+
specify { expect(described_class.new('1.2').to_s).to eq('1.2.0') }
|
30
|
+
specify { expect(described_class.new(1.2).to_s).to eq('1.2.0') }
|
31
|
+
specify { expect(described_class.new('1').to_s).to eq('1.0.0') }
|
32
|
+
specify { expect(described_class.new('').to_s).to eq('0.0.0') }
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#<=>' do
|
36
|
-
specify { described_class.new('1.2.3').
|
37
|
-
specify { described_class.new('1.2.3').
|
38
|
-
specify { described_class.new('1.2.3').
|
39
|
-
specify { described_class.new('1.10.2').
|
40
|
-
specify { described_class.new('1.10.2').
|
41
|
-
specify { described_class.new('2.10.2').
|
42
|
-
specify { described_class.new('1.10.2').
|
43
|
-
specify { described_class.new('1.10.2').
|
44
|
-
specify { described_class.new('1.10.2').
|
45
|
-
specify { described_class.new('1.10.2').
|
46
|
-
specify { described_class.new('1.2.0').
|
36
|
+
specify { expect(described_class.new('1.2.3')).to eq('1.2.3') }
|
37
|
+
specify { expect(described_class.new('1.2.3')).to be < '1.2.4' }
|
38
|
+
specify { expect(described_class.new('1.2.3')).to be < '1.2.10' }
|
39
|
+
specify { expect(described_class.new('1.10.2')).to eq('1.10.2') }
|
40
|
+
specify { expect(described_class.new('1.10.2')).to be > '1.7.2' }
|
41
|
+
specify { expect(described_class.new('2.10.2')).to be > '1.7.2' }
|
42
|
+
specify { expect(described_class.new('1.10.2')).to be < '2.7.2' }
|
43
|
+
specify { expect(described_class.new('1.10.2')).to be < described_class.new('2.7.2') }
|
44
|
+
specify { expect(described_class.new('1.10.2')).to be < 2.7 }
|
45
|
+
specify { expect(described_class.new('1.10.2')).to be < 1.11 }
|
46
|
+
specify { expect(described_class.new('1.2.0')).to eq('1.2') }
|
47
47
|
end
|
48
48
|
end
|
data/spec/chewy/runtime_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chewy::Runtime do
|
4
4
|
describe '.version' do
|
5
|
-
specify { described_class.version.
|
6
|
-
specify { described_class.version.
|
7
|
-
specify { described_class.version.
|
5
|
+
specify { expect(described_class.version).to be_a(described_class::Version) }
|
6
|
+
specify { expect(described_class.version).to be >= '1.0' }
|
7
|
+
specify { expect(described_class.version).to be < '1.4' }
|
8
8
|
end
|
9
9
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Chewy::Type::Actions do
|
4
|
-
before { Chewy.
|
3
|
+
describe Chewy::Type::Actions, :orm do
|
4
|
+
before { Chewy.massacre }
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_model(:city)
|
@@ -25,4 +25,4 @@ describe Chewy::Type::Actions do
|
|
25
25
|
describe '.reset' do
|
26
26
|
specify { expect { city.reset }.to update_index(city) }
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Chewy::Type::Adapter::ActiveRecord do
|
3
|
+
describe Chewy::Type::Adapter::ActiveRecord, :active_record do
|
4
4
|
before { stub_model(:city) }
|
5
5
|
|
6
6
|
describe '#name' do
|
7
|
-
specify { described_class.new(City).name.
|
8
|
-
specify { described_class.new(City.order(:id)).name.
|
9
|
-
specify { described_class.new(City, name: 'town').name.
|
7
|
+
specify { expect(described_class.new(City).name).to eq('City') }
|
8
|
+
specify { expect(described_class.new(City.order(:id)).name).to eq('City') }
|
9
|
+
specify { expect(described_class.new(City, name: 'town').name).to eq('Town') }
|
10
10
|
|
11
11
|
context do
|
12
12
|
before { stub_model('namespace/city') }
|
13
13
|
|
14
|
-
specify { described_class.new(Namespace::City).name.
|
15
|
-
specify { described_class.new(Namespace::City.order(:id)).name.
|
14
|
+
specify { expect(described_class.new(Namespace::City).name).to eq('City') }
|
15
|
+
specify { expect(described_class.new(Namespace::City.order(:id)).name).to eq('City') }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe '#type_name' do
|
20
|
-
specify { described_class.new(City).type_name.
|
21
|
-
specify { described_class.new(City.order(:id)).type_name.
|
22
|
-
specify { described_class.new(City, name: 'town').type_name.
|
20
|
+
specify { expect(described_class.new(City).type_name).to eq('city') }
|
21
|
+
specify { expect(described_class.new(City.order(:id)).type_name).to eq('city') }
|
22
|
+
specify { expect(described_class.new(City, name: 'town').type_name).to eq('town') }
|
23
23
|
|
24
24
|
context do
|
25
25
|
before { stub_model('namespace/city') }
|
26
26
|
|
27
|
-
specify { described_class.new(Namespace::City).type_name.
|
28
|
-
specify { described_class.new(Namespace::City.order(:id)).type_name.
|
27
|
+
specify { expect(described_class.new(Namespace::City).type_name).to eq('city') }
|
28
|
+
specify { expect(described_class.new(Namespace::City.order(:id)).type_name).to eq('city') }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -41,54 +41,54 @@ describe Chewy::Type::Adapter::ActiveRecord do
|
|
41
41
|
let!(:deleted) { 3.times.map { |i| City.create!.tap(&:destroy) } }
|
42
42
|
subject { described_class.new(City) }
|
43
43
|
|
44
|
-
specify { import.
|
44
|
+
specify { expect(import).to eq([{index: cities}]) }
|
45
45
|
|
46
|
-
specify { import(City.order(:id)).
|
47
|
-
specify { import(City.order(:id), batch_size: 2)
|
48
|
-
.
|
46
|
+
specify { expect(import(City.order(:id))).to eq([{index: cities}]) }
|
47
|
+
specify { expect(import(City.order(:id), batch_size: 2))
|
48
|
+
.to eq([{index: cities.first(2)}, {index: cities.last(1)}]) }
|
49
49
|
|
50
|
-
specify { import(cities).
|
51
|
-
specify { import(cities, batch_size: 2)
|
52
|
-
.
|
53
|
-
specify { import(cities, deleted).
|
54
|
-
specify { import(cities, deleted, batch_size: 2).
|
50
|
+
specify { expect(import(cities)).to eq([{index: cities}]) }
|
51
|
+
specify { expect(import(cities, batch_size: 2))
|
52
|
+
.to eq([{index: cities.first(2)}, {index: cities.last(1)}]) }
|
53
|
+
specify { expect(import(cities, deleted)).to eq([{index: cities, delete: deleted}]) }
|
54
|
+
specify { expect(import(cities, deleted, batch_size: 2)).to eq([
|
55
55
|
{index: cities.first(2)},
|
56
56
|
{index: cities.last(1), delete: deleted.first(1)},
|
57
|
-
{delete: deleted.last(2)}] }
|
58
|
-
|
59
|
-
specify { import(cities.map(&:id)).
|
60
|
-
specify { import(deleted.map(&:id)).
|
61
|
-
specify { import(cities.map(&:id), batch_size: 2)
|
62
|
-
.
|
63
|
-
specify { import(cities.map(&:id), deleted.map(&:id))
|
64
|
-
.
|
65
|
-
specify { import(cities.map(&:id), deleted.map(&:id), batch_size: 2).
|
57
|
+
{delete: deleted.last(2)}]) }
|
58
|
+
|
59
|
+
specify { expect(import(cities.map(&:id))).to eq([{index: cities}]) }
|
60
|
+
specify { expect(import(deleted.map(&:id))).to eq([{delete: deleted.map(&:id)}]) }
|
61
|
+
specify { expect(import(cities.map(&:id), batch_size: 2))
|
62
|
+
.to eq([{index: cities.first(2)}, {index: cities.last(1)}]) }
|
63
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id)))
|
64
|
+
.to eq([{index: cities}, {delete: deleted.map(&:id)}]) }
|
65
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id), batch_size: 2)).to eq([
|
66
66
|
{index: cities.first(2)},
|
67
67
|
{index: cities.last(1)},
|
68
68
|
{delete: deleted.first(2).map(&:id)},
|
69
|
-
{delete: deleted.last(1).map(&:id)}] }
|
69
|
+
{delete: deleted.last(1).map(&:id)}]) }
|
70
70
|
|
71
|
-
specify { import(cities.first, nil).
|
72
|
-
specify { import(cities.first.id, nil).
|
71
|
+
specify { expect(import(cities.first, nil)).to eq([{index: [cities.first]}]) }
|
72
|
+
specify { expect(import(cities.first.id, nil)).to eq([{index: [cities.first]}]) }
|
73
73
|
|
74
74
|
context do
|
75
|
-
before { deleted.map { |object| object.
|
76
|
-
specify { import(deleted).
|
75
|
+
before { deleted.map { |object| allow(object).to receive_messages(delete_from_index?: true, destroyed?: true) } }
|
76
|
+
specify { expect(import(deleted)).to eq([{delete: deleted}]) }
|
77
77
|
end
|
78
78
|
|
79
79
|
context do
|
80
|
-
before { deleted.map { |object| object.
|
81
|
-
specify { import(deleted).
|
80
|
+
before { deleted.map { |object| allow(object).to receive_messages(delete_from_index?: true, destroyed?: false) } }
|
81
|
+
specify { expect(import(deleted)).to eq([{delete: deleted}]) }
|
82
82
|
end
|
83
83
|
|
84
84
|
context do
|
85
|
-
before { deleted.map { |object| object.
|
86
|
-
specify { import(deleted).
|
85
|
+
before { deleted.map { |object| allow(object).to receive_messages(delete_from_index?: false, destroyed?: true) } }
|
86
|
+
specify { expect(import(deleted)).to eq([{delete: deleted}]) }
|
87
87
|
end
|
88
88
|
|
89
89
|
context do
|
90
|
-
before { deleted.map { |object| object.
|
91
|
-
specify { import(deleted).
|
90
|
+
before { deleted.map { |object| allow(object).to receive_messages(delete_from_index?: false, destroyed?: false) } }
|
91
|
+
specify { expect(import(deleted)).to eq([{index: deleted}]) }
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -104,10 +104,10 @@ describe Chewy::Type::Adapter::ActiveRecord do
|
|
104
104
|
let!(:deleted) { 3.times.map { |i| City.create!(rating: 42) } }
|
105
105
|
subject { described_class.new(City) }
|
106
106
|
|
107
|
-
specify { import(cities, deleted).
|
108
|
-
specify { import(cities.map(&:id), deleted.map(&:id))
|
109
|
-
.
|
110
|
-
specify { import(City.order(:id)).
|
107
|
+
specify { expect(import(cities, deleted)).to eq([{index: cities, delete: deleted}]) }
|
108
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id)))
|
109
|
+
.to eq([{index: cities, delete: deleted}]) }
|
110
|
+
specify { expect(import(City.order(:id))).to eq([{index: cities, delete: deleted}]) }
|
111
111
|
end
|
112
112
|
|
113
113
|
context 'custom primary_key' do
|
@@ -116,58 +116,58 @@ describe Chewy::Type::Adapter::ActiveRecord do
|
|
116
116
|
let!(:deleted) { 3.times.map { |i| City.create! { |c| c.rating = i + 10 }.tap(&:destroy) } }
|
117
117
|
subject { described_class.new(City) }
|
118
118
|
|
119
|
-
specify { import.
|
119
|
+
specify { expect(import).to eq([{index: cities}]) }
|
120
120
|
|
121
|
-
specify { import(City.order(:rating)).
|
122
|
-
specify { import(City.order(:rating), batch_size: 2)
|
123
|
-
.
|
121
|
+
specify { expect(import(City.order(:rating))).to eq([{index: cities}]) }
|
122
|
+
specify { expect(import(City.order(:rating), batch_size: 2))
|
123
|
+
.to eq([{index: cities.first(2)}, {index: cities.last(1)}]) }
|
124
124
|
|
125
|
-
specify { import(cities).
|
126
|
-
specify { import(cities, batch_size: 2)
|
127
|
-
.
|
128
|
-
specify { import(cities, deleted).
|
129
|
-
specify { import(cities, deleted, batch_size: 2).
|
125
|
+
specify { expect(import(cities)).to eq([{index: cities}]) }
|
126
|
+
specify { expect(import(cities, batch_size: 2))
|
127
|
+
.to eq([{index: cities.first(2)}, {index: cities.last(1)}]) }
|
128
|
+
specify { expect(import(cities, deleted)).to eq([{index: cities, delete: deleted}]) }
|
129
|
+
specify { expect(import(cities, deleted, batch_size: 2)).to eq([
|
130
130
|
{index: cities.first(2)},
|
131
131
|
{index: cities.last(1), delete: deleted.first(1)},
|
132
|
-
{delete: deleted.last(2)}] }
|
133
|
-
|
134
|
-
specify { import(cities.map(&:id)).
|
135
|
-
specify { import(cities.map(&:id), batch_size: 2)
|
136
|
-
.
|
137
|
-
specify { import(cities.map(&:id), deleted.map(&:id))
|
138
|
-
.
|
139
|
-
specify { import(cities.map(&:id), deleted.map(&:id), batch_size: 2).
|
132
|
+
{delete: deleted.last(2)}]) }
|
133
|
+
|
134
|
+
specify { expect(import(cities.map(&:id))).to eq([{index: cities}]) }
|
135
|
+
specify { expect(import(cities.map(&:id), batch_size: 2))
|
136
|
+
.to eq([{index: cities.first(2)}, {index: cities.last(1)}]) }
|
137
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id)))
|
138
|
+
.to eq([{index: cities}, {delete: deleted.map(&:id)}]) }
|
139
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id), batch_size: 2)).to eq([
|
140
140
|
{index: cities.first(2)},
|
141
141
|
{index: cities.last(1)},
|
142
142
|
{delete: deleted.first(2).map(&:id)},
|
143
|
-
{delete: deleted.last(1).map(&:id)}] }
|
143
|
+
{delete: deleted.last(1).map(&:id)}]) }
|
144
144
|
end
|
145
145
|
|
146
146
|
context 'default scope' do
|
147
|
-
let!(:cities) {
|
148
|
-
let!(:deleted) {
|
149
|
-
subject { described_class.new(City.where(
|
150
|
-
|
151
|
-
specify { import.
|
152
|
-
|
153
|
-
specify { import(City.order(:id)).
|
154
|
-
specify { import(City.order(:id), batch_size:
|
155
|
-
.
|
156
|
-
|
157
|
-
specify { import(cities).
|
158
|
-
specify { import(cities, batch_size:
|
159
|
-
.
|
160
|
-
|
161
|
-
specify { import(cities.map(&:id))
|
162
|
-
.
|
163
|
-
specify { import(cities.map(&:id), batch_size:
|
164
|
-
.
|
165
|
-
specify { import(cities.map(&:id), deleted.map(&:id))
|
166
|
-
.
|
167
|
-
specify { import(cities.map(&:id), deleted.map(&:id), batch_size:
|
168
|
-
{index: cities.first(
|
169
|
-
{delete: [cities.last.id] + deleted.first(
|
170
|
-
{delete: deleted.last(1).map(&:id)}] }
|
147
|
+
let!(:cities) { 4.times.map { |i| City.create!(rating: i/3) } }
|
148
|
+
let!(:deleted) { 3.times.map { |i| City.create!.tap(&:destroy) } }
|
149
|
+
subject { described_class.new(City.where(rating: 0)) }
|
150
|
+
|
151
|
+
specify { expect(import).to eq([{index: cities.first(3)}]) }
|
152
|
+
|
153
|
+
specify { expect(import(City.order(:id))).to eq([{index: cities.first(3)}]) }
|
154
|
+
specify { expect(import(City.order(:id), batch_size: 2))
|
155
|
+
.to eq([{index: cities.first(2)}, {index: [cities[2]]}]) }
|
156
|
+
|
157
|
+
specify { expect(import(cities)).to eq([{index: cities}]) }
|
158
|
+
specify { expect(import(cities, batch_size: 3))
|
159
|
+
.to eq([{index: cities.first(3)}, {index: cities.last(1)}]) }
|
160
|
+
|
161
|
+
specify { expect(import(cities.map(&:id)))
|
162
|
+
.to eq([{index: cities.first(3)}, {delete: [cities.last.id]}]) }
|
163
|
+
specify { expect(import(cities.map(&:id), batch_size: 2))
|
164
|
+
.to eq([{index: cities.first(2)}, {index: [cities[2]]}, {delete: [cities.last.id]}]) }
|
165
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id)))
|
166
|
+
.to eq([{index: cities.first(3)}, {delete: [cities.last.id] + deleted.map(&:id)}]) }
|
167
|
+
specify { expect(import(cities.map(&:id), deleted.map(&:id), batch_size: 3)).to eq([
|
168
|
+
{index: cities.first(3)},
|
169
|
+
{delete: [cities.last.id] + deleted.first(2).map(&:id)},
|
170
|
+
{delete: deleted.last(1).map(&:id)}]) }
|
171
171
|
end
|
172
172
|
|
173
173
|
context 'error handling' do
|
@@ -181,72 +181,72 @@ describe Chewy::Type::Adapter::ActiveRecord do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
context 'implicit scope' do
|
184
|
-
specify { subject.import { |data| true }.
|
185
|
-
specify { subject.import { |data| false }.
|
186
|
-
specify { subject.import(batch_size: 1, &data_comparer.curry[cities[0].id]).
|
187
|
-
specify { subject.import(batch_size: 1, &data_comparer.curry[cities[1].id]).
|
188
|
-
specify { subject.import(batch_size: 1, &data_comparer.curry[cities[2].id]).
|
189
|
-
specify { subject.import(batch_size: 1, &data_comparer.curry[deleted[0].id]).
|
190
|
-
specify { subject.import(batch_size: 1, &data_comparer.curry[deleted[1].id]).
|
184
|
+
specify { expect(subject.import { |data| true }).to eq(true) }
|
185
|
+
specify { expect(subject.import { |data| false }).to eq(false) }
|
186
|
+
specify { expect(subject.import(batch_size: 1, &data_comparer.curry[cities[0].id])).to eq(false) }
|
187
|
+
specify { expect(subject.import(batch_size: 1, &data_comparer.curry[cities[1].id])).to eq(false) }
|
188
|
+
specify { expect(subject.import(batch_size: 1, &data_comparer.curry[cities[2].id])).to eq(false) }
|
189
|
+
specify { expect(subject.import(batch_size: 1, &data_comparer.curry[deleted[0].id])).to eq(true) }
|
190
|
+
specify { expect(subject.import(batch_size: 1, &data_comparer.curry[deleted[1].id])).to eq(true) }
|
191
191
|
end
|
192
192
|
|
193
193
|
context 'explicit scope' do
|
194
194
|
let(:scope) { City.where(id: ids) }
|
195
195
|
|
196
|
-
specify { subject.import(scope) { |data| true }.
|
197
|
-
specify { subject.import(scope) { |data| false }.
|
198
|
-
specify { subject.import(scope, batch_size: 1, &data_comparer.curry[cities[0].id]).
|
199
|
-
specify { subject.import(scope, batch_size: 1, &data_comparer.curry[cities[1].id]).
|
200
|
-
specify { subject.import(scope, batch_size: 1, &data_comparer.curry[cities[2].id]).
|
201
|
-
specify { subject.import(scope, batch_size: 1, &data_comparer.curry[deleted[0].id]).
|
202
|
-
specify { subject.import(scope, batch_size: 1, &data_comparer.curry[deleted[1].id]).
|
196
|
+
specify { expect(subject.import(scope) { |data| true }).to eq(true) }
|
197
|
+
specify { expect(subject.import(scope) { |data| false }).to eq(false) }
|
198
|
+
specify { expect(subject.import(scope, batch_size: 1, &data_comparer.curry[cities[0].id])).to eq(false) }
|
199
|
+
specify { expect(subject.import(scope, batch_size: 1, &data_comparer.curry[cities[1].id])).to eq(false) }
|
200
|
+
specify { expect(subject.import(scope, batch_size: 1, &data_comparer.curry[cities[2].id])).to eq(false) }
|
201
|
+
specify { expect(subject.import(scope, batch_size: 1, &data_comparer.curry[deleted[0].id])).to eq(true) }
|
202
|
+
specify { expect(subject.import(scope, batch_size: 1, &data_comparer.curry[deleted[1].id])).to eq(true) }
|
203
203
|
end
|
204
204
|
|
205
205
|
context 'objects' do
|
206
|
-
specify { subject.import(cities + deleted) { |data| true }.
|
207
|
-
specify { subject.import(cities + deleted) { |data| false }.
|
208
|
-
specify { subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[0].id]).
|
209
|
-
specify { subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[1].id]).
|
210
|
-
specify { subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[2].id]).
|
211
|
-
specify { subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[0].id]).
|
212
|
-
specify { subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[1].id]).
|
206
|
+
specify { expect(subject.import(cities + deleted) { |data| true }).to eq(true) }
|
207
|
+
specify { expect(subject.import(cities + deleted) { |data| false }).to eq(false) }
|
208
|
+
specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[0].id])).to eq(false) }
|
209
|
+
specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[1].id])).to eq(false) }
|
210
|
+
specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[2].id])).to eq(false) }
|
211
|
+
specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[0].id])).to eq(false) }
|
212
|
+
specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[1].id])).to eq(false) }
|
213
213
|
end
|
214
214
|
|
215
215
|
context 'ids' do
|
216
|
-
specify { subject.import(ids) { |data| true }.
|
217
|
-
specify { subject.import(ids) { |data| false }.
|
218
|
-
specify { subject.import(ids, batch_size: 1, &data_comparer.curry[cities[0].id]).
|
219
|
-
specify { subject.import(ids, batch_size: 1, &data_comparer.curry[cities[1].id]).
|
220
|
-
specify { subject.import(ids, batch_size: 1, &data_comparer.curry[cities[2].id]).
|
221
|
-
specify { subject.import(ids, batch_size: 1, &data_comparer.curry[deleted[0].id]).
|
222
|
-
specify { subject.import(ids, batch_size: 1, &data_comparer.curry[deleted[1].id]).
|
216
|
+
specify { expect(subject.import(ids) { |data| true }).to eq(true) }
|
217
|
+
specify { expect(subject.import(ids) { |data| false }).to eq(false) }
|
218
|
+
specify { expect(subject.import(ids, batch_size: 1, &data_comparer.curry[cities[0].id])).to eq(false) }
|
219
|
+
specify { expect(subject.import(ids, batch_size: 1, &data_comparer.curry[cities[1].id])).to eq(false) }
|
220
|
+
specify { expect(subject.import(ids, batch_size: 1, &data_comparer.curry[cities[2].id])).to eq(false) }
|
221
|
+
specify { expect(subject.import(ids, batch_size: 1, &data_comparer.curry[deleted[0].id])).to eq(false) }
|
222
|
+
specify { expect(subject.import(ids, batch_size: 1, &data_comparer.curry[deleted[1].id])).to eq(false) }
|
223
223
|
end
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
227
|
describe '#load' do
|
228
228
|
context do
|
229
|
-
let!(:cities) { 3.times.map { |i| City.create!(
|
229
|
+
let!(:cities) { 3.times.map { |i| City.create!(rating: i/2) } }
|
230
230
|
let!(:deleted) { 2.times.map { |i| City.create!.tap(&:destroy) } }
|
231
231
|
|
232
232
|
let(:type) { double(type_name: 'user') }
|
233
233
|
|
234
234
|
subject { described_class.new(City) }
|
235
235
|
|
236
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }, _type: type).
|
237
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }.reverse, _type: type).
|
238
|
-
specify { subject.load(deleted.map { |c| double(id: c.id) }, _type: type).
|
239
|
-
specify { subject.load((cities + deleted).map { |c| double(id: c.id) }, _type: type).
|
240
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: ->{ where(
|
241
|
-
.
|
242
|
-
specify { subject.load(cities.map { |c| double(id: c.id) },
|
243
|
-
_type: type, scope: ->{ where(
|
244
|
-
.
|
245
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: City.where(
|
246
|
-
.
|
247
|
-
specify { subject.load(cities.map { |c| double(id: c.id) },
|
248
|
-
_type: type, scope: City.where(
|
249
|
-
.
|
236
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }, _type: type)).to eq(cities) }
|
237
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }.reverse, _type: type)).to eq(cities.reverse) }
|
238
|
+
specify { expect(subject.load(deleted.map { |c| double(id: c.id) }, _type: type)).to eq([nil, nil]) }
|
239
|
+
specify { expect(subject.load((cities + deleted).map { |c| double(id: c.id) }, _type: type)).to eq([*cities, nil, nil]) }
|
240
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: ->{ where(rating: 0) }))
|
241
|
+
.to eq(cities.first(2) + [nil]) }
|
242
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) },
|
243
|
+
_type: type, scope: ->{ where(rating: 0) }, user: {scope: ->{ where(rating: 1)}}))
|
244
|
+
.to eq([nil, nil] + cities.last(1)) }
|
245
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: City.where(rating: 1)))
|
246
|
+
.to eq([nil, nil] + cities.last(1)) }
|
247
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) },
|
248
|
+
_type: type, scope: City.where(rating: 1), user: {scope: ->{ where(rating: 0)}}))
|
249
|
+
.to eq(cities.first(2) + [nil]) }
|
250
250
|
end
|
251
251
|
|
252
252
|
context 'custom primary_key' do
|
@@ -258,20 +258,20 @@ describe Chewy::Type::Adapter::ActiveRecord do
|
|
258
258
|
|
259
259
|
subject { described_class.new(City) }
|
260
260
|
|
261
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }, _type: type).
|
262
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }.reverse, _type: type).
|
263
|
-
specify { subject.load(deleted.map { |c| double(id: c.id) }, _type: type).
|
264
|
-
specify { subject.load((cities + deleted).map { |c| double(id: c.id) }, _type: type).
|
265
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: ->{ where(country_id: 0) })
|
266
|
-
.
|
267
|
-
specify { subject.load(cities.map { |c| double(id: c.id) },
|
268
|
-
_type: type, scope: ->{ where(country_id: 0) }, user: {scope: ->{ where(country_id: 1)}})
|
269
|
-
.
|
270
|
-
specify { subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: City.where(country_id: 1))
|
271
|
-
.
|
272
|
-
specify { subject.load(cities.map { |c| double(id: c.id) },
|
273
|
-
_type: type, scope: City.where(country_id: 1), user: {scope: ->{ where(country_id: 0)}})
|
274
|
-
.
|
261
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }, _type: type)).to eq(cities) }
|
262
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }.reverse, _type: type)).to eq(cities.reverse) }
|
263
|
+
specify { expect(subject.load(deleted.map { |c| double(id: c.id) }, _type: type)).to eq([nil, nil]) }
|
264
|
+
specify { expect(subject.load((cities + deleted).map { |c| double(id: c.id) }, _type: type)).to eq([*cities, nil, nil]) }
|
265
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: ->{ where(country_id: 0) }))
|
266
|
+
.to eq(cities.first(2) + [nil]) }
|
267
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) },
|
268
|
+
_type: type, scope: ->{ where(country_id: 0) }, user: {scope: ->{ where(country_id: 1)}}))
|
269
|
+
.to eq([nil, nil] + cities.last(1)) }
|
270
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) }, _type: type, scope: City.where(country_id: 1)))
|
271
|
+
.to eq([nil, nil] + cities.last(1)) }
|
272
|
+
specify { expect(subject.load(cities.map { |c| double(id: c.id) },
|
273
|
+
_type: type, scope: City.where(country_id: 1), user: {scope: ->{ where(country_id: 0)}}))
|
274
|
+
.to eq(cities.first(2) + [nil]) }
|
275
275
|
end
|
276
276
|
end
|
277
277
|
end
|