thinking-sphinx 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +7 -1
- data/features/searching_by_model.feature +24 -30
- data/features/step_definitions/common_steps.rb +5 -5
- data/features/thinking_sphinx/db/.gitignore +1 -0
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +161 -0
- data/spec/fixtures/structure.sql +146 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/sphinx_helper.rb +61 -0
- data/spec/support/rails.rb +18 -0
- data/spec/thinking_sphinx/active_record/delta_spec.rb +24 -24
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +27 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +25 -25
- data/spec/thinking_sphinx/active_record_spec.rb +108 -107
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +38 -38
- data/spec/thinking_sphinx/association_spec.rb +69 -35
- data/spec/thinking_sphinx/context_spec.rb +61 -64
- data/spec/thinking_sphinx/search_spec.rb +7 -0
- data/spec/thinking_sphinx_spec.rb +47 -46
- metadata +49 -141
- data/VERSION +0 -1
- data/lib/cucumber/thinking_sphinx/external_world.rb +0 -12
- data/lib/cucumber/thinking_sphinx/internal_world.rb +0 -127
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +0 -20
- data/lib/thinking-sphinx.rb +0 -1
- data/lib/thinking_sphinx.rb +0 -301
- data/lib/thinking_sphinx/action_controller.rb +0 -31
- data/lib/thinking_sphinx/active_record.rb +0 -384
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +0 -52
- data/lib/thinking_sphinx/active_record/delta.rb +0 -65
- data/lib/thinking_sphinx/active_record/has_many_association.rb +0 -36
- data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
- data/lib/thinking_sphinx/active_record/log_subscriber.rb +0 -61
- data/lib/thinking_sphinx/active_record/scopes.rb +0 -93
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +0 -87
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -62
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +0 -157
- data/lib/thinking_sphinx/association.rb +0 -219
- data/lib/thinking_sphinx/attribute.rb +0 -396
- data/lib/thinking_sphinx/auto_version.rb +0 -38
- data/lib/thinking_sphinx/bundled_search.rb +0 -44
- data/lib/thinking_sphinx/class_facet.rb +0 -20
- data/lib/thinking_sphinx/configuration.rb +0 -339
- data/lib/thinking_sphinx/context.rb +0 -76
- data/lib/thinking_sphinx/core/string.rb +0 -15
- data/lib/thinking_sphinx/deltas.rb +0 -28
- data/lib/thinking_sphinx/deltas/default_delta.rb +0 -62
- data/lib/thinking_sphinx/deploy/capistrano.rb +0 -101
- data/lib/thinking_sphinx/excerpter.rb +0 -23
- data/lib/thinking_sphinx/facet.rb +0 -128
- data/lib/thinking_sphinx/facet_search.rb +0 -170
- data/lib/thinking_sphinx/field.rb +0 -98
- data/lib/thinking_sphinx/index.rb +0 -157
- data/lib/thinking_sphinx/index/builder.rb +0 -312
- data/lib/thinking_sphinx/index/faux_column.rb +0 -118
- data/lib/thinking_sphinx/join.rb +0 -37
- data/lib/thinking_sphinx/property.rb +0 -185
- data/lib/thinking_sphinx/railtie.rb +0 -46
- data/lib/thinking_sphinx/search.rb +0 -972
- data/lib/thinking_sphinx/search_methods.rb +0 -439
- data/lib/thinking_sphinx/sinatra.rb +0 -7
- data/lib/thinking_sphinx/source.rb +0 -194
- data/lib/thinking_sphinx/source/internal_properties.rb +0 -51
- data/lib/thinking_sphinx/source/sql.rb +0 -157
- data/lib/thinking_sphinx/tasks.rb +0 -130
- data/lib/thinking_sphinx/test.rb +0 -55
- data/tasks/distribution.rb +0 -33
- data/tasks/testing.rb +0 -80
@@ -7,137 +7,137 @@ end
|
|
7
7
|
describe ThinkingSphinx::AbstractAdapter do
|
8
8
|
describe '.detect' do
|
9
9
|
let(:model) { stub('model') }
|
10
|
-
|
10
|
+
|
11
11
|
it "returns a MysqlAdapter object for :mysql" do
|
12
12
|
ThinkingSphinx::AbstractAdapter.stub(:adapter_for_model => :mysql)
|
13
|
-
|
13
|
+
|
14
14
|
adapter = ThinkingSphinx::AbstractAdapter.detect(model)
|
15
15
|
adapter.should be_a(ThinkingSphinx::MysqlAdapter)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "returns a PostgreSQLAdapter object for :postgresql" do
|
19
19
|
ThinkingSphinx::AbstractAdapter.stub(:adapter_for_model => :postgresql)
|
20
|
-
|
20
|
+
|
21
21
|
adapter = ThinkingSphinx::AbstractAdapter.detect(model)
|
22
22
|
adapter.should be_a(ThinkingSphinx::PostgreSQLAdapter)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "instantiates the provided class if one is provided" do
|
26
26
|
ThinkingSphinx::AbstractAdapter.stub(:adapter_for_model => CustomAdapter)
|
27
27
|
CustomAdapter.should_receive(:new).and_return(stub('adapter'))
|
28
|
-
|
28
|
+
|
29
29
|
ThinkingSphinx::AbstractAdapter.detect(model)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "raises an exception for other responses" do
|
33
33
|
ThinkingSphinx::AbstractAdapter.stub(:adapter_for_model => :sqlite)
|
34
|
-
|
34
|
+
|
35
35
|
lambda {
|
36
36
|
ThinkingSphinx::AbstractAdapter.detect(model)
|
37
37
|
}.should raise_error
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe '.adapter_for_model' do
|
42
42
|
let(:model) { stub('model') }
|
43
|
-
|
43
|
+
|
44
44
|
after :each do
|
45
45
|
ThinkingSphinx.database_adapter = nil
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "translates strings to symbols" do
|
49
49
|
ThinkingSphinx.database_adapter = 'foo'
|
50
|
-
|
50
|
+
|
51
51
|
ThinkingSphinx::AbstractAdapter.adapter_for_model(model).should == :foo
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "passes through symbols unchanged" do
|
55
55
|
ThinkingSphinx.database_adapter = :bar
|
56
|
-
|
56
|
+
|
57
57
|
ThinkingSphinx::AbstractAdapter.adapter_for_model(model).should == :bar
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "returns standard_adapter_for_model if database_adapter is not set" do
|
61
61
|
ThinkingSphinx.database_adapter = nil
|
62
62
|
ThinkingSphinx::AbstractAdapter.stub!(:standard_adapter_for_model => :baz)
|
63
|
-
|
63
|
+
|
64
64
|
ThinkingSphinx::AbstractAdapter.adapter_for_model(model).should == :baz
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it "calls the lambda and returns it if one is provided" do
|
68
68
|
ThinkingSphinx.database_adapter = lambda { |model| :foo }
|
69
|
-
|
69
|
+
|
70
70
|
ThinkingSphinx::AbstractAdapter.adapter_for_model(model).should == :foo
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
describe '.standard_adapter_for_model' do
|
75
75
|
let(:klass) { stub('connection class') }
|
76
76
|
let(:connection) { stub('connection', :class => klass) }
|
77
77
|
let(:model) { stub('model', :connection => connection) }
|
78
|
-
|
78
|
+
|
79
79
|
it "translates a normal MySQL adapter" do
|
80
80
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::MysqlAdapter')
|
81
|
-
|
81
|
+
|
82
82
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
83
83
|
should == :mysql
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "translates a MySQL plus adapter" do
|
87
87
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::MysqlplusAdapter')
|
88
|
-
|
88
|
+
|
89
89
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
90
90
|
should == :mysql
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "translates a MySQL2 adapter" do
|
94
94
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::Mysql2Adapter')
|
95
|
-
|
95
|
+
|
96
96
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
97
97
|
should == :mysql
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it "translates a NullDB adapter to MySQL" do
|
101
101
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::NullDBAdapter')
|
102
|
-
|
102
|
+
|
103
103
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
104
104
|
should == :mysql
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
it "translates a normal PostgreSQL adapter" do
|
108
108
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter')
|
109
|
-
|
109
|
+
|
110
110
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
111
111
|
should == :postgresql
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
it "translates a JDBC MySQL adapter to MySQL" do
|
115
115
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
|
116
116
|
connection.stub(:config => {:adapter => 'jdbcmysql'})
|
117
|
-
|
117
|
+
|
118
118
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
119
119
|
should == :mysql
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
it "translates a JDBC PostgreSQL adapter to PostgreSQL" do
|
123
123
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
|
124
124
|
connection.stub(:config => {:adapter => 'jdbcpostgresql'})
|
125
|
-
|
125
|
+
|
126
126
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
127
127
|
should == :postgresql
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
it "returns other JDBC adapters without translation" do
|
131
131
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::JdbcAdapter')
|
132
132
|
connection.stub(:config => {:adapter => 'jdbcmssql'})
|
133
|
-
|
133
|
+
|
134
134
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
135
|
-
should ==
|
135
|
+
should == :jdbcmssql
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
it "returns other unknown adapters without translation" do
|
139
139
|
klass.stub(:name => 'ActiveRecord::ConnectionAdapters::FooAdapter')
|
140
|
-
|
140
|
+
|
141
141
|
ThinkingSphinx::AbstractAdapter.standard_adapter_for_model(model).
|
142
142
|
should == 'ActiveRecord::ConnectionAdapters::FooAdapter'
|
143
143
|
end
|
@@ -14,7 +14,7 @@ describe ThinkingSphinx::Association do
|
|
14
14
|
:active_record => 'AR'
|
15
15
|
)
|
16
16
|
@non_poly_reflection = stub('reflection', :name => 'non_polly')
|
17
|
-
|
17
|
+
|
18
18
|
Person.stub!(:reflect_on_association => @normal_reflection)
|
19
19
|
ThinkingSphinx::Association.stub!(
|
20
20
|
:new => @normal_association,
|
@@ -25,58 +25,85 @@ describe ThinkingSphinx::Association do
|
|
25
25
|
:new => @non_poly_reflection
|
26
26
|
)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should return an empty array if no association exists" do
|
30
30
|
Person.stub!(:reflect_on_association => nil)
|
31
|
-
|
31
|
+
|
32
32
|
ThinkingSphinx::Association.children(Person, :assoc).should == []
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "should return a single association instance in an array if assocation isn't polymorphic" do
|
36
36
|
ThinkingSphinx::Association.children(Person, :assoc).should == [@normal_association]
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should return multiple association instances for polymorphic associations" do
|
40
40
|
Person.stub!(:reflect_on_association => @poly_reflection)
|
41
|
-
|
41
|
+
|
42
42
|
ThinkingSphinx::Association.children(Person, :assoc).should ==
|
43
43
|
[@normal_association, @normal_association]
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should generate non-polymorphic 'casted' associations for each polymorphic possibility" do
|
47
|
-
|
47
|
+
reflections = double('reflections', :[]= => nil)
|
48
|
+
Person.stub!(:reflections => reflections)
|
49
|
+
|
50
|
+
Person.should_receive(:reflect_on_association).once.
|
51
|
+
and_return(@poly_reflection)
|
52
|
+
reflections.should_receive(:[]).with(:polly_Person).twice.and_return(nil)
|
48
53
|
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
49
54
|
Person, @poly_reflection
|
50
55
|
).twice
|
51
56
|
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
52
|
-
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice
|
57
|
+
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice.
|
58
|
+
and_return(@non_poly_reflection)
|
53
59
|
ThinkingSphinx::Association.should_receive(:new).with(
|
54
60
|
nil, @non_poly_reflection
|
55
61
|
).twice
|
56
|
-
|
62
|
+
|
63
|
+
ThinkingSphinx::Association.children(Person, :assoc)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should use existing non-polymorphic 'casted' associations" do
|
67
|
+
reflections = double('reflections', :[]= => nil)
|
68
|
+
Person.stub!(:reflections => reflections)
|
69
|
+
|
70
|
+
Person.stub!(:reflect_on_association).once.
|
71
|
+
and_return(@poly_reflection)
|
72
|
+
reflections.should_receive(:[]).with(:polly_Person).twice.
|
73
|
+
and_return(nil, @non_poly_reflection)
|
74
|
+
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
75
|
+
Person, @poly_reflection
|
76
|
+
).once
|
77
|
+
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
78
|
+
with(:has_many, :polly_Person, {:casted => :options}, "AR").once.
|
79
|
+
and_return(@non_poly_reflection)
|
80
|
+
ThinkingSphinx::Association.should_receive(:new).with(
|
81
|
+
nil, @non_poly_reflection
|
82
|
+
).twice
|
83
|
+
|
57
84
|
ThinkingSphinx::Association.children(Person, :assoc)
|
58
85
|
end
|
59
86
|
end
|
60
|
-
|
87
|
+
|
61
88
|
describe '#children' do
|
62
89
|
before :each do
|
63
90
|
@reflection = stub('reflection', :klass => :klass)
|
64
91
|
@association = ThinkingSphinx::Association.new(nil, @reflection)
|
65
92
|
ThinkingSphinx::Association.stub!(:children => :result)
|
66
93
|
end
|
67
|
-
|
94
|
+
|
68
95
|
it "should return the children associations for the given association" do
|
69
96
|
@association.children(:assoc).should == :result
|
70
97
|
end
|
71
|
-
|
98
|
+
|
72
99
|
it "should request children for the reflection klass" do
|
73
100
|
ThinkingSphinx::Association.should_receive(:children).
|
74
101
|
with(:klass, :assoc, @association)
|
75
|
-
|
102
|
+
|
76
103
|
@association.children(:assoc)
|
77
104
|
end
|
78
105
|
end
|
79
|
-
|
106
|
+
|
80
107
|
describe '#join_to' do
|
81
108
|
before :each do
|
82
109
|
@parent_join = stub('join assoc').as_null_object
|
@@ -84,59 +111,64 @@ describe ThinkingSphinx::Association do
|
|
84
111
|
@parent = ThinkingSphinx::Association.new(nil, nil)
|
85
112
|
@parent.stub!(:join_to => true, :join => nil)
|
86
113
|
@base_join = stub('base join', :joins => [:a, :b, :c])
|
87
|
-
|
114
|
+
|
115
|
+
if ThinkingSphinx.rails_3_1?
|
116
|
+
::ActiveRecord::Associations::JoinDependency::JoinAssociation.stub!(:new => @join)
|
117
|
+
else
|
118
|
+
::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.stub!(:new => @join)
|
119
|
+
end
|
88
120
|
end
|
89
|
-
|
121
|
+
|
90
122
|
it "should call the parent's join_to if parent has no join" do
|
91
123
|
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
92
124
|
@parent.should_receive(:join_to).with(@base_join)
|
93
|
-
|
125
|
+
|
94
126
|
@assoc.join_to(@base_join)
|
95
127
|
end
|
96
|
-
|
128
|
+
|
97
129
|
it "should not call the parent's join_to if it already has a join" do
|
98
130
|
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
99
131
|
@parent.stub!(:join => @parent_join)
|
100
132
|
@parent.should_not_receive(:join_to)
|
101
|
-
|
133
|
+
|
102
134
|
@assoc.join_to(@base_join)
|
103
135
|
end
|
104
|
-
|
136
|
+
|
105
137
|
it "should define the join association with a JoinAssociation instance" do
|
106
138
|
@assoc = ThinkingSphinx::Association.new(@parent, :ref)
|
107
|
-
|
139
|
+
|
108
140
|
@assoc.join_to(@base_join).should == @join
|
109
141
|
@assoc.join.should == @join
|
110
142
|
end
|
111
143
|
end
|
112
|
-
|
144
|
+
|
113
145
|
describe '#is_many?' do
|
114
146
|
before :each do
|
115
147
|
@parent = stub('assoc', :is_many? => :parent_is_many)
|
116
148
|
@reflection = stub('reflection', :macro => :has_many)
|
117
149
|
end
|
118
|
-
|
150
|
+
|
119
151
|
it "should return true if association is either a has_many or a habtm" do
|
120
152
|
association = ThinkingSphinx::Association.new(@parent, @reflection)
|
121
153
|
association.is_many?.should be_true
|
122
|
-
|
154
|
+
|
123
155
|
@reflection.stub!(:macro => :has_and_belongs_to_many)
|
124
156
|
association.is_many?.should be_true
|
125
157
|
end
|
126
|
-
|
158
|
+
|
127
159
|
it "should return the parent value if not a has many or habtm and there is a parent" do
|
128
160
|
association = ThinkingSphinx::Association.new(@parent, @reflection)
|
129
161
|
@reflection.stub!(:macro => :belongs_to)
|
130
162
|
association.is_many?.should == :parent_is_many
|
131
163
|
end
|
132
|
-
|
164
|
+
|
133
165
|
it "should return false if no parent and not a has many or habtm" do
|
134
166
|
association = ThinkingSphinx::Association.new(nil, @reflection)
|
135
167
|
@reflection.stub!(:macro => :belongs_to)
|
136
168
|
association.is_many?.should be_false
|
137
169
|
end
|
138
170
|
end
|
139
|
-
|
171
|
+
|
140
172
|
describe '#ancestors' do
|
141
173
|
it "should return an array of associations - including all parents" do
|
142
174
|
parent = stub('assoc', :ancestors => [:all, :ancestors])
|
@@ -144,7 +176,7 @@ describe ThinkingSphinx::Association do
|
|
144
176
|
association.ancestors.should == [:all, :ancestors, association]
|
145
177
|
end
|
146
178
|
end
|
147
|
-
|
179
|
+
|
148
180
|
describe '.polymorphic_classes' do
|
149
181
|
it "should return all the polymorphic result types as classes" do
|
150
182
|
Person.connection.stub!(:select_all => [
|
@@ -155,11 +187,12 @@ describe ThinkingSphinx::Association do
|
|
155
187
|
:active_record => Person,
|
156
188
|
:options => {:foreign_type => "person_type"}
|
157
189
|
)
|
158
|
-
|
190
|
+
ref.stub!(:foreign_type => "person_type") if ThinkingSphinx.rails_3_1?
|
191
|
+
|
159
192
|
ThinkingSphinx::Association.send(:polymorphic_classes, ref).should == [Person, Friendship]
|
160
193
|
end
|
161
194
|
end
|
162
|
-
|
195
|
+
|
163
196
|
describe '.casted_options' do
|
164
197
|
before :each do
|
165
198
|
@options = {
|
@@ -168,8 +201,9 @@ describe ThinkingSphinx::Association do
|
|
168
201
|
:polymorphic => true
|
169
202
|
}
|
170
203
|
@reflection = stub('assoc reflection', :options => @options)
|
204
|
+
@reflection.stub!(:foreign_type => "thing_type") if ThinkingSphinx.rails_3_1?
|
171
205
|
end
|
172
|
-
|
206
|
+
|
173
207
|
it "should return a new options set for a specific class" do
|
174
208
|
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
175
209
|
:polymorphic => nil,
|
@@ -179,7 +213,7 @@ describe ThinkingSphinx::Association do
|
|
179
213
|
:conditions => "::ts_join_alias::.`thing_type` = 'Person'"
|
180
214
|
}
|
181
215
|
end
|
182
|
-
|
216
|
+
|
183
217
|
it "should append to existing Array of conditions" do
|
184
218
|
@options[:conditions] = ["first condition"]
|
185
219
|
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
@@ -190,7 +224,7 @@ describe ThinkingSphinx::Association do
|
|
190
224
|
:conditions => ["first condition", "::ts_join_alias::.`thing_type` = 'Person'"]
|
191
225
|
}
|
192
226
|
end
|
193
|
-
|
227
|
+
|
194
228
|
it "should merge to an existing Hash of conditions" do
|
195
229
|
@options[:conditions] = {"field" => "value"}
|
196
230
|
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
@@ -201,7 +235,7 @@ describe ThinkingSphinx::Association do
|
|
201
235
|
:conditions => {"field" => "value", "thing_type" => "Person"}
|
202
236
|
}
|
203
237
|
end
|
204
|
-
|
238
|
+
|
205
239
|
it "should append to an existing String of conditions" do
|
206
240
|
@options[:conditions] = "first condition"
|
207
241
|
ThinkingSphinx::Association.send(:casted_options, Person, @reflection).should == {
|
@@ -1,128 +1,125 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Context do
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
4
|
+
let(:ts_context) { ThinkingSphinx::Context.new }
|
5
|
+
|
8
6
|
describe '#prepare' do
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
let(:config) { ThinkingSphinx::Configuration.instance }
|
8
|
+
let(:file_name) { 'a.rb' }
|
9
|
+
let(:model_name_lower) { 'a' }
|
10
|
+
let(:class_name) { 'A' }
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
@class_name = 'A'
|
12
|
+
before :each do
|
13
|
+
config.model_directories = ['']
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
Dir.stub(:[]).and_return([
|
15
|
+
file_name.stub!(:gsub).and_return(model_name_lower)
|
16
|
+
model_name_lower.stub!(:camelize).and_return(class_name)
|
17
|
+
Dir.stub(:[]).and_return([file_name])
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should load the files by guessing the file name" do
|
23
|
-
|
21
|
+
class_name.should_receive(:constantize).and_return(true)
|
24
22
|
|
25
|
-
|
23
|
+
ts_context.prepare
|
26
24
|
end
|
27
25
|
|
28
26
|
it "should not raise errors if the model name is nil" do
|
29
|
-
|
27
|
+
file_name.stub!(:gsub).and_return(nil)
|
30
28
|
|
31
29
|
lambda {
|
32
|
-
|
30
|
+
ts_context.prepare
|
33
31
|
}.should_not raise_error
|
34
32
|
end
|
35
33
|
|
36
34
|
it "should not raise errors if the file name does not represent a class name" do
|
37
|
-
|
35
|
+
class_name.should_receive(:constantize).and_raise(NameError)
|
38
36
|
|
39
37
|
lambda {
|
40
|
-
|
38
|
+
ts_context.prepare
|
41
39
|
}.should_not raise_error
|
42
40
|
end
|
43
41
|
|
44
42
|
# Fails in Ruby 1.9 (or maybe it's an RSpec update). Not sure why.
|
45
43
|
it "should retry if the first pass fails and contains a directory" do
|
46
|
-
|
47
|
-
|
48
|
-
@model_name_lower.should_receive(:camelize).twice
|
44
|
+
class_name.stub(:constantize).and_raise(LoadError)
|
45
|
+
model_name_lower.should_receive(:gsub!).twice.and_return(true, nil)
|
49
46
|
|
50
47
|
lambda {
|
51
|
-
|
48
|
+
ts_context.prepare
|
52
49
|
}.should_not raise_error
|
53
50
|
end
|
54
51
|
|
55
52
|
it "should catch database errors with a warning" do
|
56
|
-
|
53
|
+
class_name.should_receive(:constantize).and_raise(Mysql2::Error)
|
57
54
|
STDERR.stub!(:puts => '')
|
58
55
|
STDERR.should_receive(:puts).with('Warning: Error loading a.rb:')
|
59
|
-
|
56
|
+
|
60
57
|
lambda {
|
61
|
-
|
58
|
+
ts_context.prepare
|
62
59
|
}.should_not raise_error
|
63
|
-
end
|
64
|
-
|
60
|
+
end unless RUBY_PLATFORM == 'java'
|
61
|
+
|
65
62
|
it "should not load models if they're explicitly set in the configuration" do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
config.indexed_models = ['Alpha', 'Beta']
|
64
|
+
ts_context.prepare
|
65
|
+
|
66
|
+
ts_context.indexed_models.should == ['Alpha', 'Beta']
|
70
67
|
end
|
71
68
|
end
|
72
|
-
|
69
|
+
|
73
70
|
describe '#define_indexes' do
|
74
71
|
it "should call define_indexes on all known indexed models" do
|
75
|
-
|
72
|
+
ts_context.stub!(:indexed_models => ['Alpha', 'Beta'])
|
76
73
|
Alpha.should_receive(:define_indexes)
|
77
74
|
Beta.should_receive(:define_indexes)
|
78
|
-
|
79
|
-
|
75
|
+
|
76
|
+
ts_context.define_indexes
|
80
77
|
end
|
81
78
|
end
|
82
|
-
|
79
|
+
|
83
80
|
describe '#add_indexed_model' do
|
84
81
|
before :each do
|
85
|
-
|
82
|
+
ts_context.indexed_models.clear
|
86
83
|
end
|
87
|
-
|
84
|
+
|
88
85
|
it "should add the model to the collection" do
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
ts_context.add_indexed_model 'Alpha'
|
87
|
+
|
88
|
+
ts_context.indexed_models.should == ['Alpha']
|
92
89
|
end
|
93
|
-
|
90
|
+
|
94
91
|
it "should not duplicate models in the collection" do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
92
|
+
ts_context.add_indexed_model 'Alpha'
|
93
|
+
ts_context.add_indexed_model 'Alpha'
|
94
|
+
|
95
|
+
ts_context.indexed_models.should == ['Alpha']
|
99
96
|
end
|
100
|
-
|
97
|
+
|
101
98
|
it "should keep the collection in alphabetical order" do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
ts_context.add_indexed_model 'Beta'
|
100
|
+
ts_context.add_indexed_model 'Alpha'
|
101
|
+
|
102
|
+
ts_context.indexed_models.should == ['Alpha', 'Beta']
|
106
103
|
end
|
107
|
-
|
104
|
+
|
108
105
|
it "should translate classes to their names" do
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
ts_context.add_indexed_model Alpha
|
107
|
+
|
108
|
+
ts_context.indexed_models.should == ['Alpha']
|
112
109
|
end
|
113
110
|
end
|
114
|
-
|
111
|
+
|
115
112
|
describe '#superclass_indexed_models' do
|
116
113
|
it "should return indexed model names" do
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
ts_context.stub!(:indexed_models => ['Alpha', 'Beta'])
|
115
|
+
|
116
|
+
ts_context.superclass_indexed_models.should == ['Alpha', 'Beta']
|
120
117
|
end
|
121
|
-
|
118
|
+
|
122
119
|
it "should not include classes which have indexed superclasses" do
|
123
|
-
|
124
|
-
|
125
|
-
|
120
|
+
ts_context.stub!(:indexed_models => ['Parent', 'Person'])
|
121
|
+
|
122
|
+
ts_context.superclass_indexed_models.should == ['Person']
|
126
123
|
end
|
127
124
|
end
|
128
125
|
end
|