thinking-sphinx 1.4.6 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +6 -1
- data/features/searching_by_model.feature +24 -30
- data/features/thinking_sphinx/db/.gitignore +1 -0
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +1 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +26 -26
- data/lib/thinking_sphinx.rb +17 -26
- data/lib/thinking_sphinx/active_record.rb +69 -74
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +11 -10
- data/lib/thinking_sphinx/active_record/has_many_association.rb +2 -1
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +11 -11
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +34 -20
- data/lib/thinking_sphinx/association.rb +12 -7
- data/lib/thinking_sphinx/attribute.rb +64 -61
- data/lib/thinking_sphinx/configuration.rb +32 -36
- data/lib/thinking_sphinx/context.rb +3 -2
- data/lib/thinking_sphinx/deploy/capistrano.rb +7 -9
- data/lib/thinking_sphinx/search.rb +201 -178
- data/lib/thinking_sphinx/source/sql.rb +1 -1
- data/lib/thinking_sphinx/tasks.rb +21 -19
- data/lib/thinking_sphinx/version.rb +3 -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 +57 -0
- data/spec/sphinx_helper.rb +61 -0
- data/spec/thinking_sphinx/active_record/delta_spec.rb +24 -24
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +22 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +25 -25
- data/spec/thinking_sphinx/active_record_spec.rb +110 -109
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +38 -38
- data/spec/thinking_sphinx/association_spec.rb +20 -2
- 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 +50 -98
- data/VERSION +0 -1
- data/tasks/distribution.rb +0 -34
- 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
|
@@ -44,12 +44,30 @@ describe ThinkingSphinx::Association do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should generate non-polymorphic 'casted' associations for each polymorphic possibility" do
|
47
|
-
Person.stub!(:reflect_on_association
|
47
|
+
Person.stub!(:reflect_on_association).exactly(3).times.
|
48
|
+
and_return(@poly_reflection, nil, nil)
|
48
49
|
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
49
50
|
Person, @poly_reflection
|
50
51
|
).twice
|
51
52
|
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
52
|
-
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice
|
53
|
+
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice.
|
54
|
+
and_return(@non_poly_reflection)
|
55
|
+
ThinkingSphinx::Association.should_receive(:new).with(
|
56
|
+
nil, @non_poly_reflection
|
57
|
+
).twice
|
58
|
+
|
59
|
+
ThinkingSphinx::Association.children(Person, :assoc)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should use existing non-polymorphic 'casted' associations" do
|
63
|
+
Person.stub!(:reflect_on_association).exactly(3).times.
|
64
|
+
and_return(@poly_reflection, nil, @non_poly_reflection)
|
65
|
+
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
66
|
+
Person, @poly_reflection
|
67
|
+
).once
|
68
|
+
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
69
|
+
with(:has_many, :polly_Person, {:casted => :options}, "AR").once.
|
70
|
+
and_return(@non_poly_reflection)
|
53
71
|
ThinkingSphinx::Association.should_receive(:new).with(
|
54
72
|
nil, @non_poly_reflection
|
55
73
|
).twice
|
@@ -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
|
@@ -636,6 +636,13 @@ describe ThinkingSphinx::Search do
|
|
636
636
|
filter.attribute.should == 'sphinx_internal_id'
|
637
637
|
filter.exclude?.should be_true
|
638
638
|
end
|
639
|
+
|
640
|
+
it "should not filter out any ids if :without_ids is an empty array" do
|
641
|
+
ThinkingSphinx::Search.new(:without_ids => []).first
|
642
|
+
|
643
|
+
filter = @client.filters.last
|
644
|
+
filter.attribute.should_not == 'sphinx_internal_id'
|
645
|
+
end
|
639
646
|
end
|
640
647
|
|
641
648
|
describe 'sort mode' do
|
@@ -5,40 +5,40 @@ describe ThinkingSphinx do
|
|
5
5
|
it "should return a Context instance" do
|
6
6
|
ThinkingSphinx.context.should be_a(ThinkingSphinx::Context)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should remember changes to the Context instance" do
|
10
|
-
models = ThinkingSphinx.context.indexed_models
|
11
|
-
|
10
|
+
models = ThinkingSphinx.context.indexed_models.clone
|
11
|
+
|
12
12
|
ThinkingSphinx.context.indexed_models.replace([:model])
|
13
13
|
ThinkingSphinx.context.indexed_models.should == [:model]
|
14
|
-
|
14
|
+
|
15
15
|
ThinkingSphinx.context.indexed_models.replace(models)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
describe '.reset_context!' do
|
20
20
|
it "should remove the existing Context instance" do
|
21
21
|
existing = ThinkingSphinx.context
|
22
|
-
|
22
|
+
|
23
23
|
ThinkingSphinx.reset_context!
|
24
24
|
ThinkingSphinx.context.should_not == existing
|
25
|
-
|
25
|
+
|
26
26
|
ThinkingSphinx.reset_context! existing
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
describe '.define_indexes?' do
|
31
31
|
it "should define indexes by default" do
|
32
32
|
ThinkingSphinx.define_indexes?.should be_true
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
describe '.define_indexes=' do
|
37
37
|
it "should disable index definition" do
|
38
38
|
ThinkingSphinx.define_indexes = false
|
39
39
|
ThinkingSphinx.define_indexes?.should be_false
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should enable index definition" do
|
43
43
|
ThinkingSphinx.define_indexes = false
|
44
44
|
ThinkingSphinx.define_indexes?.should be_false
|
@@ -46,19 +46,19 @@ describe ThinkingSphinx do
|
|
46
46
|
ThinkingSphinx.define_indexes?.should be_true
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
describe '.deltas_enabled?' do
|
51
51
|
it "should index deltas by default" do
|
52
52
|
ThinkingSphinx.deltas_enabled?.should be_true
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
describe '.deltas_enabled=' do
|
57
57
|
it "should disable delta indexing" do
|
58
58
|
ThinkingSphinx.deltas_enabled = false
|
59
59
|
ThinkingSphinx.deltas_enabled?.should be_false
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "should enable delta indexing" do
|
63
63
|
ThinkingSphinx.deltas_enabled = false
|
64
64
|
ThinkingSphinx.deltas_enabled?.should be_false
|
@@ -66,20 +66,22 @@ describe ThinkingSphinx do
|
|
66
66
|
ThinkingSphinx.deltas_enabled?.should be_true
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
describe '.updates_enabled?' do
|
71
71
|
it "should update indexes by default" do
|
72
|
+
ThinkingSphinx::Configuration.stub! :environment => 'development'
|
73
|
+
|
72
74
|
ThinkingSphinx.updates_enabled = nil
|
73
75
|
ThinkingSphinx.updates_enabled?.should be_true
|
74
76
|
end
|
75
77
|
end
|
76
|
-
|
78
|
+
|
77
79
|
describe '.updates_enabled=' do
|
78
80
|
it "should disable index updating" do
|
79
81
|
ThinkingSphinx.updates_enabled = false
|
80
82
|
ThinkingSphinx.updates_enabled?.should be_false
|
81
83
|
end
|
82
|
-
|
84
|
+
|
83
85
|
it "should enable index updating" do
|
84
86
|
ThinkingSphinx.updates_enabled = false
|
85
87
|
ThinkingSphinx.updates_enabled?.should be_false
|
@@ -87,35 +89,25 @@ describe ThinkingSphinx do
|
|
87
89
|
ThinkingSphinx.updates_enabled?.should be_true
|
88
90
|
end
|
89
91
|
end
|
90
|
-
|
92
|
+
|
91
93
|
describe '.sphinx_running?' do
|
92
94
|
it "should always say Sphinx is running if flagged as being on a remote machine" do
|
93
95
|
ThinkingSphinx.remote_sphinx = true
|
94
96
|
ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
|
95
|
-
|
97
|
+
|
96
98
|
ThinkingSphinx.sphinx_running?.should be_true
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
it "should actually pay attention to Sphinx if not on a remote machine" do
|
100
102
|
ThinkingSphinx.remote_sphinx = false
|
101
103
|
ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
|
102
104
|
ThinkingSphinx.sphinx_running?.should be_false
|
103
|
-
|
105
|
+
|
104
106
|
ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
|
105
107
|
ThinkingSphinx.sphinx_running?.should be_true
|
106
108
|
end
|
107
109
|
end
|
108
|
-
|
109
|
-
describe '.version' do
|
110
|
-
it "should return the version from the stored YAML file" do
|
111
|
-
version = Jeweler::VersionHelper.new(
|
112
|
-
File.join(File.dirname(__FILE__), '..')
|
113
|
-
).to_s
|
114
|
-
|
115
|
-
ThinkingSphinx.version.should == version
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
110
|
+
|
119
111
|
describe "use_group_by_shortcut? method" do
|
120
112
|
before :each do
|
121
113
|
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
|
@@ -123,7 +115,7 @@ describe ThinkingSphinx do
|
|
123
115
|
pending "No MySQL"
|
124
116
|
return
|
125
117
|
end
|
126
|
-
|
118
|
+
|
127
119
|
@connection = stub('adapter',
|
128
120
|
:select_all => true,
|
129
121
|
:class => ActiveRecord::ConnectionAdapters::MysqlAdapter,
|
@@ -132,34 +124,43 @@ describe ThinkingSphinx do
|
|
132
124
|
::ActiveRecord::Base.stub!(
|
133
125
|
:connection => @connection
|
134
126
|
)
|
135
|
-
|
127
|
+
|
136
128
|
ThinkingSphinx.reset_use_group_by_shortcut
|
137
129
|
end
|
138
|
-
|
130
|
+
|
139
131
|
it "should return true if no ONLY_FULL_GROUP_BY" do
|
140
132
|
@connection.stub!(
|
141
133
|
:select_all => {:a => "OTHER SETTINGS"}
|
142
134
|
)
|
143
|
-
|
135
|
+
|
144
136
|
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
145
137
|
end
|
146
|
-
|
138
|
+
|
147
139
|
it "should return true if NULL value" do
|
148
140
|
@connection.stub!(
|
149
141
|
:select_all => {:a => nil}
|
150
142
|
)
|
151
|
-
|
143
|
+
|
152
144
|
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
153
145
|
end
|
154
|
-
|
146
|
+
|
147
|
+
it "should return true if using mysql2 gem" do
|
148
|
+
@connection.stub!(
|
149
|
+
:class => ActiveRecord::ConnectionAdapters::Mysql2Adapter,
|
150
|
+
:select_all => {:a => ""}
|
151
|
+
)
|
152
|
+
|
153
|
+
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
154
|
+
end unless RUBY_PLATFORM == 'java'
|
155
|
+
|
155
156
|
it "should return false if ONLY_FULL_GROUP_BY is set" do
|
156
157
|
@connection.stub!(
|
157
158
|
:select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
|
158
159
|
)
|
159
|
-
|
160
|
+
|
160
161
|
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
161
162
|
end
|
162
|
-
|
163
|
+
|
163
164
|
it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
|
164
165
|
@connection.stub!(
|
165
166
|
:select_all => {
|
@@ -167,10 +168,10 @@ describe ThinkingSphinx do
|
|
167
168
|
:b => "ONLY_FULL_GROUP_BY"
|
168
169
|
}
|
169
170
|
)
|
170
|
-
|
171
|
+
|
171
172
|
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
172
173
|
end
|
173
|
-
|
174
|
+
|
174
175
|
describe "if not using MySQL" do
|
175
176
|
before :each do
|
176
177
|
adapter = defined?(JRUBY_VERSION) ? 'JdbcAdapter' : 'PostgreSQLAdapter'
|
@@ -178,7 +179,7 @@ describe ThinkingSphinx do
|
|
178
179
|
pending "No PostgreSQL"
|
179
180
|
return
|
180
181
|
end
|
181
|
-
|
182
|
+
|
182
183
|
@connection = stub(adapter).as_null_object
|
183
184
|
@connection.stub!(
|
184
185
|
:select_all => true,
|
@@ -188,14 +189,14 @@ describe ThinkingSphinx do
|
|
188
189
|
:connection => @connection
|
189
190
|
)
|
190
191
|
end
|
191
|
-
|
192
|
+
|
192
193
|
it "should return false" do
|
193
194
|
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
194
195
|
end
|
195
|
-
|
196
|
+
|
196
197
|
it "should not call select_all" do
|
197
198
|
@connection.should_not_receive(:select_all)
|
198
|
-
|
199
|
+
|
199
200
|
ThinkingSphinx.use_group_by_shortcut?
|
200
201
|
end
|
201
202
|
end
|