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