ts-resque-delta 1.2.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -1
  3. data/.travis.yml +14 -14
  4. data/Appraisals +4 -6
  5. data/Gemfile +1 -1
  6. data/README.markdown +31 -39
  7. data/Rakefile +6 -13
  8. data/gemfiles/binary.gemfile +7 -0
  9. data/gemfiles/sphinxql.gemfile +7 -0
  10. data/lib/thinking_sphinx/deltas/resque_delta.rb +66 -76
  11. data/lib/thinking_sphinx/deltas/resque_delta/delta_job.rb +1 -113
  12. data/lib/thinking_sphinx/deltas/resque_delta/flag_as_deleted_job.rb +7 -0
  13. data/lib/ts-resque-delta.rb +0 -2
  14. data/spec/acceptance/resque_deltas_spec.rb +50 -0
  15. data/spec/acceptance/spec_helper.rb +4 -0
  16. data/spec/acceptance/support/database_cleaner.rb +11 -0
  17. data/spec/acceptance/support/sphinx_controller.rb +61 -0
  18. data/spec/acceptance/support/sphinx_helpers.rb +36 -0
  19. data/spec/internal/.gitignore +2 -0
  20. data/spec/internal/app/indices/book_index.rb +3 -0
  21. data/spec/internal/app/models/book.rb +7 -0
  22. data/spec/internal/config/database.yml +5 -0
  23. data/spec/internal/db/schema.rb +10 -0
  24. data/spec/internal/log/.gitignore +1 -0
  25. data/spec/spec_helper.rb +16 -12
  26. data/spec/thinking_sphinx/deltas/resque_delta/delta_job_spec.rb +11 -155
  27. data/spec/thinking_sphinx/deltas/resque_delta_spec.rb +3 -166
  28. data/ts-resque-delta.gemspec +19 -28
  29. metadata +90 -230
  30. data/Guardfile +0 -17
  31. data/features/resque_deltas.feature +0 -62
  32. data/features/smart_indexing.feature +0 -43
  33. data/features/step_definitions/common_steps.rb +0 -76
  34. data/features/step_definitions/resque_delta_steps.rb +0 -33
  35. data/features/step_definitions/smart_indexing_steps.rb +0 -3
  36. data/features/support/env.rb +0 -41
  37. data/features/thinking_sphinx/database.example.yml +0 -4
  38. data/features/thinking_sphinx/db/migrations/create_delayed_betas.rb +0 -4
  39. data/features/thinking_sphinx/models/delayed_beta.rb +0 -6
  40. data/gemfiles/activerecord2.gemfile +0 -8
  41. data/gemfiles/activerecord2.gemfile.lock +0 -114
  42. data/gemfiles/activerecord3.gemfile +0 -8
  43. data/gemfiles/activerecord3.gemfile.lock +0 -123
  44. data/lib/flying_sphinx/resque_delta.rb +0 -35
  45. data/lib/flying_sphinx/resque_delta/delta_job.rb +0 -14
  46. data/lib/flying_sphinx/resque_delta/flag_as_deleted_job.rb +0 -7
  47. data/lib/thinking_sphinx/deltas/resque_delta/core_index.rb +0 -116
  48. data/lib/thinking_sphinx/deltas/resque_delta/flag_as_deleted_set.rb +0 -59
  49. data/lib/thinking_sphinx/deltas/resque_delta/index_utils.rb +0 -47
  50. data/lib/thinking_sphinx/deltas/resque_delta/railtie.rb +0 -8
  51. data/lib/thinking_sphinx/deltas/resque_delta/tasks.rb +0 -38
  52. data/lib/thinking_sphinx/deltas/resque_delta/version.rb +0 -7
  53. data/spec/flying_sphinx/resque_delta/delta_job_spec.rb +0 -32
  54. data/spec/flying_sphinx/resque_delta/flag_as_deleted_job_spec.rb +0 -23
  55. data/spec/flying_sphinx/resque_delta_spec.rb +0 -130
  56. data/spec/thinking_sphinx/deltas/resque_delta/core_index_spec.rb +0 -210
  57. data/spec/thinking_sphinx/deltas/resque_delta/flag_as_deleted_set_spec.rb +0 -126
  58. data/spec/thinking_sphinx/deltas/resque_delta/index_utils_spec.rb +0 -67
@@ -0,0 +1,7 @@
1
+ class ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob
2
+ @queue = :ts_delta
3
+
4
+ def self.perform(index, document_id)
5
+ ThinkingSphinx::Deltas::DeleteJob.new(index, document_id).perform
6
+ end
7
+ end
@@ -1,3 +1 @@
1
1
  require 'thinking_sphinx/deltas/resque_delta'
2
- require 'flying_sphinx/resque_delta' if defined?(FlyingSphinx)
3
- require 'thinking_sphinx/deltas/resque_delta/railtie' if defined?(Rails::Railtie)
@@ -0,0 +1,50 @@
1
+ require 'acceptance/spec_helper'
2
+
3
+ describe 'SQL delta indexing', :live => true do
4
+ def sleep_for_sphinx
5
+ sleep ENV['CI'] ? 1.0 : 0.25
6
+ end
7
+
8
+ it "automatically indexes new records" do
9
+ guards = Book.create(
10
+ :title => 'Guards! Guards!', :author => 'Terry Pratchett'
11
+ )
12
+ index
13
+
14
+ Book.search('Terry Pratchett').to_a.should == [guards]
15
+
16
+ men = Book.create(
17
+ :title => 'Men At Arms', :author => 'Terry Pratchett'
18
+ )
19
+ work
20
+ sleep_for_sphinx
21
+
22
+ Book.search('Terry Pratchett').to_a.should == [guards, men]
23
+ end
24
+
25
+ it "automatically indexes updated records" do
26
+ book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
27
+ index
28
+
29
+ Book.search('Harry').to_a.should == [book]
30
+
31
+ book.reload.update_attributes(:author => 'Terry Pratchett')
32
+ work
33
+ sleep_for_sphinx
34
+
35
+ Book.search('Terry').to_a.should == [book]
36
+ end
37
+
38
+ it "does not match on old values" do
39
+ book = Book.create :title => 'Night Watch', :author => 'Harry Pritchett'
40
+ index
41
+
42
+ Book.search('Harry').to_a.should == [book]
43
+
44
+ book.reload.update_attributes(:author => 'Terry Pratchett')
45
+ work
46
+ sleep_for_sphinx
47
+
48
+ Book.search('Harry').should be_empty
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ root = File.expand_path File.dirname(__FILE__)
4
+ Dir["#{root}/support/**/*.rb"].each { |file| require file }
@@ -0,0 +1,11 @@
1
+ RSpec.configure do |config|
2
+ config.before(:suite) do
3
+ DatabaseCleaner.strategy = :truncation
4
+ end
5
+
6
+ config.after(:each) do
7
+ if example.example_group_instance.class.metadata[:live]
8
+ DatabaseCleaner.clean
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ class SphinxController
2
+ def initialize
3
+ if config.respond_to?(:searchd)
4
+ config.searchd.mysql41 = 9307
5
+ else
6
+ config.port = 9313
7
+ end
8
+ end
9
+
10
+ def setup
11
+ if config.respond_to?(:searchd)
12
+ FileUtils.mkdir_p config.indices_location
13
+
14
+ config.render_to_file && index
15
+
16
+ ThinkingSphinx::Configuration.reset
17
+ else
18
+ FileUtils.mkdir_p config.searchd_file_path
19
+
20
+ config.build
21
+ config.controller.index
22
+
23
+ ThinkingSphinx::Configuration.instance.reset
24
+ end
25
+
26
+ ActiveSupport::Dependencies.clear
27
+
28
+ if config.respond_to?(:searchd)
29
+ config.index_paths.each do |path|
30
+ Dir["#{path}/**/*.rb"].each { |file| $LOADED_FEATURES.delete file }
31
+ end
32
+
33
+ config.searchd.mysql41 = 9307
34
+ config.settings['quiet_deltas'] = true
35
+ config.settings['attribute_updates'] = true
36
+ else
37
+ config.port = 9313
38
+ ThinkingSphinx.suppress_delta_output = true
39
+ ThinkingSphinx.updates_enabled = true
40
+ ThinkingSphinx.deltas_enabled = true
41
+ end
42
+ end
43
+
44
+ def start
45
+ config.controller.start
46
+ end
47
+
48
+ def stop
49
+ config.controller.stop
50
+ end
51
+
52
+ def index(*indices)
53
+ config.controller.index *indices
54
+ end
55
+
56
+ private
57
+
58
+ def config
59
+ ThinkingSphinx::Configuration.instance
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ module SphinxHelpers
2
+ def sphinx
3
+ @sphinx ||= SphinxController.new
4
+ end
5
+
6
+ def index(*indices)
7
+ yield if block_given?
8
+
9
+ ThinkingSphinx.before_index_hooks.each &:call
10
+ sphinx.index *indices
11
+ sleep 0.25
12
+
13
+ ThinkingSphinx::Connection.pool.clear
14
+ end
15
+
16
+ def work
17
+ resque_worker = Resque::Worker.new("ts_delta")
18
+ resque_worker.register_worker
19
+
20
+ while job = resque_worker.reserve
21
+ resque_worker.perform(job)
22
+ end
23
+ end
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ config.include SphinxHelpers
28
+
29
+ config.before :all do |group|
30
+ sphinx.setup && sphinx.start if group.class.metadata[:live]
31
+ end
32
+
33
+ config.after :all do |group|
34
+ sphinx.stop if group.class.metadata[:live]
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ config/*.sphinx.conf
2
+ db/sphinx/*
@@ -0,0 +1,3 @@
1
+ ThinkingSphinx::Index.define :book, :with => :active_record, :delta => ThinkingSphinx::Deltas::ResqueDelta do
2
+ indexes title, author
3
+ end if ThinkingSphinx::Index.respond_to?(:define)
@@ -0,0 +1,7 @@
1
+ class Book < ActiveRecord::Base
2
+ define_index do
3
+ indexes title, author
4
+
5
+ set_property :delta => ThinkingSphinx::Deltas::ResqueDelta
6
+ end if respond_to?(:define_index)
7
+ end
@@ -0,0 +1,5 @@
1
+ test:
2
+ adapter: <%= ENV['DATABASE'] || 'mysql2' %>
3
+ database: thinking_sphinx
4
+ username: <%= ENV['DATABASE'] == 'postgresql' ? ENV['USER'] : 'root' %>
5
+ min_messages: warning
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table(:books, :force => true) do |t|
3
+ t.string :title
4
+ t.string :author
5
+ t.integer :year
6
+ t.string :blurb_file
7
+ t.boolean :delta, :default => true, :null => false
8
+ t.timestamps
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -1,15 +1,19 @@
1
- require 'thinking_sphinx'
2
- require 'thinking_sphinx/deltas/resque_delta'
3
- require 'flying_sphinx'
4
- require 'flying_sphinx/resque_delta'
5
-
6
- require 'mock_redis'
7
- require 'fakefs/spec_helpers'
8
-
9
- RSpec.configure do |c|
10
- c.filter_run :focus => true
11
- c.run_all_when_everything_filtered = true
12
- c.treat_symbols_as_metadata_keys_with_true_values = true
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ require 'thinking_sphinx/railtie'
7
+
8
+ Combustion.initialize! :active_record
9
+
10
+ root = File.expand_path File.dirname(__FILE__)
11
+ Dir["#{root}/support/**/*.rb"].each { |file| require file }
12
+
13
+ RSpec.configure do |config|
14
+ # enable filtering for examples
15
+ config.filter_run :wip => nil
16
+ config.run_all_when_everything_filtered = true
13
17
  end
