Skip to content

Commit

Permalink
tests: Fix rspec deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Nov 1, 2017
1 parent a409121 commit 1aac632
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

require 'redis'
require 'redis-namespace'

Expand Down Expand Up @@ -47,4 +45,4 @@ def self.db_current_time
::ActiveRecord::Base.connection.select_value('select NOW()').to_time
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
require 'spec_helper'

describe ThinkingSphinx::Attribute do
Expand All @@ -12,7 +11,8 @@

id_expr = ThinkingSphinx.unique_id_expression(index.send(:adapter), 0)
exptected_sql = %{ranged-query; SELECT post_id #{id_expr} AS id, region_id AS regions FROM post_regions WHERE id>=$start AND id<=$end; SELECT MIN(id), MAX(id) FROM post_regions}
index.sources.first.attributes.detect{ |x| x.unique_name == :regions }.send(:source_value, 0, false).should eql exptected_sql
expect(index.sources.first.attributes.detect { |x| x.unique_name == :regions }.send(:source_value, 0, false)).
to eq exptected_sql
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
require 'spec_helper'

describe ThinkingSphinx::Index::Builder do
Expand All @@ -10,8 +9,8 @@
end
end

it { index.local_options[:source_joins].should have(1).item }
it { index.local_options[:source_joins][:rubrics].should be_present }
it { expect(index.local_options[:source_joins].size).to eq 1 }
it { expect(index.local_options[:source_joins][:rubrics]).to be_present }
it do
join = index.local_options[:source_joins][:rubrics]
expect(join).to include(type: :left, on: "rubrics.id = model.rubric_id", as: :rubs)
Expand Down Expand Up @@ -52,8 +51,8 @@
end
end

it { index.local_options[:source_joins].should have(1).item }
it { index.local_options[:source_joins][:rubrics].should be_present }
it { expect(index.local_options[:source_joins].size).to eq 1 }
it { expect(index.local_options[:source_joins][:rubrics]).to be_present }
it do
index.local_options[:source_joins][:rubrics]
join = index.local_options[:source_joins][:rubrics]
Expand All @@ -75,9 +74,9 @@
end

it do
index.local_options[:source_joins].should have(2).item
index.local_options[:source_joins][:foo].should be_present
index.local_options[:source_joins][:baz].should be_present
expect(index.local_options[:source_joins].size).to eq 2
expect(index.local_options[:source_joins][:foo]).to be_present
expect(index.local_options[:source_joins][:baz]).to be_present
end
end

Expand All @@ -92,8 +91,8 @@
end

# 4 internal (:sphinx_internal_id, :sphinx_deleted, :class_crc, :sphinx_internal_class) + 1 user
it { index.attributes.should have(5).item }
it { index.attributes.select { |attr| attr.alias == :foo }.should be_present }
it { expect(index.attributes.size).to eq 5 }
it { expect(index.attributes.select { |attr| attr.alias == :foo }).to be_present }
end

describe 'delete_fields' do
Expand All @@ -106,8 +105,8 @@
end
end

it { index.fields.should have(1).item }
it { index.fields.select { |attr| attr.alias == :content2 }.should be_present }
it { expect(index.fields.size).to eq 1 }
it { expect(index.fields.select { |attr| attr.alias == :content2 }).to be_present }
end

describe 'limit' do
Expand All @@ -117,7 +116,7 @@
end
end

it { index.local_options[:sql_query_limit].should eq 10 }
it { expect(index.local_options[:sql_query_limit]).to eq 10 }
end

describe 'with' do
Expand All @@ -127,8 +126,8 @@
end
end

it { index.local_options[:source_cte].should have(1).item }
it { index.local_options[:source_cte][:_rubrics].should == "select id from rubrics {{where}}" }
it { expect(index.local_options[:source_cte].size).to eq 1 }
it { expect(index.local_options[:source_cte][:_rubrics]).to eq "select id from rubrics {{where}}" }
end

describe 'delete with' do
Expand All @@ -141,7 +140,7 @@
end
end

it { index.local_options[:source_cte].should have(1).item }
it { index.local_options[:source_cte][:_rubrics2].should == "select id from rubrics2" }
it { expect(index.local_options[:source_cte].size).to eq 1 }
it { expect(index.local_options[:source_cte][:_rubrics2]).to eq "select id from rubrics2" }
end
end
24 changes: 10 additions & 14 deletions spec/sphinx/integration/extensions/thinking_sphinx/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@
let(:result) { index.to_riddle(0) }

it 'generate core index' do
result.
select { |x| x.is_a?(Riddle::Configuration::Index) }.
should have(1).items
expect(result.select { |x| x.is_a?(Riddle::Configuration::Index) }.size).to eq 1
end

it 'generate rt index' do
result.
select { |x| x.is_a?(Riddle::Configuration::RealtimeIndex) }.
should have(2).items
expect(result.select { |x| x.is_a?(Riddle::Configuration::RealtimeIndex) }.size).to eq 2
end

it 'generate distributed index' do
result.
select { |x| x.is_a?(Riddle::Configuration::DistributedIndex) }.
should have(1).item
expect(result.select { |x| x.is_a?(Riddle::Configuration::DistributedIndex) }.size).to eq 1
end
end

Expand All @@ -41,11 +35,13 @@
end

describe '#to_riddle_for_rt' do
subject { index.to_riddle_for_rt(0) }
subject(:rt) { index.to_riddle_for_rt(0) }

its(:name) { should eql 'model_with_disk_rt0' }
its(:rt_field) { should have(1).item }
its(:rt_attr_uint) { should eql [:sphinx_internal_id, :sphinx_deleted, :class_crc, :region_id] }
it do
expect(rt.name).to eq 'model_with_disk_rt0'
expect(rt.rt_field.size).to eq 1
expect(rt.rt_attr_uint).to match_array([:sphinx_internal_id, :sphinx_deleted, :class_crc, :region_id])
end
end

describe '#to_riddle_for_core' do
Expand All @@ -58,7 +54,7 @@

describe '#all_names' do
it 'returns only distributed index name' do
index.all_names.should == [index.name]
expect(index.all_names).to match_array([index.name])
end
end
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# coding: utf-8
require 'spec_helper'

describe ThinkingSphinx do
let(:time) { Time.now.utc }

before { ThinkingSphinx::LastIndexing.redis.flushdb }
before { ThinkingSphinx.stub(:db_current_time).and_return(time) }
before { allow(ThinkingSphinx).to receive(:db_current_time).and_return(time) }

it do
expect(ThinkingSphinx.last_indexing_finish_time).to be_nil
expect(ThinkingSphinx.set_last_indexing_finish_time.to_i).to eq time.to_i
expect(ThinkingSphinx.last_indexing_finish_time.to_i).to eq time.to_i
end
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# coding: utf-8
require 'spec_helper'

describe ThinkingSphinx::Source::SQL do

describe '#sql_query_info' do
it 'generate default table name' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
end
index.sources.first.to_sql_query_info(0).should include('"model_with_disks"')
expect(index.sources.first.to_sql_query_info(0)).to include('"model_with_disks"')
end

it 'generate custom table name' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
set_property :source_table => 'custom_table_name'
end
index.sources.first.to_sql_query_info(0).should include('"custom_table_name"')
expect(index.sources.first.to_sql_query_info(0)).to include('"custom_table_name"')
end
end

Expand All @@ -29,7 +27,7 @@
}
end
expected_sql = 'WITH cte_table AS (select id from temp_table where "model_with_disks"."id" >= $start AND "model_with_disks"."id" <= $end)'
index.sources.first.to_sql(:offset => 0).should include(expected_sql)
expect(index.sources.first.to_sql(:offset => 0)).to include(expected_sql)
end

