Skip to content

Commit

Permalink
AutoRefresh doesn't fail after deleting index
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed Nov 10, 2014
1 parent d56612e commit 3801fbf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/elastics/auto_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def disable!(&block)
end

def included(base)
base.send :alias_method, :request_without_test_mode, :request
base.send :alias_method, :request, :request_with_test_mode
base.send :alias_method, :request_without_auto_refresh, :request
base.send :alias_method, :request, :request_with_auto_refresh
end
end

def request_with_test_mode(params)
request_without_test_mode(params).tap do
def request_with_auto_refresh(params)
request_without_auto_refresh(params).tap do
next unless AutoRefresh.enabled?
next if SKIP_IDS.include?(params[:id].to_s.downcase)
next unless METHODS.include?(params[:method].to_s.downcase)
Expand Down
7 changes: 6 additions & 1 deletion lib/elastics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ def index_exists?(index)
!!get(index: index, type: nil, id: :_mapping)
end

def refresh(index = nil)
def refresh!(index = nil)
request(method: :post, index: index, type: nil, id: :_refresh)
end

def refresh(*args)
refresh!(*args)
rescue NotFound
end

private
# Endpoint for low-level request. For easy host highjacking & instrumentation.
# Params are not used directly but kept for instrumentation purpose.
Expand Down
34 changes: 34 additions & 0 deletions spec/lib/elastics/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

describe Elastics::Client do
let(:instance) { described_class.new }
let(:index_name) { 'elastics_test' }

describe '#refresh!' do
subject { instance.refresh!(index_name) }

context 'when index exists' do
before { instance.post(index: index_name) }
after { instance.delete(index: index_name) }
it { should be }
end

context 'when index does not exist' do
it { expect { subject }.to raise_error(Elastics::NotFound) }
end
end

describe '#refresh' do
subject { instance.refresh(index_name) }

context 'when index exists' do
before { instance.post(index: index_name) }
after { instance.delete(index: index_name) }
it { should be }
end

context 'when index does not exist' do
it { should be_nil }
end
end
end

0 comments on commit 3801fbf

Please sign in to comment.