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