blob: 375e158ec05af7f55424d3eb10270faafcb565e9 (
plain)
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
131
132
133
|
require 'spec/spec_helper'
describe ThinkingSphinx do
it "should define indexes by default" do
ThinkingSphinx.define_indexes?.should be_true
end
it "should disable index definition" do
ThinkingSphinx.define_indexes = false
ThinkingSphinx.define_indexes?.should be_false
end
it "should enable index definition" do
ThinkingSphinx.define_indexes = false
ThinkingSphinx.define_indexes?.should be_false
ThinkingSphinx.define_indexes = true
ThinkingSphinx.define_indexes?.should be_true
end
it "should index deltas by default" do
ThinkingSphinx.deltas_enabled = nil
ThinkingSphinx.deltas_enabled?.should be_true
end
it "should disable delta indexing" do
ThinkingSphinx.deltas_enabled = false
ThinkingSphinx.deltas_enabled?.should be_false
end
it "should enable delta indexing" do
ThinkingSphinx.deltas_enabled = false
ThinkingSphinx.deltas_enabled?.should be_false
ThinkingSphinx.deltas_enabled = true
ThinkingSphinx.deltas_enabled?.should be_true
end
it "should update indexes by default" do
ThinkingSphinx.updates_enabled = nil
ThinkingSphinx.updates_enabled?.should be_true
end
it "should disable index updating" do
ThinkingSphinx.updates_enabled = false
ThinkingSphinx.updates_enabled?.should be_false
end
it "should enable index updating" do
ThinkingSphinx.updates_enabled = false
ThinkingSphinx.updates_enabled?.should be_false
ThinkingSphinx.updates_enabled = true
ThinkingSphinx.updates_enabled?.should be_true
end
describe "use_group_by_shortcut? method" do
before :each do
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
pending "No MySQL"
return
end
@connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance(
:select_all => true,
:config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
)
::ActiveRecord::Base.stub_method(
:connection => @connection
)
end
it "should return true if no ONLY_FULL_GROUP_BY" do
@connection.stub_method(
:select_all => {:a => "OTHER SETTINGS"}
)
ThinkingSphinx.use_group_by_shortcut?.should be_true
end
it "should return true if NULL value" do
@connection.stub_method(
:select_all => {:a => nil}
)
ThinkingSphinx.use_group_by_shortcut?.should be_true
end
it "should return false if ONLY_FULL_GROUP_BY is set" do
@connection.stub_method(
:select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
)
ThinkingSphinx.use_group_by_shortcut?.should be_false
end
it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
@connection.stub_method(
:select_all => {
:a => "OTHER SETTINGS",
:b => "ONLY_FULL_GROUP_BY"
}
)
ThinkingSphinx.use_group_by_shortcut?.should be_false
end
describe "if not using MySQL" do
before :each do
adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :PostgreSQLAdapter
unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
pending "No PostgreSQL"
return
end
@connection = ::ActiveRecord::ConnectionAdapters.const_get(adapter).stub_instance(
:select_all => true,
:config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'}
)
::ActiveRecord::Base.stub_method(
:connection => @connection
)
end
it "should return false" do
ThinkingSphinx.use_group_by_shortcut?.should be_false
end
it "should not call select_all" do
ThinkingSphinx.use_group_by_shortcut?
@connection.should_not have_received(:select_all)
end
end
end
end
|