From 0df0c6cca8b4c4e1368fa4b20b1265a8ebaed28a Mon Sep 17 00:00:00 2001 From: Mikey Hogarth Date: Sat, 23 Jan 2016 09:29:28 +0000 Subject: [PATCH 1/2] Remove memoization from index name --- lib/chewy/index.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chewy/index.rb b/lib/chewy/index.rb index 95cb8378d..51c02d962 100644 --- a/lib/chewy/index.rb +++ b/lib/chewy/index.rb @@ -32,7 +32,7 @@ def self.index_name(suggest = nil) if suggest @index_name = build_index_name(suggest, prefix: default_prefix) else - @index_name ||= begin + @index_name = begin build_index_name( name.sub(/Index\Z/, '').demodulize.underscore, prefix: default_prefix From 4719c06043db5ee774abe6f094997580fd8f4a15 Mon Sep 17 00:00:00 2001 From: Mikey Hogarth Date: Sat, 23 Jan 2016 09:45:19 +0000 Subject: [PATCH 2/2] Tests --- spec/chewy/index_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/chewy/index_spec.rb b/spec/chewy/index_spec.rb index a03453351..5f27edf0e 100644 --- a/spec/chewy/index_spec.rb +++ b/spec/chewy/index_spec.rb @@ -66,6 +66,15 @@ specify { expect(DummiesIndex.index_name).to eq('testing_dummies') } specify { expect(stub_index(:dummies) { index_name :users }.index_name).to eq('testing_users') } end + + context 'dynamic index name' do + specify do + allow(Chewy).to receive_messages(configuration: {prefix: 'testing1'}) + expect(DummiesIndex.index_name).to eq('testing1_dummies') + allow(Chewy).to receive_messages(configuration: {prefix: 'testing2'}) + expect(DummiesIndex.index_name).to eq('testing2_dummies') + end + end end describe '.default_prefix' do