Skip to content

Conversation

picandocodigo
Copy link
Member

Transferred from elastic/elasticsearch-ruby#855:

Original Pull Request message:

Queirs.const_defined? 'Foo' find not only Queries::Foo but also ::Foo,
so if program has Foo class, this method_missing call Foo.new instead of call foo method.

class Foo
   include ActiveModel::Model
   include ActiveModel::Attributes

   attribute :name, :string
end

class SearchForm
  include ActiveModel::Model
  include ActiveModel::Attributes
  include Elasticsearch::DSL

  attribute :foo

  def condition
    search do
      query do
        bool { must { term name: foo.name } }
      end
    end
  end
end

p SearchForm.new(foo: Foo.new(name: 'hello')).condition.to_hash
  • expect: {:query=>{:bool=>{:must=>[{:term=>{:name=>"name"}}]}}}
  • actual: {:query=>{:bool=>{:must=>[{:term=>{:name=>nil}}]}}}

`Queirs.const_defined? 'Foo'` find not only `Queries::Foo` but also `::Foo`,
so if program has `Foo` class, this `method_missing` call `Foo.new` instead of call `foo` method.
@picandocodigo
Copy link
Member Author

picandocodigo commented Jan 13, 2022

@masarakki would it be possible for you to add a test for this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants