tire_async_index 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Zjg2NTkzM2I5ZGE4MDE1YmRiYjY5NzhjOGU0NWFlMzZmNTI0OTcyZA==
5
- data.tar.gz: !binary |-
6
- NzBmOTM3YTgwZWUxYmI3NTVkMzM5YjFiMWYyNmRhMWQ2NGE1NjhlOQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MzEzZjc5YWFjY2NlZjBiMjE3NmI1YjcwMzRjMDExYTJlOTMzYjNjMjg3NWEz
10
- NGJmNTc4MzNhMGQ5ZWNhNWE2N2E1ZWRiZjA4MjMxMjA5NDBjYWMwN2QxYWQ4
11
- ODg0NWVkYTNmZGFhMGQzMmQ2MDM5Y2ZiZTk2MjVjMDQ1MWUxN2M=
12
- data.tar.gz: !binary |-
13
- ODgwZjgyNmYwMWNkYjY0ZGNiYWVhYzYxYzllYzc4Yjk1YmJmODc1N2UzMjZj
14
- NGJjNTUyZDgyODc4ODZiODY2NWUyY2QzMTk5ZDk0MDM2NjU1ZmJlNWZhMzU1
15
- NGQ3NWViOTFiOTU3M2FmMGQ4OTViOTc3MzIxNjBiYTNiODU0YmM=
2
+ SHA1:
3
+ metadata.gz: e1afa186dedd7fe80f38bb488bf077e1ff2e85b5
4
+ data.tar.gz: 9432299f7e026815033fc47893283e3fee927236
5
+ SHA512:
6
+ metadata.gz: 8a2647253801a63bcc58e39e73c31a2684da461f2f9f15b9191a11c6887bc3b831ad1ea2f024ef301bee17caf74e6f263410d0106d2ec66cf75b218201f9a8c9
7
+ data.tar.gz: fd6514f0d283ab6c9addd3286fc411755a69f6395bfe80b4a4b320010587a512a28d85f485f645d315b10aa8fb336026f63eafea0d666c6ed605bbd4ca3f2b74
@@ -0,0 +1,4 @@
1
+ ## 0.2.0
2
+
3
+ * ActiveModel support
4
+
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # TireAsyncIndex
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/EvilFaeton/tire_async_index.png)](http://travis-ci.org/EvilFaeton/tire_async_index)
3
+ [![Build Status](https://secure.travis-ci.org/EvilFaeton/tire_async_index.png)](http://travis-ci.org/EvilFaeton/tire_async_index) [![endorse](https://api.coderwall.com/evilfaeton/endorsecount.png)](https://coderwall.com/evilfaeton)
4
4
 
5
- It's extension for [Tire](https://github.com/karmi/tire/) (client for the Elasticsearch search engine), which allow to update index of ActiveRecord model using background job (based on [Sidekiq](https://github.com/mperham/sidekiq) or [Resque](https://github.com/resque/resque)).
5
+ It's extension for [Tire](https://github.com/karmi/tire/) (client for the Elasticsearch search engine), which allow to update index of ActiveRecord/ActiveModel model using background job (based on [Sidekiq](https://github.com/mperham/sidekiq) or [Resque](https://github.com/resque/resque)).
6
6
 
7
7
  Requirements: Ruby 1.9, 2.0, Rails => 3.0
8
8
 
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
  ## Configuration
26
26
 
27
27
  You could configure TireAsyncIndex in initializer:
28
-
28
+
29
29
  TireAsyncIndex.configure do |config|
30
30
  config.background_engine :sidekiq # or :resque
31
31
  config.use_queue :high # name of your queue
@@ -34,16 +34,21 @@ You could configure TireAsyncIndex in initializer:
34
34
  ## Usage
35
35
 
36
36
  Just add AsyncCallbacks to your model:
37
-
37
+
38
38
  class User < ActiveRecord::Base
39
39
  include Tire::Model::Search
40
40
  include Tire::Model::AsyncCallbacks
41
-
41
+
42
42
  ...
43
43
  end
44
-
44
+
45
45
  That's all.
46
46
 
47
+ ## TODO
48
+
49
+ * Add support for custom filter / custom finders
50
+ * Test for workers
51
+
47
52
  ## Contributing
48
53
 
49
54
  1. Fork it
@@ -1,36 +1,64 @@
1
1
  module Tire
2
2
  module Model
3
3
  module AsyncCallbacks
4
+
5
+ ID_CONVERSION = {
6
+ 'Moped::BSON::ObjectId' => :to_s
7
+ }
8
+
4
9
  def self.included(base)
5
- if base.respond_to?(:after_commit)
6
- index_update = lambda {
7
- case TireAsyncIndex.engine
8
- when :sidekiq
9
- SidekiqUpdateIndexWorker.perform_async(base.name, id)
10
- when :resque
11
- Resque.enqueue(ResqueUpdateIndexJob, base.name, id)
12
- else
13
- tire.update_index
14
- end
10
+ # Bind after save or create callback
11
+ if base.respond_to? :after_commit
12
+ base.send :after_commit, :async_tire_save_index
15
13
 
16
- self
17
- }
14
+ elsif base.respond_to? :after_save
15
+ base.send :after_save, :async_tire_save_index
16
+ end
18
17
 
19
- base.send :after_commit, index_update, on: :create
20
- base.send :after_commit, index_update, on: :update
21
- base.send :after_commit, lambda { tire.update_index }, order: :first, on: :destroy
18
+ # Bind before destroy callback
19
+ if base.respond_to? :before_destroy
20
+ base.send :before_destroy, :async_tire_delete_index
22
21
  end
22
+ end
23
+
24
+ private
25
+
26
+ def async_tire_save_index
27
+ async_tire_callback :update
28
+ end
23
29
 
24
- if base.respond_to?(:before_destroy) && !base.instance_methods.map(&:to_sym).include?(:destroyed?)
25
- base.class_eval do
26
- before_destroy { @destroyed = true }
27
- def destroyed?; !!@destroyed; end
28
- end
30
+ def async_tire_delete_index
31
+ async_tire_callback :delete
32
+ end
33
+
34
+ def async_tire_callback(type)
35
+ case TireAsyncIndex.engine
36
+ when :sidekiq
37
+ TireAsyncIndex::Workers::SidekiqUpdateIndex.
38
+ perform_async type, self.class.name, async_tire_object_id
39
+
40
+ when :resque
41
+ Resque.enqueue TireAsyncIndex::Workers::ResqueUpdateIndex,
42
+ type, self.class.name, async_tire_object_id
43
+
44
+ else
45
+ case type
46
+ when :update
47
+ tire.update_index
48
+ when :delete
49
+ tire.index.remove self
50
+ end
29
51
  end
52
+ end
30
53
 
54
+ def async_tire_object_id
55
+ if (method = ID_CONVERSION[self.id.class.name])
56
+ self.id.send(method)
57
+ else
58
+ self.id
59
+ end
31
60
  end
32
61
 
33
62
  end
34
-
35
63
  end
36
64
  end
@@ -21,12 +21,19 @@ module TireAsyncIndex
21
21
  end
22
22
 
23
23
  def reconfig_workers
24
- SidekiqUpdateIndexWorker.sidekiq_options_hash["queue"] = TireAsyncIndex.queue if defined?(Sidekiq)
24
+ if defined?(Sidekiq)
25
+ Workers::SidekiqUpdateIndex.sidekiq_options_hash["queue"] = TireAsyncIndex.queue
26
+ end
27
+ end
28
+
29
+ module Workers
30
+ autoload :UpdateIndex, 'tire_async_index/workers/update_index'
25
31
  end
26
32
 
27
33
  end
28
34
 
29
- require 'tire_async_index/workers/sidekiq_update_index_worker' if defined?(Sidekiq)
30
- require 'tire_async_index/workers/resque_update_index_job' if defined?(Resque)
35
+ require 'tire_async_index/workers/sidekiq_update_index' if defined?(Sidekiq)
36
+ require 'tire_async_index/workers/resque_update_index' if defined?(Resque)
31
37
  require 'tire/model/async_callbacks'
38
+
32
39
  TireAsyncIndex.configure {}
@@ -1,3 +1,3 @@
1
1
  module TireAsyncIndex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,11 @@
1
+ module TireAsyncIndex
2
+ module Workers
3
+ class ResqueUpdateIndex < UpdateIndex
4
+ def self.queue; TireAsyncIndex.queue end
5
+
6
+ def self.perform(*args)
7
+ self.new.perform *args
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module TireAsyncIndex
2
+ module Workers
3
+ class SidekiqUpdateIndex < UpdateIndex
4
+ include Sidekiq::Worker
5
+ sidekiq_options queue: :normal
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ module TireAsyncIndex
2
+ module Workers
3
+
4
+ # Worker for updating ElasticSearch index
5
+ class UpdateIndex
6
+
7
+ # Update or delete ElasticSearch index based on the action_type parameter.
8
+ #
9
+ # Parameters:
10
+ # action_type - Determine index direction. (allowed value - Update or Delete)
11
+ # class_name - Model class name
12
+ # id - Document id
13
+ #
14
+ def perform(action_type, class_name, id)
15
+ klass = Kernel.const_get(class_name)
16
+
17
+ case action_type.to_sym
18
+ when :update
19
+ object = klass.find(id)
20
+
21
+ if object.present? && object.respond_to?(:tire)
22
+ object.tire.update_index
23
+ end
24
+ when :delete
25
+
26
+ klass.new.tap do |inst|
27
+ inst.tire.index.remove(inst.tire.document_type, { _id: id })
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,142 @@
1
+ require 'test_helper'
2
+ require 'tire'
3
+ require 'sidekiq'
4
+ require 'resque'
5
+ require 'tire_async_index'
6
+
7
+ class AmUser
8
+ extend ActiveModel::Callbacks
9
+ define_model_callbacks :save, :destroy
10
+
11
+ include Tire::Model::AsyncCallbacks
12
+ attr_accessor :id
13
+
14
+ def save
15
+ run_callbacks :save do
16
+ end
17
+ end
18
+
19
+ def destroy
20
+ run_callbacks :destroy do
21
+ end
22
+ end
23
+ end
24
+
25
+ describe TireAsyncIndex do
26
+
27
+ before(:all) do
28
+ TireAsyncIndex.configuration = TireAsyncIndex::Configuration.new
29
+ end
30
+
31
+ context "configurable" do
32
+ it "valid default config settings" do
33
+ TireAsyncIndex.queue.should eql :normal
34
+ TireAsyncIndex.engine.should eql :none
35
+ end
36
+
37
+ it "set queue name" do
38
+ TireAsyncIndex.configure do |config|
39
+ config.use_queue :high
40
+ end
41
+
42
+ TireAsyncIndex.queue.should eql :high
43
+ end
44
+
45
+ it "should be able to set sidekiq as engine" do
46
+ TireAsyncIndex.configure do |config|
47
+ config.background_engine :sidekiq
48
+ end
49
+
50
+ TireAsyncIndex.engine.should eql :sidekiq
51
+ end
52
+
53
+ it "should be able to set resque as engine" do
54
+ TireAsyncIndex.configure do |config|
55
+ config.background_engine :resque
56
+ end
57
+
58
+ TireAsyncIndex.engine.should eql :resque
59
+ end
60
+
61
+ it "should not be able to set not supported engine" do
62
+ expect {
63
+ TireAsyncIndex.configure do |config|
64
+ config.background_engine :some_engine
65
+ end
66
+ }.to raise_error(TireAsyncIndex::EngineNotFound)
67
+ end
68
+ end
69
+
70
+ context "integration" do
71
+
72
+ describe '#after_save' do
73
+ it "should not start backroub on no engine" do
74
+ TireAsyncIndex.configure do |config|
75
+ config.background_engine :none
76
+ end
77
+ a = AmUser.new.tap { |a| a.id = 23 }
78
+ tire = double(:Tire)
79
+ a.stub(:tire) { tire }
80
+ tire.should_receive(:update_index)
81
+ a.save
82
+ end
83
+
84
+ it "should start sidekiq" do
85
+ TireAsyncIndex.configure do |config|
86
+ config.background_engine :sidekiq
87
+ end
88
+
89
+ TireAsyncIndex::Workers::SidekiqUpdateIndex.should_receive(:perform_async).with(:update, "AmUser", instance_of(Fixnum))
90
+
91
+ AmUser.new.tap { |a| a.id = 23 }.save
92
+ end
93
+
94
+ it "should start resque" do
95
+ TireAsyncIndex.configure do |config|
96
+ config.background_engine :resque
97
+ end
98
+
99
+ Resque.should_receive(:enqueue).with(TireAsyncIndex::Workers::ResqueUpdateIndex, :update, "AmUser", instance_of(Fixnum))
100
+
101
+ AmUser.new.tap { |a| a.id = 23 }.save
102
+ end
103
+ end
104
+
105
+ describe '#after_destroy' do
106
+
107
+ it 'should directly invoke remove index' do
108
+ TireAsyncIndex.configure do |config|
109
+ config.background_engine :none
110
+ end
111
+
112
+ a = AmUser.new.tap { |a| a.id = 23 }
113
+ tire = double(:Tire, index: double(:index))
114
+ a.stub(:tire) { tire }
115
+
116
+ tire.index.should_receive(:remove)
117
+ a.destroy
118
+ end
119
+
120
+ it 'should enqueue sidekiq job' do
121
+ TireAsyncIndex.configure do |config|
122
+ config.background_engine :sidekiq
123
+ end
124
+
125
+ TireAsyncIndex::Workers::SidekiqUpdateIndex.should_receive(:perform_async).with(:delete, "AmUser", instance_of(Fixnum))
126
+
127
+ AmUser.new.tap { |a| a.id = 23 }.destroy
128
+ end
129
+
130
+ it "should enqueue resque job" do
131
+ TireAsyncIndex.configure do |config|
132
+ config.background_engine :resque
133
+ end
134
+
135
+ Resque.should_receive(:enqueue).with(TireAsyncIndex::Workers::ResqueUpdateIndex, :delete, "AmUser", instance_of(Fixnum))
136
+
137
+ AmUser.new.tap { |a| a.id = 23 }.destroy
138
+ end
139
+ end
140
+
141
+ end
142
+ end
@@ -0,0 +1,130 @@
1
+ require 'test_helper'
2
+ require 'tire'
3
+ require 'sidekiq'
4
+ require 'resque'
5
+ require 'tire_async_index'
6
+
7
+ class ArUser < ActiveRecord::Base
8
+ include Tire::Model::AsyncCallbacks
9
+ end
10
+
11
+ describe TireAsyncIndex do
12
+
13
+ before(:all) do
14
+ TireAsyncIndex.configuration = TireAsyncIndex::Configuration.new
15
+ end
16
+
17
+ context "configurable" do
18
+ it "valid default config settings" do
19
+ TireAsyncIndex.queue.should eql :normal
20
+ TireAsyncIndex.engine.should eql :none
21
+ end
22
+
23
+ it "set queue name" do
24
+ TireAsyncIndex.configure do |config|
25
+ config.use_queue :high
26
+ end
27
+
28
+ TireAsyncIndex.queue.should eql :high
29
+ end
30
+
31
+ it "should be able to set sidekiq as engine" do
32
+ TireAsyncIndex.configure do |config|
33
+ config.background_engine :sidekiq
34
+ end
35
+
36
+ TireAsyncIndex.engine.should eql :sidekiq
37
+ end
38
+
39
+ it "should be able to set resque as engine" do
40
+ TireAsyncIndex.configure do |config|
41
+ config.background_engine :resque
42
+ end
43
+
44
+ TireAsyncIndex.engine.should eql :resque
45
+ end
46
+
47
+ it "should not be able to set not supported engine" do
48
+ expect {
49
+ TireAsyncIndex.configure do |config|
50
+ config.background_engine :some_engine
51
+ end
52
+ }.to raise_error(TireAsyncIndex::EngineNotFound)
53
+ end
54
+ end
55
+
56
+ context "integration" do
57
+
58
+ describe '#after_save' do
59
+ it "should not start backroub on no engine" do
60
+ TireAsyncIndex.configure do |config|
61
+ config.background_engine :none
62
+ end
63
+
64
+ a = ArUser.new
65
+ a.stub(:tire) { a }
66
+ a.should_receive(:update_index)
67
+ a.save
68
+ end
69
+
70
+ it "should start sidekiq" do
71
+ TireAsyncIndex.configure do |config|
72
+ config.background_engine :sidekiq
73
+ end
74
+
75
+ TireAsyncIndex::Workers::SidekiqUpdateIndex.should_receive(:perform_async).with(:update, "ArUser", instance_of(Fixnum))
76
+
77
+ a = ArUser.new
78
+ a.save
79
+ end
80
+
81
+ it "should start resque" do
82
+ TireAsyncIndex.configure do |config|
83
+ config.background_engine :resque
84
+ end
85
+
86
+ Resque.should_receive(:enqueue).with(TireAsyncIndex::Workers::ResqueUpdateIndex, :update, "ArUser", instance_of(Fixnum))
87
+
88
+ a = ArUser.new
89
+ a.save
90
+ end
91
+ end
92
+
93
+ describe '#after_destroy' do
94
+
95
+ it 'should directly invoke remove index' do
96
+ TireAsyncIndex.configure do |config|
97
+ config.background_engine :none
98
+ end
99
+
100
+ a = ArUser.new.tap { |a| a.id = 23 }
101
+ tire = double(:Tire, index: double(:index))
102
+ a.stub(:tire) { tire }
103
+
104
+ tire.index.should_receive(:remove)
105
+ a.destroy
106
+ end
107
+
108
+ it 'should enqueue sidekiq job' do
109
+ TireAsyncIndex.configure do |config|
110
+ config.background_engine :sidekiq
111
+ end
112
+
113
+ TireAsyncIndex::Workers::SidekiqUpdateIndex.should_receive(:perform_async).with(:delete, "ArUser", instance_of(Fixnum))
114
+
115
+ ArUser.new.tap { |a| a.id = 23 }.destroy
116
+ end
117
+
118
+ it "should enqueue resque job" do
119
+ TireAsyncIndex.configure do |config|
120
+ config.background_engine :resque
121
+ end
122
+
123
+ Resque.should_receive(:enqueue).with(TireAsyncIndex::Workers::ResqueUpdateIndex, :delete, "ArUser", instance_of(Fixnum))
124
+
125
+ ArUser.new.tap { |a| a.id = 23 }.destroy
126
+ end
127
+ end
128
+
129
+ end
130
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tire_async_index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Efremov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tire
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
@@ -70,56 +70,56 @@ dependencies:
70
70
  name: activerecord-nulldb-adapter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sidekiq
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: resque
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description: Update tire (elasticsearch) index async with Sidekiq or Resque
@@ -132,6 +132,7 @@ files:
132
132
  - .gitignore
133
133
  - .rspec
134
134
  - .travis.yml
135
+ - Changelog.md
135
136
  - Gemfile
136
137
  - LICENSE.txt
137
138
  - README.md
@@ -141,11 +142,13 @@ files:
141
142
  - lib/tire_async_index/configuration.rb
142
143
  - lib/tire_async_index/exceptions.rb
143
144
  - lib/tire_async_index/version.rb
144
- - lib/tire_async_index/workers/resque_update_index_job.rb
145
- - lib/tire_async_index/workers/sidekiq_update_index_worker.rb
145
+ - lib/tire_async_index/workers/resque_update_index.rb
146
+ - lib/tire_async_index/workers/sidekiq_update_index.rb
147
+ - lib/tire_async_index/workers/update_index.rb
148
+ - spec/active_model_tire_async_index_spec.rb
149
+ - spec/active_record_tire_async_index_spec.rb
146
150
  - spec/test_helper.rb
147
151
  - spec/test_schema.rb
148
- - spec/tire_async_index_spec.rb
149
152
  - tire_async_index.gemspec
150
153
  homepage: http://github.com/EvilFaeton/tire_async_index
151
154
  licenses:
@@ -157,12 +160,12 @@ require_paths:
157
160
  - lib
158
161
  required_ruby_version: !ruby/object:Gem::Requirement
159
162
  requirements:
160
- - - ! '>='
163
+ - - '>='
161
164
  - !ruby/object:Gem::Version
162
165
  version: '0'
163
166
  required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  requirements:
165
- - - ! '>='
168
+ - - '>='
166
169
  - !ruby/object:Gem::Version
167
170
  version: '0'
168
171
  requirements: []
@@ -172,6 +175,7 @@ signing_key:
172
175
  specification_version: 4
173
176
  summary: Update tire (elasticsearch) index async with Sidekiq or Resque
174
177
  test_files:
178
+ - spec/active_model_tire_async_index_spec.rb
179
+ - spec/active_record_tire_async_index_spec.rb
175
180
  - spec/test_helper.rb
176
181
  - spec/test_schema.rb
177
- - spec/tire_async_index_spec.rb
@@ -1,11 +0,0 @@
1
- class ResqueUpdateIndexJob
2
-
3
- def self.queue
4
- TireAsyncIndex.queue
5
- end
6
-
7
- def self.perform class_name, id
8
- class_name.constantize.find_by_id(id).try(:update_index)
9
- end
10
-
11
- end
@@ -1,10 +0,0 @@
1
- class SidekiqUpdateIndexWorker
2
-
3
- include Sidekiq::Worker
4
- sidekiq_options queue: :normal
5
-
6
- def perform class_name, id
7
- class_name.constantize.find_by_id(id).try(:update_index)
8
- end
9
-
10
- end
@@ -1,86 +0,0 @@
1
- require 'test_helper'
2
- require 'tire'
3
- require 'sidekiq'
4
- require 'resque'
5
- require 'tire_async_index'
6
-
7
- class User < ActiveRecord::Base
8
- include Tire::Model::AsyncCallbacks
9
- end
10
-
11
- describe TireAsyncIndex do
12
- context "configurable" do
13
- it "valid default config settings" do
14
- TireAsyncIndex.queue.should eql :normal
15
- TireAsyncIndex.engine.should eql :none
16
- end
17
-
18
- it "set queue name" do
19
- TireAsyncIndex.configure do |config|
20
- config.use_queue :high
21
- end
22
-
23
- TireAsyncIndex.queue.should eql :high
24
- end
25
-
26
- it "should be able to set sidekiq as engine" do
27
- TireAsyncIndex.configure do |config|
28
- config.background_engine :sidekiq
29
- end
30
-
31
- TireAsyncIndex.engine.should eql :sidekiq
32
- end
33
-
34
- it "should be able to set resque as engine" do
35
- TireAsyncIndex.configure do |config|
36
- config.background_engine :resque
37
- end
38
-
39
- TireAsyncIndex.engine.should eql :resque
40
- end
41
-
42
- it "should not be able to set not supported engine" do
43
- expect {
44
- TireAsyncIndex.configure do |config|
45
- config.background_engine :some_engine
46
- end
47
- }.to raise_error(TireAsyncIndex::EngineNotFound)
48
- end
49
- end
50
-
51
- context "integration" do
52
-
53
- it "should not start backroub on no engine" do
54
- TireAsyncIndex.configure do |config|
55
- config.background_engine :none
56
- end
57
- a = User.new
58
- a.stub(:tire) { a }
59
- a.should_receive(:update_index)
60
- a.save
61
- end
62
-
63
- it "should start sidekiq" do
64
- TireAsyncIndex.configure do |config|
65
- config.background_engine :sidekiq
66
- end
67
-
68
- SidekiqUpdateIndexWorker.should_receive(:perform_async).with("User", instance_of(Fixnum))
69
-
70
- a = User.new
71
- a.save
72
- end
73
-
74
- it "should start resque" do
75
- TireAsyncIndex.configure do |config|
76
- config.background_engine :resque
77
- end
78
-
79
- Resque.should_receive(:enqueue).with(ResqueUpdateIndexJob, "User", instance_of(Fixnum))
80
-
81
- a = User.new
82
- a.save
83
- end
84
-
85
- end
86
- end