14
18
 
15
19
  SPEC_BIN_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'bin'))
@@ -2,172 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::Deltas::ResqueDelta::DeltaJob do
4
4
  subject do
5
- ThinkingSphinx::Deltas::ResqueDelta::DeltaJob.tap do |s|
6
- s.stub(:` => true)
7
- s.stub(:puts => nil)
8
- end
5
+ ThinkingSphinx::Deltas::ResqueDelta::DeltaJob
9
6
  end
10
7
 
11
8
  describe '.perform' do
12
- before :each do
13
- ThinkingSphinx.suppress_delta_output = false
14
- ThinkingSphinx::Deltas::ResqueDelta.stub(:locked?).and_return(false)
15
- ThinkingSphinx.stub(:sphinx_running? => false)
16
- end
17
-
18
- it "should output the delta indexing by default" do
19
- subject.should_receive(:puts)
20
- subject.perform('foo_delta')
21
- end
22
-
23
- it "should not output the delta indexing if requested" do
24
- ThinkingSphinx.suppress_delta_output = true
25
- subject.should_not_receive(:puts)
26
- subject.perform('foo_delta')
27
- end
28
-
29
- it "should process just the requested index" do
30
- subject.should_receive(:`) do |c|
31
- c.should match(/foo_delta/)
32
- c.should_not match(/--all/)
33
- end
34
- subject.perform('foo_delta')
35
- end
36
-
37
- context 'when an index is locked' do
38
- before do
39
- ThinkingSphinx::Deltas::ResqueDelta.stub(:locked?) do |index_name|
40
- index_name == 'foo_delta' ? true : false
41
- end
42
- end
43
-
44
- it "should not start the indexer" do
45
- subject.should_not_receive(:`)
46
- subject.perform('foo_delta')
47
- end
48
-
49
- it "should start the indexer for unlocked indexes" do
50
- subject.should_receive(:`)
51
- subject.perform('bar_delta')
52
- end
53
- end
54
-
55
- context 'with flag as deleted document ids' do
56
- let(:client) { stub('client', :update => true) }
57
- let(:document_ids) { [1, 2, 3] }
58
-
59
- before :each do
60
- ThinkingSphinx.updates_enabled = true
61
-
62
- ThinkingSphinx::Configuration.instance.stub(:client => client)
63
- ThinkingSphinx.stub(:sphinx_running? => true)
64
-
65
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.stub(:processing_members => document_ids)
66
- subject.stub(:filter_flag_as_deleted_ids => document_ids)
67
- end
68
-
69
- it 'should get the processing set of flag as deleted document ids' do
70
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.should_receive(:processing_members).with('foo_core')
71
- subject.perform('foo_delta')
72
- end
73
-
74
- it "should not update if Sphinx isn't running" do
75
- ThinkingSphinx.stub(:sphinx_running? => false)
76
- client.should_not_receive(:update)
77
- subject.perform('foo_delta')
78
- end
9
+ let(:job) { double 'Job', :perform => true }
79
10
 
