thinking-sphinx 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/Appraisals +13 -0
- data/Gemfile +2 -1
- data/HISTORY +19 -0
- data/README.textile +3 -2
- data/gemfiles/rails_3_2.gemfile +2 -1
- data/gemfiles/rails_4_0.gemfile +2 -1
- data/gemfiles/rails_4_1.gemfile +2 -1
- data/gemfiles/rails_4_2.gemfile +2 -1
- data/gemfiles/rails_5_0.gemfile +12 -0
- data/lib/thinking_sphinx.rb +2 -0
- data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
- data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
- data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
- data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
- data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
- data/lib/thinking_sphinx/configuration.rb +3 -2
- data/lib/thinking_sphinx/connection.rb +23 -10
- data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
- data/lib/thinking_sphinx/errors.rb +25 -0
- data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
- data/lib/thinking_sphinx/railtie.rb +1 -1
- data/lib/thinking_sphinx/rake_interface.rb +71 -23
- data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
- data/lib/thinking_sphinx/real_time/populator.rb +3 -3
- data/lib/thinking_sphinx/tasks.rb +7 -8
- data/lib/thinking_sphinx/wildcard.rb +1 -1
- data/spec/acceptance/association_scoping_spec.rb +5 -5
- data/spec/acceptance/attribute_access_spec.rb +4 -4
- data/spec/acceptance/attribute_updates_spec.rb +3 -3
- data/spec/acceptance/batch_searching_spec.rb +4 -4
- data/spec/acceptance/big_integers_spec.rb +6 -6
- data/spec/acceptance/connection_spec.rb +23 -0
- data/spec/acceptance/excerpts_spec.rb +8 -8
- data/spec/acceptance/facets_spec.rb +13 -13
- data/spec/acceptance/geosearching_spec.rb +8 -8
- data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
- data/spec/acceptance/index_options_spec.rb +16 -16
- data/spec/acceptance/indexing_spec.rb +3 -3
- data/spec/acceptance/paginating_search_results_spec.rb +3 -3
- data/spec/acceptance/real_time_updates_spec.rb +4 -4
- data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
- data/spec/acceptance/search_counts_spec.rb +2 -2
- data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
- data/spec/acceptance/searching_across_models_spec.rb +6 -6
- data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
- data/spec/acceptance/searching_on_fields_spec.rb +9 -9
- data/spec/acceptance/searching_with_filters_spec.rb +16 -16
- data/spec/acceptance/searching_with_sti_spec.rb +9 -9
- data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
- data/spec/acceptance/sorting_search_results_spec.rb +6 -6
- data/spec/acceptance/specifying_sql_spec.rb +62 -62
- data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
- data/spec/acceptance/sql_deltas_spec.rb +7 -7
- data/spec/acceptance/support/database_cleaner.rb +1 -1
- data/spec/acceptance/support/sphinx_controller.rb +4 -1
- data/spec/acceptance/support/sphinx_helpers.rb +4 -0
- data/spec/acceptance/suspended_deltas_spec.rb +9 -9
- data/spec/internal/app/indices/article_index.rb +2 -2
- data/spec/internal/app/indices/book_index.rb +2 -1
- data/spec/internal/app/indices/product_index.rb +0 -2
- data/spec/internal/app/models/categorisation.rb +8 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/json_column.rb +5 -1
- data/spec/support/multi_schema.rb +3 -1
- data/spec/support/sphinx_yaml_helpers.rb +1 -1
- data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
- data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
- data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
- data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
- data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
- data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
- data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
- data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
- data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
- data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
- data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
- data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
- data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
- data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
- data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
- data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
- data/spec/thinking_sphinx/configuration_spec.rb +81 -81
- data/spec/thinking_sphinx/connection_spec.rb +13 -13
- data/spec/thinking_sphinx/deletion_spec.rb +11 -11
- data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
- data/spec/thinking_sphinx/deltas_spec.rb +12 -12
- data/spec/thinking_sphinx/errors_spec.rb +30 -30
- data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
- data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
- data/spec/thinking_sphinx/index_set_spec.rb +7 -7
- data/spec/thinking_sphinx/index_spec.rb +24 -24
- data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
- data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
- data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
- data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
- data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
- data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
- data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
- data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
- data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
- data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
- data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
- data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
- data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
- data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
- data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
- data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
- data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
- data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
- data/spec/thinking_sphinx/scopes_spec.rb +5 -5
- data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
- data/spec/thinking_sphinx/search/query_spec.rb +10 -10
- data/spec/thinking_sphinx/search_spec.rb +28 -28
- data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
- data/spec/thinking_sphinx_spec.rb +6 -6
- data/thinking-sphinx.gemspec +4 -4
- metadata +12 -9
@@ -10,20 +10,20 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks do
|
|
10
10
|
let(:callbacks) { double('callbacks', :after_destroy => nil) }
|
11
11
|
|
12
12
|
before :each do
|
13
|
-
ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks.
|
14
|
-
|
13
|
+
allow(ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks).
|
14
|
+
to receive_messages :new => callbacks
|
15
15
|
end
|
16
16
|
|
17
17
|
it "builds an object from the instance" do
|
18
|
-
ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks.
|
19
|
-
|
18
|
+
expect(ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks).
|
19
|
+
to receive(:new).with(instance).and_return(callbacks)
|
20
20
|
|
21
21
|
ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks.
|
22
22
|
after_destroy(instance)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "invokes after_destroy on the object" do
|
26
|
-
callbacks.
|
26
|
+
expect(callbacks).to receive(:after_destroy)
|
27
27
|
|
28
28
|
ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks.
|
29
29
|
after_destroy(instance)
|
@@ -37,19 +37,19 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks do
|
|
37
37
|
let(:instance) { double('instance', :id => 7, :new_record? => false) }
|
38
38
|
|
39
39
|
before :each do
|
40
|
-
ThinkingSphinx::IndexSet.
|
40
|
+
allow(ThinkingSphinx::IndexSet).to receive_messages :new => index_set
|
41
41
|
end
|
42
42
|
|
43
43
|
it "performs the deletion for the index and instance" do
|
44
|
-
ThinkingSphinx::Deletion.
|
44
|
+
expect(ThinkingSphinx::Deletion).to receive(:perform).with(index, 7)
|
45
45
|
|
46
46
|
callbacks.after_destroy
|
47
47
|
end
|
48
48
|
|
49
49
|
it "doesn't do anything if the instance is a new record" do
|
50
|
-
instance.
|
50
|
+
allow(instance).to receive_messages :new_record? => true
|
51
51
|
|
52
|
-
ThinkingSphinx::Deletion.
|
52
|
+
expect(ThinkingSphinx::Deletion).not_to receive(:perform)
|
53
53
|
|
54
54
|
callbacks.after_destroy
|
55
55
|
end
|
@@ -57,7 +57,7 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks do
|
|
57
57
|
it 'does nothing if callbacks are suspended' do
|
58
58
|
ThinkingSphinx::Callbacks.suspend!
|
59
59
|
|
60
|
-
ThinkingSphinx::Deletion.
|
60
|
+
expect(ThinkingSphinx::Deletion).not_to receive(:perform)
|
61
61
|
|
62
62
|
callbacks.after_destroy
|
63
63
|
|
@@ -11,7 +11,7 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
before :each do
|
14
|
-
ThinkingSphinx::Configuration.
|
14
|
+
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
|
15
15
|
end
|
16
16
|
|
17
17
|
[:after_commit, :before_save].each do |callback|
|
@@ -19,20 +19,20 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
19
19
|
let(:callbacks) { double('callbacks', callback => nil) }
|
20
20
|
|
21
21
|
before :each do
|
22
|
-
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
23
|
-
|
22
|
+
allow(ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks).
|
23
|
+
to receive_messages :new => callbacks
|
24
24
|
end
|
25
25
|
|
26
26
|
it "builds an object from the instance" do
|
27
|
-
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
28
|
-
|
27
|
+
expect(ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks).
|
28
|
+
to receive(:new).with(instance).and_return(callbacks)
|
29
29
|
|
30
30
|
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
31
31
|
send(callback, instance)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "invokes #{callback} on the object" do
|
35
|
-
callbacks.
|
35
|
+
expect(callbacks).to receive(callback)
|
36
36
|
|
37
37
|
ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks.
|
38
38
|
send(callback, instance)
|
@@ -46,18 +46,18 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
46
46
|
}
|
47
47
|
|
48
48
|
before :each do
|
49
|
-
config.
|
49
|
+
allow(config).to receive_messages :index_set_class => double(:new => [index])
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'without delta indices' do
|
53
53
|
it "does not fire a delta index when no delta indices" do
|
54
|
-
processor.
|
54
|
+
expect(processor).not_to receive(:index)
|
55
55
|
|
56
56
|
callbacks.after_commit
|
57
57
|
end
|
58
58
|
|
59
59
|
it "does not delete the instance from any index" do
|
60
|
-
processor.
|
60
|
+
expect(processor).not_to receive(:delete)
|
61
61
|
|
62
62
|
callbacks.after_commit
|
63
63
|
end
|
@@ -70,53 +70,53 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
70
70
|
:delta_processor => processor) }
|
71
71
|
|
72
72
|
before :each do
|
73
|
-
ThinkingSphinx::Deltas.
|
73
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => false
|
74
74
|
|
75
|
-
config.
|
75
|
+
allow(config).to receive_messages :index_set_class => double(
|
76
76
|
:new => [core_index, delta_index]
|
77
77
|
)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "only indexes delta indices" do
|
81
|
-
processor.
|
81
|
+
expect(processor).to receive(:index).with(delta_index)
|
82
82
|
|
83
83
|
callbacks.after_commit
|
84
84
|
end
|
85
85
|
|
86
86
|
it "does not process delta indices when deltas are suspended" do
|
87
|
-
ThinkingSphinx::Deltas.
|
87
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => true
|
88
88
|
|
89
|
-
processor.
|
89
|
+
expect(processor).not_to receive(:index)
|
90
90
|
|
91
91
|
callbacks.after_commit
|
92
92
|
end
|
93
93
|
|
94
94
|
it "deletes the instance from the core index" do
|
95
|
-
processor.
|
95
|
+
expect(processor).to receive(:delete).with(core_index, instance)
|
96
96
|
|
97
97
|
callbacks.after_commit
|
98
98
|
end
|
99
99
|
|
100
100
|
it "does not index if model's delta flag is not true" do
|
101
|
-
processor.
|
101
|
+
allow(processor).to receive_messages :toggled? => false
|
102
102
|
|
103
|
-
processor.
|
103
|
+
expect(processor).not_to receive(:index)
|
104
104
|
|
105
105
|
callbacks.after_commit
|
106
106
|
end
|
107
107
|
|
108
108
|
it "does not delete if model's delta flag is not true" do
|
109
|
-
processor.
|
109
|
+
allow(processor).to receive_messages :toggled? => false
|
110
110
|
|
111
|
-
processor.
|
111
|
+
expect(processor).not_to receive(:delete)
|
112
112
|
|
113
113
|
callbacks.after_commit
|
114
114
|
end
|
115
115
|
|
116
116
|
it "does not delete when deltas are suspended" do
|
117
|
-
ThinkingSphinx::Deltas.
|
117
|
+
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => true
|
118
118
|
|
119
|
-
processor.
|
119
|
+
expect(processor).not_to receive(:delete)
|
120
120
|
|
121
121
|
callbacks.after_commit
|
122
122
|
end
|
@@ -129,19 +129,42 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
|
|
129
129
|
}
|
130
130
|
|
131
131
|
before :each do
|
132
|
-
config.
|
132
|
+
allow(config).to receive_messages :index_set_class => double(:new => [index])
|
133
|
+
allow(instance).to receive_messages(
|
134
|
+
:changed? => true,
|
135
|
+
:new_record? => false
|
136
|
+
)
|
133
137
|
end
|
134
138
|
|
135
139
|
it "sets delta to true if there are delta indices" do
|
136
|
-
processor.
|
140
|
+
expect(processor).to receive(:toggle).with(instance)
|
137
141
|
|
138
142
|
callbacks.before_save
|
139
143
|
end
|
140
144
|
|
141
145
|
it "does not try to set delta to true if there are no delta indices" do
|
142
|
-
index.
|
146
|
+
allow(index).to receive_messages :delta? => false
|
147
|
+
|
148
|
+
expect(processor).not_to receive(:toggle)
|
149
|
+
|
150
|
+
callbacks.before_save
|
151
|
+
end
|
152
|
+
|
153
|
+
it "does not try to set delta to true if the instance is unchanged" do
|
154
|
+
allow(instance).to receive_messages :changed? => false
|
155
|
+
|
156
|
+
expect(processor).not_to receive(:toggle)
|
157
|
+
|
158
|
+
callbacks.before_save
|
159
|
+
end
|
160
|
+
|
161
|
+
it "does set delta to true if the instance is unchanged but new" do
|
162
|
+
allow(instance).to receive_messages(
|
163
|
+
:changed? => false,
|
164
|
+
:new_record? => true
|
165
|
+
)
|
143
166
|
|
144
|
-
processor.
|
167
|
+
expect(processor).to receive(:toggle)
|
145
168
|
|
146
169
|
callbacks.before_save
|
147
170
|
end
|
@@ -30,7 +30,7 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
|
|
30
30
|
stub_const 'ThinkingSphinx::Connection', double
|
31
31
|
stub_const 'Riddle::Query', double(:update => 'SphinxQL')
|
32
32
|
|
33
|
-
ThinkingSphinx::Connection.
|
33
|
+
allow(ThinkingSphinx::Connection).to receive(:take).and_yield(connection)
|
34
34
|
|
35
35
|
source.attributes.replace([
|
36
36
|
double(:name => 'foo', :updateable? => true,
|
@@ -40,41 +40,41 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
|
|
40
40
|
double(:name => 'baz', :updateable? => false)
|
41
41
|
])
|
42
42
|
|
43
|
-
instance.
|
43
|
+
allow(instance).to receive_messages :changed => ['bar_column', 'baz'], :bar_column => 7
|
44
44
|
end
|
45
45
|
|
46
46
|
it "does not send any updates to Sphinx if updates are disabled" do
|
47
47
|
configuration.settings['attribute_updates'] = false
|
48
48
|
|
49
|
-
connection.
|
49
|
+
expect(connection).not_to receive(:execute)
|
50
50
|
|
51
51
|
callbacks.after_update
|
52
52
|
end
|
53
53
|
|
54
54
|
it "builds an update query with only updateable attributes that have changed" do
|
55
|
-
Riddle::Query.
|
55
|
+
expect(Riddle::Query).to receive(:update).
|
56
56
|
with('article_core', 3, 'bar' => 7).and_return('SphinxQL')
|
57
57
|
|
58
58
|
callbacks.after_update
|
59
59
|
end
|
60
60
|
|
61
61
|
it "sends the update query through to Sphinx" do
|
62
|
-
connection.
|
62
|
+
expect(connection).to receive(:execute).with('SphinxQL')
|
63
63
|
|
64
64
|
callbacks.after_update
|
65
65
|
end
|
66
66
|
|
67
67
|
it "doesn't care if the update fails at Sphinx's end" do
|
68
|
-
connection.
|
68
|
+
allow(connection).to receive(:execute).
|
69
69
|
and_raise(ThinkingSphinx::ConnectionError.new(''))
|
70
70
|
|
71
|
-
|
71
|
+
expect { callbacks.after_update }.not_to raise_error
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'does nothing if callbacks are suspended' do
|
75
75
|
ThinkingSphinx::Callbacks.suspend!
|
76
76
|
|
77
|
-
connection.
|
77
|
+
expect(connection).not_to receive(:execute)
|
78
78
|
|
79
79
|
callbacks.after_update
|
80
80
|
|
@@ -4,7 +4,7 @@ describe ThinkingSphinx::ActiveRecord::Column do
|
|
4
4
|
describe '#__name' do
|
5
5
|
it "returns the top item" do
|
6
6
|
column = ThinkingSphinx::ActiveRecord::Column.new(:content)
|
7
|
-
column.__name.
|
7
|
+
expect(column.__name).to eq(:content)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -14,27 +14,27 @@ describe ThinkingSphinx::ActiveRecord::Column do
|
|
14
14
|
|
15
15
|
it "returns itself when it's a string column" do
|
16
16
|
column = ThinkingSphinx::ActiveRecord::Column.new('foo')
|
17
|
-
column.__replace(base, replacements).collect(&:__path).
|
18
|
-
|
17
|
+
expect(column.__replace(base, replacements).collect(&:__path)).
|
18
|
+
to eq([['foo']])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns itself when the base of the stack does not match" do
|
22
22
|
column = ThinkingSphinx::ActiveRecord::Column.new(:b, :c)
|
23
|
-
column.__replace(base, replacements).collect(&:__path).
|
24
|
-
|
23
|
+
expect(column.__replace(base, replacements).collect(&:__path)).
|
24
|
+
to eq([[:b, :c]])
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns an array of new columns " do
|
28
28
|
column = ThinkingSphinx::ActiveRecord::Column.new(:a, :b, :e)
|
29
|
-
column.__replace(base, replacements).collect(&:__path).
|
30
|
-
|
29
|
+
expect(column.__replace(base, replacements).collect(&:__path)).
|
30
|
+
to eq([[:a, :c, :e], [:a, :d, :e]])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '#__stack' do
|
35
35
|
it "returns all but the top item" do
|
36
36
|
column = ThinkingSphinx::ActiveRecord::Column.new(:users, :posts, :id)
|
37
|
-
column.__stack.
|
37
|
+
expect(column.__stack).to eq([:users, :posts])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -43,28 +43,28 @@ describe ThinkingSphinx::ActiveRecord::Column do
|
|
43
43
|
|
44
44
|
it "shifts the current name to the stack" do
|
45
45
|
column.email
|
46
|
-
column.__stack.
|
46
|
+
expect(column.__stack).to eq([:user])
|
47
47
|
end
|
48
48
|
|
49
49
|
it "adds the new method call as the name" do
|
50
50
|
column.email
|
51
|
-
column.__name.
|
51
|
+
expect(column.__name).to eq(:email)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "returns itself" do
|
55
|
-
column.email.
|
55
|
+
expect(column.email).to eq(column)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#string?' do
|
60
60
|
it "is true when the name is a string" do
|
61
61
|
column = ThinkingSphinx::ActiveRecord::Column.new('content')
|
62
|
-
column.
|
62
|
+
expect(column).to be_a_string
|
63
63
|
end
|
64
64
|
|
65
65
|
it "is false when the name is a symbol" do
|
66
66
|
column = ThinkingSphinx::ActiveRecord::Column.new(:content)
|
67
|
-
column.
|
67
|
+
expect(column).not_to be_a_string
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -15,22 +15,22 @@ describe ThinkingSphinx::ActiveRecord::ColumnSQLPresenter do
|
|
15
15
|
|
16
16
|
before do
|
17
17
|
stub_const 'Joiner::Path', double(:new => path)
|
18
|
-
adapter.
|
18
|
+
allow(adapter).to receive(:quote) { |arg| "`#{arg}`" }
|
19
19
|
end
|
20
20
|
|
21
21
|
context "when there's no explicit db name" do
|
22
|
-
before { associations.
|
22
|
+
before { allow(associations).to receive_messages(:alias_for => 'table_name') }
|
23
23
|
|
24
24
|
it 'returns quoted table and column names' do
|
25
|
-
presenter.with_table.
|
25
|
+
expect(presenter.with_table).to eq('`table_name`.`column_name`')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when an eplicit db name is provided' do
|
30
|
-
before { associations.
|
30
|
+
before { allow(associations).to receive_messages(:alias_for => 'db_name.table_name') }
|
31
31
|
|
32
32
|
it 'returns properly quoted table name with column name' do
|
33
|
-
presenter.with_table.
|
33
|
+
expect(presenter.with_table).to eq('`db_name`.`table_name`.`column_name`')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -9,23 +9,23 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::AbstractAdapter do
|
|
9
9
|
|
10
10
|
describe '#quote' do
|
11
11
|
it "uses the model's connection to quote columns" do
|
12
|
-
connection.
|
12
|
+
expect(connection).to receive(:quote_column_name).with('foo')
|
13
13
|
|
14
14
|
adapter.quote 'foo'
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns the quoted value" do
|
18
|
-
connection.
|
18
|
+
allow(connection).to receive_messages :quote_column_name => '"foo"'
|
19
19
|
|
20
|
-
adapter.quote('foo').
|
20
|
+
expect(adapter.quote('foo')).to eq('"foo"')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#quoted_table_name' do
|
25
25
|
it "passes the method through to the model" do
|
26
|
-
model.
|
26
|
+
expect(model).to receive(:quoted_table_name).and_return('"articles"')
|
27
27
|
|
28
|
-
adapter.quoted_table_name.
|
28
|
+
expect(adapter.quoted_table_name).to eq('"articles"')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -7,50 +7,50 @@ describe ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter do
|
|
7
7
|
let(:model) { double('model') }
|
8
8
|
|
9
9
|
it "returns 1 for true" do
|
10
|
-
adapter.boolean_value(true).
|
10
|
+
expect(adapter.boolean_value(true)).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "returns 0 for false" do
|
14
|
-
adapter.boolean_value(false).
|
14
|
+
expect(adapter.boolean_value(false)).to eq(0)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#cast_to_string' do
|
18
18
|
it "casts the clause to characters" do
|
19
|
-
adapter.cast_to_string('foo').
|
19
|
+
expect(adapter.cast_to_string('foo')).to eq("CAST(foo AS char)")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '#cast_to_timestamp' do
|
24
24
|
it "converts to unix timestamps" do
|
25
|
-
adapter.cast_to_timestamp('created_at').
|
26
|
-
|
25
|
+
expect(adapter.cast_to_timestamp('created_at')).
|
26
|
+
to eq('UNIX_TIMESTAMP(created_at)')
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe '#concatenate' do
|
31
31
|
it "concatenates with the given separator" do
|
32
|
-
adapter.concatenate('foo, bar, baz', ',').
|
33
|
-
|
32
|
+
expect(adapter.concatenate('foo, bar, baz', ',')).
|
33
|
+
to eq("CONCAT_WS(',', foo, bar, baz)")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#convert_nulls' do
|
38
38
|
it "translates arguments to an IFNULL SQL call" do
|
39
|
-
adapter.convert_nulls('id', 5).
|
39
|
+
expect(adapter.convert_nulls('id', 5)).to eq('IFNULL(id, 5)')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe '#convert_blank' do
|
44
44
|
it "translates arguments to a COALESCE NULLIF SQL call" do
|
45
|
-
adapter.convert_blank('id', 5).
|
45
|
+
expect(adapter.convert_blank('id', 5)).to eq("COALESCE(NULLIF(id, ''), 5)")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
|
50
50
|
describe '#group_concatenate' do
|
51
51
|
it "group concatenates the clause with the given separator" do
|
52
|
-
adapter.group_concatenate('foo', ',').
|
53
|
-
|
52
|
+
expect(adapter.group_concatenate('foo', ',')).
|
53
|
+
to eq("GROUP_CONCAT(DISTINCT foo SEPARATOR ',')")
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|