forked from pat/ts-delayed-delta
/
flag_as_deleted_job_spec.rb
78 lines (59 loc) · 2.1 KB
/
flag_as_deleted_job_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'spec_helper'
describe ThinkingSphinx::Deltas::FlagAsDeletedJob do
describe '#perform' do
before :each do
ThinkingSphinx.updates_enabled = true
@client = stub('client', :update => true)
ThinkingSphinx::Configuration.instance.stub!(:client => @client)
ThinkingSphinx.stub!(:search_for_id => true)
ThinkingSphinx.stub!(:sphinx_running? => true)
@job = ThinkingSphinx::Deltas::FlagAsDeletedJob.new(['foo_core'], 12)
end
it "should not update if Sphinx isn't running" do
ThinkingSphinx.stub!(:sphinx_running? => false)
@client.should_not_receive(:update)
@job.perform
end
it "should not update if the document isn't in the index" do
ThinkingSphinx.stub!(:search_for_id => false)
@client.should_not_receive(:update)
@job.perform
end
it "should update the specified index" do
@client.should_receive(:update) do |index, attributes, values|
index.should == 'foo_core'
end
@job.perform
end
it "should update all specified indices" do
@job.indices = ['foo_core', 'bar_core']
@client.should_receive(:update).with('foo_core', anything, anything)
@client.should_receive(:update).with('bar_core', anything, anything)
@job.perform
end
it "should update the sphinx_deleted attribute" do
@client.should_receive(:update) do |index, attributes, values|
attributes.should == ['sphinx_deleted']
end
@job.perform
end
it "should set sphinx_deleted for the given document to true" do
@client.should_receive(:update) do |index, attributes, values|
values[12].should == [1]
end
@job.perform
end
it "should check for the existence of the document in the specified index" do
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
index.should == 'foo_core'
end
@job.perform
end
it "should check for the existence of the given document id" do
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
id.should == 12
end
@job.perform
end
end
end