fog-core 1.24.0 → 1.25.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.
- checksums.yaml +5 -13
- data/.rubocop.yml +20 -0
- data/changelog.md +17 -0
- data/fog-core.gemspec +2 -1
- data/lib/fog/account.rb +3 -5
- data/lib/fog/billing.rb +3 -4
- data/lib/fog/cdn.rb +3 -5
- data/lib/fog/compute.rb +17 -20
- data/lib/fog/compute/models/server.rb +21 -26
- data/lib/fog/core.rb +61 -60
- data/lib/fog/core/association.rb +15 -0
- data/lib/fog/core/associations/default.rb +21 -3
- data/lib/fog/core/associations/many_identities.rb +8 -2
- data/lib/fog/core/associations/many_models.rb +7 -2
- data/lib/fog/core/associations/one_identity.rb +6 -1
- data/lib/fog/core/associations/one_model.rb +5 -1
- data/lib/fog/core/attributes.rb +41 -44
- data/lib/fog/core/attributes/array.rb +5 -1
- data/lib/fog/core/attributes/boolean.rb +5 -1
- data/lib/fog/core/attributes/default.rb +12 -2
- data/lib/fog/core/attributes/float.rb +5 -1
- data/lib/fog/core/attributes/integer.rb +5 -1
- data/lib/fog/core/attributes/string.rb +5 -1
- data/lib/fog/core/attributes/time.rb +5 -1
- data/lib/fog/core/attributes/timestamp.rb +5 -1
- data/lib/fog/core/collection.rb +22 -27
- data/lib/fog/core/connection.rb +5 -6
- data/lib/fog/core/credentials.rb +7 -7
- data/lib/fog/core/current_machine.rb +10 -8
- data/lib/fog/core/deprecated_connection_accessors.rb +0 -1
- data/lib/fog/core/deprecation.rb +0 -2
- data/lib/fog/core/errors.rb +3 -5
- data/lib/fog/core/hmac.rb +4 -6
- data/lib/fog/core/logger.rb +10 -11
- data/lib/fog/core/mock.rb +19 -25
- data/lib/fog/core/model.rb +9 -20
- data/lib/fog/core/provider.rb +6 -9
- data/lib/fog/core/scp.rb +14 -24
- data/lib/fog/core/service.rb +28 -31
- data/lib/fog/core/ssh.rb +16 -24
- data/lib/fog/core/stringify_keys.rb +7 -9
- data/lib/fog/core/time.rb +5 -7
- data/lib/fog/core/utils.rb +24 -20
- data/lib/fog/core/uuid.rb +2 -3
- data/lib/fog/core/version.rb +3 -1
- data/lib/fog/core/wait_for.rb +2 -2
- data/lib/fog/core/wait_for_defaults.rb +13 -10
- data/lib/fog/core/whitelist_keys.rb +1 -1
- data/lib/fog/dns.rb +6 -8
- data/lib/fog/identity.rb +5 -6
- data/lib/fog/image.rb +3 -5
- data/lib/fog/metering.rb +3 -6
- data/lib/fog/monitoring.rb +3 -5
- data/lib/fog/network.rb +4 -6
- data/lib/fog/orchestration.rb +3 -5
- data/lib/fog/schema/data_validator.rb +17 -22
- data/lib/fog/storage.rb +22 -16
- data/lib/fog/support.rb +3 -6
- data/lib/fog/test_helpers.rb +10 -10
- data/lib/fog/test_helpers/collection_helper.rb +23 -43
- data/lib/fog/test_helpers/compute/flavors_helper.rb +4 -10
- data/lib/fog/test_helpers/compute/server_helper.rb +3 -9
- data/lib/fog/test_helpers/compute/servers_helper.rb +0 -4
- data/lib/fog/test_helpers/formats_helper.rb +13 -14
- data/lib/fog/test_helpers/helper.rb +9 -4
- data/lib/fog/test_helpers/mock_helper.rb +92 -94
- data/lib/fog/test_helpers/model_helper.rb +7 -15
- data/lib/fog/test_helpers/responds_to_helper.rb +1 -3
- data/lib/fog/test_helpers/succeeds_helper.rb +1 -3
- data/lib/fog/volume.rb +3 -6
- data/lib/fog/vpn.rb +3 -5
- data/lib/tasks/test_task.rb +2 -6
- data/spec/compute_spec.rb +11 -13
- data/spec/connection_spec.rb +24 -14
- data/spec/credentials_spec.rb +23 -23
- data/spec/current_machine_spec.rb +6 -6
- data/spec/fake_app/fake_service.rb +18 -0
- data/spec/fake_app/models/collection.rb +5 -0
- data/spec/fake_app/models/model.rb +2 -0
- data/spec/fake_app/requests/request.rb +11 -0
- data/spec/fog_attribute_spec.rb +178 -136
- data/spec/identity_spec.rb +11 -13
- data/spec/mocking_spec.rb +7 -8
- data/spec/service_spec.rb +21 -7
- data/spec/spec_helper.rb +14 -8
- data/spec/storage_spec.rb +25 -13
- data/spec/test_helpers/formats_helper_spec.rb +52 -52
- data/spec/test_helpers/schema_validator_spec.rb +45 -45
- data/spec/timeout_spec.rb +1 -2
- data/spec/utils_spec.rb +2 -2
- data/spec/uuid_spec.rb +1 -1
- data/spec/wait_for_spec.rb +7 -4
- metadata +57 -33
data/spec/fog_attribute_spec.rb
CHANGED
@@ -1,28 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
class FogAttributeTestModel < Fog::Model
|
5
|
-
identity :id
|
6
|
-
attribute :key, :aliases => "keys", :squash => "id"
|
7
|
-
attribute :time, :type => :time
|
8
|
-
attribute :bool, :type => :boolean
|
9
|
-
attribute :float, :type => :float
|
10
|
-
attribute :integer, :type => :integer
|
11
|
-
attribute :string, :type => :string
|
12
|
-
attribute :timestamp, :type => :timestamp
|
13
|
-
attribute :array, :type => :array
|
14
|
-
attribute :default, :default => 'default_value', :aliases => :some_name
|
15
|
-
attribute :another_default, :default => false
|
16
|
-
|
17
|
-
has_one :one_object, :single_associations
|
18
|
-
has_many :many_objects, :multiple_associations
|
19
|
-
has_one_identity :one_identity, :single_associations
|
20
|
-
has_many_identities :many_identities, :multiple_associations
|
21
|
-
|
22
|
-
def service
|
23
|
-
Service.new
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require "spec_helper"
|
2
|
+
require "xmlrpc/datetime"
|
26
3
|
|
27
4
|
class Service
|
28
5
|
def single_associations
|
@@ -34,30 +11,57 @@ class Service
|
|
34
11
|
end
|
35
12
|
end
|
36
13
|
|
14
|
+
class FogSingleAssociationModel < Fog::Model
|
15
|
+
identity :id
|
16
|
+
attribute :name, :type => :string
|
17
|
+
end
|
18
|
+
|
19
|
+
class FogMultipleAssociationsModel < Fog::Model
|
20
|
+
identity :id
|
21
|
+
attribute :name, :type => :string
|
22
|
+
end
|
23
|
+
|
37
24
|
class FogSingleAssociationCollection
|
38
25
|
def get(id)
|
39
26
|
FogSingleAssociationModel.new(:id => id)
|
40
27
|
end
|
41
28
|
end
|
42
29
|
|
43
|
-
class FogMultipleAssociationsCollection
|
30
|
+
class FogMultipleAssociationsCollection < Fog::Association
|
31
|
+
model FogMultipleAssociationsModel
|
32
|
+
|
44
33
|
def get(id)
|
45
34
|
FogMultipleAssociationsModel.new(:id => id)
|
46
35
|
end
|
47
36
|
end
|
48
37
|
|
49
|
-
class
|
38
|
+
class FogAttributeTestModel < Fog::Model
|
50
39
|
identity :id
|
51
|
-
attribute :
|
52
|
-
|
40
|
+
attribute :key, :aliases => "keys", :squash => "id"
|
41
|
+
attribute :time, :type => :time
|
42
|
+
attribute :bool, :type => :boolean
|
43
|
+
attribute :float, :type => :float
|
44
|
+
attribute :integer, :type => :integer
|
45
|
+
attribute :string, :type => :string
|
46
|
+
attribute :timestamp, :type => :timestamp
|
47
|
+
attribute :array, :type => :array
|
48
|
+
attribute :default, :default => "default_value", :aliases => :some_name
|
49
|
+
attribute :another_default, :default => false
|
50
|
+
attribute :good_name, :as => :Badname
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
57
62
|
end
|
58
63
|
|
59
64
|
describe "Fog::Attributes" do
|
60
|
-
|
61
65
|
let(:model) { FogAttributeTestModel.new }
|
62
66
|
|
63
67
|
it "should not create alias for nil" do
|
@@ -66,12 +70,12 @@ describe "Fog::Attributes" do
|
|
66
70
|
|
67
71
|
describe "squash 'id'" do
|
68
72
|
it "squashes if the key is a String" do
|
69
|
-
model.merge_attributes("keys" => {:id => "value"})
|
70
|
-
assert_equal"value", model.key
|
73
|
+
model.merge_attributes("keys" => { :id => "value" })
|
74
|
+
assert_equal "value", model.key
|
71
75
|
end
|
72
76
|
|
73
77
|
it "squashes if the key is a Symbol" do
|
74
|
-
model.merge_attributes("keys" => {"id" => "value"})
|
78
|
+
model.merge_attributes("keys" => { "id" => "value" })
|
75
79
|
assert_equal "value", model.key
|
76
80
|
end
|
77
81
|
end
|
@@ -134,7 +138,7 @@ describe "Fog::Attributes" do
|
|
134
138
|
end
|
135
139
|
|
136
140
|
it "returns a string as float" do
|
137
|
-
model.merge_attributes(:float =>
|
141
|
+
model.merge_attributes(:float => "1")
|
138
142
|
assert_in_delta 1.0, model.float
|
139
143
|
end
|
140
144
|
end
|
@@ -146,7 +150,7 @@ describe "Fog::Attributes" do
|
|
146
150
|
end
|
147
151
|
|
148
152
|
it "returns a string as integer" do
|
149
|
-
model.merge_attributes(:integer =>
|
153
|
+
model.merge_attributes(:integer => "1")
|
150
154
|
assert_in_delta 1, model.integer
|
151
155
|
end
|
152
156
|
end
|
@@ -154,31 +158,31 @@ describe "Fog::Attributes" do
|
|
154
158
|
describe ":type => :string" do
|
155
159
|
it "returns a float as string" do
|
156
160
|
model.merge_attributes(:string => 1.5)
|
157
|
-
assert_equal
|
161
|
+
assert_equal "1.5", model.string
|
158
162
|
end
|
159
163
|
|
160
164
|
it "returns a integer as string" do
|
161
165
|
model.merge_attributes(:string => 1)
|
162
|
-
assert_equal
|
166
|
+
assert_equal "1", model.string
|
163
167
|
end
|
164
168
|
end
|
165
169
|
|
166
170
|
describe ":type => :timestamp" do
|
167
171
|
it "returns a date as time" do
|
168
172
|
model.merge_attributes(:timestamp => Date.new(2008, 10, 12))
|
169
|
-
assert_equal
|
173
|
+
assert_equal "2008-10-12 00:00", model.timestamp.strftime("%Y-%m-%d %M:%S")
|
170
174
|
assert_instance_of Fog::Time, model.timestamp
|
171
175
|
end
|
172
176
|
|
173
177
|
it "returns a time as time" do
|
174
178
|
model.merge_attributes(:timestamp => Time.mktime(2007, 11, 1, 15, 25))
|
175
|
-
assert_equal
|
179
|
+
assert_equal "2007-11-01 25:00", model.timestamp.strftime("%Y-%m-%d %M:%S")
|
176
180
|
assert_instance_of Fog::Time, model.timestamp
|
177
181
|
end
|
178
182
|
|
179
183
|
it "returns a date_time as time" do
|
180
184
|
model.merge_attributes(:timestamp => DateTime.new(2007, 11, 1, 15, 25, 0))
|
181
|
-
assert_equal
|
185
|
+
assert_equal "2007-11-01 25:00", model.timestamp.strftime("%Y-%m-%d %M:%S")
|
182
186
|
assert_instance_of Fog::Time, model.timestamp
|
183
187
|
end
|
184
188
|
end
|
@@ -205,12 +209,12 @@ describe "Fog::Attributes" do
|
|
205
209
|
|
206
210
|
it "returns a single element as array" do
|
207
211
|
model.merge_attributes(:array => 1.5)
|
208
|
-
assert_equal [
|
212
|
+
assert_equal [1.5], model.array
|
209
213
|
end
|
210
214
|
|
211
215
|
it "returns an array as array" do
|
212
|
-
model.merge_attributes(:array => [
|
213
|
-
assert_equal [
|
216
|
+
model.merge_attributes(:array => [1, 2])
|
217
|
+
assert_equal [1, 2], model.array
|
214
218
|
end
|
215
219
|
end
|
216
220
|
|
@@ -220,17 +224,17 @@ describe "Fog::Attributes" do
|
|
220
224
|
end
|
221
225
|
|
222
226
|
it "should return the value of the object when default is not defined" do
|
223
|
-
model.merge_attributes(
|
227
|
+
model.merge_attributes(:bool => false)
|
224
228
|
assert_equal model.bool, false
|
225
229
|
end
|
226
230
|
|
227
231
|
it "should return the default value on a new object with value equal nil" do
|
228
|
-
assert_equal model.default,
|
232
|
+
assert_equal model.default, "default_value"
|
229
233
|
end
|
230
234
|
|
231
235
|
it "should return the value on a new object with value not equal nil" do
|
232
|
-
model.default =
|
233
|
-
assert_equal model.default,
|
236
|
+
model.default = "not default"
|
237
|
+
assert_equal model.default, "not default"
|
234
238
|
end
|
235
239
|
|
236
240
|
it "should return false when default value is false on a new object" do
|
@@ -238,12 +242,12 @@ describe "Fog::Attributes" do
|
|
238
242
|
end
|
239
243
|
|
240
244
|
it "should return the value of the persisted object" do
|
241
|
-
model.merge_attributes(
|
245
|
+
model.merge_attributes(:id => "some-crazy-id", :default => 23)
|
242
246
|
assert_equal model.default, 23
|
243
247
|
end
|
244
248
|
|
245
249
|
it "should return nil on a persisted object without a value" do
|
246
|
-
model.merge_attributes(
|
250
|
+
model.merge_attributes(:id => "some-crazy-id")
|
247
251
|
assert_equal model.default, nil
|
248
252
|
end
|
249
253
|
|
@@ -259,14 +263,19 @@ describe "Fog::Attributes" do
|
|
259
263
|
end
|
260
264
|
|
261
265
|
it "should create a getter to save the association model" do
|
262
|
-
model.merge_attributes(:one_object => FogSingleAssociationModel.new(:id =>
|
266
|
+
model.merge_attributes(:one_object => FogSingleAssociationModel.new(:id => "123"))
|
263
267
|
assert_instance_of FogSingleAssociationModel, model.one_object
|
264
|
-
assert_equal model.one_object.attributes,
|
268
|
+
assert_equal model.one_object.attributes, :id => "123"
|
265
269
|
end
|
266
270
|
|
267
271
|
it "should create a setter that accept an object as param" do
|
268
|
-
model.one_object = FogSingleAssociationModel.new(:id =>
|
269
|
-
assert_equal model.one_object.attributes,
|
272
|
+
model.one_object = FogSingleAssociationModel.new(:id => "123")
|
273
|
+
assert_equal model.one_object.attributes, :id => "123"
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should create an alias to single" do
|
277
|
+
model.merge_attributes(:single => FogSingleAssociationModel.new(:id => "123"))
|
278
|
+
assert_equal model.one_object.attributes, :id => "123"
|
270
279
|
end
|
271
280
|
end
|
272
281
|
|
@@ -276,65 +285,94 @@ describe "Fog::Attributes" do
|
|
276
285
|
end
|
277
286
|
|
278
287
|
it "should create a getter to load the association model" do
|
279
|
-
model.merge_attributes(:one_identity =>
|
288
|
+
model.merge_attributes(:one_identity => "123")
|
280
289
|
assert_instance_of FogSingleAssociationModel, model.one_identity
|
281
|
-
assert_equal model.one_identity.attributes,
|
290
|
+
assert_equal model.one_identity.attributes, :id => "123"
|
282
291
|
end
|
283
292
|
|
284
293
|
describe "should create a setter that accept" do
|
285
294
|
it "an id as param" do
|
286
|
-
model.one_identity =
|
287
|
-
assert_equal model.one_identity.attributes,
|
295
|
+
model.one_identity = "123"
|
296
|
+
assert_equal model.one_identity.attributes, :id => "123"
|
288
297
|
end
|
289
298
|
|
290
299
|
it "a model as param" do
|
291
|
-
model.one_identity = FogSingleAssociationModel.new(:id =>
|
292
|
-
assert_equal model.one_identity.attributes,
|
300
|
+
model.one_identity = FogSingleAssociationModel.new(:id => "123")
|
301
|
+
assert_equal model.one_identity.attributes, :id => "123"
|
293
302
|
end
|
294
303
|
end
|
295
304
|
end
|
296
305
|
|
297
306
|
describe ".has_many" do
|
307
|
+
it "should return an instance of Fog::Association" do
|
308
|
+
model.many_objects = [FogMultipleAssociationsModel.new(:id => "456")]
|
309
|
+
assert_instance_of Fog::Association, model.many_objects
|
310
|
+
end
|
311
|
+
|
298
312
|
it "should create an instance_variable to save the associated objects" do
|
299
313
|
assert_equal model.many_objects, []
|
300
314
|
end
|
301
315
|
|
302
316
|
it "should create a getter to save all associated models" do
|
303
|
-
model.merge_attributes(:many_objects => [
|
304
|
-
assert_instance_of
|
317
|
+
model.merge_attributes(:many_objects => [FogMultipleAssociationsModel.new(:id => "456")])
|
318
|
+
assert_instance_of Fog::Association, model.many_objects
|
305
319
|
assert_equal model.many_objects.size, 1
|
306
320
|
assert_instance_of FogMultipleAssociationsModel, model.many_objects.first
|
307
|
-
assert_equal model.many_objects.first.attributes,
|
321
|
+
assert_equal model.many_objects.first.attributes, :id => "456"
|
308
322
|
end
|
309
323
|
|
310
324
|
it "should create a setter that accept an array of objects as param" do
|
311
|
-
model.many_objects = [
|
312
|
-
assert_equal model.many_objects.first.attributes,
|
325
|
+
model.many_objects = [FogMultipleAssociationsModel.new(:id => "456")]
|
326
|
+
assert_equal model.many_objects.first.attributes, :id => "456"
|
327
|
+
end
|
328
|
+
|
329
|
+
describe "with a custom collection class" do
|
330
|
+
it "should return an instance of that collection class" do
|
331
|
+
model.objects = [FogMultipleAssociationsModel.new(:id => "456")]
|
332
|
+
assert_instance_of FogMultipleAssociationsCollection, model.objects
|
333
|
+
end
|
313
334
|
end
|
314
335
|
end
|
315
336
|
|
316
337
|
describe ".has_many_identities" do
|
338
|
+
it "should return an instance of Fog::Association" do
|
339
|
+
model.many_identities = ["456"]
|
340
|
+
assert_instance_of Fog::Association, model.many_identities
|
341
|
+
end
|
342
|
+
|
317
343
|
it "should create an instance_variable to save the associations identities" do
|
318
344
|
assert_equal model.many_identities, []
|
319
345
|
end
|
320
346
|
|
321
347
|
it "should create a getter to load all association models" do
|
322
|
-
model.merge_attributes(:many_identities => [
|
323
|
-
assert_instance_of
|
348
|
+
model.merge_attributes(:many_identities => ["456"])
|
349
|
+
assert_instance_of Fog::Association, model.many_identities
|
324
350
|
assert_equal model.many_identities.size, 1
|
325
351
|
assert_instance_of FogMultipleAssociationsModel, model.many_identities.first
|
326
|
-
assert_equal model.many_identities.first.attributes,
|
352
|
+
assert_equal model.many_identities.first.attributes, :id => "456"
|
327
353
|
end
|
328
354
|
|
329
355
|
describe "should create a setter that accept an array of" do
|
330
356
|
it "ids as param" do
|
331
|
-
model.many_identities = [
|
332
|
-
assert_equal model.many_identities.first.attributes,
|
357
|
+
model.many_identities = ["456"]
|
358
|
+
assert_equal model.many_identities.first.attributes, :id => "456"
|
333
359
|
end
|
334
360
|
|
335
361
|
it "models as param" do
|
336
|
-
model.many_identities = [
|
337
|
-
assert_equal model.many_identities.first.attributes,
|
362
|
+
model.many_identities = [FogMultipleAssociationsModel.new(:id => "456")]
|
363
|
+
assert_equal model.many_identities.first.attributes, :id => "456"
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should create an alias to multiple" do
|
368
|
+
model.merge_attributes(:multiple => ["456"])
|
369
|
+
assert_equal model.many_identities.first.attributes, :id => "456"
|
370
|
+
end
|
371
|
+
|
372
|
+
describe "with a custom collection class" do
|
373
|
+
it "should return an instance of that collection class" do
|
374
|
+
model.identities = ["456"]
|
375
|
+
assert_instance_of FogMultipleAssociationsCollection, model.identities
|
338
376
|
end
|
339
377
|
end
|
340
378
|
end
|
@@ -342,37 +380,39 @@ describe "Fog::Attributes" do
|
|
342
380
|
describe "#all_attributes" do
|
343
381
|
describe "on a persisted object" do
|
344
382
|
it "should return all attributes without default values" do
|
345
|
-
model.merge_attributes(
|
383
|
+
model.merge_attributes(:id => 2, :float => 3.2, :integer => 55_555_555)
|
346
384
|
assert model.persisted?
|
347
|
-
assert_equal model.all_attributes,
|
385
|
+
assert_equal model.all_attributes, :id => 2,
|
348
386
|
:key => nil,
|
349
387
|
:time => nil,
|
350
388
|
:bool => nil,
|
351
389
|
:float => 3.2,
|
352
|
-
:integer =>
|
390
|
+
:integer => 55_555_555,
|
353
391
|
:string => nil,
|
354
392
|
:timestamp => nil,
|
355
393
|
:array => [],
|
356
394
|
:default => nil,
|
357
|
-
:another_default => nil
|
395
|
+
:another_default => nil,
|
396
|
+
:Badname => nil
|
358
397
|
end
|
359
398
|
end
|
360
399
|
|
361
400
|
describe "on a new object" do
|
362
401
|
it "should return all attributes including default values for empty attributes" do
|
363
|
-
model.merge_attributes(
|
402
|
+
model.merge_attributes(:float => 3.2, :integer => 55_555_555)
|
364
403
|
refute model.persisted?
|
365
|
-
assert_equal model.all_attributes,
|
404
|
+
assert_equal model.all_attributes, :id => nil,
|
366
405
|
:key => nil,
|
367
406
|
:time => nil,
|
368
407
|
:bool => nil,
|
369
408
|
:float => 3.2,
|
370
|
-
:integer =>
|
409
|
+
:integer => 55_555_555,
|
371
410
|
:string => nil,
|
372
411
|
:timestamp => nil,
|
373
412
|
:array => [],
|
374
|
-
:default =>
|
375
|
-
:another_default => false
|
413
|
+
:default => "default_value",
|
414
|
+
:another_default => false,
|
415
|
+
:Badname => nil
|
376
416
|
end
|
377
417
|
end
|
378
418
|
end
|
@@ -380,23 +420,27 @@ describe "Fog::Attributes" do
|
|
380
420
|
describe "#all_associations" do
|
381
421
|
describe "without any association" do
|
382
422
|
it "should return all associations empty" do
|
383
|
-
assert_equal model.all_associations,
|
384
|
-
|
385
|
-
|
386
|
-
|
423
|
+
assert_equal model.all_associations, :one_object => nil,
|
424
|
+
:many_objects => [],
|
425
|
+
:Crazyname => nil,
|
426
|
+
:many_identities => [],
|
427
|
+
:objects => [],
|
428
|
+
:identities => []
|
387
429
|
end
|
388
430
|
end
|
389
431
|
|
390
432
|
describe "with associations" do
|
391
433
|
it "should return all association objects" do
|
392
434
|
@one_object = FogMultipleAssociationsModel.new
|
393
|
-
@many_objects = [
|
435
|
+
@many_objects = [@one_object]
|
394
436
|
model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
|
395
|
-
model.merge_attributes(:one_identity =>
|
396
|
-
assert_equal model.all_associations,
|
437
|
+
model.merge_attributes(:one_identity => "XYZ", :many_identities => %w(ABC))
|
438
|
+
assert_equal model.all_associations, :one_object => @one_object,
|
397
439
|
:many_objects => @many_objects,
|
398
|
-
:
|
399
|
-
:many_identities => %w(ABC)
|
440
|
+
:Crazyname => "XYZ",
|
441
|
+
:many_identities => %w(ABC),
|
442
|
+
:objects => [],
|
443
|
+
:identities => []
|
400
444
|
end
|
401
445
|
end
|
402
446
|
end
|
@@ -405,61 +449,59 @@ describe "Fog::Attributes" do
|
|
405
449
|
describe "on a persisted object" do
|
406
450
|
it "should return all association and attributes but no default values" do
|
407
451
|
@one_object = FogMultipleAssociationsModel.new
|
408
|
-
@many_objects = [
|
409
|
-
model.merge_attributes(:id => 2, :float => 3.2, :integer =>
|
452
|
+
@many_objects = [@one_object]
|
453
|
+
model.merge_attributes(:id => 2, :float => 3.2, :integer => 55_555_555)
|
410
454
|
model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
|
411
|
-
model.merge_attributes(:one_identity =>
|
455
|
+
model.merge_attributes(:one_identity => "XYZ", :many_identities => %w(ABC))
|
412
456
|
assert model.persisted?
|
413
|
-
assert_equal model.all_associations_and_attributes,
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
457
|
+
assert_equal model.all_associations_and_attributes, :id => 2,
|
458
|
+
:key => nil,
|
459
|
+
:time => nil,
|
460
|
+
:bool => nil,
|
461
|
+
:float => 3.2,
|
462
|
+
:integer => 55_555_555,
|
463
|
+
:string => nil,
|
464
|
+
:timestamp => nil,
|
465
|
+
:array => [],
|
466
|
+
:default => nil,
|
467
|
+
:another_default => nil,
|
468
|
+
:Badname => nil,
|
469
|
+
:one_object => @one_object,
|
470
|
+
:many_objects => @many_objects,
|
471
|
+
:objects => [],
|
472
|
+
:identities => [],
|
473
|
+
:Crazyname => "XYZ",
|
474
|
+
:many_identities => %w(ABC)
|
428
475
|
end
|
429
476
|
end
|
430
477
|
|
431
478
|
describe "on a non persisted object" do
|
432
479
|
it "should return all association and attributes and the default value for blank attributes" do
|
433
480
|
@one_object = FogMultipleAssociationsModel.new
|
434
|
-
@many_objects = [
|
435
|
-
model.merge_attributes(:float => 3.2, :integer =>
|
481
|
+
@many_objects = [@one_object]
|
482
|
+
model.merge_attributes(:float => 3.2, :integer => 55_555_555)
|
436
483
|
model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
|
437
|
-
model.merge_attributes(:one_identity =>
|
484
|
+
model.merge_attributes(:one_identity => "XYZ", :many_identities => %w(ABC))
|
438
485
|
refute model.persisted?
|
439
|
-
assert_equal model.all_associations_and_attributes,
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
486
|
+
assert_equal model.all_associations_and_attributes, :id => nil,
|
487
|
+
:key => nil,
|
488
|
+
:time => nil,
|
489
|
+
:bool => nil,
|
490
|
+
:float => 3.2,
|
491
|
+
:integer => 55_555_555,
|
492
|
+
:string => nil,
|
493
|
+
:timestamp => nil,
|
494
|
+
:array => [],
|
495
|
+
:default => "default_value",
|
496
|
+
:another_default => false,
|
497
|
+
:Badname => nil,
|
498
|
+
:one_object => @one_object,
|
499
|
+
:many_objects => @many_objects,
|
500
|
+
:objects => [],
|
501
|
+
:identities => [],
|
502
|
+
:Crazyname => "XYZ",
|
503
|
+
:many_identities => %w(ABC)
|
454
504
|
end
|
455
505
|
end
|
456
506
|
end
|
457
|
-
|
458
|
-
describe "aliases accessors" do
|
459
|
-
it "should have accessors to the original attribute" do
|
460
|
-
model.merge_attributes(:default => true)
|
461
|
-
assert model.respond_to?(:some_name)
|
462
|
-
assert model.some_name
|
463
|
-
end
|
464
|
-
end
|
465
507
|
end
|