chewy 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -8
  3. data/Appraisals +8 -0
  4. data/CHANGELOG.md +33 -6
  5. data/Gemfile +6 -4
  6. data/README.md +240 -111
  7. data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
  8. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
  9. data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
  10. data/gemfiles/sequel.4.23.gemfile +13 -0
  11. data/lib/chewy.rb +24 -11
  12. data/lib/chewy/config.rb +4 -4
  13. data/lib/chewy/index.rb +1 -1
  14. data/lib/chewy/index/settings.rb +1 -1
  15. data/lib/chewy/query.rb +43 -4
  16. data/lib/chewy/railtie.rb +2 -2
  17. data/lib/chewy/rake_helper.rb +62 -0
  18. data/lib/chewy/rspec/update_index.rb +3 -3
  19. data/lib/chewy/strategy.rb +6 -0
  20. data/lib/chewy/strategy/active_job.rb +28 -0
  21. data/lib/chewy/strategy/atomic.rb +1 -1
  22. data/lib/chewy/strategy/sidekiq.rb +3 -1
  23. data/lib/chewy/type.rb +2 -1
  24. data/lib/chewy/type/adapter/active_record.rb +9 -2
  25. data/lib/chewy/type/adapter/base.rb +6 -0
  26. data/lib/chewy/type/adapter/mongoid.rb +7 -1
  27. data/lib/chewy/type/adapter/orm.rb +1 -1
  28. data/lib/chewy/type/adapter/sequel.rb +125 -0
  29. data/lib/chewy/type/mapping.rb +26 -1
  30. data/lib/chewy/type/observe.rb +40 -17
  31. data/lib/chewy/version.rb +1 -1
  32. data/lib/sequel/plugins/chewy_observe.rb +71 -0
  33. data/lib/tasks/chewy.rake +19 -61
  34. data/spec/chewy/config_spec.rb +9 -5
  35. data/spec/chewy/fields/base_spec.rb +21 -7
  36. data/spec/chewy/index/actions_spec.rb +5 -5
  37. data/spec/chewy/query_spec.rb +69 -0
  38. data/spec/chewy/runtime_spec.rb +1 -1
  39. data/spec/chewy/strategy/active_job_spec.rb +49 -0
  40. data/spec/chewy/strategy_spec.rb +2 -2
  41. data/spec/chewy/type/adapter/sequel_spec.rb +46 -0
  42. data/spec/chewy/type/import_spec.rb +4 -2
  43. data/spec/chewy/type/mapping_spec.rb +19 -0
  44. data/spec/chewy/type/observe_spec.rb +43 -14
  45. data/spec/chewy_spec.rb +2 -3
  46. data/spec/spec_helper.rb +6 -3
  47. data/spec/support/active_record.rb +5 -8
  48. data/spec/support/mongoid.rb +5 -8
  49. data/spec/support/sequel.rb +69 -0
  50. metadata +14 -3
@@ -57,9 +57,8 @@ describe Chewy do
57
57
  end
58
58
 
59
59
  context 'model scope', :orm do
60
- before { stub_model(:country) }
61
- before { stub_model(:city) { belongs_to :country } }
62
- subject { described_class.create_type(CitiesIndex, City.includes(:country)) }
60
+ before { stub_model(:city) }
61
+ subject { described_class.create_type(CitiesIndex, City.where(rating: 1)) }
63
62
 
64
63
  it { is_expected.to be_a Class }
65
64
  it { is_expected.to be < Chewy::Type }
@@ -4,6 +4,7 @@ Bundler.require
4
4
 
5
5
  begin
6
6
  require 'active_record'
7
+ require 'sequel'
7
8
  rescue LoadError
8
9
  end
9
10
 
@@ -38,10 +39,12 @@ if defined?(::ActiveRecord)
38
39
  require 'support/active_record'
39
40
  elsif defined?(::Mongoid)
40
41
  require 'support/mongoid'
42
+ elsif defined?(::Sequel)
43
+ require 'support/sequel'
41
44
  else
42
45
  RSpec.configure do |config|
43
- config.filter_run_excluding :orm
44
- config.filter_run_excluding :mongoid
45
- config.filter_run_excluding :active_record
46
+ [:orm, :mongoid, :active_record, :sequel].each do |group|
47
+ config.filter_run_excluding(group)
48
+ end
46
49
  end
47
50
  end
@@ -21,16 +21,12 @@ end
21
21
  module ActiveRecordClassHelpers
22
22
  extend ActiveSupport::Concern
23
23
 
24
- def stub_model name, superclass = nil, &block
25
- stub_class(name, superclass || ActiveRecord::Base, &block)
26
- end
27
-
28
- def active_record?
29
- true
24
+ def adapter
25
+ :active_record
30
26
  end
31
27
 
32
- def mongoid?
33
- false
28
+ def stub_model name, superclass = nil, &block
29
+ stub_class(name, superclass || ActiveRecord::Base, &block)
34
30
  end
35
31
  end
36
32
 
@@ -38,6 +34,7 @@ RSpec.configure do |config|
38
34
  config.include ActiveRecordClassHelpers
39
35
 
40
36
  config.filter_run_excluding :mongoid
37
+ config.filter_run_excluding :sequel
41
38
 
42
39
  config.before(:suite) do
43
40
  DatabaseCleaner.clean_with :truncation
@@ -40,6 +40,10 @@ module MongoidClassHelpers
40
40
  end
41
41
  end
42
42
 
43
+ def adapter
44
+ :mongoid
45
+ end
46
+
43
47
  def stub_model name, superclass = nil, &block
44
48
  mixin = "MongoidClassHelpers::#{name.to_s.camelize}".safe_constantize || Mongoid::Document
45
49
  superclass ||= Class.new do
@@ -49,20 +53,13 @@ module MongoidClassHelpers
49
53
 
50
54
  stub_class(name, superclass, &block)
51
55
  end
52
-
53
- def active_record?
54
- false
55
- end
56
-
57
- def mongoid?
58
- true
59
- end
60
56
  end
61
57
 
62
58
  RSpec.configure do |config|
63
59
  config.include MongoidClassHelpers
64
60
 
65
61
  config.filter_run_excluding :active_record
62
+ config.filter_run_excluding :sequel
66
63
 
67
64
  config.before(:suite) do
68
65
  DatabaseCleaner.clean_with :truncation
@@ -0,0 +1,69 @@
1
+ require 'database_cleaner'
2
+
3
+ DB = Sequel.sqlite
4
+
5
+ DB.create_table :countries do
6
+ primary_key :id
7
+ column :name, :string
8
+ column :country_code, :string
9
+ column :rating, :integer
10
+ end
11
+
12
+ DB.create_table :cities do
13
+ primary_key :id
14
+ column :country_id, :integer
15
+ column :name, :string
16
+ column :rating, :integer
17
+ end
18
+
19
+ Sequel::Model.plugin :chewy_observe
20
+
21
+ module SequelClassHelpers
22
+ extend ActiveSupport::Concern
23
+
24
+ class AdaptedSequelModel < Sequel::Model
25
+ # Allow to set primary key using mass assignment.
26
+ unrestrict_primary_key
27
+
28
+ # Aliases for compatibility with specs that were written with ActiveRecord in mind...
29
+ alias_method :save!, :save
30
+ alias_method :update_attributes, :update
31
+ alias_method :update_attributes!, :update
32
+
33
+ class << self
34
+ alias_method :create!, :create
35
+ end
36
+ end
37
+
38
+ def adapter
39
+ :sequel
40
+ end
41
+
42
+ def stub_model(name, &block)
43
+ stub_class(name, AdaptedSequelModel, &block).tap do |klass|
44
+ # Sequel doesn't work well with dynamically created classes,
45
+ # so we must set the dataset (table) name manually.
46
+ klass.dataset = name.to_s.pluralize.to_sym
47
+ end
48
+ end
49
+ end
50
+
51
+ RSpec.configure do |config|
52
+ config.include SequelClassHelpers
53
+
54
+ config.filter_run_excluding :active_record
55
+ config.filter_run_excluding :mongoid
56
+
57
+ config.before(:suite) do
58
+ DatabaseCleaner.clean_with :truncation
59
+ DatabaseCleaner.strategy = :truncation
60
+ end
61
+
62
+ config.before do
63
+ DatabaseCleaner.start
64
+ end
65
+
66
+ config.after do
67
+ DatabaseCleaner.clean
68
+ end
69
+ end
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.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-30 00:00:00.000000000 Z
11
+ date: 2015-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -205,6 +205,7 @@ files:
205
205
  - gemfiles/rails.4.2.mongoid.gemfile
206
206
  - gemfiles/rails.4.2.mongoid.kaminari.gemfile
207
207
  - gemfiles/rails.4.2.mongoid.will_paginate.gemfile
208
+ - gemfiles/sequel.4.23.gemfile
208
209
  - lib/chewy.rb
209
210
  - lib/chewy/backports/deep_dup.rb
210
211
  - lib/chewy/backports/duplicable.rb
@@ -247,6 +248,7 @@ files:
247
248
  - lib/chewy/query/pagination/will_paginate.rb
