cfoundry 1.5.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cfoundry/test_support.rb +2 -2
- data/lib/cfoundry/v2/app.rb +3 -6
- data/lib/cfoundry/v2/model.rb +1 -0
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/client_spec.rb +1 -1
- data/spec/cfoundry/rest_client_spec.rb +1 -1
- data/spec/cfoundry/trace_helpers_spec.rb +6 -6
- data/spec/cfoundry/upload_helpers_spec.rb +125 -137
- data/spec/cfoundry/v2/app_event_spec.rb +63 -59
- data/spec/cfoundry/v2/app_spec.rb +195 -188
- data/spec/cfoundry/v2/client_spec.rb +60 -56
- data/spec/cfoundry/v2/domain_spec.rb +9 -6
- data/spec/cfoundry/v2/model_magic/model_magic/attribute_spec.rb +89 -88
- data/spec/cfoundry/v2/model_magic/model_magic/has_summary_spec.rb +12 -13
- data/spec/cfoundry/v2/model_magic/model_magic/to_many_spec.rb +46 -52
- data/spec/cfoundry/v2/model_magic/model_magic/to_one_spec.rb +96 -87
- data/spec/cfoundry/v2/model_spec.rb +236 -241
- data/spec/cfoundry/v2/organization_spec.rb +20 -22
- data/spec/cfoundry/v2/quota_definition_spec.rb +45 -47
- data/spec/cfoundry/v2/route_spec.rb +28 -25
- data/spec/cfoundry/v2/space_spec.rb +9 -11
- data/spec/cfoundry/validator_spec.rb +69 -67
- data/spec/factories/app_events_factory.rb +7 -0
- data/spec/factories/apps_factory.rb +11 -0
- data/spec/factories/clients_factory.rb +5 -0
- data/spec/factories/domains_factory.rb +7 -0
- data/spec/factories/organizations_factory.rb +11 -0
- data/spec/factories/quota_definitions_factory.rb +8 -0
- data/spec/factories/routes_factory.rb +10 -0
- data/spec/factories/spaces_factory.rb +10 -0
- data/spec/factories/users_factory.rb +10 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/support/factory_girl.rb +6 -0
- data/spec/support/shared_examples/model_summary_examples.rb +7 -7
- data/spec/support/test_model_builder.rb +10 -0
- metadata +83 -71
- data/spec/fakes/app_fake.rb +0 -5
- data/spec/fakes/domain_fake.rb +0 -5
- data/spec/fakes/framework_fake.rb +0 -5
- data/spec/fakes/organization_fake.rb +0 -5
- data/spec/fakes/route_fake.rb +0 -5
- data/spec/fakes/runtime_fake.rb +0 -5
- data/spec/fakes/service_fake.rb +0 -5
- data/spec/fakes/service_instance_fake.rb +0 -5
- data/spec/fakes/service_plan_fake.rb +0 -5
- data/spec/fakes/space_fake.rb +0 -5
- data/spec/fakes/user_fake.rb +0 -5
- data/spec/support/fake_helper.rb +0 -248
- data/spec/support/randoms.rb +0 -3
data/spec/fakes/app_fake.rb
DELETED
data/spec/fakes/domain_fake.rb
DELETED
data/spec/fakes/route_fake.rb
DELETED
data/spec/fakes/runtime_fake.rb
DELETED
data/spec/fakes/service_fake.rb
DELETED
data/spec/fakes/space_fake.rb
DELETED
data/spec/fakes/user_fake.rb
DELETED
data/spec/support/fake_helper.rb
DELETED
@@ -1,248 +0,0 @@
|
|
1
|
-
module Fake
|
2
|
-
module FakeMethods
|
3
|
-
def fake_client(attributes = {})
|
4
|
-
CFoundry::V2::FakeClient.new.fake(attributes)
|
5
|
-
end
|
6
|
-
|
7
|
-
def fake(what, attributes = {})
|
8
|
-
fake_client.send(what).fake(attributes)
|
9
|
-
end
|
10
|
-
|
11
|
-
def fake_list(what, count, attributes = {})
|
12
|
-
objs = []
|
13
|
-
|
14
|
-
count.times do
|
15
|
-
objs << fake(what, attributes)
|
16
|
-
end
|
17
|
-
|
18
|
-
objs
|
19
|
-
end
|
20
|
-
|
21
|
-
def fake_model(name = :my_fake_model, &init)
|
22
|
-
# There is a difference between ruby 1.8.7 and 1.8.8 in the order that
|
23
|
-
# the inherited callback gets called. In 1.8.7 the inherited callback
|
24
|
-
# is called after the block; in 1.8.8 and later it's called before.
|
25
|
-
# The upshot for us is we need a failproof way of getting the name
|
26
|
-
# to klass. So we're using a global variable to hand off the value.
|
27
|
-
# Please don't shoot us. - ESH & MMB
|
28
|
-
$object_name = name
|
29
|
-
klass = Class.new(CFoundry::V2::FakeModel) do
|
30
|
-
self.object_name = name
|
31
|
-
end
|
32
|
-
|
33
|
-
klass.class_eval(&init) if init
|
34
|
-
|
35
|
-
klass
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def fake(attributes = {})
|
40
|
-
fake_attributes(attributes).each do |k, v|
|
41
|
-
send(:"#{k}=", v)
|
42
|
-
setup_reverse_relationship(v)
|
43
|
-
end
|
44
|
-
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.define_many_association(target, plural)
|
49
|
-
target.class_eval do
|
50
|
-
define_method(plural) do |*args|
|
51
|
-
options, _ = args
|
52
|
-
options ||= {}
|
53
|
-
|
54
|
-
vals = get_many(plural) || []
|
55
|
-
|
56
|
-
if options[:query]
|
57
|
-
by, val = options[:query]
|
58
|
-
vals.select do |v|
|
59
|
-
v.send(by) == val
|
60
|
-
end
|
61
|
-
else
|
62
|
-
vals
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
module CFoundry::V2
|
70
|
-
class Model
|
71
|
-
include Fake
|
72
|
-
|
73
|
-
attr_writer :client
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def get_many(plural)
|
78
|
-
@cache[plural]
|
79
|
-
end
|
80
|
-
|
81
|
-
def fake_attributes(attributes)
|
82
|
-
fakes = default_fakes
|
83
|
-
|
84
|
-
# default relationships to other fake objects
|
85
|
-
self.class.to_one_relations.each do |name, opts|
|
86
|
-
# remove _guid (not an actual attribute)
|
87
|
-
fakes.delete :"#{name}_guid"
|
88
|
-
next if fakes.key?(name)
|
89
|
-
|
90
|
-
fakes[name] =
|
91
|
-
if opts.key?(:default)
|
92
|
-
opts[:default]
|
93
|
-
else
|
94
|
-
@client.send(opts[:as] || name).fake
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# make sure that the attributes provided are set after the defaults
|
99
|
-
#
|
100
|
-
# we have to do this for cases like environment_json vs. env,
|
101
|
-
# where one would clobber the other
|
102
|
-
attributes.each do |k, _|
|
103
|
-
fakes.delete k
|
104
|
-
end
|
105
|
-
|
106
|
-
fakes = fakes.to_a
|
107
|
-
fakes += attributes.to_a
|
108
|
-
|
109
|
-
fakes
|
110
|
-
end
|
111
|
-
|
112
|
-
# override this to provide basic attributes (like name) dynamically
|
113
|
-
def default_fakes
|
114
|
-
self.class.defaults.merge(
|
115
|
-
:guid => random_string("fake-#{object_name}-guid"))
|
116
|
-
end
|
117
|
-
|
118
|
-
def setup_reverse_relationship(v)
|
119
|
-
if v.is_a?(Array)
|
120
|
-
v.each do |x|
|
121
|
-
setup_reverse_relationship(x)
|
122
|
-
end
|
123
|
-
|
124
|
-
return
|
125
|
-
end
|
126
|
-
|
127
|
-
return unless v.is_a?(Model)
|
128
|
-
|
129
|
-
relation, type = find_reverse_relationship(v)
|
130
|
-
|
131
|
-
v.client = @client
|
132
|
-
|
133
|
-
if type == :one
|
134
|
-
v.send(:"#{relation}=", self)
|
135
|
-
elsif type == :many
|
136
|
-
v.send(:"#{relation}=", v.send(relation) + [self])
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def find_reverse_relationship(v)
|
141
|
-
singular = object_name
|
142
|
-
plural = plural_object_name
|
143
|
-
|
144
|
-
v.class.to_one_relations.each do |attr, opts|
|
145
|
-
return [attr, :one] if attr == singular
|
146
|
-
return [attr, :one] if opts[:as] == singular
|
147
|
-
end
|
148
|
-
|
149
|
-
v.class.to_many_relations.each do |attr, opts|
|
150
|
-
return [attr, :many] if attr == plural
|
151
|
-
return [attr, :many] if opts[:as] == singular
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
class FakeBase < Base
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
class FakeClient < Client
|
162
|
-
include Fake
|
163
|
-
|
164
|
-
def initialize(target = "http://example.com", token = nil)
|
165
|
-
@base = FakeBase.new(target, token)
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
|
170
|
-
def get_many(plural)
|
171
|
-
instance_variable_get(:"@#{plural}")
|
172
|
-
end
|
173
|
-
|
174
|
-
def fake_attributes(attributes)
|
175
|
-
attributes
|
176
|
-
end
|
177
|
-
|
178
|
-
def setup_reverse_relationship(v)
|
179
|
-
if v.is_a?(Model)
|
180
|
-
v.client = self
|
181
|
-
elsif v.is_a?(Array)
|
182
|
-
v.each do |x|
|
183
|
-
setup_reverse_relationship(x)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
|
190
|
-
class FakeModel < CFoundry::V2::Model
|
191
|
-
attr_reader :diff
|
192
|
-
|
193
|
-
def self.inherited(klass)
|
194
|
-
class << klass
|
195
|
-
attr_writer :object_name
|
196
|
-
end
|
197
|
-
|
198
|
-
# There is a difference between ruby 1.8.7 and 1.8.8 in the order that
|
199
|
-
# the inherited callback gets called. In 1.8.7 the inherited callback
|
200
|
-
# is called after the block; in 1.8.8 and later it's called before.
|
201
|
-
# The upshot for us is we need a failproof way of getting the name
|
202
|
-
# to klass. So we're using a global variable to hand off the value.
|
203
|
-
# Please don't shoot us. - ESH & MMB
|
204
|
-
klass.object_name = $object_name
|
205
|
-
super
|
206
|
-
end
|
207
|
-
|
208
|
-
class << self
|
209
|
-
attr_writer :object_name
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
|
214
|
-
module ModelMagic
|
215
|
-
def self.define_client_methods(&blk)
|
216
|
-
FakeClient.module_eval(&blk)
|
217
|
-
end
|
218
|
-
|
219
|
-
def self.define_base_client_methods(&blk)
|
220
|
-
FakeBase.module_eval(&blk)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
Model.objects.each_value do |klass|
|
225
|
-
klass.to_many_relations.each do |plural, _|
|
226
|
-
Fake.define_many_association(klass, plural)
|
227
|
-
end
|
228
|
-
|
229
|
-
FakeClient.class_eval do
|
230
|
-
plural = klass.plural_object_name
|
231
|
-
|
232
|
-
attr_writer plural
|
233
|
-
Fake.define_many_association(self, plural)
|
234
|
-
|
235
|
-
define_method(klass.object_name) do |*args|
|
236
|
-
guid, _ = args
|
237
|
-
|
238
|
-
if guid
|
239
|
-
get_many(klass.plural_object_name).find do |o|
|
240
|
-
o.guid == guid
|
241
|
-
end || super(*args)
|
242
|
-
else
|
243
|
-
super(*args)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
data/spec/support/randoms.rb
DELETED