Skip to content

Commit

Permalink
chore: fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jul 4, 2024
1 parent cb42744 commit 4368a25
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 67 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ RSpec/MessageSpies:
RSpec/FilePath:
Enabled: false

RSpec/SpecFilePathFormat:
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
Enabled: false

Expand Down
128 changes: 64 additions & 64 deletions spec/esse/active_record/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,70 +173,6 @@
model.touch
end

context "when the document has a routing key" do
let(:model_class) do
Class.new(County) do
include Esse::ActiveRecord::Model
index_callbacks 'geographies:county', on: %i[update]
end
end
let(:il) { create_record(State, name: 'Illinois') }
let(:ny) { create_record(State, name: 'New York') }
let(:county) { create_record(model_class, name: 'Cook', state: il) }

it 'indexes the document in new routing and deletes the document from previous routing' do
expect(GeographiesIndex).to receive(:index).and_call_original
expect(GeographiesIndex).to esse_receive_request(:index).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: ny.id,
body: {name: 'Cook', type: 'county', state: { id: ny.id, name: ny.name }},
).and_return(index_ok_response)

expect(GeographiesIndex).to receive(:delete).and_call_original
expect(GeographiesIndex).to esse_receive_request(:delete).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: il.id,
).and_return('result' => 'deleted')

county.update(state: ny)
end

it 'does not delete the document when the routing key is not changed' do
expect(GeographiesIndex).to receive(:index).and_call_original
expect(GeographiesIndex).to esse_receive_request(:index).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: il.id,
body: {name: 'Cook County', type: 'county', state: { id: il.id, name: il.name }},
).and_return(index_ok_response)

expect(GeographiesIndex).not_to receive(:delete)

county.update(name: 'Cook County')
end

it 'does not raise error when the document does not exist' do
expect(GeographiesIndex).to receive(:index).and_call_original
expect(GeographiesIndex).to esse_receive_request(:index).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: ny.id,
body: {name: 'Cook', type: 'county', state: { id: ny.id, name: ny.name }},
).and_return(index_ok_response)

expect(GeographiesIndex).to receive(:delete).and_call_original
expect(GeographiesIndex).to esse_receive_request(:delete).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: il.id,
).and_raise_http_status(404, { 'error' => { 'type' => 'not_found' } })

county.update(state: ny)
end
end

it 'index the associated model using the block definition' do
model_class = Class.new(County) do
include Esse::ActiveRecord::Model
Expand Down Expand Up @@ -302,6 +238,70 @@
end
end

context 'when on :update with a the document that has a routing key' do
let(:model_class) do
Class.new(County) do
include Esse::ActiveRecord::Model
index_callbacks 'geographies:county', on: %i[update]
end
end
let(:il) { create_record(State, name: 'Illinois') }
let(:ny) { create_record(State, name: 'New York') }
let(:county) { create_record(model_class, name: 'Cook', state: il) }

it 'indexes the document in new routing and deletes the document from previous routing' do
expect(GeographiesIndex).to receive(:index).and_call_original
expect(GeographiesIndex).to esse_receive_request(:index).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: ny.id,
body: {name: 'Cook', type: 'county', state: { id: ny.id, name: ny.name }},
).and_return(index_ok_response)

expect(GeographiesIndex).to receive(:delete).and_call_original
expect(GeographiesIndex).to esse_receive_request(:delete).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: il.id,
).and_return('result' => 'deleted')

county.update(state: ny)
end

it 'does not delete the document when the routing key is not changed' do
expect(GeographiesIndex).to receive(:index).and_call_original
expect(GeographiesIndex).to esse_receive_request(:index).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: il.id,
body: {name: 'Cook County', type: 'county', state: { id: il.id, name: il.name }},
).and_return(index_ok_response)

expect(GeographiesIndex).not_to receive(:delete)

county.update(name: 'Cook County')
end

it 'does not raise error when the document does not exist' do
expect(GeographiesIndex).to receive(:index).and_call_original
expect(GeographiesIndex).to esse_receive_request(:index).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: ny.id,
body: {name: 'Cook', type: 'county', state: { id: ny.id, name: ny.name }},
).and_return(index_ok_response)

expect(GeographiesIndex).to receive(:delete).and_call_original
expect(GeographiesIndex).to esse_receive_request(:delete).with(
id: county.id,
index: GeographiesIndex.index_name,
routing: il.id,
).and_raise_http_status(404, { 'error' => { 'type' => 'not_found' } })

county.update(state: ny)
end
end

context 'when on destroy' do
let(:delete_ok_response) { { 'result' => 'deleted' } }

Expand Down

0 comments on commit 4368a25

Please sign in to comment.