fog-core 2.1.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +2 -0
  3. data/.github/dependabot.yml +10 -0
  4. data/.github/workflows/ci.yml +32 -0
  5. data/.rubocop.yml +16 -12
  6. data/.rubocop_todo.yml +724 -0
  7. data/CONTRIBUTING.md +5 -1
  8. data/Gemfile +1 -1
  9. data/README.md +2 -1
  10. data/Rakefile +2 -14
  11. data/SECURITY.md +6 -0
  12. data/changelog.md +241 -141
  13. data/fog-core.gemspec +13 -9
  14. data/lib/fog/account.rb +0 -16
  15. data/lib/fog/billing.rb +0 -11
  16. data/lib/fog/compute/models/server.rb +7 -3
  17. data/lib/fog/compute.rb +3 -25
  18. data/lib/fog/core/association.rb +1 -0
  19. data/lib/fog/core/attributes/default.rb +7 -0
  20. data/lib/fog/core/attributes.rb +42 -5
  21. data/lib/fog/core/cache.rb +58 -55
  22. data/lib/fog/core/collection.rb +9 -3
  23. data/lib/fog/core/connection.rb +4 -6
  24. data/lib/fog/core/current_machine.rb +1 -1
  25. data/lib/fog/core/errors.rb +1 -1
  26. data/lib/fog/core/logger.rb +5 -2
  27. data/lib/fog/core/mock.rb +7 -2
  28. data/lib/fog/core/model.rb +34 -5
  29. data/lib/fog/core/provider.rb +37 -4
  30. data/lib/fog/core/scp.rb +16 -11
  31. data/lib/fog/core/service.rb +5 -5
  32. data/lib/fog/core/services_mixin.rb +62 -10
  33. data/lib/fog/core/ssh.rb +49 -25
  34. data/lib/fog/core/stringify_keys.rb +0 -2
  35. data/lib/fog/core/time.rb +2 -2
  36. data/lib/fog/core/uuid.rb +2 -8
  37. data/lib/fog/core/version.rb +3 -1
  38. data/lib/fog/core/wait_for.rb +2 -1
  39. data/lib/fog/core/wait_for_defaults.rb +2 -0
  40. data/lib/fog/core.rb +57 -59
  41. data/lib/fog/dns.rb +0 -11
  42. data/lib/fog/formatador.rb +9 -8
  43. data/lib/fog/monitoring.rb +0 -11
  44. data/lib/fog/network.rb +0 -12
  45. data/lib/fog/schema/data_validator.rb +1 -0
  46. data/lib/fog/storage.rb +15 -30
  47. data/lib/fog/support.rb +0 -12
  48. data/lib/fog/test_helpers/collection_helper.rb +2 -0
  49. data/lib/fog/test_helpers/formats_helper.rb +2 -2
  50. data/lib/fog/test_helpers/helper.rb +3 -3
  51. data/lib/fog/test_helpers/minitest/assertions.rb +1 -1
  52. data/lib/fog/test_helpers/minitest/expectations.rb +1 -1
  53. data/lib/fog/test_helpers/mock_helper.rb +84 -84
  54. data/lib/fog/test_helpers/succeeds_helper.rb +2 -2
  55. data/lib/fog/test_helpers/types_helper.rb +1 -0
  56. data/lib/fog/vpn.rb +0 -12
  57. data/lib/tasks/test_task.rb +4 -5
  58. metadata +58 -85
  59. data/.travis.yml +0 -39
  60. data/spec/compute/models/server_spec.rb +0 -229
  61. data/spec/compute_spec.rb +0 -95
  62. data/spec/connection_spec.rb +0 -105
  63. data/spec/core/cache_spec.rb +0 -191
  64. data/spec/core/model_spec.rb +0 -36
  65. data/spec/core/stringify_keys_spec.rb +0 -38
  66. data/spec/core/whitelist_keys_spec.rb +0 -36
  67. data/spec/credentials_spec.rb +0 -88
  68. data/spec/current_machine_spec.rb +0 -36
  69. data/spec/fake_app/fake_service.rb +0 -18
  70. data/spec/fake_app/models/collection.rb +0 -5
  71. data/spec/fake_app/models/model.rb +0 -2
  72. data/spec/fake_app/requests/request.rb +0 -11
  73. data/spec/fog_attribute_spec.rb +0 -549
  74. data/spec/formatador_spec.rb +0 -154
  75. data/spec/identity_spec.rb +0 -95
  76. data/spec/mocking_spec.rb +0 -84
  77. data/spec/service_spec.rb +0 -201
  78. data/spec/spec_helper.rb +0 -19
  79. data/spec/storage_spec.rb +0 -114
  80. data/spec/test_helpers/formats_helper_spec.rb +0 -121
  81. data/spec/test_helpers/schema_validator_spec.rb +0 -101
  82. data/spec/timeout_spec.rb +0 -20
  83. data/spec/utils_spec.rb +0 -29
  84. data/spec/uuid_spec.rb +0 -11
  85. data/spec/wait_for_spec.rb +0 -30
