model_test.rb
1.38 KB
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
require_relative "test_helper"
describe "Model#should_index?" do
it 'Model.reindex checks for #should_index?' do
indexed = Animal.new(name: 'should')
indexed.stubs(:should_index?).returns(true)
not_indexed = Animal.new(name: 'should not')
not_indexed.stubs(:should_index?).returns(false)
[indexed, not_indexed].each(&:save!)
Animal.searchkick_index.refresh
assert_search 'should', ['should'], {}, Animal
end
it 'Model#reindex checks for #should_index?' do
Animal.any_instance.stubs(:should_index?).returns(false)
store_names ['should not', 'shouldnt'], Animal
Animal.reindex
Animal.searchkick_index.refresh
assert_search 'should', [], {}, Animal
end
it 'indexes existing model after the #should_index? switched to true' do
subject = Animal.new(name: 'should')
subject.stubs(:should_index?).returns(false)
subject.save!
subject.stubs(:should_index?).returns(true)
subject.save!
Animal.searchkick_index.refresh
assert_search 'should', ['should'], {}, Animal
end
it 'removes the existing model from index after the #should_index? switched to false' do
subject = Animal.new(name: 'should')
subject.stubs(:should_index?).returns(true)
subject.save!
subject.stubs(:should_index?).returns(false)
subject.save!
Animal.searchkick_index.refresh
assert_search 'should', [], {}, Animal
end
end