cfoundry 1.5.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/lib/cfoundry/test_support.rb +2 -2
  2. data/lib/cfoundry/v2/app.rb +3 -6
  3. data/lib/cfoundry/v2/model.rb +1 -0
  4. data/lib/cfoundry/version.rb +1 -1
  5. data/spec/cfoundry/client_spec.rb +1 -1
  6. data/spec/cfoundry/rest_client_spec.rb +1 -1
  7. data/spec/cfoundry/trace_helpers_spec.rb +6 -6
  8. data/spec/cfoundry/upload_helpers_spec.rb +125 -137
  9. data/spec/cfoundry/v2/app_event_spec.rb +63 -59
  10. data/spec/cfoundry/v2/app_spec.rb +195 -188
  11. data/spec/cfoundry/v2/client_spec.rb +60 -56
  12. data/spec/cfoundry/v2/domain_spec.rb +9 -6
  13. data/spec/cfoundry/v2/model_magic/model_magic/attribute_spec.rb +89 -88
  14. data/spec/cfoundry/v2/model_magic/model_magic/has_summary_spec.rb +12 -13
  15. data/spec/cfoundry/v2/model_magic/model_magic/to_many_spec.rb +46 -52
  16. data/spec/cfoundry/v2/model_magic/model_magic/to_one_spec.rb +96 -87
  17. data/spec/cfoundry/v2/model_spec.rb +236 -241
  18. data/spec/cfoundry/v2/organization_spec.rb +20 -22
  19. data/spec/cfoundry/v2/quota_definition_spec.rb +45 -47
  20. data/spec/cfoundry/v2/route_spec.rb +28 -25
  21. data/spec/cfoundry/v2/space_spec.rb +9 -11
  22. data/spec/cfoundry/validator_spec.rb +69 -67
  23. data/spec/factories/app_events_factory.rb +7 -0
  24. data/spec/factories/apps_factory.rb +11 -0
  25. data/spec/factories/clients_factory.rb +5 -0
  26. data/spec/factories/domains_factory.rb +7 -0
  27. data/spec/factories/organizations_factory.rb +11 -0
  28. data/spec/factories/quota_definitions_factory.rb +8 -0
  29. data/spec/factories/routes_factory.rb +10 -0
  30. data/spec/factories/spaces_factory.rb +10 -0
  31. data/spec/factories/users_factory.rb +10 -0
  32. data/spec/spec_helper.rb +5 -4
  33. data/spec/support/factory_girl.rb +6 -0
  34. data/spec/support/shared_examples/model_summary_examples.rb +7 -7
  35. data/spec/support/test_model_builder.rb +10 -0
  36. metadata +83 -71
  37. data/spec/fakes/app_fake.rb +0 -5
  38. data/spec/fakes/domain_fake.rb +0 -5
  39. data/spec/fakes/framework_fake.rb +0 -5
  40. data/spec/fakes/organization_fake.rb +0 -5
  41. data/spec/fakes/route_fake.rb +0 -5
  42. data/spec/fakes/runtime_fake.rb +0 -5
  43. data/spec/fakes/service_fake.rb +0 -5
  44. data/spec/fakes/service_instance_fake.rb +0 -5
  45. data/spec/fakes/service_plan_fake.rb +0 -5
  46. data/spec/fakes/space_fake.rb +0 -5
  47. data/spec/fakes/user_fake.rb +0 -5
  48. data/spec/support/fake_helper.rb +0 -248
  49. data/spec/support/randoms.rb +0 -3
@@ -1,299 +1,294 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::V2::Model do
4
- let(:client) { fake_client }
5
- let(:guid) { random_string("my-object-guid") }
6
- let(:manifest) { {:metadata => {:foo => "bar"}} }
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
- subject { klass.new(guid, client, manifest) }
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
- describe "create" do
20
- it "uses #create!" do
21
- mock(subject).create!
22
- subject.create
23
- end
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
- context "without errors" do
26
- it "returns true" do
27
- mock(subject).create!
28
- subject.create.should == true
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
- context "with errors" do
33
- before do
34
- stub(subject.class).model_name { ActiveModel::Name.new(subject, nil, "abstract_model") }
35
- stub(subject).create! { raise CFoundry::APIError.new("HELP") }
36
- end
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
- it "does not raise an exception" do
39
- expect { subject.create }.to_not raise_error
40
- end
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
- it "returns false" do
43
- subject.create.should == false
44
- end
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
- context "without model-specific errors" do
47
- it "adds generic base error " do
48
- subject.create
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
- context "with model-specific errors" do
54
- it "does not set the generic error on base" do
55
- subject.create
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
- describe "#update!" do
97
- before do
98
- stub(client.base).put
99
- subject.foo = "bar"
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
- describe "delete" do
119
- it "uses #delete!" do
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
- it "passes options along to delete!" do
125
- mock(subject).delete!(:recursive => true) { true }
126
- subject.delete(:recursive => true)
127
- end
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
- context "without errors" do
130
- it "returns true" do
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
- context "with errors" do
137
- before do
138
- stub(subject.class).model_name { ActiveModel::Name.new(subject, nil, "abstract_model") }
139
- stub(subject).delete! { raise CFoundry::APIError.new("HELP") }
112
+ model.diff.should be_present
113
+ model.update!
114
+ model.diff.should_not be_present
115
+ end
140
116
  end
