chewy 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +0 -1
  4. data/.travis.yml +2 -2
  5. data/Appraisals +6 -2
  6. data/CHANGELOG.md +29 -1
  7. data/Gemfile +4 -0
  8. data/README.md +137 -19
  9. data/chewy.gemspec +1 -0
  10. data/gemfiles/rails.3.2.activerecord.gemfile +2 -0
  11. data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -1
  12. data/gemfiles/rails.4.0.activerecord.gemfile +2 -0
  13. data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +1 -1
  14. data/gemfiles/rails.4.0.mongoid.gemfile +2 -0
  15. data/gemfiles/rails.4.0.mongoid.kaminari.gemfile +1 -1
  16. data/gemfiles/rails.4.1.activerecord.gemfile +2 -0
  17. data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +1 -1
  18. data/gemfiles/rails.4.1.mongoid.gemfile +2 -0
  19. data/gemfiles/rails.4.1.mongoid.kaminari.gemfile +1 -1
  20. data/gemfiles/rails.4.2.activerecord.gemfile +2 -0
  21. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -1
  22. data/gemfiles/rails.4.2.mongoid.gemfile +2 -0
  23. data/gemfiles/rails.4.2.mongoid.kaminari.gemfile +1 -1
  24. data/lib/chewy.rb +1 -2
  25. data/lib/chewy/config.rb +3 -3
  26. data/lib/chewy/fields/base.rb +27 -30
  27. data/lib/chewy/fields/root.rb +9 -19
  28. data/lib/chewy/query.rb +34 -1
  29. data/lib/chewy/railtie.rb +1 -0
  30. data/lib/chewy/rspec/update_index.rb +16 -6
  31. data/lib/chewy/strategy.rb +12 -0
  32. data/lib/chewy/strategy/atomic.rb +1 -1
  33. data/lib/chewy/strategy/resque.rb +26 -0
  34. data/lib/chewy/strategy/sidekiq.rb +26 -0
  35. data/lib/chewy/strategy/urgent.rb +1 -1
  36. data/lib/chewy/type.rb +2 -0
  37. data/lib/chewy/type/adapter/active_record.rb +7 -3
  38. data/lib/chewy/type/adapter/mongoid.rb +5 -0
  39. data/lib/chewy/type/adapter/orm.rb +1 -1
  40. data/lib/chewy/type/crutch.rb +31 -0
  41. data/lib/chewy/type/import.rb +7 -6
  42. data/lib/chewy/type/mapping.rb +7 -3
  43. data/lib/chewy/type/observe.rb +24 -35
  44. data/lib/chewy/version.rb +1 -1
  45. data/spec/chewy/fields/base_spec.rb +26 -19
  46. data/spec/chewy/query_spec.rb +13 -0
  47. data/spec/chewy/runtime_spec.rb +1 -1
  48. data/spec/chewy/strategy/resque_spec.rb +35 -0
  49. data/spec/chewy/strategy/sidekiq_spec.rb +35 -0
  50. data/spec/chewy/type/adapter/mongoid_spec.rb +18 -9
  51. data/spec/chewy/type/mapping_spec.rb +14 -9
  52. data/spec/chewy/type/observe_spec.rb +22 -7
  53. data/spec/spec_helper.rb +1 -0
  54. metadata +23 -2
@@ -20,14 +20,17 @@ describe Chewy::Type::Mapping do
20
20
  end
21
21
 
22
22
  describe '.field' do
23
- specify { expect(product.root_object.nested.keys).to match_array([:name, :surname, :title, :price]) }
24
- specify { expect(product.root_object.nested.values).to satisfy { |v| v.all? { |f| f.is_a? Chewy::Fields::Base } } }
23
+ specify { expect(product.root_object.children.map(&:name)).to eq([:name, :surname, :title, :price]) }
24
+ specify { expect(product.root_object.children.map(&:parent)).to eq([product.root_object] * 4) }
25
25
 
26
- specify { expect(product.root_object.nested[:title].nested.keys).to eq([:subfield1]) }
27
- specify { expect(product.root_object.nested[:title].nested[:subfield1]).to be_a Chewy::Fields::Base }
26
+ specify { expect(product.root_object.children[0].children.map(&:name)).to eq([]) }
27
+ specify { expect(product.root_object.children[1].children.map(&:name)).to eq([]) }
28
28
 
29
- specify { expect(product.root_object.nested[:price].nested.keys).to eq([:subfield2]) }
30
- specify { expect(product.root_object.nested[:price].nested[:subfield2]).to be_a Chewy::Fields::Base }
29
+ specify { expect(product.root_object.children[2].children.map(&:name)).to eq([:subfield1]) }
30
+ specify { expect(product.root_object.children[2].children.map(&:parent)).to eq([product.root_object.children[2]]) }
31
+
32
+ specify { expect(product.root_object.children[3].children.map(&:name)).to eq([:subfield2]) }
33
+ specify { expect(product.root_object.children[3].children.map(&:parent)).to eq([product.root_object.children[3]]) }
31
34
  end
32
35
 
33
36
  describe '.mappings_hash' do
@@ -60,7 +63,7 @@ describe Chewy::Type::Mapping do
60
63
  end
61
64
  end
62
65
 
63
- specify { expect(product.mappings_hash[:product][:_parent]).to eq({ 'type' => 'project' }) }
66
+ specify { expect(product.mappings_hash[:product][:_parent]).to eq({ type: 'project' }) }
64
67
  end
65
68
  end
66
69
  end
@@ -76,7 +79,9 @@ describe Chewy::Type::Mapping do
76
79
  end
77
80
  end
78
81
 
79
- specify { expect(product.root_object.nested[:title].nested.keys).to eq([:subfield1]) }
80
- specify { expect(product.root_object.nested[:title].nested[:subfield1]).to be_a Chewy::Fields::Base }
82
+ specify { expect(product.root_object.children.map(&:name)).to eq([:title]) }
83
+ specify { expect(product.root_object.children.map(&:parent)).to eq([product.root_object]) }
84
+ specify { expect(product.root_object.children[0].children.map(&:name)).to eq([:subfield1]) }
85
+ specify { expect(product.root_object.children[0].children.map(&:parent)).to eq([product.root_object.children[0]]) }
81
86
  end
82
87
  end
@@ -22,7 +22,9 @@ describe Chewy::Type::Import do
22
22
  before do
23
23
  stub_model(:city) do
24
24
  update_index('cities#city') { self }
25
- update_index 'countries#country', :country
25
+ update_index 'countries#country' do
26
+ changes['country_id'] || previous_changes['country_id'] || country
27
+ end
26
28
  end
27
29
 
28
30
  stub_model(:country) do
@@ -42,14 +44,27 @@ describe Chewy::Type::Import do
42
44
  end
43
45
  end
44
46
 
45
- let(:city) { Chewy.strategy(:atomic) { City.create!(id: 1, country: Country.create!(id: 1)) } }
46
- let(:country) { Chewy.strategy(:atomic) { Country.create!(id: 1, cities: 2.times.map { |i| City.create!(id: i) }) } }
47
+ context do
48
+ let!(:country1) { Chewy.strategy(:atomic) { Country.create!(id: 1) } }
49
+ let!(:country2) { Chewy.strategy(:atomic) { Country.create!(id: 2) } }
50
+ let!(:city) { Chewy.strategy(:atomic) { City.create!(id: 1, country: country1) } }
51
+
52
+ specify { expect { city.save! }.to update_index('cities#city').and_reindex(city) }
53
+ specify { expect { city.save! }.to update_index('countries#country').and_reindex(country1) }
54
+
55
+ specify { expect { city.update_attributes!(country: nil) }.to update_index('cities#city').and_reindex(city) }
56
+ specify { expect { city.update_attributes!(country: nil) }.to update_index('countries#country').and_reindex(country1) }
47
57
 
48
- specify { expect { city.save! }.to update_index('cities#city').and_reindex(city) }
49
- specify { expect { city.save! }.to update_index('countries#country').and_reindex(city.country) }
50
- specify { expect { country.save! }.to update_index('cities#city').and_reindex(country.cities) }
51
- specify { expect { country.save! }.to update_index('countries#country').and_reindex(country) }
58
+ specify { expect { city.update_attributes!(country: country2) }.to update_index('cities#city').and_reindex(city) }
59
+ specify { expect { city.update_attributes!(country: country2) }.to update_index('countries#country').and_reindex(country1, country2) }
60
+ end
61
+
62
+ context do
63
+ let!(:country) { Chewy.strategy(:atomic) { Country.create!(id: 1, cities: 2.times.map { |i| City.create!(id: i) }) } }
52
64
 
65
+ specify { expect { country.save! }.to update_index('cities#city').and_reindex(country.cities) }
66
+ specify { expect { country.save! }.to update_index('countries#country').and_reindex(country) }
67
+ end
53
68
  end
54
69
 
55
70
  context 'transactions', :active_record do
@@ -28,6 +28,7 @@ Chewy.settings = {
28
28
 
29
29
  RSpec.configure do |config|
30
30
  config.mock_with :rspec
31
+ config.order = :random
31
32
 
32
33
  config.include FailHelpers
33
34
  config.include ClassHelpers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chewy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-25 00:00:00.000000000 Z
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: resque_spec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: activesupport
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +257,8 @@ files:
243
257
  - lib/chewy/strategy/atomic.rb
244
258
  - lib/chewy/strategy/base.rb
245
259
  - lib/chewy/strategy/bypass.rb
260
+ - lib/chewy/strategy/resque.rb
261
+ - lib/chewy/strategy/sidekiq.rb
246
262
  - lib/chewy/strategy/urgent.rb
247
263
  - lib/chewy/type.rb
248
264
  - lib/chewy/type/actions.rb
@@ -251,6 +267,7 @@ files:
251
267
  - lib/chewy/type/adapter/mongoid.rb
252
268
  - lib/chewy/type/adapter/object.rb
253
269
  - lib/chewy/type/adapter/orm.rb
270
+ - lib/chewy/type/crutch.rb
254
271
  - lib/chewy/type/import.rb
255
272
  - lib/chewy/type/mapping.rb
256
273
  - lib/chewy/type/observe.rb
@@ -295,6 +312,8 @@ files:
295
312
  - spec/chewy/runtime/version_spec.rb
296
313
  - spec/chewy/runtime_spec.rb
297
314
  - spec/chewy/search_spec.rb
315
+ - spec/chewy/strategy/resque_spec.rb
316
+ - spec/chewy/strategy/sidekiq_spec.rb
298
317
  - spec/chewy/strategy_spec.rb
299
318
  - spec/chewy/type/actions_spec.rb
300
319
  - spec/chewy/type/adapter/active_record_spec.rb
@@ -372,6 +391,8 @@ test_files:
372
391
  - spec/chewy/runtime/version_spec.rb
373
392
  - spec/chewy/runtime_spec.rb
374
393
  - spec/chewy/search_spec.rb
394
+ - spec/chewy/strategy/resque_spec.rb
395
+ - spec/chewy/strategy/sidekiq_spec.rb
375
396
  - spec/chewy/strategy_spec.rb
376
397
  - spec/chewy/type/actions_spec.rb
377
398
  - spec/chewy/type/adapter/active_record_spec.rb