forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaming_inheritance_test.rb
94 lines (72 loc) · 2.59 KB
/
naming_inheritance_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require "test_helper"
class Elasticsearch::Model::NamingInheritanceTest < Test::Unit::TestCase
def setup
Elasticsearch::Model.settings[:inheritance_enabled] = true
end
def teardown
Elasticsearch::Model.settings[:inheritance_enabled] = false
end
context "Naming module with inheritance" do
class ::TestBase
extend ActiveModel::Naming
extend Elasticsearch::Model::Naming::ClassMethods
include Elasticsearch::Model::Naming::InstanceMethods
end
class ::Animal < ::TestBase
extend ActiveModel::Naming
extend Elasticsearch::Model::Naming::ClassMethods
include Elasticsearch::Model::Naming::InstanceMethods
index_name "mammals"
document_type "mammal"
end
class ::Dog < ::Animal
end
module ::MyNamespace
class Dog < ::Animal
end
end
class ::Cat < ::Animal
extend ActiveModel::Naming
extend Elasticsearch::Model::Naming::ClassMethods
include Elasticsearch::Model::Naming::InstanceMethods
index_name "cats"
document_type "cat"
end
should "return the default index_name" do
assert_equal "test_bases", TestBase.index_name
assert_equal "test_bases", TestBase.new.index_name
end
should "return the explicit index_name" do
assert_equal "mammals", Animal.index_name
assert_equal "mammals", Animal.new.index_name
assert_equal "cats", Cat.index_name
assert_equal "cats", Cat.new.index_name
end
should "return the ancestor index_name" do
assert_equal "mammals", Dog.index_name
assert_equal "mammals", Dog.new.index_name
end
should "return the ancestor index_name for namespaced model" do
assert_equal "mammals", ::MyNamespace::Dog.index_name
assert_equal "mammals", ::MyNamespace::Dog.new.index_name
end
should "return the default document_type" do
assert_equal "test_base", TestBase.document_type
assert_equal "test_base", TestBase.new.document_type
end
should "return the explicit document_type" do
assert_equal "mammal", Animal.document_type
assert_equal "mammal", Animal.new.document_type
assert_equal "cat", Cat.document_type
assert_equal "cat", Cat.new.document_type
end
should "return the ancestor document_type" do
assert_equal "mammal", Dog.document_type
assert_equal "mammal", Dog.new.document_type
end
should "return the ancestor document_type for namespaced model" do
assert_equal "mammal", ::MyNamespace::Dog.document_type
assert_equal "mammal", ::MyNamespace::Dog.new.document_type
end
end
end