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
@@ -1,299 +1,294 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
let(:klass) {
|
8
|
-
fake_model do
|
9
|
-
attribute :foo, :string, :read => :x, :write => [:y, :z]
|
10
|
-
|
11
|
-
def attribute_for_error(e)
|
12
|
-
e.error_code == 1 ? :foo : :base
|
13
|
-
end
|
14
|
-
end
|
15
|
-
}
|
3
|
+
class TestModel < CFoundry::V2::Model
|
4
|
+
attribute :foo, :string
|
5
|
+
to_one :domain
|
6
|
+
end
|
16
7
|
|
17
|
-
|
8
|
+
module CFoundry
|
9
|
+
module V2
|
10
|
+
describe Model do
|
11
|
+
let(:client) { build(:client) }
|
12
|
+
let(:guid) { "my-object-guid" }
|
13
|
+
let(:manifest) { {:metadata => {:guid => "some-guid-1"}, :entity => {}} }
|
14
|
+
let(:model) { TestModel.new(guid, client, manifest) }
|
15
|
+
|
16
|
+
describe "create" do
|
17
|
+
it "uses #create!" do
|
18
|
+
mock(model).create!
|
19
|
+
model.create
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
context "without errors" do
|
23
|
+
it "returns true" do
|
24
|
+
mock(model).create!
|
25
|
+
model.create.should == true
|
26
|
+
end
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
context "with errors" do
|
30
|
+
before do
|
31
|
+
stub(model.class).model_name { ActiveModel::Name.new(model, nil, "abstract_model") }
|
32
|
+
stub(model).create! { raise CFoundry::APIError.new("HELP") }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does not raise an exception" do
|
36
|
+
expect { model.create }.to_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns false" do
|
40
|
+
model.create.should == false
|
41
|
+
end
|
42
|
+
|
43
|
+
context "without model-specific errors" do
|
44
|
+
it "adds generic base error " do
|
45
|
+
model.create
|
46
|
+
model.errors.full_messages.first.should =~ /cloud controller reported an error/i
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with model-specific errors" do
|
51
|
+
it "does not set the generic error on base" do
|
52
|
+
model.create
|
53
|
+
model.errors.size.should == 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
29
57
|
end
|
30
|
-
end
|
31
58
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
59
|
+
describe "#create!" do
|
60
|
+
before do
|
61
|
+
stub(client.base).post {
|
62
|
+
{:metadata => {:guid => "123"}}
|
63
|
+
}
|
64
|
+
model.foo = "bar"
|
65
|
+
end
|
37
66
|
|
38
|
-
|
39
|
-
|
40
|
-
|
67
|
+
it "posts to the model's create url with appropriate arguments" do
|
68
|
+
mock(client.base).post("v2", :test_models,
|
69
|
+
:content => :json,
|
70
|
+
:accept => :json,
|
71
|
+
:payload => {:foo => "bar"}
|
72
|
+
) { {:metadata => {}} }
|
73
|
+
model.create!
|
74
|
+
end
|
41
75
|
|
42
|
-
|
43
|
-
|
44
|
-
|
76
|
+
it "clears diff" do
|
77
|
+
model.diff.should be_present
|
78
|
+
model.create!
|
79
|
+
model.diff.should_not be_present
|
80
|
+
end
|
45
81
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
subject.errors.full_messages.first.should =~ /cloud controller reported an error/i
|
82
|
+
it "sets manifest from the response" do
|
83
|
+
model.create!
|
84
|
+
model.manifest.should == {:metadata => {:guid => "123"}}
|
50
85
|
end
|
51
|
-
end
|
52
86
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
subject.errors.size.should == 1
|
87
|
+
it "sets guid from the response metadata" do
|
88
|
+
model.create!
|
89
|
+
model.guid.should == "123"
|
57
90
|
end
|
58
91
|
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#create!" do
|
63
|
-
before do
|
64
|
-
stub(client.base).post {
|
65
|
-
{:metadata => {:guid => "123"}}
|
66
|
-
}
|
67
|
-
subject.foo = "bar"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "posts to the model's create url with appropriate arguments" do
|
71
|
-
mock(client.base).post("v2", :my_fake_models,
|
72
|
-
:content => :json,
|
73
|
-
:accept => :json,
|
74
|
-
:payload => {:foo => "bar"}
|
75
|
-
) { {:metadata => {}} }
|
76
|
-
subject.create!
|
77
|
-
end
|
78
|
-
|
79
|
-
it "clears diff" do
|
80
|
-
subject.diff.should be_present
|
81
|
-
subject.create!
|
82
|
-
subject.diff.should_not be_present
|
83
|
-
end
|
84
|
-
|
85
|
-
it "sets manifest from the response" do
|
86
|
-
subject.create!
|
87
|
-
subject.manifest.should == {:metadata => {:guid => "123"}}
|
88
|
-
end
|
89
|
-
|
90
|
-
it "sets guid from the response metadata" do
|
91
|
-
subject.create!
|
92
|
-
subject.guid.should == "123"
|
93
|
-
end
|
94
|
-
end
|
95
92
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
it "updates using the client with the v2 api, its plural model name, object guid, and diff object" do
|
103
|
-
mock(client.base).put("v2", :my_fake_models, guid,
|
104
|
-
:content => :json,
|
105
|
-
:accept => :json,
|
106
|
-
:payload => {:foo => "bar"}
|
107
|
-
)
|
108
|
-
subject.update!
|
109
|
-
end
|
110
|
-
|
111
|
-
it "clears diff" do
|
112
|
-
subject.diff.should be_present
|
113
|
-
subject.update!
|
114
|
-
subject.diff.should_not be_present
|
115
|
-
end
|
116
|
-
end
|
93
|
+
describe "#update!" do
|
94
|
+
before do
|
95
|
+
stub(client.base).put
|
96
|
+
end
|
117
97
|
|
118
|
-
|
119
|
-
|
120
|
-
mock(subject).delete!({}) { true }
|
121
|
-
subject.delete
|
122
|
-
end
|
98
|
+
it "updates using the client with the v2 api, its plural model name, object guid, and diff object" do
|
99
|
+
model.foo = "bar"
|
123
100
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
101
|
+
mock(client.base).put("v2", :test_models, guid,
|
102
|
+
:content => :json,
|
103
|
+
:accept => :json,
|
104
|
+
:payload => {:foo => "bar"}
|
105
|
+
)
|
106
|
+
model.update!
|
107
|
+
end
|
128
108
|
|
129
|
-
|
130
|
-
|
131
|
-
mock(subject).delete!({}) { true }
|
132
|
-
subject.delete.should == true
|
133
|
-
end
|
134
|
-
end
|
109
|
+
it "clears diff" do
|
110
|
+
model.foo = "bar"
|
135
111
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
112
|
+
model.diff.should be_present
|
113
|
+
model.update!
|
114
|
+
model.diff.should_not be_present
|
115
|
+
end
|
140
116
|
end
|
141
117
|
|
142
|
-
|
143
|
-
|
144
|
-
|
118
|
+
describe "delete" do
|
119
|
+
it "uses #delete!" do
|
120
|
+
mock(model).delete!({}) { true }
|
121
|
+
model.delete
|
122
|
+
end
|
145
123
|
|
146
|
-
|
147
|
-
|
148
|
-
|
124
|
+
it "passes options along to delete!" do
|
125
|
+
mock(model).delete!(:recursive => true) { true }
|
126
|
+
model.delete(:recursive => true)
|
127
|
+
end
|
149
128
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
129
|
+
context "without errors" do
|
130
|
+
it "returns true" do
|
131
|
+
mock(model).delete!({}) { true }
|
132
|
+
model.delete.should == true
|
133
|
+
end
|
154
134
|
end
|
155
|
-
end
|
156
135
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
136
|
+
context "with errors" do
|
137
|
+
before do
|
138
|
+
stub(model.class).model_name { ActiveModel::Name.new(model, nil, "abstract_model") }
|
139
|
+
stub(model).delete! { raise CFoundry::APIError.new("HELP") }
|
140
|
+
end
|
141
|
+
|
142
|
+
it "does not raise an exception" do
|
143
|
+
expect { model.delete }.to_not raise_error
|
144
|
+
end
|
145
|
+
|
146
|
+
it "returns false" do
|
147
|
+
model.delete.should == false
|
148
|
+
end
|
149
|
+
|
150
|
+
context "without model-specific errors" do
|
151
|
+
it "adds generic base error " do
|
152
|
+
model.delete
|
153
|
+
model.errors.full_messages.first.should =~ /cloud controller reported an error/i
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "with model-specific errors" do
|
158
|
+
it "does not set the generic error on base" do
|
159
|
+
model.delete
|
160
|
+
model.errors.size.should == 1
|
161
|
+
end
|
162
|
+
end
|
161
163
|
end
|
162
164
|
end
|
163
|
-
end
|
164
|
-
end
|
165
165
|
|
166
|
-
|
167
|
-
|
166
|
+
describe "#delete!" do
|
167
|
+
before { stub(client.base).delete }
|
168
168
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
169
|
+
context "without options" do
|
170
|
+
it "deletes using the client with the v2 api, its plural model name, object guid, and empty params hash" do
|
171
|
+
mock(client.base).delete("v2", :test_models, guid, :params => {})
|
172
|
+
model.delete!
|
173
|
+
end
|
174
|
+
end
|
175
175
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
context "with options" do
|
177
|
+
it "sends delete with the object guid and options" do
|
178
|
+
options = {:excellent => "billandted"}
|
179
|
+
mock(client.base).delete("v2", :test_models, guid, :params => options)
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
181
|
+
model.delete!(options)
|
182
|
+
end
|
183
|
+
end
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
185
|
+
it "clears its manifest metadata" do
|
186
|
+
model.manifest.should have_key(:metadata)
|
187
|
+
model.delete!
|
188
|
+
model.manifest.should_not have_key(:metadata)
|
189
|
+
end
|
190
190
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
191
|
+
it "clears the diff" do
|
192
|
+
model.foo = "bar"
|
193
|
+
model.diff.should be_present
|
194
|
+
model.delete!
|
195
|
+
model.diff.should_not be_present
|
196
|
+
end
|
197
197
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
198
|
+
it "delete me" do
|
199
|
+
begin
|
200
|
+
model.delete!
|
201
|
+
rescue => ex
|
202
|
+
ex.message.should_not =~ /\?/
|
203
|
+
end
|
204
|
+
end
|
203
205
|
end
|
204
|
-
end
|
205
|
-
end
|
206
206
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
207
|
+
describe "#to_key" do
|
208
|
+
context "when persisted" do
|
209
|
+
it "returns an enumerable containing the guid" do
|
210
|
+
model.to_key.should respond_to(:each)
|
211
|
+
model.to_key.first.should == guid
|
212
|
+
end
|
213
|
+
end
|
214
214
|
|
215
|
-
|
216
|
-
|
215
|
+
context "when not persisted" do
|
216
|
+
let(:guid) { nil }
|
217
217
|
|
218
|
-
|
219
|
-
|
218
|
+
it "returns nil" do
|
219
|
+
model.to_key.should be_nil
|
220
|
+
end
|
221
|
+
end
|
220
222
|
end
|
221
|
-
end
|
222
|
-
end
|
223
223
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
224
|
+
describe "#to_param" do
|
225
|
+
context "when persisted" do
|
226
|
+
it "returns the guid as a string" do
|
227
|
+
model.to_param.should be_a(String)
|
228
|
+
model.to_param.should == guid
|
229
|
+
end
|
230
|
+
end
|
231
231
|
|
232
|
-
|
233
|
-
|
232
|
+
context "when not persisted" do
|
233
|
+
let(:guid) { nil }
|
234
234
|
|
235
|
-
|
236
|
-
|
235
|
+
it "returns nil" do
|
236
|
+
model.to_param.should be_nil
|
237
|
+
end
|
238
|
+
end
|
237
239
|
end
|
238
|
-
end
|
239
|
-
end
|
240
240
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
241
|
+
describe "#persisted?" do
|
242
|
+
context "on a new object" do
|
243
|
+
let(:guid) { nil }
|
244
|
+
it "returns false" do
|
245
|
+
model.should_not be_persisted
|
246
|
+
end
|
247
|
+
end
|
248
248
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
249
|
+
context "on an object with a guid" do
|
250
|
+
it "returns false" do
|
251
|
+
model.should be_persisted
|
252
|
+
end
|
253
|
+
end
|
254
254
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
255
|
+
context "on an object that has been deleted" do
|
256
|
+
before do
|
257
|
+
stub(client.base).delete
|
258
|
+
model.delete
|
259
|
+
end
|
260
260
|
|
261
|
-
|
262
|
-
|
261
|
+
it "returns false" do
|
262
|
+
model.should_not be_persisted
|
263
|
+
end
|
264
|
+
end
|
263
265
|
end
|
264
|
-
end
|
265
|
-
end
|
266
266
|
|
267
|
-
|
268
|
-
|
269
|
-
client.fake_model_with_attribute
|
270
|
-
}
|
267
|
+
describe "creating a new object" do
|
268
|
+
let(:new_object) { client.test_model }
|
271
269
|
|
272
|
-
|
270
|
+
describe "getting attributes" do
|
273
271
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
272
|
+
it "does not go to cloud controller" do
|
273
|
+
expect {
|
274
|
+
new_object.foo
|
275
|
+
}.to_not raise_error
|
276
|
+
end
|
279
277
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
278
|
+
it "remembers set values" do
|
279
|
+
new_object.foo = "bar"
|
280
|
+
new_object.foo.should == "bar"
|
281
|
+
end
|
282
|
+
end
|
285
283
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
284
|
+
describe "getting associations" do
|
285
|
+
describe "to_one associations" do
|
286
|
+
it "returns the an empty object of the association's type" do
|
287
|
+
new_object.domain.guid.should be_nil
|
288
|
+
end
|
289
|
+
end
|
290
290
|
end
|
291
291
|
end
|
292
292
|
end
|
293
293
|
end
|
294
294
|
end
|
295
|
-
|
296
|
-
class FakeModelWithAttribute < CFoundry::V2::FakeModel
|
297
|
-
attribute :time, :string
|
298
|
-
to_one :domain
|
299
|
-
end
|