@@ -41,6 +41,10 @@ class TestEnhancedTransactionType < TestTransactionType
41
41
attribute :client_data , TestClientDataType
42
42
end
43
43
44
+ class TestMultipleClientTransactionType < TestTransactionType
45
+ attribute :clients , TestClientDataType , collection : true
46
+ end
47
+
44
48
context 'inheritance' do
45
49
should 'correctly set up a class after inheriting' do
46
50
mod_parent = TestTransactionType . builder_methods_module
@@ -152,6 +156,44 @@ class TestEnhancedTransactionType < TestTransactionType
152
156
assert_equal 'USD' , obj . amount . currency
153
157
end
154
158
159
+ should 'build an object with a collection attribute' do
160
+ obj = TestMultipleClientTransactionType . build do |t |
161
+ t . cvv_code = '321'
162
+ t . amount do |a |
163
+ a . value = 45.0
164
+ a . currency = 'USD'
165
+ end
166
+ t . clients do |c |
167
+ c . first_name = 'Mateusz'
168
+ c . last_name = 'Gobbins'
169
+
170
+ end
171
+ t . clients do |c |
172
+ c . first_name = 'Michal'
173
+ c . last_name = 'Zapow'
174
+
175
+ end
176
+ end
177
+
178
+ assert obj . is_a? ( TestTransactionType )
179
+ assert_equal '321' , obj . cvv_code
180
+ assert obj . amount . is_a? ( TestAmountType )
181
+ assert_equal 45.0 , obj . amount . value
182
+ assert_equal 'USD' , obj . amount . currency
183
+ assert obj . clients . is_a? ( ::Array ) , "Should be and Array, got: #{ obj . clients . class . inspect } "
184
+ assert_equal 2 , obj . clients . length
185
+
186
+ cli = obj . clients . first
187
+ assert_equal 'Mateusz' , cli . first_name
188
+ assert_equal 'Gobbins' , cli . last_name
189
+ assert_equal '[email protected] ' , cli . email
190
+
191
+ cli = obj . clients . last
192
+ assert_equal 'Michal' , cli . first_name
193
+ assert_equal 'Zapow' , cli . last_name
194
+ assert_equal '[email protected] ' , cli . email
195
+ end
196
+
155
197
should 'build an object through the alt DSL' do
156
198
obj = TestTransactionType . build do |t |
157
199
t . cvv_code = '321'
0 commit comments