fog-core 1.23.0 → 1.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -5
- data/CONTRIBUTORS.md +3 -0
- data/Rakefile +5 -15
- data/changelog.md +11 -0
- data/fog-core.gemspec +1 -1
- data/lib/fog/core.rb +8 -2
- data/lib/fog/core/associations/default.rb +15 -0
- data/lib/fog/core/associations/many_identities.rb +26 -0
- data/lib/fog/core/associations/many_models.rb +21 -0
- data/lib/fog/core/associations/one_identity.rb +22 -0
- data/lib/fog/core/associations/one_model.rb +21 -0
- data/lib/fog/core/attributes.rb +43 -7
- data/lib/fog/core/attributes/array.rb +9 -1
- data/lib/fog/core/attributes/default.rb +20 -7
- data/lib/fog/core/model.rb +11 -0
- data/lib/fog/core/version.rb +3 -0
- data/spec/fog_attribute_spec.rb +283 -3
- data/spec/spec_helper.rb +9 -1
- metadata +8 -3
- data/lib/fog/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjU4ODI0MTQ2ZDlkOWNmMGI4ZDliZjY3ZDdmOGY1Yjc0MzYyMjVlOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmZiYWEzZTU5YTdiYzc4YzkyNWEyMzFkMzMzNDQ3NWQzNGM5MWRmNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzAzM2Q4MDM0ODg3MjQ1MmEzYzJlMDQ0Yjc1YmMxNjU1ZGJjNTQ5NzNhMWQ4
|
10
|
+
ZWY4OTYzZDZmZDc2NGY1OGMyYmRjOWYwOTk0ZDJjZTE2NjFiYjUwZmQ3OGNm
|
11
|
+
NjNjNWNiZmIwNjQwMmY2OThkOWQ0Y2YyZDQyOTAzNTU5YTA2M2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mjc1YTY5MDQyODM5MDQwODkyOWE4ZTkyNzNjZmZiNDc4OWFkMDcyZmUyZmEy
|
14
|
+
NWMxZmMwYWMyNGYxMmMyN2M5MWEwMGYwNjA5ZjdmODA2MjBkNWZlZjczZTJl
|
15
|
+
OGMwN2M2MjAwOTgwNjZkMjczMGFjYjJkM2JkZTUzMTJiYjg2YzE=
|
data/.travis.yml
CHANGED
@@ -9,7 +9,6 @@ rvm:
|
|
9
9
|
- 1.9.2
|
10
10
|
- 1.9.3
|
11
11
|
- 2.0.0
|
12
|
-
- 2.1.0
|
13
12
|
- jruby-18mode
|
14
13
|
- jruby-19mode
|
15
14
|
- jruby-head
|
@@ -53,7 +52,4 @@ notifications:
|
|
53
52
|
- "[#%{build_number}] %{compare_url}"
|
54
53
|
on_success: always
|
55
54
|
on_failure: always
|
56
|
-
use_notice: false
|
57
|
-
|
58
|
-
before_install:
|
59
|
-
- gem update --system # todo: workaround for https://github.com/rubygems/rubygems/pull/763
|
55
|
+
use_notice: false
|
data/CONTRIBUTORS.md
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
* Chris Johnson <wchrisjohnson@gmail.com>
|
3
3
|
* Dominic Cleal <dcleal@redhat.com>
|
4
4
|
* Evan Light <evan@tripledogdare.net>
|
5
|
+
* Mike Hagedorn <mike@silverchairsolutions.com>
|
6
|
+
* Naoto TAKAHASHI <tnaoto@gmail.com>
|
5
7
|
* Paul Thornthwaite <paul@brightbox.co.uk>
|
6
8
|
* Paul Thornthwaite <tokengeek@gmail.com>
|
9
|
+
* Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
|
7
10
|
* Wesley Beary <geemus+github@gmail.com>
|
8
11
|
* geemus <geemus@gmail.com>
|
9
12
|
* mountkin <moutkin@gmail.com>
|
data/Rakefile
CHANGED
@@ -1,33 +1,23 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
|
3
|
-
task :travis => ['test:travis', 'coveralls_push_workaround']
|
4
3
|
task :default => [:test]
|
5
4
|
|
6
5
|
require "rake/testtask"
|
7
6
|
|
8
|
-
|
9
7
|
Rake::TestTask.new do |t|
|
10
8
|
t.libs << "lib"
|
11
9
|
t.libs << "spec"
|
12
10
|
t.pattern = "spec/**/*_spec.rb"
|
13
11
|
end
|
14
12
|
|
15
|
-
|
13
|
+
task :travis do
|
16
14
|
mock = 'true' || ENV['FOG_MOCK']
|
17
|
-
|
18
|
-
# jruby coveralls causes an OOM in travis
|
19
|
-
ENV['COVERAGE'] = 'false' if RUBY_PLATFORM == 'java'
|
20
|
-
sh("export FOG_MOCK=#{mock} && rake")
|
21
|
-
end
|
22
|
-
end
|
15
|
+
sh("export FOG_MOCK=#{mock} && rake")
|
23
16
|
|
24
|
-
|
25
|
-
#Fog::Rake::ChangelogTask.new
|
26
|
-
task :coveralls_push_workaround do
|
27
|
-
use_coveralls = (Gem::Version.new(RUBY_VERSION.dup) > Gem::Version.new('1.9.2'))
|
28
|
-
if (ENV['COVERAGE'] != 'false') && use_coveralls
|
17
|
+
if ENV['COVERAGE']
|
29
18
|
require 'coveralls/rake/task'
|
19
|
+
|
30
20
|
Coveralls::RakeTask.new
|
31
21
|
Rake::Task["coveralls:push"].invoke
|
32
22
|
end
|
33
|
-
end
|
23
|
+
end
|
data/changelog.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
1.24.0 08/26/2014
|
2
|
+
==========================================================
|
3
|
+
|
4
|
+
fixes for defaulting attributes
|
5
|
+
add method for getting all attributes
|
6
|
+
add methods for associations
|
7
|
+
add all_attributes, all_associations and all_associations_and_attributes helper methods
|
8
|
+
remove no-longer-needed gem update on travis
|
9
|
+
add all_values
|
10
|
+
fixes to avoid path conflicts with fog/fog
|
11
|
+
|
1
12
|
1.23.0 07/16/2014
|
2
13
|
==========================================================
|
3
14
|
|
data/fog-core.gemspec
CHANGED
data/lib/fog/core.rb
CHANGED
@@ -11,16 +11,22 @@ require 'timeout'
|
|
11
11
|
require 'ipaddr'
|
12
12
|
|
13
13
|
# internal core dependencies
|
14
|
-
require "fog/version"
|
14
|
+
require "fog/core/version"
|
15
|
+
|
15
16
|
require 'fog/core/attributes'
|
16
17
|
require 'fog/core/attributes/default'
|
18
|
+
require 'fog/core/attributes/array'
|
17
19
|
require 'fog/core/attributes/boolean'
|
18
20
|
require 'fog/core/attributes/float'
|
19
21
|
require 'fog/core/attributes/integer'
|
20
22
|
require 'fog/core/attributes/string'
|
21
23
|
require 'fog/core/attributes/time'
|
22
24
|
require 'fog/core/attributes/timestamp'
|
23
|
-
require 'fog/core/
|
25
|
+
require 'fog/core/associations/default'
|
26
|
+
require 'fog/core/associations/many_identities'
|
27
|
+
require 'fog/core/associations/many_models'
|
28
|
+
require 'fog/core/associations/one_model'
|
29
|
+
require 'fog/core/associations/one_identity'
|
24
30
|
require 'fog/core/collection'
|
25
31
|
require 'fog/core/connection'
|
26
32
|
require 'fog/core/credentials'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fog
|
2
|
+
module Associations
|
3
|
+
class Default
|
4
|
+
attr_reader :model, :name
|
5
|
+
|
6
|
+
def initialize(model, name, collection_name)
|
7
|
+
@model = model
|
8
|
+
@name = name
|
9
|
+
model.associations[name] = collection_name
|
10
|
+
create_setter
|
11
|
+
create_getter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Fog
|
2
|
+
module Associations
|
3
|
+
class ManyIdentities < Default
|
4
|
+
def create_setter
|
5
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
6
|
+
def #{name}=(new_#{name})
|
7
|
+
associations[:#{name}] = Array(new_#{name}).map do |association|
|
8
|
+
association.respond_to?(:identity) ? association.identity : association
|
9
|
+
end
|
10
|
+
end
|
11
|
+
EOS
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_getter
|
15
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
16
|
+
def #{name}
|
17
|
+
return [] if associations[:#{name}].nil?
|
18
|
+
Array(associations[:#{name}]).map do |association|
|
19
|
+
service.send(self.class.associations[:#{name}]).get(association)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
EOS
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fog
|
2
|
+
module Associations
|
3
|
+
class ManyModels < Default
|
4
|
+
def create_setter
|
5
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
6
|
+
def #{name}=(new_#{name})
|
7
|
+
associations[:#{name}] = Array(new_#{name})
|
8
|
+
end
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_getter
|
13
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
14
|
+
def #{name}
|
15
|
+
Array(associations[:#{name}])
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fog
|
2
|
+
module Associations
|
3
|
+
class OneIdentity < Default
|
4
|
+
def create_setter
|
5
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
6
|
+
def #{name}=(new_#{name})
|
7
|
+
associations[:#{name}] = new_#{name}.respond_to?(:identity) ? new_#{name}.identity : new_#{name}
|
8
|
+
end
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_getter
|
13
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
14
|
+
def #{name}
|
15
|
+
return nil if associations[:#{name}].nil?
|
16
|
+
service.send(self.class.associations[:#{name}]).get(associations[:#{name}])
|
17
|
+
end
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fog
|
2
|
+
module Associations
|
3
|
+
class OneModel < Default
|
4
|
+
def create_setter
|
5
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
6
|
+
def #{name}=(new_#{name})
|
7
|
+
associations[:#{name}] = new_#{name}
|
8
|
+
end
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_getter
|
13
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
14
|
+
def #{name}
|
15
|
+
associations[:#{name}]
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/fog/core/attributes.rb
CHANGED
@@ -10,6 +10,10 @@ module Fog
|
|
10
10
|
@aliases ||= {}
|
11
11
|
end
|
12
12
|
|
13
|
+
def associations
|
14
|
+
@associations ||= {}
|
15
|
+
end
|
16
|
+
|
13
17
|
def attributes
|
14
18
|
@attributes ||= []
|
15
19
|
end
|
@@ -20,13 +24,23 @@ module Fog
|
|
20
24
|
|
21
25
|
def attribute(name, options = {})
|
22
26
|
type = options.fetch(:type, 'default').to_s.capitalize
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
Fog::Attributes::const_get(type).new(self, name, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_one(name, collection_name)
|
31
|
+
Fog::Associations::OneModel.new(self, name, collection_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_many(name, collection_name)
|
35
|
+
Fog::Associations::ManyModels.new(self, name, collection_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_one_identity(name, collection_name)
|
39
|
+
Fog::Associations::OneIdentity.new(self, name, collection_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_many_identities(name, collection_name)
|
43
|
+
Fog::Associations::ManyIdentities.new(self, name, collection_name)
|
30
44
|
end
|
31
45
|
|
32
46
|
def identity(name, options = {})
|
@@ -54,6 +68,28 @@ module Fog
|
|
54
68
|
@attributes ||= {}
|
55
69
|
end
|
56
70
|
|
71
|
+
def associations
|
72
|
+
@associations ||= {}
|
73
|
+
end
|
74
|
+
|
75
|
+
def all_attributes
|
76
|
+
self.class.attributes.inject({}) do |hash, attribute|
|
77
|
+
hash[attribute] = send(attribute)
|
78
|
+
hash
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def all_associations
|
83
|
+
self.class.associations.keys.inject({}) do |hash, association|
|
84
|
+
hash[association] = associations[association] || send(association)
|
85
|
+
hash
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def all_associations_and_attributes
|
90
|
+
all_attributes.merge(all_associations)
|
91
|
+
end
|
92
|
+
|
57
93
|
def dup
|
58
94
|
copy = super
|
59
95
|
copy.dup_attributes!
|
@@ -4,7 +4,15 @@ module Fog
|
|
4
4
|
def create_setter
|
5
5
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
6
6
|
def #{name}=(new_#{name})
|
7
|
-
attributes[:#{name}] =
|
7
|
+
attributes[:#{name}] = Array(new_#{name})
|
8
|
+
end
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_getter
|
13
|
+
model.class_eval <<-EOS, __FILE__, __LINE__
|
14
|
+
def #{name}
|
15
|
+
Array(attributes[:#{name}])
|
8
16
|
end
|
9
17
|
EOS
|
10
18
|
end
|
@@ -1,19 +1,21 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
3
|
class Default
|
4
|
-
attr_reader :model, :name, :squash
|
5
|
-
|
4
|
+
attr_reader :model, :name, :squash, :aliases, :default
|
5
|
+
|
6
6
|
def initialize(model, name, options)
|
7
7
|
@model = model
|
8
|
+
@model.attributes << name
|
8
9
|
@name = name
|
9
10
|
@squash = options.fetch(:squash, false)
|
10
|
-
|
11
|
-
|
12
|
-
def create
|
11
|
+
@aliases = options.fetch(:aliases, [])
|
12
|
+
@default = options[:default]
|
13
13
|
create_setter
|
14
14
|
create_getter
|
15
|
+
create_aliases
|
16
|
+
set_defaults
|
15
17
|
end
|
16
|
-
|
18
|
+
|
17
19
|
def create_setter
|
18
20
|
if squash
|
19
21
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -43,13 +45,24 @@ module Fog
|
|
43
45
|
def create_getter
|
44
46
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
45
47
|
def #{name}
|
46
|
-
|
48
|
+
return attributes[:#{name}] unless attributes[:#{name}].nil?
|
49
|
+
if !attributes.key?(:#{name}) && !self.class.default_values[:#{name}].nil? && !persisted?
|
47
50
|
return self.class.default_values[:#{name}]
|
48
51
|
end
|
49
52
|
attributes[:#{name}]
|
50
53
|
end
|
51
54
|
EOS
|
52
55
|
end
|
56
|
+
|
57
|
+
def create_aliases
|
58
|
+
Array(aliases).each do |alias_name|
|
59
|
+
model.aliases[alias_name] = name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_defaults
|
64
|
+
model.default_values[name] = default unless default.nil?
|
65
|
+
end
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
data/lib/fog/core/model.rb
CHANGED
@@ -77,5 +77,16 @@ module Fog
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def method_missing(method_name, *args)
|
81
|
+
if self.class.aliases.include?(method_name)
|
82
|
+
send(self.class.aliases[method_name])
|
83
|
+
else
|
84
|
+
super
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def respond_to?(method_name, include_private = false)
|
89
|
+
super || self.class.aliases.include?(method_name)
|
90
|
+
end
|
80
91
|
end
|
81
92
|
end
|
data/spec/fog_attribute_spec.rb
CHANGED
@@ -11,7 +11,49 @@ class FogAttributeTestModel < Fog::Model
|
|
11
11
|
attribute :string, :type => :string
|
12
12
|
attribute :timestamp, :type => :timestamp
|
13
13
|
attribute :array, :type => :array
|
14
|
-
attribute :default, :default => 'default_value'
|
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
|
26
|
+
|
27
|
+
class Service
|
28
|
+
def single_associations
|
29
|
+
FogSingleAssociationCollection.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def multiple_associations
|
33
|
+
FogMultipleAssociationsCollection.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class FogSingleAssociationCollection
|
38
|
+
def get(id)
|
39
|
+
FogSingleAssociationModel.new(:id => id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class FogMultipleAssociationsCollection
|
44
|
+
def get(id)
|
45
|
+
FogMultipleAssociationsModel.new(:id => id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class FogSingleAssociationModel < Fog::Model
|
50
|
+
identity :id
|
51
|
+
attribute :name, :type => :string
|
52
|
+
end
|
53
|
+
|
54
|
+
class FogMultipleAssociationsModel < Fog::Model
|
55
|
+
identity :id
|
56
|
+
attribute :name, :type => :string
|
15
57
|
end
|
16
58
|
|
17
59
|
describe "Fog::Attributes" do
|
@@ -19,7 +61,7 @@ describe "Fog::Attributes" do
|
|
19
61
|
let(:model) { FogAttributeTestModel.new }
|
20
62
|
|
21
63
|
it "should not create alias for nil" do
|
22
|
-
FogAttributeTestModel.aliases.
|
64
|
+
refute FogAttributeTestModel.aliases.keys.include?(nil)
|
23
65
|
end
|
24
66
|
|
25
67
|
describe "squash 'id'" do
|
@@ -142,11 +184,25 @@ describe "Fog::Attributes" do
|
|
142
184
|
end
|
143
185
|
|
144
186
|
describe ":type => :array" do
|
187
|
+
it "returns an empty array when not initialized" do
|
188
|
+
assert_equal [], model.array
|
189
|
+
end
|
190
|
+
|
145
191
|
it "returns an empty array as an empty array" do
|
146
192
|
model.merge_attributes(:array => [])
|
147
193
|
assert_equal [], model.array
|
148
194
|
end
|
149
195
|
|
196
|
+
it "returns nil as an empty array" do
|
197
|
+
model.merge_attributes(:array => nil)
|
198
|
+
assert_equal [], model.array
|
199
|
+
end
|
200
|
+
|
201
|
+
it "returns an array with nil as an array with nil" do
|
202
|
+
model.merge_attributes(:array => [nil])
|
203
|
+
assert_equal [nil], model.array
|
204
|
+
end
|
205
|
+
|
150
206
|
it "returns a single element as array" do
|
151
207
|
model.merge_attributes(:array => 1.5)
|
152
208
|
assert_equal [ 1.5 ], model.array
|
@@ -168,10 +224,19 @@ describe "Fog::Attributes" do
|
|
168
224
|
assert_equal model.bool, false
|
169
225
|
end
|
170
226
|
|
171
|
-
it "should return the default value on a new object" do
|
227
|
+
it "should return the default value on a new object with value equal nil" do
|
172
228
|
assert_equal model.default, 'default_value'
|
173
229
|
end
|
174
230
|
|
231
|
+
it "should return the value on a new object with value not equal nil" do
|
232
|
+
model.default = 'not default'
|
233
|
+
assert_equal model.default, 'not default'
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should return false when default value is false on a new object" do
|
237
|
+
assert_equal model.another_default, false
|
238
|
+
end
|
239
|
+
|
175
240
|
it "should return the value of the persisted object" do
|
176
241
|
model.merge_attributes({ :id => 'some-crazy-id', :default => 23 })
|
177
242
|
assert_equal model.default, 23
|
@@ -181,5 +246,220 @@ describe "Fog::Attributes" do
|
|
181
246
|
model.merge_attributes({ :id => 'some-crazy-id' })
|
182
247
|
assert_equal model.default, nil
|
183
248
|
end
|
249
|
+
|
250
|
+
it "should return nil when an attribute with default value is setted to nil" do
|
251
|
+
model.default = nil
|
252
|
+
assert_equal model.default, nil
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe ".has_one" do
|
257
|
+
it "should create an instance_variable to save the association object" do
|
258
|
+
assert_equal model.one_object, nil
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should create a getter to save the association model" do
|
262
|
+
model.merge_attributes(:one_object => FogSingleAssociationModel.new(:id => '123'))
|
263
|
+
assert_instance_of FogSingleAssociationModel, model.one_object
|
264
|
+
assert_equal model.one_object.attributes, { :id => '123' }
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should create a setter that accept an object as param" do
|
268
|
+
model.one_object = FogSingleAssociationModel.new(:id => '123')
|
269
|
+
assert_equal model.one_object.attributes, { :id => '123' }
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe ".has_one_identity" do
|
274
|
+
it "should create an instance_variable to save the association identity" do
|
275
|
+
assert_equal model.one_identity, nil
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should create a getter to load the association model" do
|
279
|
+
model.merge_attributes(:one_identity => '123')
|
280
|
+
assert_instance_of FogSingleAssociationModel, model.one_identity
|
281
|
+
assert_equal model.one_identity.attributes, { :id => '123' }
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "should create a setter that accept" do
|
285
|
+
it "an id as param" do
|
286
|
+
model.one_identity = '123'
|
287
|
+
assert_equal model.one_identity.attributes, { :id => '123' }
|
288
|
+
end
|
289
|
+
|
290
|
+
it "a model as param" do
|
291
|
+
model.one_identity = FogSingleAssociationModel.new(:id => '123')
|
292
|
+
assert_equal model.one_identity.attributes, { :id => '123' }
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe ".has_many" do
|
298
|
+
it "should create an instance_variable to save the associated objects" do
|
299
|
+
assert_equal model.many_objects, []
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should create a getter to save all associated models" do
|
303
|
+
model.merge_attributes(:many_objects => [ FogMultipleAssociationsModel.new(:id => '456') ])
|
304
|
+
assert_instance_of Array, model.many_objects
|
305
|
+
assert_equal model.many_objects.size, 1
|
306
|
+
assert_instance_of FogMultipleAssociationsModel, model.many_objects.first
|
307
|
+
assert_equal model.many_objects.first.attributes, { :id => '456' }
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should create a setter that accept an array of objects as param" do
|
311
|
+
model.many_objects = [ FogMultipleAssociationsModel.new(:id => '456') ]
|
312
|
+
assert_equal model.many_objects.first.attributes, { :id => '456' }
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe ".has_many_identities" do
|
317
|
+
it "should create an instance_variable to save the associations identities" do
|
318
|
+
assert_equal model.many_identities, []
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should create a getter to load all association models" do
|
322
|
+
model.merge_attributes(:many_identities => [ '456' ])
|
323
|
+
assert_instance_of Array, model.many_identities
|
324
|
+
assert_equal model.many_identities.size, 1
|
325
|
+
assert_instance_of FogMultipleAssociationsModel, model.many_identities.first
|
326
|
+
assert_equal model.many_identities.first.attributes, { :id => '456' }
|
327
|
+
end
|
328
|
+
|
329
|
+
describe "should create a setter that accept an array of" do
|
330
|
+
it "ids as param" do
|
331
|
+
model.many_identities = [ '456' ]
|
332
|
+
assert_equal model.many_identities.first.attributes, { :id => '456' }
|
333
|
+
end
|
334
|
+
|
335
|
+
it "models as param" do
|
336
|
+
model.many_identities = [ FogMultipleAssociationsModel.new(:id => '456') ]
|
337
|
+
assert_equal model.many_identities.first.attributes, { :id => '456' }
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "#all_attributes" do
|
343
|
+
describe "on a persisted object" do
|
344
|
+
it "should return all attributes without default values" do
|
345
|
+
model.merge_attributes( :id => 2, :float => 3.2, :integer => 55555555 )
|
346
|
+
assert model.persisted?
|
347
|
+
assert_equal model.all_attributes, { :id => 2,
|
348
|
+
:key => nil,
|
349
|
+
:time => nil,
|
350
|
+
:bool => nil,
|
351
|
+
:float => 3.2,
|
352
|
+
:integer => 55555555,
|
353
|
+
:string => nil,
|
354
|
+
:timestamp => nil,
|
355
|
+
:array => [],
|
356
|
+
:default => nil,
|
357
|
+
:another_default => nil }
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe "on a new object" do
|
362
|
+
it "should return all attributes including default values for empty attributes" do
|
363
|
+
model.merge_attributes( :float => 3.2, :integer => 55555555 )
|
364
|
+
refute model.persisted?
|
365
|
+
assert_equal model.all_attributes, { :id => nil,
|
366
|
+
:key => nil,
|
367
|
+
:time => nil,
|
368
|
+
:bool => nil,
|
369
|
+
:float => 3.2,
|
370
|
+
:integer => 55555555,
|
371
|
+
:string => nil,
|
372
|
+
:timestamp => nil,
|
373
|
+
:array => [],
|
374
|
+
:default => 'default_value',
|
375
|
+
:another_default => false }
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
describe "#all_associations" do
|
381
|
+
describe "without any association" do
|
382
|
+
it "should return all associations empty" do
|
383
|
+
assert_equal model.all_associations, { :one_object => nil,
|
384
|
+
:many_objects => [],
|
385
|
+
:one_identity => nil,
|
386
|
+
:many_identities => [] }
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe "with associations" do
|
391
|
+
it "should return all association objects" do
|
392
|
+
@one_object = FogMultipleAssociationsModel.new
|
393
|
+
@many_objects = [ @one_object ]
|
394
|
+
model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
|
395
|
+
model.merge_attributes(:one_identity => 'XYZ', :many_identities => %w(ABC))
|
396
|
+
assert_equal model.all_associations, { :one_object => @one_object,
|
397
|
+
:many_objects => @many_objects,
|
398
|
+
:one_identity => 'XYZ',
|
399
|
+
:many_identities => %w(ABC) }
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe "#all_associations_and_attributes" do
|
405
|
+
describe "on a persisted object" do
|
406
|
+
it "should return all association and attributes but no default values" do
|
407
|
+
@one_object = FogMultipleAssociationsModel.new
|
408
|
+
@many_objects = [ @one_object ]
|
409
|
+
model.merge_attributes(:id => 2, :float => 3.2, :integer => 55555555)
|
410
|
+
model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
|
411
|
+
model.merge_attributes(:one_identity => 'XYZ', :many_identities => %w(ABC))
|
412
|
+
assert model.persisted?
|
413
|
+
assert_equal model.all_associations_and_attributes, { :id => 2,
|
414
|
+
:key => nil,
|
415
|
+
:time => nil,
|
416
|
+
:bool => nil,
|
417
|
+
:float => 3.2,
|
418
|
+
:integer => 55555555,
|
419
|
+
:string => nil,
|
420
|
+
:timestamp => nil,
|
421
|
+
:array => [],
|
422
|
+
:default => nil,
|
423
|
+
:another_default => nil,
|
424
|
+
:one_object => @one_object,
|
425
|
+
:many_objects => @many_objects,
|
426
|
+
:one_identity => 'XYZ',
|
427
|
+
:many_identities => %w(ABC) }
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe "on a non persisted object" do
|
432
|
+
it "should return all association and attributes and the default value for blank attributes" do
|
433
|
+
@one_object = FogMultipleAssociationsModel.new
|
434
|
+
@many_objects = [ @one_object ]
|
435
|
+
model.merge_attributes(:float => 3.2, :integer => 55555555)
|
436
|
+
model.merge_attributes(:one_object => @one_object, :many_objects => @many_objects)
|
437
|
+
model.merge_attributes(:one_identity => 'XYZ', :many_identities => %w(ABC))
|
438
|
+
refute model.persisted?
|
439
|
+
assert_equal model.all_associations_and_attributes, { :id => nil,
|
440
|
+
:key => nil,
|
441
|
+
:time => nil,
|
442
|
+
:bool => nil,
|
443
|
+
:float => 3.2,
|
444
|
+
:integer => 55555555,
|
445
|
+
:string => nil,
|
446
|
+
:timestamp => nil,
|
447
|
+
:array => [],
|
448
|
+
:default => 'default_value',
|
449
|
+
:another_default => false,
|
450
|
+
:one_object => @one_object,
|
451
|
+
:many_objects => @many_objects,
|
452
|
+
:one_identity => 'XYZ',
|
453
|
+
:many_identities => %w(ABC) }
|
454
|
+
end
|
455
|
+
end
|
456
|
+
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
|
184
464
|
end
|
185
465
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Light
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -218,6 +218,11 @@ files:
|
|
218
218
|
- lib/fog/compute.rb
|
219
219
|
- lib/fog/compute/models/server.rb
|
220
220
|
- lib/fog/core.rb
|
221
|
+
- lib/fog/core/associations/default.rb
|
222
|
+
- lib/fog/core/associations/many_identities.rb
|
223
|
+
- lib/fog/core/associations/many_models.rb
|
224
|
+
- lib/fog/core/associations/one_identity.rb
|
225
|
+
- lib/fog/core/associations/one_model.rb
|
221
226
|
- lib/fog/core/attributes.rb
|
222
227
|
- lib/fog/core/attributes/array.rb
|
223
228
|
- lib/fog/core/attributes/boolean.rb
|
@@ -246,6 +251,7 @@ files:
|
|
246
251
|
- lib/fog/core/time.rb
|
247
252
|
- lib/fog/core/utils.rb
|
248
253
|
- lib/fog/core/uuid.rb
|
254
|
+
- lib/fog/core/version.rb
|
249
255
|
- lib/fog/core/wait_for.rb
|
250
256
|
- lib/fog/core/wait_for_defaults.rb
|
251
257
|
- lib/fog/core/whitelist_keys.rb
|
@@ -270,7 +276,6 @@ files:
|
|
270
276
|
- lib/fog/test_helpers/model_helper.rb
|
271
277
|
- lib/fog/test_helpers/responds_to_helper.rb
|
272
278
|
- lib/fog/test_helpers/succeeds_helper.rb
|
273
|
-
- lib/fog/version.rb
|
274
279
|
- lib/fog/volume.rb
|
275
280
|
- lib/fog/vpn.rb
|
276
281
|
- lib/tasks/test_task.rb
|
data/lib/fog/version.rb
DELETED