forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaming_test.rb
103 lines (78 loc) · 3.28 KB
/
naming_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
95
96
97
98
99
100
101
102
103
require 'test_helper'
class Elasticsearch::Model::NamingTest < Test::Unit::TestCase
context "Naming module" do
class ::DummyNamingModel
extend ActiveModel::Naming
extend Elasticsearch::Model::Naming::ClassMethods
include Elasticsearch::Model::Naming::InstanceMethods
end
module ::MyNamespace
class DummyNamingModelInNamespace
extend ActiveModel::Naming
extend Elasticsearch::Model::Naming::ClassMethods
include Elasticsearch::Model::Naming::InstanceMethods
end
end
should "return the default index_name" do
assert_equal 'dummy_naming_models', DummyNamingModel.index_name
assert_equal 'dummy_naming_models', DummyNamingModel.new.index_name
end
should "return the sanitized default index_name for namespaced model" do
assert_equal 'my_namespace-dummy_naming_model_in_namespaces', ::MyNamespace::DummyNamingModelInNamespace.index_name
assert_equal 'my_namespace-dummy_naming_model_in_namespaces', ::MyNamespace::DummyNamingModelInNamespace.new.index_name
end
should "return the default document_type" do
assert_equal 'dummy_naming_model', DummyNamingModel.document_type
assert_equal 'dummy_naming_model', DummyNamingModel.new.document_type
end
should "set and return the index_name" do
DummyNamingModel.index_name 'foobar'
assert_equal 'foobar', DummyNamingModel.index_name
d = DummyNamingModel.new
d.index_name 'foobar_d'
assert_equal 'foobar_d', d.index_name
modifier = 'r'
d.index_name Proc.new{ "foobar_#{modifier}" }
assert_equal 'foobar_r', d.index_name
modifier = 'z'
assert_equal 'foobar_z', d.index_name
modifier = 'f'
d.index_name { "foobar_#{modifier}" }
assert_equal 'foobar_f', d.index_name
modifier = 't'
assert_equal 'foobar_t', d.index_name
end
should "set the index_name with setter" do
DummyNamingModel.index_name = 'foobar_index_S'
assert_equal 'foobar_index_S', DummyNamingModel.index_name
d = DummyNamingModel.new
d.index_name = 'foobar_index_s'
assert_equal 'foobar_index_s', d.index_name
assert_equal 'foobar_index_S', DummyNamingModel.index_name
modifier2 = 'y'
DummyNamingModel.index_name = Proc.new{ "foobar_index_#{modifier2}" }
assert_equal 'foobar_index_y', DummyNamingModel.index_name
modifier = 'r'
d.index_name = Proc.new{ "foobar_index_#{modifier}" }
assert_equal 'foobar_index_r', d.index_name
modifier = 'z'
assert_equal 'foobar_index_z', d.index_name
assert_equal 'foobar_index_y', DummyNamingModel.index_name
end
should "set and return the document_type" do
DummyNamingModel.document_type 'foobar'
assert_equal 'foobar', DummyNamingModel.document_type
d = DummyNamingModel.new
d.document_type 'foobar_d'
assert_equal 'foobar_d', d.document_type
end
should "set the document_type with setter" do
DummyNamingModel.document_type = 'foobar_type_S'
assert_equal 'foobar_type_S', DummyNamingModel.document_type
d = DummyNamingModel.new
d.document_type = 'foobar_type_s'
assert_equal 'foobar_type_s', d.document_type
assert_equal 'foobar_type_S', DummyNamingModel.document_type
end
end
end