141
117
 
142
- it "does not raise an exception" do
143
- expect { subject.delete }.to_not raise_error
144
- end
118
+ describe "delete" do
119
+ it "uses #delete!" do
120
+ mock(model).delete!({}) { true }
121
+ model.delete
122
+ end
145
123
 
146
- it "returns false" do
147
- subject.delete.should == false
148
- end
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
- context "without model-specific errors" do
151
- it "adds generic base error " do
152
- subject.delete
153
- subject.errors.full_messages.first.should =~ /cloud controller reported an error/i
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
- context "with model-specific errors" do
158
- it "does not set the generic error on base" do
159
- subject.delete
160
- subject.errors.size.should == 1
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
- describe "#delete!" do
167
- before { stub(client.base).delete }
166
+ describe "#delete!" do
167
+ before { stub(client.base).delete }
168
168
 
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", :my_fake_models, guid, :params => {})
172
- subject.delete!
173
- end
174
- end
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
- 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", :my_fake_models, guid, :params => options)
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
- subject.delete!(options)
182
- end
183
- end
181
+ model.delete!(options)
182
+ end
183
+ end
184
184
 
185
- it "clears its manifest metadata" do
186
- subject.manifest.should have_key(:metadata)
187
- subject.delete!
188
- subject.manifest.should_not have_key(:metadata)
189
- end
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
- it "clears the diff" do
192
- subject.foo = "bar"
193
- subject.diff.should be_present
194
- subject.delete!
195
- subject.diff.should_not be_present
196
- end
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
- it "delete me" do
199
- begin
200
- subject.delete!
201
- rescue => ex
202
- ex.message.should_not =~ /\?/
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
- describe "#to_key" do
208
- context "when persisted" do
209
- it "returns an enumerable containing the guid" do
210
- subject.to_key.should respond_to(:each)
211
- subject.to_key.first.should == guid
212
- end
213
- end
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
- context "when not persisted" do
216
- let(:guid) { nil }
215
+ context "when not persisted" do
216
+ let(:guid) { nil }
217
217
 
218
- it "returns nil" do
219
- subject.to_key.should be_nil
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
- describe "#to_param" do
225
- context "when persisted" do
226
- it "returns the guid as a string" do
227
- subject.to_param.should be_a(String)
228
- subject.to_param.should == guid
229
- end
230
- end
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
- context "when not persisted" do
233
- let(:guid) { nil }
232
+ context "when not persisted" do
233
+ let(:guid) { nil }
234
234
 
235
- it "returns nil" do
236
- subject.to_param.should be_nil
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
- describe "#persisted?" do
242
- context "on a new object" do
243
- let(:guid) { nil }
244
- it "returns false" do
245
- subject.should_not be_persisted
246
- end
247
- end
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
- context "on an object with a guid" do
250
- it "returns false" do
251
- subject.should be_persisted
252
- end
253
- end
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
- context "on an object that has been deleted" do
256
- before do
257
- stub(client.base).delete
258
- subject.delete
259
- end
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
- it "returns false" do
262
- subject.should_not be_persisted
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
- describe "creating a new object" do
268
- let(:new_object) {
269
- client.fake_model_with_attribute
270
- }
267
+ describe "creating a new object" do
268
+ let(:new_object) { client.test_model }
271
269
 
272
- describe "getting attributes" do
270
+ describe "getting attributes" do
273
271
 
274
- it "does not go to cloud controller" do
275
- expect {
276
- new_object.time
277
- }.to_not raise_error
278
- end
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
- it "remembers set values" do
281
- new_object.time = "now"
282
- new_object.time.should == "now"
283
- end
284
- end
278
+ it "remembers set values" do
279
+ new_object.foo = "bar"
280
+ new_object.foo.should == "bar"
281
+ end
282
+ end
285
283
 
286
- describe "getting associations" do
287
- describe "to_one associations" do
288
- it "returns the an empty object of the association's type" do
289
- new_object.domain.guid.should be_nil
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