80
- it "should validate the document ids with sphinx" do
81
- subject.should_receive(:filter_flag_as_deleted_ids).with(document_ids, 'foo_core')
82
-
83
- subject.perform('foo_delta')
84
- end
85
-
86
- context "with invalid ids" do
87
- before :each do
88
- subject.stub(:filter_flag_as_deleted_ids => document_ids.reject {|x| x == 2} )
89
- end
90
-
91
- it "should not update documents that aren't in the index" do
92
- client.should_receive(:update) do |index, attributes, values|
93
- values.should_not include(2)
94
- end
95
- subject.perform('foo_delta')
96
- end
97
-
98
- it "should update documents that are in the index" do
99
- client.should_receive(:update) do |index, attributes, values|
100
- values.keys.should eql(document_ids.reject{|x| x == 2})
101
- end
102
- subject.perform('foo_delta')
103
- end
104
- end
105
-
106
- it "should update the specified index" do
107
- client.should_receive(:update) do |index, attributes, values|
108
- index.should == 'foo_core'
109
- end
110
- subject.perform('foo_delta')
111
- end
112
-
113
- it "should update the sphinx_deleted attribute" do
114
- client.should_receive(:update) do |index, attributes, values|
115
- attributes.should == ['sphinx_deleted']
116
- end
117
- subject.perform('foo_delta')
118
- end
119
-
120
- it "should set sphinx_deleted for valid documents to true" do
121
- client.should_receive(:update) do |index, attributes, values|
122
- document_ids.each {|id| values[id].should == [1] }
123
- end
124
- subject.perform('foo_delta')
125
- end
126
-
127
- context "without any ids" do
128
- let(:document_ids) { [] }
129
-
130
- it "should not validate the ids with sphinx" do
131
- subject.should_not_receive(:filter_flag_as_deleted_ids)
132
- subject.perform('foo_delta')
133
- end
134
- end
135
- end
136
- end
137
-
138
- describe '.around_perform_lock1' do
139
11
  before :each do
