Skip to content

Commit

Permalink
Merge pull request #1252 from jdelStrother/logsubscriber-deprecations
Browse files Browse the repository at this point in the history
Fixes for Rails 7.1
  • Loading branch information
pat authored Jun 16, 2024
2 parents fda3d0a + b541835 commit 8ced2ef
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
ruby: [ '2.7', '3.0', '3.1', '3.2' ]
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0' ]
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0', '7_1' ]
database: [ 'mysql2', 'postgresql' ]
sphinx_version: [ '2.2.11', '3.4.1' ]
sphinx_engine: [ 'sphinx' ]
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
fail-fast: false
matrix:
ruby: [ '2.7', '3.0', '3.1', '3.2' ]
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0' ]
rails: [ '5_0', '5_1', '5_2', '6_0', '6_1', '7_0', '7_1' ]
database: [ 'mysql2', 'postgresql' ]
sphinx_version: [ '4.0.2', '6.0.0' ]
sphinx_engine: [ 'manticore' ]
Expand Down
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ appraise 'rails_7_0' do
gem 'mysql2', '~> 0.5.0', :platform => :ruby
gem 'pg', '~> 1.0', :platform => :ruby
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.7

appraise 'rails_7_1' do
gem 'rails', '~> 7.1.0'
gem 'mysql2', '~> 0.5.0', :platform => :ruby
gem 'pg', '~> 1.0', :platform => :ruby
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.7
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/active_record/filter_reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ThinkingSphinx::ActiveRecord::FilterReflection
ReflectionGenerator = case ActiveRecord::VERSION::STRING.to_f
when 5.2..7.0
when 5.2..7.1
ThinkingSphinx::ActiveRecord::Depolymorph::OverriddenReflection
when 4.1..5.1
ThinkingSphinx::ActiveRecord::Depolymorph::AssociationReflection
Expand Down
20 changes: 16 additions & 4 deletions lib/thinking_sphinx/active_record/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@

class ThinkingSphinx::ActiveRecord::LogSubscriber < ActiveSupport::LogSubscriber
def guard(event)
identifier = color 'Sphinx', GREEN, true
identifier = colored_text "Sphinx"
warn " #{identifier} #{event.payload[:guard]}"
end

def message(event)
identifier = color 'Sphinx', GREEN, true
identifier = colored_text "Sphinx"
debug " #{identifier} #{event.payload[:message]}"
end

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

def caution(event)
identifier = color 'Sphinx', GREEN, true
identifier = colored_text "Sphinx"
warn " #{identifier} #{event.payload[:caution]}"
end

private

if Rails.gem_version >= Gem::Version.new("7.1.0")
def colored_text(text)
color text, GREEN, bold: true
end
else
def colored_text(text)
color text, GREEN, true
end
end
end

ThinkingSphinx::ActiveRecord::LogSubscriber.attach_to :thinking_sphinx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Callbacks; end

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

callbacks.after_update
end
Expand Down
10 changes: 5 additions & 5 deletions spec/thinking_sphinx/active_record/interpreter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

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

instance.has column, :as => :other_name
end
Expand Down Expand Up @@ -141,7 +141,7 @@

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

instance.indexes column, :as => :other_name
end
Expand Down Expand Up @@ -230,19 +230,19 @@
end

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

instance.set_database :foo => :bar
end

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

instance.set_database 'other'
end

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

instance.set_database :other
end
Expand Down
5 changes: 3 additions & 2 deletions spec/thinking_sphinx/excerpter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
:before_match => '<b>', :chunk_separator => ' -- ')

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

excerpter.excerpt!('all of the words')
Expand Down
4 changes: 2 additions & 2 deletions spec/thinking_sphinx/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

ThinkingSphinx::Index.define(:user, :with => :active_record)
end
Expand Down Expand Up @@ -100,7 +100,7 @@

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

ThinkingSphinx::Index.define(:user, :with => :real_time)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/thinking_sphinx/middlewares/sphinxql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SphinxQLSubclass
allow(index_set.first).to receive_messages :reference => :user

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

middleware.call [context]
Expand Down Expand Up @@ -215,7 +215,7 @@ def self.table_name; 'cats'; end
end

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

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

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

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

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

middleware.call [context]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/thinking_sphinx/panes/excerpts_pane_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Panes; end
search.options[:excerpts] = {:before_match => 'foo'}

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

pane.excerpts
end
Expand Down
10 changes: 5 additions & 5 deletions spec/thinking_sphinx/real_time/interpreter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

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

instance.has column, :as => :other_name
end
Expand Down Expand Up @@ -84,7 +84,7 @@

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

instance.indexes column, :as => :other_name
end
Expand Down Expand Up @@ -112,23 +112,23 @@

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

instance.indexes column, :sortable => true
end

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

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

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

instance.indexes :title, :sortable => true
Expand Down
4 changes: 2 additions & 2 deletions spec/thinking_sphinx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

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

ThinkingSphinx.count('foo', :bar => :baz)
Expand All @@ -35,7 +35,7 @@
end

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

ThinkingSphinx.search('foo', :bar => :baz)
Expand Down
4 changes: 2 additions & 2 deletions thinking-sphinx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'appraisal', '~> 1.0.2'
s.add_development_dependency 'combustion', '~> 1.1'
s.add_development_dependency 'database_cleaner', '~> 1.6.0'
s.add_development_dependency 'rspec', '~> 3.7.0'
s.add_development_dependency 'database_cleaner', '~> 2.0.2'
s.add_development_dependency 'rspec', '~> 3.12.0'
s.add_development_dependency 'rspec-retry', '~> 0.5.6'
end

0 comments on commit 8ced2ef

Please sign in to comment.