248
249
  - lib/chewy/query/scoping.rb
249
250
  - lib/chewy/railtie.rb
251
+ - lib/chewy/rake_helper.rb
250
252
  - lib/chewy/repository.rb
251
253
  - lib/chewy/rspec.rb
252
254
  - lib/chewy/rspec/update_index.rb
@@ -254,6 +256,7 @@ files:
254
256
  - lib/chewy/runtime/version.rb
255
257
  - lib/chewy/search.rb
256
258
  - lib/chewy/strategy.rb
259
+ - lib/chewy/strategy/active_job.rb
257
260
  - lib/chewy/strategy/atomic.rb
258
261
  - lib/chewy/strategy/base.rb
259
262
  - lib/chewy/strategy/bypass.rb
@@ -267,6 +270,7 @@ files:
267
270
  - lib/chewy/type/adapter/mongoid.rb
268
271
  - lib/chewy/type/adapter/object.rb
269
272
  - lib/chewy/type/adapter/orm.rb
273
+ - lib/chewy/type/adapter/sequel.rb
270
274
  - lib/chewy/type/crutch.rb
271
275
  - lib/chewy/type/import.rb
272
276
  - lib/chewy/type/mapping.rb
@@ -275,6 +279,7 @@ files:
275
279
  - lib/chewy/version.rb
276
280
  - lib/generators/chewy/install_generator.rb
277
281
  - lib/generators/templates/chewy.yml
282
+ - lib/sequel/plugins/chewy_observe.rb
278
283
  - lib/tasks/chewy.rake
279
284
  - spec/chewy/config_spec.rb
280
285
  - spec/chewy/fields/base_spec.rb
@@ -312,6 +317,7 @@ files:
312
317
  - spec/chewy/runtime/version_spec.rb
313
318
  - spec/chewy/runtime_spec.rb
314
319
  - spec/chewy/search_spec.rb
320
+ - spec/chewy/strategy/active_job_spec.rb
315
321
  - spec/chewy/strategy/resque_spec.rb
316
322
  - spec/chewy/strategy/sidekiq_spec.rb
317
323
  - spec/chewy/strategy_spec.rb
@@ -319,6 +325,7 @@ files:
319
325
  - spec/chewy/type/adapter/active_record_spec.rb
320
326
  - spec/chewy/type/adapter/mongoid_spec.rb
321
327
  - spec/chewy/type/adapter/object_spec.rb
328
+ - spec/chewy/type/adapter/sequel_spec.rb
322
329
  - spec/chewy/type/import_spec.rb
323
330
  - spec/chewy/type/mapping_spec.rb
324
331
  - spec/chewy/type/observe_spec.rb
@@ -330,6 +337,7 @@ files:
330
337
  - spec/support/class_helpers.rb
331
338
  - spec/support/fail_helpers.rb
332
339
  - spec/support/mongoid.rb
340
+ - spec/support/sequel.rb
333
341
  homepage: https://github.com/toptal/chewy
334
342
  licenses:
335
343
  - MIT
@@ -350,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
358
  version: '0'
351
359
  requirements: []
352
360
  rubyforge_project:
353
- rubygems_version: 2.4.5
361
+ rubygems_version: 2.4.5.1
354
362
  signing_key:
355
363
  specification_version: 4
356
364
  summary: Elasticsearch ODM client wrapper
@@ -391,6 +399,7 @@ test_files:
391
399
  - spec/chewy/runtime/version_spec.rb
392
400
  - spec/chewy/runtime_spec.rb
393
401
  - spec/chewy/search_spec.rb
402
+ - spec/chewy/strategy/active_job_spec.rb
394
403
  - spec/chewy/strategy/resque_spec.rb
395
404
  - spec/chewy/strategy/sidekiq_spec.rb
396
405
  - spec/chewy/strategy_spec.rb
@@ -398,6 +407,7 @@ test_files:
398
407
  - spec/chewy/type/adapter/active_record_spec.rb
399
408
  - spec/chewy/type/adapter/mongoid_spec.rb
400
409
  - spec/chewy/type/adapter/object_spec.rb
410
+ - spec/chewy/type/adapter/sequel_spec.rb
401
411
  - spec/chewy/type/import_spec.rb
402
412
  - spec/chewy/type/mapping_spec.rb
403
413
  - spec/chewy/type/observe_spec.rb
@@ -409,3 +419,4 @@ test_files:
409
419
  - spec/support/class_helpers.rb
410
420
  - spec/support/fail_helpers.rb
411
421
  - spec/support/mongoid.rb
422
+ - spec/support/sequel.rb