@@ -90,36 +90,56 @@ class NotFound < Exception; end
90
90
assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :bar ] [ :type ]
91
91
end
92
92
93
- %w( string long double boolean multi_field ) . each do |outer_type |
94
- should "define embedded fields for #{ outer_type } " do
95
- mappings = Elasticsearch ::Model ::Indexing ::Mappings . new :mytype
96
-
97
- mappings . indexes :foo , type : outer_type do
98
- indexes :raw , analyzer : 'keyword'
99
- end
93
+ should "define multiple fields" do
94
+ mappings = Elasticsearch ::Model ::Indexing ::Mappings . new :mytype
100
95
101
- foo_mapping = mappings . to_hash [ :mytype ] [ :properties ] [ :foo ]
96
+ mappings . indexes :foo_1 , type : 'string' do
97
+ indexes :raw , analyzer : 'keyword'
98
+ end
102
99
103
- assert_equal outer_type , foo_mapping [ :type ]
104
- assert_nil foo_mapping [ :properties ]
105
- assert_equal 'string' , foo_mapping [ :fields ] [ :raw ] [ :type ]
100
+ mappings . indexes :foo_2 , type : 'multi_field' do
101
+ indexes :raw , analyzer : 'keyword'
106
102
end
103
+
104
+ assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_1 ] [ :type ]
105
+ assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_1 ] [ :fields ] [ :raw ] [ :type ]
106
+ assert_equal 'keyword' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_1 ] [ :fields ] [ :raw ] [ :analyzer ]
107
+ assert_nil mappings . to_hash [ :mytype ] [ :properties ] [ :foo_1 ] [ :properties ]
108
+
109
+ assert_equal 'multi_field' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_2 ] [ :type ]
110
+ assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_2 ] [ :fields ] [ :raw ] [ :type ]
111
+ assert_equal 'keyword' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_2 ] [ :fields ] [ :raw ] [ :analyzer ]
112
+ assert_nil mappings . to_hash [ :mytype ] [ :properties ] [ :foo_2 ] [ :properties ]
107
113
end
108
114
109
- %w( object nested ) . each do |outer_type |
110
- should "define embedded properties for #{ outer_type } " do
111
- mappings = Elasticsearch ::Model ::Indexing ::Mappings . new :mytype
115
+ should "define embedded properties" do
116
+ mappings = Elasticsearch ::Model ::Indexing ::Mappings . new :mytype
112
117
113
- mappings . indexes :foo , type : outer_type do
114
- indexes :bar
115
- end
118
+ mappings . indexes :foo do
119
+ indexes :bar
120
+ end
116
121
117
- foo_mapping = mappings . to_hash [ :mytype ] [ :properties ] [ :foo ]
122
+ mappings . indexes :foo_object , type : 'object' do
123
+ indexes :bar
124
+ end
118
125
119
- assert_equal outer_type , foo_mapping [ :type ]
120
- assert_nil foo_mapping [ :fields ]
121
- assert_equal 'string' , foo_mapping [ :properties ] [ :bar ] [ :type ]
126
+ mappings . indexes :foo_nested , type : 'nested' do
127
+ indexes :bar
122
128
end
129
+
130
+ # Object is the default when `type` is missing and there's a block passed
131
+ #
132
+ assert_equal 'object' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo ] [ :type ]
133
+ assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo ] [ :properties ] [ :bar ] [ :type ]
134
+ assert_nil mappings . to_hash [ :mytype ] [ :properties ] [ :foo ] [ :fields ]
135
+
136
+ assert_equal 'object' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_object ] [ :type ]
137
+ assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_object ] [ :properties ] [ :bar ] [ :type ]
138
+ assert_nil mappings . to_hash [ :mytype ] [ :properties ] [ :foo_object ] [ :fields ]
139
+
140
+ assert_equal 'nested' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_nested ] [ :type ]
141
+ assert_equal 'string' , mappings . to_hash [ :mytype ] [ :properties ] [ :foo_nested ] [ :properties ] [ :bar ] [ :type ]
142
+ assert_nil mappings . to_hash [ :mytype ] [ :properties ] [ :foo_nested ] [ :fields ]
123
143
end
124
144
end
125
145
0 commit comments