forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_test.rb
57 lines (46 loc) · 1.77 KB
/
module_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'test_helper'
class Elasticsearch::Model::ModuleTest < Test::Unit::TestCase
context "The main module" do
context "client" do
should "have a default" do
client = Elasticsearch::Model.client
assert_not_nil client
assert_instance_of Elasticsearch::Transport::Client, client
end
should "be settable" do
begin
Elasticsearch::Model.client = "Foobar"
assert_equal "Foobar", Elasticsearch::Model.client
ensure
Elasticsearch::Model.client = nil
end
end
end
context "when included in module/class, " do
class ::DummyIncludingModel; end
class ::DummyIncludingModelWithSearchMethodDefined
def self.search(query, options={})
"SEARCH"
end
end
should "include and set up the proxy" do
DummyIncludingModel.__send__ :include, Elasticsearch::Model
assert_respond_to DummyIncludingModel, :__elasticsearch__
assert_respond_to DummyIncludingModel.new, :__elasticsearch__
end
should "delegate important methods to the proxy" do
DummyIncludingModel.__send__ :include, Elasticsearch::Model
assert_respond_to DummyIncludingModel, :search
assert_respond_to DummyIncludingModel, :mappings
assert_respond_to DummyIncludingModel, :settings
assert_respond_to DummyIncludingModel, :index_name
assert_respond_to DummyIncludingModel, :document_type
assert_respond_to DummyIncludingModel, :import
end
should "not override existing method" do
DummyIncludingModelWithSearchMethodDefined.__send__ :include, Elasticsearch::Model
assert_equal 'SEARCH', DummyIncludingModelWithSearchMethodDefined.search('foo')
end
end
end
end