140
- Resque.stub(:encode => 'DeltaJobsAreAwesome')
141
- Resque.stub_chain(:redis, :lrem)
142
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.stub(:get_subset_for_processing)
143
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.stub(:clear_processing)
144
- end
145
-
146
- it 'should clear all other delta jobs' do
147
- Resque.redis.should_receive(:lrem).with("queue:#{subject.instance_variable_get(:@queue)}", 0, 'DeltaJobsAreAwesome')
148
-
149
- subject.around_perform_lock1('foo_delta') {}
12
+ ThinkingSphinx::Deltas::ResqueDelta.stub :locked? => false
13
+ ThinkingSphinx::Deltas::IndexJob.stub :new => job
150
14
  end
151
15
 
152
- it 'should set up the processing set of document ids' do
153
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.should_receive(:get_subset_for_processing).with('foo_core')
16
+ it "sets up the internal Thinking Sphinx job with the provided index" do
17
+ ThinkingSphinx::Deltas::IndexJob.should_receive(:new).with('foo_delta').
18
+ and_return(job)
154
19
 
155
- subject.around_perform_lock1('foo_delta') {}
20
+ subject.perform 'foo_delta'
156
21
  end
157
22
 
158
- it 'should clear the processing set when finished' do
159
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.should_receive(:clear_processing).with('foo_core')
160
-
161
- subject.around_perform_lock1('foo_delta') {}
162
- end
163
- end
164
-
165
- describe '.lock_failed' do
166
- it 'should enqueue the delta job again' do
167
- Resque.stub(:enqueue => true)
168
- Resque.should_receive(:enqueue)
23
+ it "should execute the internal job" do
24
+ job.should_receive :perform
169
25
 
170
- subject.lock_failed('foo_delta')
26
+ subject.perform 'foo_delta'
171
27
  end
172
28
  end
173
29
  end
@@ -2,127 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::Deltas::ResqueDelta do
4
4
  before :each do
5
- ThinkingSphinx.updates_enabled = true
6
- ThinkingSphinx.deltas_enabled = true
7
-
8
5
  Resque.redis = MockRedis.new
9
6
  end
10
7
 
11
- describe '#index' do
12
- def flag_as_deleted_document_in_set?
13
- Resque.redis.sismember(ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.set_name('foo_core'), 42)
14
- end
15
-
16
- subject do
17
- ThinkingSphinx::Deltas::ResqueDelta.new(
18
- stub('instance'), {}
19
- ).tap do |s|
20
- s.stub(:toggled).and_return(true)
21
- s.stub(:lock)
22
- s.stub(:unlock)
23
- s.stub(:locked?).and_return(false)
24
- end
25
- end
26
-
27
- let(:model) do
28
- stub('foo').tap do |m|
29
- m.stub(:name => 'foo')
30
- m.stub(:source_of_sphinx_index => m)
31
- m.stub(:core_index_names => ['foo_core'])
32
- m.stub(:delta_index_names => ['foo_delta'])
33
- end
34
- end
35
-
36
- let(:instance) do
37
- stub('instance').tap do |i|
38
- i.stub(:sphinx_document_id => 42)
39
- end
40
- end
41
-
42
- before :each do
43
- Resque.stub(:enqueue => true)
44
- end
45
-
46
- context 'updates disabled' do
47
- before :each do
48
- ThinkingSphinx.updates_enabled = false
49
- end
50
-
51
- it "should not enqueue a delta job" do
52
- Resque.should_not_receive(:enqueue)
53
- subject.index(model)
54
- end
55
-
56
- it "should not add a flag as deleted document to the set" do
57
- subject.index(model, instance)
58
- flag_as_deleted_document_in_set?.should be_false
59
- end
60
- end
61
-
62
- context 'deltas disabled' do
63
- before :each do
64
- ThinkingSphinx.deltas_enabled = false
65
- end
66
-
67
- it "should not enqueue a delta job" do
68
- Resque.should_not_receive(:enqueue)
69
- subject.index(model)
70
- end
71
-
72
- it "should not add a flag as deleted document to the set" do
73
- subject.index(model, instance)
74
- flag_as_deleted_document_in_set?.should be_false
75
- end
76
- end
77
-
78
- context "instance isn't toggled" do
79
- before :each do
80
- subject.stub(:toggled => false)
81
- end
82
-
83
- it "should not enqueue a delta job" do
84
- Resque.should_not_receive(:enqueue)
85
- subject.index(model, instance)
86
- end
87
-
88
- it "should not add a flag as deleted document to the set" do
89
- subject.index(model, instance)
90
- flag_as_deleted_document_in_set?.should be_false
91
- end
92
- end
93
-
94
- it "should enqueue a delta job" do
95
- Resque.should_receive(:enqueue).once.with(
96
- ThinkingSphinx::Deltas::ResqueDelta::DeltaJob,
97
- 'foo_delta'
98
- )
99
- subject.index(model)
100
- end
101
-
102
- it "should add the flag as deleted document id to the set" do
103
- subject.index(model, instance)
104
- flag_as_deleted_document_in_set?.should be_true
105
- end
106
-
107
- context "delta index is locked" do
108
- before :each do
109
- ThinkingSphinx::Deltas::ResqueDelta.stub(:locked?).and_return(true)
110
- end
111
-
112
- it "should not enqueue a delta job" do
113
- Resque.should_not_receive(:enqueue)
114
- subject.index(model, instance)
115
- end
116
-
117
- it "should add the flag as deleted document id to the set" do
118
- subject.index(model, instance)
119
- flag_as_deleted_document_in_set?.should be_true
120
- end
121
- end
122
- end
123
-
124
- describe '.clear_thinking_sphinx_queues' do
125
- subject { ThinkingSphinx::Deltas::ResqueDelta.clear_thinking_sphinx_queues }
8
+ describe '.cancel_jobs' do
9
+ subject { ThinkingSphinx::Deltas::ResqueDelta.cancel_jobs }
126
10
 
