Skip to content

Commit

Permalink
fix broken tests in helper and transmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Oct 2, 2013
1 parent 2665ef9 commit 3ab3e75
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 49 deletions.
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

require 'mock_redis'
require 'redis-classy'
require 'rspec/rails'

RSpec.configure do |config|
config.backtrace_exclusion_patterns = [/lib\/rspec\/(core|expectations|matchers|mocks)/]
Expand Down
5 changes: 0 additions & 5 deletions spec/sphinx/integration/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@
after { helper.rebuild }
end

describe '#truncate_index' do
it { expect(Rye).to receive(:shell).with(:echo, /TRUNCATE RTINDEX index_name/) }
after { helper.send(:truncate_index, 'index_name') }
end

describe '#dump_delta_index' do
let(:model) { double('model') }
let(:records) { [double('record')] }
Expand Down
78 changes: 34 additions & 44 deletions spec/sphinx/integration/transmitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,56 @@
require 'spec_helper'

describe Sphinx::Integration::Transmitter do
let!(:record){ ModelWithRt.create!(:content => 'test content') }
let(:connection){ mock(Sphinx::Integration::Mysql::Connection) }
let(:transmitter) { described_class.new(ModelWithRt) }
let(:record) { mock_model ModelWithRt }

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

before do
ThinkingSphinx.stub(:take_connection).and_yield(connection)
record.stub(
:sphinx_document_id => 1,
:exists_in_sphinx? => true
)
end

subject { record.transmitter }

let(:delete_core_sql){ 'UPDATE model_with_rt_core SET sphinx_deleted = 1 WHERE id = %s' }

context 'when destroy' do
let(:delete_sql){ 'DELETE FROM model_with_rt_rt WHERE id = %s' }
let(:delete_delta_sql){ 'DELETE FROM model_with_rt_delta_rt WHERE id = %s' }

it 'delete in rt' do
connection.should_receive(:execute).with(delete_sql % record.sphinx_document_id).ordered
connection.should_receive(:execute).with(delete_core_sql % record.sphinx_document_id).ordered
subject.delete
describe '#replace' do
it do
expect(transmitter).to receive(:transmitted_data).and_return(:field => 123)
expect(transmitter).to receive(:sphinx_replace)
expect(transmitter).to receive(:sphinx_soft_delete)
end
after { transmitter.replace(record) }
end

context 'when full reindex' do
it 'delete in delta_rt' do
Redis::Mutex.with_lock(:full_reindex, :expire => 3.hours) do
connection.should_receive(:execute).with(delete_sql % record.sphinx_document_id).ordered
connection.should_receive(:execute).with(delete_core_sql % record.sphinx_document_id).ordered
connection.should_receive(:execute).with(delete_delta_sql % record.sphinx_document_id).ordered
subject.delete
end
end
describe '#delete' do
it do
expect(transmitter).to receive(:sphinx_delete)
expect(transmitter).to receive(:sphinx_soft_delete)
end
after { transmitter.delete(record) }
end

context 'when save' do
it 'replace in rt' do
connection.should_receive(:execute).with(RSpec::Mocks::ArgumentMatchers::RegexpMatcher.new(/^REPLACE INTO model_with_rt_rt/)).ordered
connection.should_receive(:execute).with(delete_core_sql % record.sphinx_document_id).ordered
subject.replace
end
describe '#update' do
it { expect(transmitter).to receive(:update_fields) }
after { transmitter.update(record, :field => 123) }
end

context 'when full reindex' do
it 'replace in delta_rt' do
Redis::Mutex.with_lock(:full_reindex, :expire => 3.hours) do
connection.should_receive(:execute).with(RSpec::Mocks::ArgumentMatchers::RegexpMatcher.new(/^REPLACE INTO model_with_rt_rt/)).ordered
connection.should_receive(:execute).with(delete_core_sql % record.sphinx_document_id).ordered
connection.should_receive(:execute).with(RSpec::Mocks::ArgumentMatchers::RegexpMatcher.new(/^REPLACE INTO model_with_rt_delta_rt/)).ordered
subject.replace
end
describe '#update_fields' do
context 'when writes delta' do
before { transmitter.stub(:write_delta? => true) }
it do
expect(transmitter).to receive(:sphinx_select).and_return([{'sphinx_internal_id' => 123}])
expect(ModelWithRt).to receive(:where).with(:id => [123]).and_return([record])
expect(transmitter).to receive(:replace).with(record)
end
after { transmitter.update_fields({:field => 123}, {:id => 1}) }
end
end

describe 'class methods' do
describe 'update_all_fields' do
it 'update fields in rt index by condition' do
connection.should_receive(:execute).with('UPDATE model_with_rt SET rubric_id = 123 WHERE id = 1')
described_class.update_all_fields(ModelWithRt, {:rubric_id => 123}, 'id = 1')
context 'when no writes delta' do
it do
expect(transmitter).to receive(:sphinx_update)
end
after { transmitter.update_fields({:field => 123}, {:id => 1}) }
end
end
end

0 comments on commit 3ab3e75

Please sign in to comment.