Sha256: b2450e22bd42fb640b8f5a69466c6183bf2ed212dd462e498398178f68fa1fe1

Contents?: true

Size: 1.78 KB

Versions: 11

Compression:

Stored size: 1.78 KB

Contents

require 'spec/spec_helper'

describe ThinkingSphinx::Deltas::Job do
  describe '.enqueue' do
    before :each do
      ThinkingSphinx::Deltas::Job.stub!(:count => 0)
    end
    
    it "should enqueue if there's no existing jobs for the same index" do
      Delayed::Job.should_receive(:enqueue)
      
      ThinkingSphinx::Deltas::Job.enqueue(stub('object'))
    end
    
    it "should not enqueue the job if there's an existing job already" do
      ThinkingSphinx::Deltas::Job.stub!(:count => 1)
      Delayed::Job.should_not_receive(:enqueue)
      
      ThinkingSphinx::Deltas::Job.enqueue(stub('object'))
    end
  end
  
  describe '.cancel_thinking_sphinx_jobs' do
    before :each do
      ThinkingSphinx::Deltas::Job.stub!(:connection, stub('connection'))
      ThinkingSphinx::Deltas::Job.stub!(:delete_all => true)
    end
    
    it "should not delete any rows if the delayed_jobs table does not exist" do
      ThinkingSphinx::Deltas::Job.connection.stub!(:tables => [])
      ThinkingSphinx::Deltas::Job.should_not_receive(:delete_all)
      
      ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
    end
    
    it "should delete rows if the delayed_jobs table does exist" do
      ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
      ThinkingSphinx::Deltas::Job.should_receive(:delete_all)
      
      ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
    end
    
    it "should delete only Thinking Sphinx jobs" do
      ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
      ThinkingSphinx::Deltas::Job.should_receive(:delete_all) do |sql|
        sql.should match(/handler LIKE '--- !ruby\/object:ThinkingSphinx::Deltas::\%'/)
      end
      
      ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
ts-delayed-delta-1.1.2 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.1.1 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.1.0 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.0.4 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.0.3 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
namxam-ts-delayed-delta-1.0.3 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
warp-ts-delayed-delta-1.0.3 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
warp-ts-delayed-delta-1.0.2 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.0.2 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.0.1 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
ts-delayed-delta-1.0.0 spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb