Skip to content

Commit 8ced2ef

Browse files
authored
Merge pull request #1252 from jdelStrother/logsubscriber-deprecations
Fixes for Rails 7.1
2 parents fda3d0a + b541835 commit 8ced2ef

File tree

13 files changed

+50
-31
lines changed

13 files changed

+50
-31
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
ruby: [ '2.7', '3.0', '3.1', '3.2' ]
13-
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0' ]
13+
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0', '7_1' ]
1414
database: [ 'mysql2', 'postgresql' ]
1515
sphinx_version: [ '2.2.11', '3.4.1' ]
1616
sphinx_engine: [ 'sphinx' ]
@@ -74,7 +74,7 @@ jobs:
7474
fail-fast: false
7575
matrix:
7676
ruby: [ '2.7', '3.0', '3.1', '3.2' ]
77-
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0' ]
77+
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0', '7_1' ]
7878
database: [ 'mysql2', 'postgresql' ]
7979
sphinx_version: [ '4.0.2', '6.0.0' ]
8080
sphinx_engine: [ 'manticore' ]

Appraisals

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ appraise 'rails_7_0' do
4545
gem 'mysql2', '~> 0.5.0', :platform => :ruby
4646
gem 'pg', '~> 1.0', :platform => :ruby
4747
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.7
48+
49+
appraise 'rails_7_1' do
50+
gem 'rails', '~> 7.1.0'
51+
gem 'mysql2', '~> 0.5.0', :platform => :ruby
52+
gem 'pg', '~> 1.0', :platform => :ruby
53+
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.7

lib/thinking_sphinx/active_record/filter_reflection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ThinkingSphinx::ActiveRecord::FilterReflection
44
ReflectionGenerator = case ActiveRecord::VERSION::STRING.to_f
5-
when 5.2..7.0
5+
when 5.2..7.1
66
ThinkingSphinx::ActiveRecord::Depolymorph::OverriddenReflection
77
when 4.1..5.1
88
ThinkingSphinx::ActiveRecord::Depolymorph::AssociationReflection

lib/thinking_sphinx/active_record/log_subscriber.rb

+16-4
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,36 @@
22

33
class ThinkingSphinx::ActiveRecord::LogSubscriber < ActiveSupport::LogSubscriber
44
def guard(event)
5-
identifier = color 'Sphinx', GREEN, true
5+
identifier = colored_text "Sphinx"
66
warn " #{identifier} #{event.payload[:guard]}"
77
end
88

99
def message(event)
10-
identifier = color 'Sphinx', GREEN, true
10+
identifier = colored_text "Sphinx"
1111
debug " #{identifier} #{event.payload[:message]}"
1212
end
1313

1414
def query(event)
15-
identifier = color('Sphinx Query (%.1fms)' % event.duration, GREEN, true)
15+
identifier = colored_text("Sphinx Query (%.1fms)" % event.duration)
1616
debug " #{identifier} #{event.payload[:query]}"
1717
end
1818

1919
def caution(event)
20-
identifier = color 'Sphinx', GREEN, true
20+
identifier = colored_text "Sphinx"
2121
warn " #{identifier} #{event.payload[:caution]}"
2222
end
23+
24+
private
25+
26+
if Rails.gem_version >= Gem::Version.new("7.1.0")
27+
def colored_text(text)
28+
color text, GREEN, bold: true
29+
end
30+
else
31+
def colored_text(text)
32+
color text, GREEN, true
33+
end
34+
end
2335
end
2436

2537
ThinkingSphinx::ActiveRecord::LogSubscriber.attach_to :thinking_sphinx

spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Callbacks; end
6060

6161
it "builds an update query with only updateable attributes that have changed" do
6262
expect(Riddle::Query).to receive(:update).
63-
with('article_core', 3, 'bar' => 7).and_return('SphinxQL')
63+
with('article_core', 3, { 'bar' => 7 }).and_return('SphinxQL')
6464

6565
callbacks.after_update
6666
end

spec/thinking_sphinx/active_record/interpreter_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
it "passes through options to the attribute" do
9595
expect(ThinkingSphinx::ActiveRecord::Attribute).to receive(:new).
96-
with(model, column, :as => :other_name).and_return(attribute)
96+
with(model, column, { :as => :other_name }).and_return(attribute)
9797

9898
instance.has column, :as => :other_name
9999
end
@@ -141,7 +141,7 @@
141141

142142
it "passes through options to the field" do
143143
expect(ThinkingSphinx::ActiveRecord::Field).to receive(:new).
144-
with(model, column, :as => :other_name).and_return(field)
144+
with(model, column, { :as => :other_name }).and_return(field)
145145

146146
instance.indexes column, :as => :other_name
147147
end
@@ -230,19 +230,19 @@
230230
end
231231

232232
it "sends through a hash if provided" do
233-
expect(source).to receive(:set_database_settings).with(:foo => :bar)
233+
expect(source).to receive(:set_database_settings).with({ :foo => :bar })
234234

235235
instance.set_database :foo => :bar
236236
end
237237

238238
it "finds the environment settings if given a string key" do
239-
expect(source).to receive(:set_database_settings).with(:baz => 'qux')
239+
expect(source).to receive(:set_database_settings).with({ :baz => 'qux' })
240240

241241
instance.set_database 'other'
242242
end
243243

244244
it "finds the environment settings if given a symbol key" do
245-
expect(source).to receive(:set_database_settings).with(:baz => 'qux')
245+
expect(source).to receive(:set_database_settings).with({ :baz => 'qux' })
246246

247247
instance.set_database :other
248248
end

spec/thinking_sphinx/excerpter_spec.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
:before_match => '<b>', :chunk_separator => ' -- ')
2929

3030
expect(Riddle::Query).to receive(:snippets).
31-
with('all of the words', 'index', 'all words',
31+
with('all of the words', 'index', 'all words', {
3232
:before_match => '<b>', :after_match => '</span>',
33-
:chunk_separator => ' -- ').
33+
:chunk_separator => ' -- '
34+
}).
3435
and_return('CALL SNIPPETS')
3536

3637
excerpter.excerpt!('all of the words')

spec/thinking_sphinx/index_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
it "creates an ActiveRecord index" do
2121
expect(ThinkingSphinx::ActiveRecord::Index).to receive(:new).
22-
with(:user, :with => :active_record).and_return index
22+
with(:user, { :with => :active_record }).and_return index
2323

2424
ThinkingSphinx::Index.define(:user, :with => :active_record)
2525
end
@@ -100,7 +100,7 @@
100100

101101
it "creates a real-time index" do
102102
expect(ThinkingSphinx::RealTime::Index).to receive(:new).
103-
with(:user, :with => :real_time).and_return index
103+
with(:user, { :with => :real_time }).and_return index
104104

105105
ThinkingSphinx::Index.define(:user, :with => :real_time)
106106
end

spec/thinking_sphinx/middlewares/sphinxql_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class SphinxQLSubclass
6161
allow(index_set.first).to receive_messages :reference => :user
6262

6363
expect(set_class).to receive(:new).
64-
with(:classes => [klass], :indices => ['user_core']).
64+
with({ :classes => [klass], :indices => ['user_core'] }).
6565
and_return(index_set)
6666

6767
middleware.call [context]
@@ -215,7 +215,7 @@ def self.table_name; 'cats'; end
215215
end
216216

217217
it "filters out deleted values by default" do
218-
expect(sphinx_sql).to receive(:where).with(:sphinx_deleted => false).
218+
expect(sphinx_sql).to receive(:where).with({ :sphinx_deleted => false }).
219219
and_return(sphinx_sql)
220220

221221
middleware.call [context]
@@ -253,7 +253,7 @@ def self.table_name; 'cats'; end
253253
search.options[:with_all] = {:tag_ids => [1, 7]}
254254

255255
expect(sphinx_sql).to receive(:where_all).
256-
with(:tag_ids => [1, 7]).and_return(sphinx_sql)
256+
with({ :tag_ids => [1, 7] }).and_return(sphinx_sql)
257257