127
11
  before :all do
128
12
  class RandomJob
@@ -132,7 +16,7 @@ describe ThinkingSphinx::Deltas::ResqueDelta do
132
16
 
133
17
  before :each do
134
18
  Resque.enqueue(ThinkingSphinx::Deltas::ResqueDelta::DeltaJob, 'foo_delta')
135
- Resque.enqueue(ThinkingSphinx::Deltas::ResqueDelta::DeltaJob, 'bar_delta')
19
+ Resque.enqueue(ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob, 'bar_delta')
136
20
  Resque.enqueue(RandomJob, '1234')
137
21
  end
138
22
 
@@ -141,51 +25,4 @@ describe ThinkingSphinx::Deltas::ResqueDelta do
141
25
  Resque.size('ts_delta').should eq(0)
142
26
  end
143
27
  end
144
-
145
- describe '.lock' do
146
- it 'should set the lock key in redis' do
147
- ThinkingSphinx::Deltas::ResqueDelta.lock('foo')
148
- Resque.redis.get("#{ThinkingSphinx::Deltas::ResqueDelta.job_prefix}:index:foo:locked").should eql('true')
149
- end
150
- end
151
-
152
- describe '.unlock' do
153
- it 'should unset the lock key in redis' do
154
- Resque.redis.set("#{ThinkingSphinx::Deltas::ResqueDelta.job_prefix}:index:foo:locked", 'true')
155
- ThinkingSphinx::Deltas::ResqueDelta.unlock('foo')
156
- Resque.redis.get("#{ThinkingSphinx::Deltas::ResqueDelta.job_prefix}:index:foo:locked").should be_nil
157
- end
158
- end
159
-
160
- describe '.locked?' do
161
- subject { ThinkingSphinx::Deltas::ResqueDelta.locked?('foo') }
162
-
163
- context "when lock key in redis is true" do
164
- before { Resque.redis.set("#{ThinkingSphinx::Deltas::ResqueDelta.job_prefix}:index:foo:locked", 'true') }
165
- it { should be_true }
166
- end
167
-
168
- context "when lock key in redis is nil" do
169
- it { should be_false }
170
- end
171
- end
172
-
173
- describe '.prepare_for_core_index' do
174
- subject { ThinkingSphinx::Deltas::ResqueDelta.prepare_for_core_index('foo') }
175
-
176
- before :each do
177
- Resque.stub(:dequeue)
178
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.stub(:clear!)
179
- end
180
-
181
- it "should call FlagAsDeletedSet.clear!" do
182
- ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.should_receive(:clear!).with('foo_core')
183
- subject
184
- end
185
-
186
- it "should clear delta jobs" do
187
- Resque.should_receive(:dequeue).with(ThinkingSphinx::Deltas::ResqueDelta::DeltaJob, 'foo_delta')
188
- subject
189
- end
190
- end
191
28
  end