it 'generate joins' do
Expand Down Expand Up @@ -61,23 +59,23 @@
'LEFT JOIN rubrics AS rubrics_alias ON model_with_disks.rubric_id = rubrics_alias.id ' \
'LEFT JOIN products AS products ON model_with_disks.products_id = products.id ' \
'LEFT JOIN public.traits AS traits_alias ON model_with_disks.traits_id = traits_alias.id'
index.sources.first.to_sql(:offset => 0).should include(expected_sql)
expect(index.sources.first.to_sql(:offset => 0)).to include(expected_sql)
end

it 'generate no groupping' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
set_property :source_no_grouping => true
end
index.sources.first.to_sql(:offset => 0).should_not include('GROUP BY')
expect(index.sources.first.to_sql(:offset => 0)).to_not include('GROUP BY')
end

it 'generate limit' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
set_property :sql_query_limit => 1000
end
index.sources.first.to_sql(:offset => 0).should include('LIMIT 100')
expect(index.sources.first.to_sql(:offset => 0)).to include('LIMIT 100')
end
end

Expand All @@ -88,15 +86,15 @@
indexes 'content', :as => :content
set_property :sql_query_range => expected_sql
end
index.sources.first.to_sql_query_range({}).should include(expected_sql)
expect(index.sources.first.to_sql_query_range({})).to include(expected_sql)
end

