Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion elasticsearch-model/lib/elasticsearch/model/indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ def delete_document(options={})
def update_document(options={})
if changed_attributes = self.instance_variable_get(:@__changed_attributes)
attributes = if respond_to?(:as_indexed_json)
changed_attributes.select { |k,v| self.as_indexed_json.keys.include? k }
keys = self.as_indexed_json.keys.map(&:to_s)
changed_attributes.select { |k,v| keys.include? k }
else
changed_attributes
end
Expand Down
20 changes: 10 additions & 10 deletions elasticsearch-model/test/unit/indexing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def self.before_save(&block)
(@callbacks ||= {})[block.hash] = block
end

def changed_attributes; [:foo]; end
def changed_attributes; ["foo"]; end

def changes
{:foo => ['One', 'Two']}
{"foo" => ['One', 'Two']}
end
end

Expand All @@ -143,14 +143,14 @@ def self.before_save(&block)
(@callbacks ||= {})[block.hash] = block
end

def changed_attributes; [:foo, :bar]; end
def changed_attributes; ['foo', 'bar']; end

def changes
{:foo => ['A', 'B'], :bar => ['C', 'D']}
{'foo' => ['A', 'B'], 'bar' => ['C', 'D']}
end

def as_indexed_json(options={})
{ :foo => 'B' }
{ 'foo' => 'B' }
end
end

Expand All @@ -163,7 +163,7 @@ def as_indexed_json(options={})
instance = ::DummyIndexingModelWithCallbacks.new
instance.expects(:instance_variable_set).with do |name, value|
assert_equal :@__changed_attributes, name
assert_equal({foo: 'Two'}, value)
assert_equal({'foo' => 'Two'}, value)
end

::DummyIndexingModelWithCallbacks.__send__ :include, Elasticsearch::Model::Indexing::InstanceMethods
Expand Down Expand Up @@ -260,13 +260,13 @@ def as_indexed_json(options={})
instance = ::DummyIndexingModelWithCallbacks.new

# Set the fake `changes` hash
instance.instance_variable_set(:@__changed_attributes, {foo: 'bar'})
instance.instance_variable_set(:@__changed_attributes, {'foo' => 'bar'})

client.expects(:update).with do |payload|
assert_equal 'foo', payload[:index]
assert_equal 'bar', payload[:type]
assert_equal '1', payload[:id]
assert_equal({foo: 'bar'}, payload[:body][:doc])
assert_equal({'foo' => 'bar'}, payload[:body][:doc])
end

instance.expects(:client).returns(client)
Expand All @@ -282,10 +282,10 @@ def as_indexed_json(options={})
instance = ::DummyIndexingModelWithCallbacksAndCustomAsIndexedJson.new

# Set the fake `changes` hash
instance.instance_variable_set(:@__changed_attributes, {foo: 'B', bar: 'D' })
instance.instance_variable_set(:@__changed_attributes, {'foo' => 'B', 'bar' => 'D' })

client.expects(:update).with do |payload|
assert_equal({foo: 'B'}, payload[:body][:doc])
assert_equal({'foo' => 'B'}, payload[:body][:doc])
end

instance.expects(:client).returns(client)
Expand Down