Sha256: ffaf075f0e7dbc3fceb0a2e3f52e96179dab07e9d087b616be02c7b6b19b8727

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require 'test_helper'

class EsSearchableTest < ActiveSupport::TestCase
	setup do
	  class Foo
			include EsSearchable
		end
	end

	test "self.es_collection" do
		assert_kind_of EsSearchable::SearchCollection, Foo.es_collection
	end

	test "self.handle_es_response" do
		assert_equal Foo.handle_es_response('xxxx'), 'xxxx'
	end

	test "self.client" do
		client = Foo.client
		assert_kind_of Elasticsearch::Transport::Client, Foo.client

		transport = client.transport
		assert_equal transport.max_retries, EsSearchable.retry_on_failure
		assert_kind_of Logger, transport.logger
		assert_equal transport.options[:reload_on_failure], EsSearchable.reload_on_failure
		assert_equal transport.options[:hosts], EsSearchable.hosts
	end

	test "self.es_search" do
		Foo.client.stubs(:search).returns('search_result')
		assert_equal Foo.es_search({}), 'search_result'
	end

	test "self.es_index" do
		Foo.es_index 'index'
		assert_equal Foo.instance_variable_get(:@index), 'index'

		Foo.es_index nil
	end

	test 'self.index returns the default index' do
		assert_equal Foo.index, 'foos'
	end

	test 'self.index returns index setted by self.es_index method' do
		Foo.es_index 'index'
		assert_equal Foo.index, 'index'
		Foo.es_index nil
	end

	test "delegate SearchMethods to es_collection" do
		EsSearchable::SearchMethods.each do |method|
			assert Foo.respond_to?("es_#{method}")
			assert_equal Foo.send("es_#{method}", {id: 1}).search_params,
				Foo.es_collection.send(method, {id: 1}).search_params
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
es_searchable-0.2.1 test/es_searchable_test.rb
es_searchable-0.2.0 test/es_searchable_test.rb
es_searchable-0.1.1 test/es_searchable_test.rb