ts-delayed-delta 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,9 @@ require 'cucumber/thinking_sphinx/internal_world'
11
11
  world = Cucumber::ThinkingSphinx::InternalWorld.new
12
12
  world.configure_database
13
13
 
14
- require 'thinking_sphinx'
14
+ SphinxVersion = ENV['VERSION'] || '0.9.8'
15
+
16
+ require "thinking_sphinx/#{SphinxVersion}"
15
17
  require 'thinking_sphinx/deltas/delayed_delta'
16
18
 
17
19
  world.setup
@@ -1,14 +1,14 @@
1
1
  # A simple job class that processes a given index.
2
2
  #
3
3
  class ThinkingSphinx::Deltas::DeltaJob
4
- attr_accessor :index
4
+ attr_accessor :indexes
5
5
 
6
6
  # Initialises the object with an index name.
7
7
  #
8
8
  # @param [String] index the name of the Sphinx index
9
9
  #
10
- def initialize(index)
11
- @index = index
10
+ def initialize(indexes)
11
+ @indexes = indexes
12
12
  end
13
13
 
14
14
  # Runs Sphinx's indexer tool to process the index. Currently assumes Sphinx is
@@ -19,7 +19,7 @@ class ThinkingSphinx::Deltas::DeltaJob
19
19
  def perform
20
20
  config = ThinkingSphinx::Configuration.instance
21
21
 
22
- output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --rotate #{index}`
22
+ output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --rotate #{indexes.join(' ')}`
23
23
  puts output unless ThinkingSphinx.suppress_delta_output?
24
24
 
25
25
  true
@@ -2,7 +2,7 @@
2
2
  # 'deleted'.
3
3
  #
4
4
  class ThinkingSphinx::Deltas::FlagAsDeletedJob
5
- attr_accessor :index, :document_id
5
+ attr_accessor :indexes, :document_id
6
6
 
7
7
  # Initialises the object with an index name and document id. Please note that
8
8
  # the document id is Sphinx's unique identifier, and will almost certainly not
@@ -11,8 +11,8 @@ class ThinkingSphinx::Deltas::FlagAsDeletedJob
11
11
  # @param [String] index The index name
12
12
  # @param [Integer] document_id The document id
13
13
  #
14
- def initialize(index, document_id)
15
- @index, @document_id = index, document_id
14
+ def initialize(indexes, document_id)
15
+ @indexes, @document_id = indexes, document_id
16
16
  end
17
17
 
18
18
  # Updates the sphinx_deleted attribute for the given document, setting the
@@ -26,12 +26,14 @@ class ThinkingSphinx::Deltas::FlagAsDeletedJob
26
26
  def perform
27
27
  config = ThinkingSphinx::Configuration.instance
28
28
 
29
- config.client.update(
30
- @index,
31
- ['sphinx_deleted'],
32
- {@document_id => [1]}
33
- ) if ThinkingSphinx.sphinx_running? &&
34
- ThinkingSphinx::Search.search_for_id(@document_id, @index)
29
+ indexes.each do |index|
30
+ config.client.update(
31
+ index,
32
+ ['sphinx_deleted'],
33
+ {@document_id => [1]}
34
+ ) if ThinkingSphinx.sphinx_running? &&
35
+ ThinkingSphinx::Search.search_for_id(@document_id, index)
36
+ end
35
37
 
36
38
  true
37
39
  end
@@ -16,7 +16,7 @@ class ThinkingSphinx::Deltas::Job < Delayed::Job
16
16
  # @param [Integer] priority (0)
17
17
  #
18
18
  def self.enqueue(object, priority = 0)
19
- Delayed::Job.enqueue(object, priority) unless duplicates_exist(object)
19
+ ::Delayed::Job.enqueue(object, priority) unless duplicates_exist(object)
20
20
  end
21
21
 
22
22
  # Remove all Thinking Sphinx/Delayed Delta jobs from the queue. If the
@@ -34,13 +34,13 @@ class ThinkingSphinx::Deltas::DelayedDelta < ThinkingSphinx::Deltas::DefaultDelt
34
34
  return true if skip? instance
35
35
 
36
36
  ThinkingSphinx::Deltas::Job.enqueue(
37
- ThinkingSphinx::Deltas::DeltaJob.new(delta_index_name(model)),
37
+ ThinkingSphinx::Deltas::DeltaJob.new(model.delta_index_names),
38
38
  ThinkingSphinx::Configuration.instance.delayed_job_priority
39
39
  )
40
40
 
41
41
  Delayed::Job.enqueue(
42
42
  ThinkingSphinx::Deltas::FlagAsDeletedJob.new(
43
- core_index_name(model), instance.sphinx_document_id
43
+ model.core_index_names, instance.sphinx_document_id
44
44
  ),
45
45
  ThinkingSphinx::Configuration.instance.delayed_job_priority
46
46
  ) if instance
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,9 @@ require 'rubygems'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
- require 'thinking_sphinx'
7
+ SphinxVersion = ENV['VERSION'] || '0.9.8'
8
+
9
+ require "thinking_sphinx/#{SphinxVersion}"
8
10
  require 'thinking_sphinx/deltas/delayed_delta'
9
11
 
10
12
  Spec::Runner.configure do |config|
@@ -5,7 +5,7 @@ describe ThinkingSphinx::Deltas::DeltaJob do
5
5
  before :each do
6
6
  ThinkingSphinx.suppress_delta_output = false
7
7
 
8
- @delta_job = ThinkingSphinx::Deltas::DeltaJob.new('foo_core')
8
+ @delta_job = ThinkingSphinx::Deltas::DeltaJob.new(['foo_core'])
9
9
  @delta_job.stub! :` => true
10
10
  @delta_job.stub! :puts => nil
11
11
  end
@@ -23,7 +23,7 @@ describe ThinkingSphinx::Deltas::DeltaJob do
23
23
  @delta_job.perform
24
24
  end
25
25
 
26
- it "should process just the requested index" do
26
+ it "should process just the requested indexes" do
27
27
  @delta_job.should_receive(:`) do |command|
28
28
  command.should match(/foo_core/)
29
29
  command.should_not match(/--all/)
@@ -31,5 +31,16 @@ describe ThinkingSphinx::Deltas::DeltaJob do
31
31
 
32
32
  @delta_job.perform
33
33
  end
34
+
35
+ context 'multiple indexes' do
36
+ it "should process all requested indexes" do
37
+ @delta_job.indexes = ['foo_core', 'bar_core']
38
+ @delta_job.should_receive(:`) do |command|
39
+ command.should match(/foo_core bar_core/)
40
+ end
41
+
42
+ @delta_job.perform
43
+ end
44
+ end
34
45
  end
35
46
  end
@@ -10,7 +10,7 @@ describe ThinkingSphinx::Deltas::FlagAsDeletedJob do
10
10
  ThinkingSphinx::Search.stub!(:search_for_id => true)
11
11
  ThinkingSphinx.stub!(:sphinx_running? => true)
12
12
 
13
- @job = ThinkingSphinx::Deltas::FlagAsDeletedJob.new('foo_core', 12)
13
+ @job = ThinkingSphinx::Deltas::FlagAsDeletedJob.new(['foo_core'], 12)
14
14
  end
15
15
 
16
16
  it "should not update if Sphinx isn't running" do
@@ -35,6 +35,14 @@ describe ThinkingSphinx::Deltas::FlagAsDeletedJob do
35
35
  @job.perform
36
36
  end
37
37
 
38
+ it "should update all specified indexes" do
39
+ @job.indexes = ['foo_core', 'bar_core']
40
+ @client.should_receive(:update).with('foo_core', anything, anything)
41
+ @client.should_receive(:update).with('bar_core', anything, anything)
42
+
43
+ @job.perform
44
+ end
45
+
38
46
  it "should update the sphinx_deleted attribute" do
39
47
  @client.should_receive(:update) do |index, attributes, values|
40
48
  attributes.should == ['sphinx_deleted']
@@ -8,7 +8,7 @@ describe ThinkingSphinx::Deltas::DelayedDelta do
8
8
  ThinkingSphinx::Configuration.instance.delayed_job_priority = 2
9
9
 
10
10
  ThinkingSphinx::Deltas::Job.stub!(:enqueue => true)
11
- Delayed::Job.stub!(:enqueue => true)
11
+ Delayed::Job.stub!(:enqueue => true, :inspect => "Delayed::Job")
12
12
 
13
13
  @delayed_delta = ThinkingSphinx::Deltas::DelayedDelta.new(
14
14
  stub('instance'), {}
@@ -18,6 +18,8 @@ describe ThinkingSphinx::Deltas::DelayedDelta do
18
18
  @model = stub('foo')
19
19
  @model.stub!(:name => 'foo')
20
20
  @model.stub!(:source_of_sphinx_index => @model)
21
+ @model.stub!(:core_index_names => ['foo_core'])
22
+ @model.stub!(:delta_index_names => ['foo_delta'])
21
23
 
22
24
  @instance = stub('instance')
23
25
  @instance.stub!(:sphinx_document_id => 42)
@@ -77,9 +79,9 @@ describe ThinkingSphinx::Deltas::DelayedDelta do
77
79
  end
78
80
  end
79
81
 
80
- it "should enqueue a delta job for the appropriate index" do
82
+ it "should enqueue a delta job for the appropriate indexes" do
81
83
  ThinkingSphinx::Deltas::Job.should_receive(:enqueue) do |job, priority|
82
- job.index.should == 'foo_delta'
84
+ job.indexes.should == ['foo_delta']
83
85
  end
84
86
 
85
87
  @delayed_delta.index(@model)
@@ -93,9 +95,9 @@ describe ThinkingSphinx::Deltas::DelayedDelta do
93
95
  @delayed_delta.index(@model)
94
96
  end
95
97
 
96
- it "should enqueue a flag-as-deleted job for the appropriate index" do
98
+ it "should enqueue a flag-as-deleted job for the appropriate indexes" do
97
99
  Delayed::Job.should_receive(:enqueue) do |job, priority|
98
- job.index.should == 'foo_core'
100
+ job.indexes.should == ['foo_core']
99
101
  end
100
102
 
101
103
  @delayed_delta.index(@model, @instance)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ts-delayed-delta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-03 00:00:00 +11:00
12
+ date: 2009-11-26 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thinking-sphinx
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.6
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: delayed_job
17
27
  type: :runtime