Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minitest assertions and indexing controls. #396

Merged
merged 7 commits into from
Aug 6, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
spec for minitesthelper
  • Loading branch information
Robert L. Carpenter committed Jun 27, 2016
commit 1225e6ecf66782f6718e76a5dc601942625984b5
91 changes: 91 additions & 0 deletions spec/chewy/minitest/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
require 'spec_helper'
require 'chewy/minitest'

describe :minitest_helper do
class << self
alias_method :teardown, :after
end

def assert_includes haystack, needle, comment
expect(haystack).to include(needle)
end

include ::Chewy::Minitest::Helpers

before do
Chewy.massacre
end

before do
stub_index(:dummies) do
define_type :dummy do
root value: ->(o){{}}
end
end
end

context 'assert_indexes' do
specify 'doesn\'t fail when index updates correctly' do
expect {
assert_indexes DummiesIndex::Dummy do
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
end
}.to_not raise_error
end

specify 'fails when index doesn\'t update' do
expect {
assert_indexes DummiesIndex::Dummy do
end
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end

specify 'SearchIndexReceiver catches the indexes' do
receiver = assert_indexes DummiesIndex::Dummy do
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
end

expect(receiver).to be_a(SearchIndexReceiver)

expect(
receiver.indexes_for(DummiesIndex::Dummy)
.map {|index| index[:_id]}
.sort
).to eq([41,42])
end

specify 'Real index is bypassed when asserting' do
expect(DummiesIndex::Dummy).not_to receive(:bulk)

assert_indexes DummiesIndex::Dummy do
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
end
end

specify 'Real index is allowed when asserting' do
expect(DummiesIndex::Dummy).to receive(:bulk)

assert_indexes DummiesIndex::Dummy, bypass_actual_index: false do
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
end
end
end

context 'run_indexing' do
specify 'pushes onto the chewy strategy stack' do
Chewy.strategy :bypass do
run_indexing do
expect(Chewy.strategy).to be(:atomic)
end
end
end

specify 'allows tester to specify the strategy' do
Chewy.strategy :atomic do
run_indexing strategy: :bypass do
expect(Chewy.strategy).to be(:bypass)
end
end
end
end
end