Skip to content

Commit

Permalink
[Fix #679] Clear cache (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalina-Vakulchyk authored Apr 8, 2021
1 parent 86ee881 commit e4ed1eb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Changes

* [#679](https://github.com/toptal/chewy/issues/679): Wrapped `Elasticsearch::API::Indices::Actions#clear_cache` with `.clear_cache` in Index class ([@Vitalina-Vakulchyk][])
* [#495](https://github.com/toptal/chewy/issues/495): Ability to change Rails console strategy with `Chewy.console_strategy` ([@Vitalina-Vakulchyk][])
* [#778](https://github.com/toptal/chewy/pull/778): **(Breaking)** Drop support for Ruby 2.5 ([@Vitalina-Vakulchyk][])
* [#776](https://github.com/toptal/chewy/pull/776): **(Breaking)** Removal of unnecessary features and integrations ([@Vitalina-Vakulchyk][]):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Chewy is an ODM (Object Document Mapper), built on top of the [the official Elas
* [Elasticsearch compatibility matrix](#elasticsearch-compatibility-matrix)
* [Active Record](#active-record)
* [Getting Started](#getting-started)
* [Minimal client setting](*minimal-client-setting)
* [Minimal client setting](#minimal-client-setting)
* [Elasticsearch](#elasticsearch)
* [Index](#index)
* [Model](#model)
Expand Down
4 changes: 4 additions & 0 deletions lib/chewy/index/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def journal
@journal ||= Chewy::Journal.new(self)
end

def clear_cache(args = {index: index_name})
client.indices.clear_cache(args)
end

private

def optimize_index_settings(index_name)
Expand Down
51 changes: 51 additions & 0 deletions spec/chewy/index/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,55 @@
describe '.journal' do
specify { expect(DummiesIndex.journal).to be_a(Chewy::Journal) }
end

describe '.clear_cache' do
before do
stub_model(:city)
stub_index(:cities) do
define_type City
end
end

let(:index_name) { 'test_index' }
let(:index_name_with_prefix) { 'cities_test_index' }
let(:unexisted_index_name) { 'wrong_index' }

context 'with existing index' do
before do
CitiesIndex.create(index_name)
end

specify do
expect(CitiesIndex)
.to receive(:clear_cache)
.and_call_original
expect { CitiesIndex.clear_cache({index: index_name_with_prefix}) }
.not_to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
end
end

context 'with unexisting index' do
specify do
expect(CitiesIndex)
.to receive(:clear_cache)
.and_call_original
expect { CitiesIndex.clear_cache({index: unexisted_index_name}) }
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
end
end

context 'without arguments' do
before do
CitiesIndex.create
end

specify do
expect(CitiesIndex)
.to receive(:clear_cache)
.and_call_original
expect { CitiesIndex.clear_cache }
.not_to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
end
end
end
end

0 comments on commit e4ed1eb

Please sign in to comment.