258258
middleware.call [context]
259259
end
@@ -262,7 +262,7 @@ def self.table_name; 'cats'; end
262262
search.options[:without_all] = {:tag_ids => [1, 7]}
263263

264264
expect(sphinx_sql).to receive(:where_not_all).
265-
with(:tag_ids => [1, 7]).and_return(sphinx_sql)
265+
with({ :tag_ids => [1, 7] }).and_return(sphinx_sql)
266266

267267
middleware.call [context]
268268
end

spec/thinking_sphinx/panes/excerpts_pane_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module Panes; end
4545
search.options[:excerpts] = {:before_match => 'foo'}
4646

4747
expect(ThinkingSphinx::Excerpter).to receive(:new).
48-
with(anything, anything, :before_match => 'foo').and_return(excerpter)
48+
with(anything, anything, { :before_match => 'foo' }).and_return(excerpter)
4949

5050
pane.excerpts
5151
end

spec/thinking_sphinx/real_time/interpreter_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
it "passes through options to the attribute" do
5151
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
52-
with(column, :as => :other_name).and_return(attribute)
52+
with(column, { :as => :other_name }).and_return(attribute)
5353

5454
instance.has column, :as => :other_name
5555
end
@@ -84,7 +84,7 @@
8484

8585
it "passes through options to the field" do
8686
expect(ThinkingSphinx::RealTime::Field).to receive(:new).
87-
with(column, :as => :other_name).and_return(field)
87+
with(column, { :as => :other_name }).and_return(field)
8888

8989
instance.indexes column, :as => :other_name
9090
end
@@ -112,23 +112,23 @@
112112

113113
it "adds the _sort suffix to the field's name" do
114114
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
115-
with(column, :as => :col_sort, :type => :string).
115+
with(column, { :as => :col_sort, :type => :string }).
116116
and_return(attribute)
117117

118118
instance.indexes column, :sortable => true
119119
end
120120

121121
it "respects given aliases" do
122122
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
123-
with(column, :as => :other_sort, :type => :string).
123+
with(column, { :as => :other_sort, :type => :string }).
124124
and_return(attribute)
125125

126126
instance.indexes column, :sortable => true, :as => :other
127127
end
128128

129129
it "respects symbols instead of columns" do
130130
expect(ThinkingSphinx::RealTime::Attribute).to receive(:new).
131-
with(:title, :as => :title_sort, :type => :string).
131+
with(:title, { :as => :title_sort, :type => :string }).
132132
and_return(attribute)
133133

134134
instance.indexes :title, :sortable => true

spec/thinking_sphinx_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
end
1717

1818
it "passes through the given query and options" do
19-
expect(ThinkingSphinx::Search).to receive(:new).with('foo', :bar => :baz).
19+
expect(ThinkingSphinx::Search).to receive(:new).with('foo', { :bar => :baz }).
2020
and_return(search)
2121

2222
ThinkingSphinx.count('foo', :bar => :baz)
@@ -35,7 +35,7 @@
3535
end
3636

3737
it "passes through the given query and options" do
38-
expect(ThinkingSphinx::Search).to receive(:new).with('foo', :bar => :baz).
38+
expect(ThinkingSphinx::Search).to receive(:new).with('foo', { :bar => :baz }).
3939
and_return(search)
4040

4141
ThinkingSphinx.search('foo', :bar => :baz)

thinking-sphinx.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
3030

3131
s.add_development_dependency 'appraisal', '~> 1.0.2'
3232
s.add_development_dependency 'combustion', '~> 1.1'
33-
s.add_development_dependency 'database_cleaner', '~> 1.6.0'
34-
s.add_development_dependency 'rspec', '~> 3.7.0'
33+
s.add_development_dependency 'database_cleaner', '~> 2.0.2'
34+
s.add_development_dependency 'rspec', '~> 3.12.0'
3535
s.add_development_dependency 'rspec-retry', '~> 0.5.6'
3636
end

0 commit comments

Comments
 (0)