@@ -1,549 +0,0 @@
1
- require "spec_helper"
2
-
3
- class Service
4
- def single_associations
5
- FogSingleAssociationCollection.new
6
- end
7
-
8
- def multiple_associations
9
- FogMultipleAssociationsCollection.new
10
- end
11
- end
12
-
13
- class FogSingleAssociationModel < Fog::Model
14
- identity :id
15
- attribute :name, :type => :string
16
- end
17
-
18
- class FogMultipleAssociationsModel < Fog::Model
19
- identity :id
20
- attribute :name, :type => :string
21
- end
22
-
23
- class FogSingleAssociationCollection
24
- def get(id)
25
- FogSingleAssociationModel.new(:id => id)
26
- end
27
- end
28
-
29
- class FogMultipleAssociationsCollection < Fog::Association
30
- model FogMultipleAssociationsModel
31
-
32
- def get(id)
33
- FogMultipleAssociationsModel.new(:id => id)
34
- end
35
- end
36
-
37
- class FogAttributeTestModel < Fog::Model
38
- identity :id
39
- attribute :key, :aliases => "keys", :squash => "id"
40
- attribute :time, :type => :time
41
- attribute :bool, :type => :boolean
42
- attribute :float, :type => :float
43
- attribute :integer, :type => :integer
44
- attribute :string, :type => :string
45
- attribute :timestamp, :type => :timestamp
46
- attribute :array, :type => :array
47
- attribute :default, :default => "default_value", :aliases => :some_name
48
- attribute :another_default, :default => false
49
- attribute :good_name, :as => :Badname
50
-
51
- has_one :one_object, :single_associations, :aliases => :single
52
- has_many :many_objects, :multiple_associations
53
- has_many :objects, :multiple_associations, :association_class => FogMultipleAssociationsCollection
54
- has_one_identity :one_identity, :single_associations, :as => :Crazyname
55
- has_many_identities :many_identities, :multiple_associations, :aliases => :multiple
56
- has_many_identities :identities, :multiple_associations, :association_class => FogMultipleAssociationsCollection
57
-
58
- def service
59
- Service.new
60
- end
61
-
62
- def requires_one_test
63
- requires_one :key, :time
64
- end
65
-
66
- def requires_test
67
- requires :string, :integer
68
- end
69
- end
70
-
71
- describe "Fog::Attributes" do
72
- let(:model) { FogAttributeTestModel.new }
73
-
74
- it "should not create alias for nil" do
75
- refute FogAttributeTestModel.aliases.keys.include?(nil)
76
- end
77
-
78
- describe "squash 'id'" do
79
- it "squashes if the key is a String" do
80
- model.merge_attributes("keys" => { :id => "value" })
81
- assert_equal "value", model.key
82
- end
83
-
84
- it "squashes if the key is a Symbol" do
85
- model.merge_attributes("keys" => { "id" => "value" })
86
- assert_equal "value", model.key
87
- end
88
- end
89
-
90
- describe ":type => time" do
91
- it "returns nil when provided nil" do
92
- model.merge_attributes(:time => nil)
93
- refute model.time
94
- end
95
-
96
- it "returns '' when provided ''" do
97
- model.merge_attributes(:time => "")
98
- assert_equal "", model.time
99
- end
100
-
101
- it "returns a Time object when passed a Time object" do
102
- now = Time.now
103
- model.merge_attributes(:time => now.to_s)
104
- assert_equal Time.parse(now.to_s), model.time
105
- end
106
-
107
- it "returns a Time object when passed a string that is monkeypatched" do
108
- now = Time.now
109
- string = now.to_s
110
- def string.to_time
111
- "<3 <3 <3"
112
- end
113
- model.merge_attributes(:time => string)
114
- assert_equal Time.parse(string), model.time
115
- end
116
- end
117
-
118
- describe ":type => :boolean" do
119
- it "returns the String 'true' as a boolean" do
120
- model.merge_attributes(:bool => "true")
121
- assert_equal true, model.bool
122
- end
123
-
124
- it "returns true as true" do
125
- model.merge_attributes(:bool => true)
126
- assert_equal true, model.bool
127
- end
128
-
129
- it "returns the String 'false' as a boolean" do
130
- model.merge_attributes(:bool => "false")
131
- assert_equal false, model.bool
132
- end
133
-
134
- it "returns false as false" do
135
- model.merge_attributes(:bool => false)
136
- assert_equal false, model.bool
137
- end
138
-
139
- it "returns a non-true/false value as nil" do
140
- model.merge_attributes(:bool => "foo")
141
- refute model.bool
142
- end
143
- end
144
-
145
- describe ":type => :float" do
146
- it "returns an integer as float" do
147
- model.merge_attributes(:float => 1)
148
- assert_in_delta 1.0, model.float
149
- end
150
-
151
- it "returns a string as float" do
152
- model.merge_attributes(:float => "1")
153
- assert_in_delta 1.0, model.float
154
- end
155
- end
156
-
157
- describe ":type => :integer" do
158
- it "returns a float as integer" do
159
- model.merge_attributes(:integer => 1.5)
160
- assert_in_delta 1, model.integer
161
- end
162
-
163
- it "returns a string as integer" do
164
- model.merge_attributes(:integer => "1")
165
- assert_in_delta 1, model.integer
166
- end
167
- end
168
-
169
- describe ":type => :string" do
170
- it "returns a float as string" do
171
- model.merge_attributes(:string => 1.5)
172
- assert_equal "1.5", model.string
173
- end
174
-
175
- it "returns a integer as string" do
176
- model.merge_attributes(:string => 1)
177
- assert_equal "1", model.string
178
- end
179
- end
180
-
181
- describe ":type => :timestamp" do
182
- it "returns a date as time" do
183
- model.merge_attributes(:timestamp => Date.new(2008, 10, 12))
184
- assert_equal "2008-10-12 00:00", model.timestamp.strftime("%Y-%m-%d %M:%S")
185
- assert_instance_of Fog::Time, model.timestamp
186
- end
187
-
188
- it "returns a time as time" do
189
- model.merge_attributes(:timestamp => Time.mktime(2007, 11, 1, 15, 25))
190
- assert_equal "2007-11-01 25:00", model.timestamp.strftime("%Y-%m-%d %M:%S")
191
- assert_instance_of Fog::Time, model.timestamp
192
- end
193
-
194
- it "returns a date_time as time" do
195
- model.merge_attributes(:timestamp => DateTime.new(2007, 11, 1, 15, 25, 0))
196
- assert_equal "2007-11-01 25:00", model.timestamp.strftime("%Y-%m-%d %M:%S")
197
- assert_instance_of Fog::Time, model.timestamp
198
- end
199
- end
200
-
201
- describe ":type => :array" do
202
- it "returns an empty array when not initialized" do
203
- assert_equal [], model.array
204
- end
205
-
206
- it "returns an empty array as an empty array" do
207
- model.merge_attributes(:array => [])
208
- assert_equal [], model.array
209
- end
210
-
211
- it "returns nil as an empty array" do
212
- model.merge_attributes(:array => nil)
213
- assert_equal [], model.array
214
- end
215
-
216
- it "returns an array with nil as an array with nil" do
217
- model.merge_attributes(:array => [nil])
218
- assert_equal [nil], model.array
219
- end
220
-
221
- it "returns a single element as array" do
222
- model.merge_attributes(:array => 1.5)
223
- assert_equal [1.5], model.array
224
- end
225
-
226
- it "returns an array as array" do
227
- model.merge_attributes(:array => [1, 2])
228
- assert_equal [1, 2], model.array
229
- end
230
- end
231
-
232
- describe ":default => 'default_value'" do
233
- it "should return nil when default is not defined on a new object" do
234
- assert_nil model.bool
235
- end
236
-
237
- it "should return the value of the object when default is not defined" do
238
- model.merge_attributes(:bool => false)
239
- assert_equal model.bool, false
240
- end
241
-
242
- it "should return the default value on a new object with value equal nil" do
243
- assert_equal model.default, "default_value"
244
- end
245
-
246
- it "should return the value on a new object with value not equal nil" do
247
- model.default = "not default"
248
- assert_equal model.default, "not default"
249
- end
250
-
251
- it "should return false when default value is false on a new object" do
252
- assert_equal model.another_default, false
253
- end
254
-
255
- it "should return the value of the persisted object" do
256
- model.merge_attributes(:id => "some-crazy-id", :default => 23)
257
- assert_equal model.default, 23
258
- end
259
-
260
- it "should return nil on a persisted object without a value" do
261
- model.merge_attributes(:id => "some-crazy-id")
262
- assert_nil model.default
263
- end
264
-
265
- it "should return nil when an attribute with default value is setted to nil" do
266
- model.default = nil
267
- assert_nil model.default
268
- end
269
- end
270
-
271
- describe ".has_one" do
272
- it "should create an instance_variable to save the association object" do
273
- assert_nil model.one_object
274
- end
275
-
276
- it "should create a getter to save the association model" do
277
- model.merge_attributes(:one_object => FogSingleAssociationModel.new(:id => "123"))
278
- assert_instance_of FogSingleAssociationModel, model.one_object
279
- assert_equal model.one_object.attributes, :id => "123"
280
- end
281
-
282
- it "should create a setter that accept an object as param" do
283
- model.one_object = FogSingleAssociationModel.new(:id => "123")
284
- assert_equal model.one_object.attributes, :id => "123"
285
- end
286
-
287
- it "should create an alias to single" do
288
- model.merge_attributes(:single => FogSingleAssociationModel.new(:id => "123"))
289
- assert_equal model.one_object.attributes, :id => "123"
290
- end
291
- end
292
-
293
- describe ".has_one_identity" do
294
- it "should create an instance_variable to save the association identity" do
295
- assert_nil model.one_identity
296
- end
297
-
298
- it "should create a getter to load the association model" do
299
- model.merge_attributes(:one_identity => "123")
300
- assert_instance_of FogSingleAssociationModel, model.one_identity
301
- assert_equal model.one_identity.attributes, :id => "123"
302
- end
303
-
304
- describe "should create a setter that accept" do
305
- it "an id as param" do
306
- model.one_identity = "123"
307
- assert_equal model.one_identity.attributes, :id => "123"
308
- end
309
-
310
- it "a model as param" do
311
- model.one_identity = FogSingleAssociationModel.new(:id => "123")
312
- assert_equal model.one_identity.attributes, :id => "123"
313
- end
314
- end
315
- end
316
-
317
- describe ".has_many" do
318
- it "should return an instance of Fog::Association" do
319
- model.many_objects = [FogMultipleAssociationsModel.new(:id => "456")]
320
- assert_instance_of Fog::Association, model.many_objects
321
- end
322
-
323
- it "should create an instance_variable to save the associated objects" do
324
- assert_equal model.many_objects, []
325
- end
326
-
327
- it "should create a getter to save all associated models" do
328
- model.merge_attributes(:many_objects => [FogMultipleAssociationsModel.new(:id => "456")])
329
- assert_instance_of Fog::Association, model.many_objects
330
- assert_equal model.many_objects.size, 1
331
- assert_instance_of FogMultipleAssociationsModel, model.many_objects.first
332
- assert_equal model.many_objects.first.attributes, :id => "456"
333
- end
334
-
335
- it "should create a setter that accept an array of objects as param" do
336
- model.many_objects = [FogMultipleAssociationsModel.new(:id => "456")]
337
- assert_equal model.many_objects.first.attributes, :id => "456"
338
- end
339
-
340
- describe "with a custom collection class" do
341
- it "should return an instance of that collection class" do
342
- model.objects = [FogMultipleAssociationsModel.new(:id => "456")]
343
- assert_instance_of FogMultipleAssociationsCollection, model.objects
344
- end
345
- end
346
- end
347
-
348
- describe "#requires_one" do
349
- it "should require at least one attribute is supplied" do
350
- FogAttributeTestModel.new(:key => :key, :time => Time.now).requires_one_test
351
- FogAttributeTestModel.new(:time => Time.now).requires_one_test
352
- FogAttributeTestModel.new(:key => :key).requires_one_test
353
- FogAttributeTestModel.new(:key => :key, :integer => 1).requires_one_test
354
-
355
- assert_raises ArgumentError do
356
- FogAttributeTestModel.new(:integer => 1).requires_one_test
357
- end
358
- end
359
- end
360
-
361
- describe "#requires" do
362
- it "should require all attributes are supplied" do
363
- FogAttributeTestModel.new(:string => "string", :integer => 1).requires_test
364
-
365
- assert_raises ArgumentError do
366
- FogAttributeTestModel.new(:integer => 1).requires_test
367
- end
368
-
369
- assert_raises ArgumentError do
370
- FogAttributeTestModel.new(:string => "string").requires_test
371
- end
372
-
373
- assert_raises ArgumentError do
374
- FogAttributeTestModel.new(:key => :key).requires_test
375
- end
376
- end
377
- end
378
-
379
- describe ".has_many_identities" do
380
- it "should return an instance of Fog::Association" do
381
- model.many_identities = ["456"]
382
- assert_instance_of Fog::Association, model.many_identities
383
- end
384
-
385
- it "should create an instance_variable to save the associations identities" do
386
- assert_equal model.many_identities, []
387
- end
388
-
389
- it "should create a getter to load all association models" do
390
- model.merge_attributes(:many_identities => ["456"])
391
- assert_instance_of Fog::Association, model.many_identities
392
- assert_equal model.many_identities.size, 1
393
- assert_instance_of FogMultipleAssociationsModel, model.many_identities.first
394
- assert_equal model.many_identities.first.attributes, :id => "456"
395
- end
396
-
397
- describe "should create a setter that accept an array of" do
398
- it "ids as param" do
399
- model.many_identities = ["456"]
400
- assert_equal model.many_identities.first.attributes, :id => "456"
401
- end
402
-
403
- it "models as param" do
404
- model.many_identities = [FogMultipleAssociationsModel.new(:id => "456")]
405
- assert_equal model.many_identities.first.attributes, :id => "456"
406
- end
407
- end
408
-
409
- it "should create an alias to multiple" do
410
- model.merge_attributes(:multiple => ["456"])
411
- assert_equal model.many_identities.first.attributes, :id => "456"
412
- end
413
-
414
- describe "with a custom collection class" do
415
- it "should return an instance of that collection class" do
416
- model.identities = ["456"]
417
- assert_instance_of FogMultipleAssociationsCollection, model.identities
418
- end
419
- end
420
- end
421
-
422
- describe "#all_attributes" do
423
- describe "on a persisted object" do
424
- it "should return all attributes without default values" do
425
- model.merge_attributes(:id => 2, :float => 3.2, :integer => 55_555_555)
426
- assert model.persisted?
427
- assert_equal model.all_attributes, :id => 2,
428
- :key => nil,
429
- :time => nil,
430
- :bool => nil,
431
- :float => 3.2,
432
- :integer => 55_555_555,
433
- :string => nil,
434
- :timestamp => nil,
435
- :array => [],
436
- :default => nil,
437
- :another_default => nil,
438
- :Badname => nil
439
- end
440
- end
441
-
442
- describe "on a new object" do
443
- it "should return all attributes including default values for empty attributes" do
444
- model.merge_attributes(:float => 3.2, :integer => 55_555_555)
445
- refute model.persisted?
446
- assert_equal model.all_attributes, :id => nil,
447
- :key => nil,
448
- :time => nil,
449
- :bool => nil,
450
- :float => 3.2,
451
- :integer => 55_555_555,
452
- :string => nil,
453
- :timestamp => nil,
454
- :array => [],
455
- :default => "default_value",
456
- :another_default => false,
457
- :Badname => nil
458
- end
459
- end
460
- end
461
-
462
- describe "#all_associations" do
463
- describe "without any association" do
464
- it "should return all associations empty" do
465
- assert_equal model.all_associations, :one_object => nil,
466
- :many_objects => [],
467
- :Crazyname => nil,
468
- :many_identities => [],
469
- :objects => [],
470
- :identities => []
471
- end
472
- end
473
-
474
- describe "with associations" do
475
- it "should return all association objects" do
476
- @one_object = FogMultipleAssociationsModel.new
477
- @many_objects = [@one_object]
478
- model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
479
- model.merge_attributes(:one_identity => "XYZ", :many_identities => %w(ABC))
480
- assert_equal model.all_associations, :one_object => @one_object,
481
- :many_objects => @many_objects,
482
- :Crazyname => "XYZ",
483
- :many_identities => %w(ABC),
484
- :objects => [],
485
- :identities => []
486
- end
487
- end
488
- end
489
-
490
- describe "#all_associations_and_attributes" do
491
- describe "on a persisted object" do
492
- it "should return all association and attributes but no default values" do
493
- @one_object = FogMultipleAssociationsModel.new
494
- @many_objects = [@one_object]
495
- model.merge_attributes(:id => 2, :float => 3.2, :integer => 55_555_555)
496
- model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
497
- model.merge_attributes(:one_identity => "XYZ", :many_identities => %w(ABC))
498
- assert model.persisted?
499
- assert_equal model.all_associations_and_attributes, :id => 2,
500
- :key => nil,
501
- :time => nil,
502
- :bool => nil,
503
- :float => 3.2,
504
- :integer => 55_555_555,
505
- :string => nil,
506
- :timestamp => nil,
507
- :array => [],
508
- :default => nil,
509
- :another_default => nil,
510
- :Badname => nil,
511
- :one_object => @one_object,
512
- :many_objects => @many_objects,
513
- :objects => [],
514
- :identities => [],
515
- :Crazyname => "XYZ",
516
- :many_identities => %w(ABC)
517
- end
518
- end
519
-
520
- describe "on a non persisted object" do
521
- it "should return all association and attributes and the default value for blank attributes" do
522
- @one_object = FogMultipleAssociationsModel.new
523
- @many_objects = [@one_object]
524
- model.merge_attributes(:float => 3.2, :integer => 55_555_555)
525
- model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
526
- model.merge_attributes(:one_identity => "XYZ", :many_identities => %w(ABC))
527
- refute model.persisted?
528
- assert_equal model.all_associations_and_attributes, :id => nil,
529
- :key => nil,
530
- :time => nil,
531
- :bool => nil,
532
- :float => 3.2,
533
- :integer => 55_555_555,
534
- :string => nil,
535
- :timestamp => nil,
536
- :array => [],
537
- :default => "default_value",
538
- :another_default => false,
539
- :Badname => nil,
540
- :one_object => @one_object,
541
- :many_objects => @many_objects,
542
- :objects => [],
543
- :identities => [],
544
- :Crazyname => "XYZ",
545
- :many_identities => %w(ABC)
546
- end
547
- end
548
- end
549
- end
@@ -1,154 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Fog::Formatador do
4
- describe "when object is Fog::Collection instance" do
5
- before do
6
- @member_class = Class.new(Fog::Model) do
7
- attribute :name
8
-
9
- def self.name
10
- "MemberGadget"
11
- end
12
- end
13
-
14
- @collection_class = Class.new(Fog::Collection) do
15
- model @member_class
16
-
17
- attribute :attr_one
18
- attribute :attr_two
19
-
20
- def self.name
21
- "InspectionGadget"
22
- end
23
-
24
- def all
25
- self
26
- end
27
- end
28
-
29
- @collection = @collection_class.new(:attr_one => "String", :attr_two => 5)
30
- @collection << @member_class.new(:name => "Member name")
31
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
32
- <InspectionGadget
33
- attr_one=\"String\",
34
- attr_two=5
35
- [
36
- <MemberGadget
37
- name=\"Member name\"
38
- >
39
- ]
40
- >
41
- EOS
42
- end
43
-
44
- it "returns formatted representation" do
45
- Fog::Formatador.format(@collection).must_equal @expected
46
- end
47
- end
48
-
49
- describe "when object is Fog::Collection without attributes" do
50
- before do
51
- @collection_class = Class.new(Fog::Collection) do
52
- def all
53
- self
54
- end
55
- end
56
-
57
- @collection = @collection_class.new
58
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
59
- <
60
- [
61
-
62
- ]
63
- >
64
- EOS
65
- end
66
-
67
- it "returns formatted representation" do
68
- Fog::Formatador.format(@collection).must_equal @expected
69
- end
70
- end
71
-
72
- describe "when object has is Fog::Collection but ignoring nested objects" do
73
- before do
74
- @collection_class = Class.new(Fog::Collection) do
75
- attribute :name
76
-
77
- def all
78
- self
79
- end
80
- end
81
- @collection = @collection_class.new(:name => "Name")
82
- @collection << "this"
83
- end
84
-
85
- it "returns formatted representation" do
86
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
87
- <
88
- name=\"Name\"
89
- >
90
- EOS
91
-
92
- opts = { :include_nested => false }
93
- Fog::Formatador.format(@collection, opts).must_equal @expected
94
- end
95
- end
96
-
97
- describe "when object is not enumerable" do
98
- before do
99
- @class = Class.new
100
- @subject = @class.new
101
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
102
- <
103
- >
104
- EOS
105
- end
106
-
107
- it "returns formatted representation" do
108
- Fog::Formatador.format(@subject).must_equal @expected
109
- end
110
- end
111
-
112
- describe "when object responds to non-enumerable '#map'" do
113
- before do
114
- @member = Class.new(Fog::Model) do
115
- def self.name
116
- "IPAddress"
117
- end
118
-
119
- # This map action is unrelated to Enumerable (See GH-138)
120
- def map
121
- raise "Do not call me when inspecting!"
122
- end
123
- end
124
-
125
- @collection_class = Class.new(Fog::Collection) do
126
- model @member
127
-
128
- def self.name
129
- "IPAddressCollection"
130
- end
131
-
132
- def all
133
- self
134
- end
135
- end
136
-
137
- @collection = @collection_class.new
138
- @collection << @member.new
139
-
140
- @expected = <<-EOS.gsub(/^ {6}/, "").chomp!
141
- <IPAddressCollection
142
- [
143
- <IPAddress
144
- >
145
- ]
146
- >
147
- EOS
148
- end
149
-
150
- it "returns formatted representation" do
151
- Fog::Formatador.format(@collection).must_equal @expected
152
- end
153
- end
154
- end