diff --git a/lib/chewy/index.rb b/lib/chewy/index.rb index f5ff4348f..95cb8378d 100644 --- a/lib/chewy/index.rb +++ b/lib/chewy/index.rb @@ -30,18 +30,24 @@ class Index # def self.index_name(suggest = nil) if suggest - @index_name = build_index_name(suggest, prefix: Chewy.configuration[:prefix]) + @index_name = build_index_name(suggest, prefix: default_prefix) else @index_name ||= begin build_index_name( name.sub(/Index\Z/, '').demodulize.underscore, - prefix: Chewy.configuration[:prefix] + prefix: default_prefix ) if name end end @index_name or raise UndefinedIndex end + # Prefix to use + # + def self.default_prefix + Chewy.configuration[:prefix] + end + # Defines type for the index. Arguments depends on adapter used. For # ActiveRecord you can pass model or scope and options # diff --git a/spec/chewy/index_spec.rb b/spec/chewy/index_spec.rb index 10282ce79..a03453351 100644 --- a/spec/chewy/index_spec.rb +++ b/spec/chewy/index_spec.rb @@ -68,6 +68,11 @@ end end + describe '.default_prefix' do + before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) } + specify { expect(Class.new(Chewy::Index).default_prefix).to eq('testing') } + end + describe '.define_type' do specify { expect(DummiesIndex.type_hash['dummy']).to eq(DummiesIndex::Dummy) }