public
Description: ultrasphinx's is_indexed rspec matcher
Homepage:
Clone URL: git://github.com/nando/be_indexed.git
be_indexed / spec / ultrasphinx / matchers / be_indexed_spec.rb
100644 130 lines (96 sloc) 3.35 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require File.dirname(__FILE__) + '/../../spec_helper'
require 'spec/ultrasphinx/matchers/be_indexed'
 
class DummyNotIndexed < ActiveRecord::Base; end
 
describe "not indexed" do
  include Spec::Ultrasphinx::Matchers
 
  it 'should not be indexed' do
    DummyNotIndexed.should_not be_indexed
  end
  
  it 'should not be indexed using some fields' do
    DummyNotIndexed.should_not be_indexed.using_fields([:field_one, :field_two])
  end
end
 
 
class DummyIndexedOne < ActiveRecord::Base
  is_indexed :fields => [:field_one, :field_two]
end
 
describe "indexed using some fields" do
  include Spec::Ultrasphinx::Matchers
  
  it 'should be indexed' do
    DummyIndexedOne.should be_indexed
  end
  
  it 'should be indexed using that fields' do
    DummyIndexedOne.should be_indexed.using_fields([:field_one, :field_two])
  end
  
  it 'should not be indexed using other fields' do
    DummyIndexedOne.should_not be_indexed.using_fields([:field_one, :field_four])
  end
  
  it 'should not be delta indexed' do
    DummyIndexedOne.should_not be_indexed.with_delta
  end
  
  it 'should be indexed and without delta (explicit)' do
    DummyIndexedOne.should be_indexed.with_delta(false)
  end
end
 
class DummyIndexedTwo < ActiveRecord::Base
  is_indexed :fields => :field_one, :delta => true
end
 
describe "indexed using a field and delta activated (true)" do
  include Spec::Ultrasphinx::Matchers
  
  it 'should be indexed' do
    DummyIndexedTwo.should be_indexed
  end
  
  it 'should be indexed using that field' do
    DummyIndexedTwo.should be_indexed.using_fields(:field_one)
  end
  
  it 'should be delta indexed using that field' do
    DummyIndexedTwo.should be_indexed.using_fields(:field_one).with_delta
  end
  
  it 'should not be indexed using other field' do
    DummyIndexedTwo.should_not be_indexed.using_fields(:field_four)
  end
  
  it 'should not be indexed using other fields' do
    DummyIndexedTwo.should_not be_indexed.using_fields([:field_one, :field_four])
  end
  
  it 'should be delta indexed and then using that field' do
    DummyIndexedTwo.should be_indexed.with_delta.using_fields(:field_one)
  end
  
  it 'should be not indexed and without delta (explicit)' do
    DummyIndexedTwo.should_not be_indexed.with_delta(false)
  end
end
 
class DummyIndexedThree < ActiveRecord::Base
  is_indexed :fields => :field_one, :delta => {:field => 'cache_version'}
end
 
describe "delta indexing with an specific field" do
  include Spec::Ultrasphinx::Matchers
  
  it do
    DummyIndexedThree.should be_indexed.with_delta
  end
  
  it do
    DummyIndexedThree.should be_indexed.with_delta(:field => 'cache_version')
  end
  
  it do
    DummyIndexedThree.should be_indexed.with_delta('field' => :cache_version)
  end
  
  it do
    DummyIndexedThree.should_not be_indexed.with_delta(false)
  end
  
  it do
    DummyIndexedThree.should_not be_indexed.with_delta(:field => 'updated_at')
  end
 
end
 
 
class DummyIndexedRaw < ActiveRecord::Base
  is_indexed
end
describe "indexed raw" do
  include Spec::Ultrasphinx::Matchers
  
  it 'should be indexed' do
    DummyIndexedRaw.should be_indexed
  end
  
  it 'should not be delta indexed' do
    DummyIndexedRaw.should_not be_indexed.with_delta
  end
  
  it 'should not be indexed with any field' do
    DummyIndexedRaw.should_not be_indexed.using_fields(:field_one)
  end
end