Skip to content

Commit 36bb08e

Browse files
ryanschkarmi
authored andcommitted
[MODEL] Stop requiring empty block for setting mapping options
This just bit me when trying to configure a class that includes Elasticsearch::Persistence::Model. Since the attribute definitions handle setting up the mapping, I just wanted to set dynamic and _routing. I had to resort to debugging to find out that I had to pass an empty block to get the #mapping method to actually do something with my options. Closes elastic#393
1 parent 6b81a77 commit 36bb08e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

elasticsearch-model/lib/elasticsearch/model/indexing.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ module ClassMethods
133133
def mapping(options={}, &block)
134134
@mapping ||= Mappings.new(document_type, options)
135135

136-
if block_given?
137-
@mapping.options.update(options)
136+
@mapping.options.update(options) unless options.empty?
138137

138+
if block_given?
139139
@mapping.instance_eval(&block)
140140
return self
141141
else

elasticsearch-model/test/unit/indexing_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class NotFound < Exception; end
106106
end
107107

108108
should "update and return the index mappings" do
109-
DummyIndexingModel.mappings foo: 'boo' do; end
110-
DummyIndexingModel.mappings bar: 'bam' do; end
109+
DummyIndexingModel.mappings foo: 'boo'
110+
DummyIndexingModel.mappings bar: 'bam'
111111
assert_equal( { dummy_indexing_model: { foo: "boo", bar: "bam", properties: {} } },
112112
DummyIndexingModel.mappings.to_hash )
113113
end

0 commit comments

Comments
 (0)