it 'no generate query range' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
set_property :disable_range => true
end
index.sources.first.to_sql_query_range({}).should be_blank
expect(index.sources.first.to_sql_query_range({})).to be_blank
end
end

Expand All @@ -105,15 +103,15 @@
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
end
index.sources.first.to_sql_query_info(0).should include('"model_with_disks"')
expect(index.sources.first.to_sql_query_info(0)).to include('"model_with_disks"')
end

it 'generate custom table name' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
set_property :source_table => 'custom_table_name'
end
index.sources.first.to_sql_query_info(0).should include('"custom_table_name"')
expect(index.sources.first.to_sql_query_info(0)).to include('"custom_table_name"')
end
end

Expand All @@ -122,15 +120,15 @@
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
end
index.sources.first.sql_select_clause(0).should include('"model_with_disks"."id"')
expect(index.sources.first.sql_select_clause(0)).to include('"model_with_disks"."id"')
end

it 'generate custom table name' do
index = ThinkingSphinx::Index::Builder.generate(ModelWithDisk, nil) do
indexes 'content', :as => :content
set_property :source_table => 'custom_table_name'
end
index.sources.first.sql_select_clause(0).should include('"custom_table_name"."id"')
expect(index.sources.first.sql_select_clause(0)).to include('"custom_table_name"."id"')
end
end

Expand All @@ -140,7 +138,7 @@
indexes 'content', :as => :content
set_property :use_own_sql_query_range => true
end
index.sources.first.sql_select_clause(0).should_not include('$start', '$end')
expect(index.sources.first.sql_select_clause(0)).to_not include('$start', '$end')
end
end

Expand All @@ -150,8 +148,7 @@
indexes 'content', :as => :content
group_by! :id, :region_id
end
index.sources.first.sql_group_clause.should eql 'id, region_id'
expect(index.sources.first.sql_group_clause).to eq 'id, region_id'
end
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end

before do
index_source.stub(:db_config).and_return(db_config)
allow(index_source).to receive(:db_config).and_return(db_config)
index_source.instance_variable_set(:@database_configuration, db_config[:test])
end

Expand Down
4 changes: 2 additions & 2 deletions spec/sphinx/integration/server_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

it "fails if all servers dies" do
expect { pool.take { |_| raise } }.to raise_error
expect { pool.take { |_| raise } }.to raise_error(RuntimeError)
end
end

Expand All @@ -43,7 +43,7 @@
end

it "fails if all servers dies" do
expect { pool.take_all { |_| raise } }.to raise_error
expect { pool.take_all { |_| raise } }.to raise_error(RuntimeError)
end
end
end
4 changes: 2 additions & 2 deletions spec/sphinx/integration/transmitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
client
end

before(:all){ ThinkingSphinx.context.define_indexes }
before(:all) { ThinkingSphinx.context.define_indexes }

before do
allow(transmitter).to receive(:write_disabled?).and_return(false)

record.stub(
allow(record).to receive_messages(
sphinx_document_id: 1,
exists_in_sphinx?: true,
model_with_rt_rubrics: []
Expand Down

0 comments on commit 1aac632

Please sign in to comment.