From 12371b4198edb2c24b6b675f3acc5cd731946d48 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Wed, 22 Apr 2020 14:35:41 -0700 Subject: [PATCH 1/2] [MODEL] Do not override existing methods --- elasticsearch-model/lib/elasticsearch/model.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticsearch-model/lib/elasticsearch/model.rb b/elasticsearch-model/lib/elasticsearch/model.rb index d50308d8d..04adaffc1 100644 --- a/elasticsearch-model/lib/elasticsearch/model.rb +++ b/elasticsearch-model/lib/elasticsearch/model.rb @@ -112,7 +112,7 @@ def self.included(base) # Delegate common methods to the `__elasticsearch__` ClassMethodsProxy, unless they are defined already class << self METHODS.each do |method| - delegate method, to: :__elasticsearch__ unless self.respond_to?(method) + delegate method, to: :__elasticsearch__ unless self.public_instance_methods.include?(method) end end end From a2c295040d0abffc493edc2e9bce600bff0a0d14 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Sat, 11 Jul 2020 10:50:00 -0700 Subject: [PATCH 2/2] fix spec to cover this case --- elasticsearch-model/spec/elasticsearch/model/module_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/elasticsearch-model/spec/elasticsearch/model/module_spec.rb b/elasticsearch-model/spec/elasticsearch/model/module_spec.rb index 3f7d682d0..72c90f4c5 100644 --- a/elasticsearch-model/spec/elasticsearch/model/module_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/module_spec.rb @@ -48,6 +48,7 @@ def self.search(query, options={}) end DummyIncludingModel.__send__ :include, Elasticsearch::Model + DummyIncludingModelWithSearchMethodDefined.__send__ :include, Elasticsearch::Model end after(:all) do