cfoundry 1.5.3 → 2.0.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.
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,11 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::V2::Domain do
4
- let(:client) { fake_client }
3
+ module CFoundry
4
+ module V2
5
+ describe Domain do
6
+ let(:space) { build(:space) }
7
+ let(:domain) { build(:domain, :spaces => [space]) }
5
8
 
6
- subject { CFoundry::V2::Domain.new("domain-id-1", client) }
7
-
8
- it "should have a spaces association" do
9
- expect(subject.spaces).to eq([])
9
+ it "should have a spaces association" do
10
+ expect(domain.spaces).to eq([space])
11
+ end
12
+ end
10
13
  end
11
14
  end
@@ -1,119 +1,120 @@
1
1
  require "spec_helper"
2
2
 
3
- module CFoundry::V2
4
- describe ModelMagic do
5
- let(:client) { fake_client }
6
- let(:mymodel) { fake_model }
7
- let(:guid) { random_string("my-object-guid") }
8
- let(:myobject) { mymodel.new(guid, client) }
9
-
10
- describe 'attributes' do
11
- describe 'reading' do
12
- let(:mymodel) { fake_model { attribute :foo, :object } }
13
-
14
- context 'when it exists in the manifest' do
15
- subject { myobject.fake(:foo => "bar") }
16
-
17
- it 'returns the value from the manifest' do
18
- expect(subject.foo).to eq "bar"
19
- end
20
-
21
- context 'and the default is nil but the value is false' do
22
- let(:mymodel) {
23
- fake_model { attribute :foo, :object, :default => nil }
24
- }
25
-
26
- subject { myobject.fake(:foo => false) }
3
+ module CFoundry
4
+ module V2
5
+ describe ModelMagic do
6
+ describe "attributes" do
7
+ let(:guid) { "test-model-guid-1" }
8
+ let(:client) { build(:client) }
9
+
10
+ describe "reading" do
11
+ context "when it exists in the manifest" do
12
+ let(:manifest) { {:metadata => {}, :entity => {:foo => "bar"}} }
13
+
14
+ let(:model) do
15
+ TestModelBuilder.build(guid, client, manifest) { attribute :foo, :object }
16
+ end
27
17
 
28
- it 'returns false' do
29
- expect(subject.foo).to eq false
18
+ it "returns the value from the manifest" do
19
+ expect(model.foo).to eq "bar"
30
20
  end
31
- end
32
21
 
33
- context 'and the default is false but the value is nil' do
34
- let(:mymodel) {
35
- fake_model { attribute :foo, :object, :default => false }
36
- }
22
+ context "and the default is nil but the value is false" do
23
+ let(:model) do
24
+ TestModelBuilder.build(guid, client, manifest) { attribute :foo, :object, :default => nil }
25
+ end
37
26
 
38
- subject { myobject.fake(:foo => nil) }
27
+ before do
28
+ model.foo = false
29
+ end
39
30
 
40
- it 'returns nil' do
41
- expect(subject.foo).to eq nil
31
+ it "returns false" do
32
+ expect(model.foo).to eq false
33
+ end
42
34
  end
43
- end
44
- end
45
35
 
46
- context 'when the manifest has not been acquired' do
47
- it 'retrieves the manifest the first time' do
48
- mock(client.base).my_fake_model(guid) {
49
- {:entity => {:foo => "fizz"}}
50
- }.ordered
36
+ context "and the default is false but the value is nil" do
37
+ let(:model) do
38
+ TestModelBuilder.build(guid, client, manifest) { attribute :foo, :object, :default => false }
39
+ end
51
40
 
52
- expect(myobject.foo).to eq "fizz"
41
+ before do
42
+ model.foo = nil
43
+ end
53
44
 
54
- dont_allow(client.base).my_fake_model.ordered
55
-
56
- expect(myobject.foo).to eq "fizz"
45
+ it "returns nil" do
46
+ expect(model.foo).to eq nil
47
+ end
48
+ end
57
49
  end
58
- end
59
50
 
60
- context 'when it does not exist in the manifest' do
61
- let(:mymodel) {
62
- fake_model { attribute :foo, :object, :default => "foo" }
63
- }
51
+ context "when the manifest has not been acquired" do
52
+ let(:model) do
53
+ TestModelBuilder.build(guid, client) { attribute :foo, :object }
54
+ end
64
55
 
65
- subject { myobject.fake }
56
+ it "retrieves the manifest the first time" do
57
+ mock(client.base).test_model("test-model-guid-1") {
58
+ {:entity => {:foo => "fizz"}}
59
+ }.ordered
66
60
 
67
- it 'returns the default value' do
68
- expect(subject.foo).to eq "foo"
69
- end
70
- end
61
+ expect(model.foo).to eq "fizz"
71
62
 
72
- context 'when the attribute has a custom json key' do
73
- let(:mymodel) {
74
- fake_model { attribute :foo, :object, :at => :not_foo }
75
- }
63
+ dont_allow(client.base).model.ordered
76
64
 
77
- subject { myobject.fake }
65
+ expect(model.foo).to eq "fizz"
66
+ end
67
+ end
78
68
 
79
- it 'retrieves the attribute using the custom key' do
80
- stub(client.base).my_fake_model(guid) {
81
- {:entity => {:not_foo => "fizz"}}
82
- }
69
+ context "when it does not exist in the manifest" do
70
+ let(:model) do
71
+ TestModelBuilder.build(guid, client, {:entity => {}}) { attribute :foo, :object, :default => "foo" }
72
+ end
83
73
 
84
- expect(myobject.foo).to eq "fizz"
74
+ it "returns the default value" do
75
+ expect(model.foo).to eq "foo"
76
+ end
85
77
  end
86
- end
87
- end
88
78
 
89
- describe 'writing' do
90
- context 'when the attribute has a custom json key' do
91
- let(:mymodel) {
92
- fake_model { attribute :foo, :object, :at => :not_foo }
93
- }
79
+ context "when the attribute has a custom json key" do
80
+ let(:model) do
81
+ TestModelBuilder.build(guid, client) { attribute :foo, :object, :at => :not_foo }
82
+ end
94
83
 
95
- subject { myobject }
84
+ before do
85
+ stub(client.base).test_model("test-model-guid-1") {
86
+ {:entity => {:not_foo => "fizz"}}
87
+ }
88
+ end
96
89
 
97
- it "uses the 'at' value in the update payload" do
98
- mock(client.base).put("v2", :my_fake_models, subject.guid, hash_including(:payload => {:not_foo => 123}))
99
- subject.foo = 123
100
- subject.update!
90
+ it "retrieves the attribute using the custom key" do
91
+ expect(model.foo).to eq "fizz"
92
+ end
101
93
  end
94
+ end
102
95
 
103
- it "uses the 'at' value in the create payload" do
104
- subject.foo = 123
96
+ describe "writing" do
97
+ context "when the attribute has a custom json key" do
98
+ let(:model) do
99
+ TestModelBuilder.build(guid, client) { attribute :foo, :object, :at => :not_foo }
100
+ end
105
101
 
106
- mock(client.base).post(
107
- "v2", :my_fake_models,
108
- hash_including(:payload => {:not_foo => 123})
109
- ) { {:metadata => {}} }
102
+ it "uses the 'at' value in the update payload" do
103
+ mock(client.base).put("v2", :test_models, model.guid, hash_including(:payload => {:not_foo => 123}))
104
+ model.foo = 123
105
+ model.update!
106
+ end
110
107
 
111
- subject.create!
112
- end
108
+ it "uses the 'at' value in the create payload" do
109
+ model.foo = 123
110
+ mock(client.base).post("v2", :test_models, hash_including(:payload => {:not_foo => 123})) { {:metadata => {}} }
111
+ model.create!
112
+ end
113
113
 
114
- it "is then readable via the attribute name" do
115
- subject.foo = 123
116
- expect(subject.foo).to eq 123
114
+ it "is then readable via the attribute name" do
115
+ model.foo = 123
116
+ expect(model.foo).to eq 123
117
+ end
117
118
  end
118
119
  end
119
120
  end
@@ -1,18 +1,17 @@
1
1
  require "spec_helper"
2
2
 
3
- module CFoundry::V2
4
- describe ModelMagic do
5
- let(:client) { fake_client }
6
- let(:guid) { random_string("my-object-guid") }
7
- let(:myobject) { mymodel.new(guid, client) }
8
-
9
- describe 'summarization for an arbitrary model' do
10
- let(:mymodel) { fake_model { attribute :foo, :string } }
11
- let(:summary_attributes) { {:foo => "abcd"} }
12
-
13
- subject { myobject }
3
+ class TestModel < CFoundry::V2::Model
4
+ attribute :foo, :string
5
+ end
14
6
 
15
- it_behaves_like 'a summarizeable model'
7
+ module CFoundry
8
+ module V2
9
+ describe ModelMagic do
10
+ it_behaves_like "a summarizeable model" do
11
+ let(:summary_attributes) { {:foo => "abcd"} }
12
+ let(:client) { build(:client) }
13
+ subject { TestModel.new("some-guid-1", client) }
14
+ end
16
15
  end
17
16
  end
18
- end
17
+ end
@@ -1,59 +1,53 @@
1
1
  require "spec_helper"
2
2
 
3
- module CFoundry::V2
4
- include ModelMagic::ToMany
5
-
6
- class AssociatedModel < FakeModel
7
- attribute :attribute, String
8
- end
9
-
10
- describe ModelMagic::ToMany do
11
- let(:client) { fake_client }
12
- let(:mymodel) { fake_model }
13
- let(:guid) { random_string("my-object-guid") }
14
- let(:myobject) { mymodel.new(guid, client) }
15
-
16
- describe "to_many relationships" do
17
- describe "associated create" do
18
- let!(:model) { fake_model { to_many :associated_models } }
19
- let(:instance) { model.new(nil, client).fake }
20
- let!(:create_request) { WebMock.stub_request(:post, /v2\/associated_model/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json) }
21
- let!(:add_request) { WebMock.stub_request(:put, /v2\/my_fake_models\/.*\/associated_models/).to_return(:body => {}.to_json) }
22
-
23
- before do
24
- stub_request(:get, /v2\/my_fake_models\/.*\/associated_models/)
25
- instance.associated_models = []
26
- end
27
-
28
- it "returns a new associated object" do
29
- instance.create_associated_model.should be_a(AssociatedModel)
30
- end
31
-
32
- it "sets the relation" do
33
- created = instance.create_associated_model
34
- instance.associated_models.should include(created)
35
- end
36
-
37
- context "with attributes for the association" do
38
- it "sets these attributes on the association" do
39
- created = instance.create_associated_model(:attribute => "value")
40
- created.attribute.should == "value"
41
- end
42
- end
43
-
44
- it "calls out to cloud_controller" do
45
- instance.create_associated_model
46
- create_request.should have_been_requested
47
- end
48
-
49
- context "when creation fails" do
50
- let!(:create_request) { WebMock.stub_request(:post, /v2\/associated_model/).to_raise(:not_authorized) }
51
-
52
- it "raises an exception" do
53
- expect { instance.create_associated_model }.to raise_error(StandardError)
3
+ class AssociatedModel < CFoundry::V2::Model
4
+ attribute :attribute, String
5
+ end
6
+
7
+ module CFoundry
8
+ module V2
9
+ module ModelMagic
10
+ describe ToMany do
11
+ let(:client) { build(:client) }
12
+
13
+ describe "to_many relationships" do
14
+ describe "associated create" do
15
+ let(:model) do
16
+ TestModelBuilder.build("test-model-guid-1", client) { to_many :associated_models }
17
+ end
18
+
19
+ before do
20
+ WebMock.stub_request(:put, /v2\/test_models\/.*\/associated_models/).to_return(:body => {}.to_json)
21
+ WebMock.stub_request(:post, /v2\/associated_model/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json)
22
+ stub_request(:get, /v2\/test_models\/.*\/associated_models/)
23
+ model.associated_models = []
24
+ end
25
+
26
+ it "returns a new associated object" do
27
+ model.create_associated_model.should be_a(AssociatedModel)
28
+ end
29
+
30
+ it "sets the relation" do
31
+ created = model.create_associated_model
32
+ model.associated_models.should include(created)
33
+ end
34
+
35
+ context "with attributes for the association" do
36
+ it "sets these attributes on the association" do
37
+ created = model.create_associated_model(:attribute => "value")
38
+ created.attribute.should == "value"
39
+ end
40
+ end
41
+
42
+ context "when creation fails" do
43
+ it "raises an exception" do
44
+ WebMock.stub_request(:post, /v2\/associated_model/).to_raise(:not_authorized)
45
+ expect { model.create_associated_model }.to raise_error(StandardError)
46
+ end
47
+ end
54
48
  end
55
49
  end
56
50
  end
57
51
  end
58
52
  end
59
- end
53
+ end
@@ -1,94 +1,103 @@
1
1
  require "spec_helper"
2
2
 
3
- module CFoundry::V2
4
- include ModelMagic::ToOne
5
- class Associated < FakeModel
6
- attribute :attribute, String
7
- end
8
-
9
- describe ModelMagic::ToOne do
10
- let(:client) { fake_client }
11
- let(:mymodel) { fake_model }
12
- let(:guid) { random_string("my-object-guid") }
13
- let(:myobject) { mymodel.new(guid, client) }
14
-
15
- describe 'to_one relationships' do
16
- describe 'writing' do
17
- let!(:mymodel) { fake_model { to_one :foo } }
18
- let!(:othermodel) { fake_model :foo }
19
-
20
- let(:myobject) { mymodel.new(nil, client).fake }
21
- let(:otherobject) { othermodel.new(nil, client).fake }
22
-
23
- subject { myobject.foo = otherobject }
24
-
25
- it "sets the GUID in the manifest to the object's GUID" do
26
- expect { subject }.to change {
27
- myobject.manifest[:entity][:foo_guid]
28
- }.to(otherobject.guid)
29
- end
30
-
31
- it "tracks internal changes in the diff" do
32
- expect { subject }.to change { myobject.diff }.to(
33
- :foo_guid => otherobject.guid)
34
- end
35
-
36
- it "tracks high-level changes in .changes" do
37
- before = myobject.foo
38
- expect { subject }.to change { myobject.changes }.to(
39
- :foo => [before, otherobject])
40
- end
41
-
42
- it "returns the assigned value" do
43
- myobject.send(:foo=, otherobject).should == otherobject
44
- end
45
-
46
- context "when there is a default" do
47
- let(:mymodel) { fake_model { to_one :foo, :default => nil } }
48
-
49
- subject { myobject.foo = nil }
50
-
51
- it "allows setting to the default" do
52
- myobject.foo = otherobject
53
-
54
- expect { subject }.to change {
55
- myobject.manifest[:entity][:foo_guid]
56
- }.from(otherobject.guid).to(nil)
3
+ class AssociatedModel < CFoundry::V2::Model
4
+ attribute :attribute, String
5
+ end
6
+
7
+ module CFoundry
8
+ module V2
9
+ module ModelMagic
10
+ describe ToOne do
11
+ let(:client) { build(:client) }
12
+ let(:model) { model.new("my-object-guid-1", client) }
13
+
14
+ describe "to_one relationships" do
15
+ describe "writing" do
16
+ let(:model) do
17
+ TestModelBuilder.build("my-model-guid-1", client) { to_one :associated_model }
18
+ end
19
+
20
+ let(:other_model) do
21
+ AssociatedModel.new("my-model-guid-2", client)
22
+ end
23
+
24
+ before do
25
+ stub_request(:get, /v2\/test_models\/.*/).to_return(:body => {:entity => {}}.to_json)
26
+ end
27
+
28
+ it "sets the GUID in the manifest to the object's GUID" do
29
+ expect {
30
+ model.associated_model = other_model
31
+ }.to change { model.manifest[:entity][:associated_model_guid] }.to(other_model.guid)
32
+ end
33
+
34
+ it "tracks internal changes in the diff" do
35
+ expect {
36
+ model.associated_model = other_model
37
+ }.to change { model.diff }.to(:associated_model_guid => other_model.guid)
38
+ end
39
+
40
+ it "tracks high-level changes in .changes" do
41
+ previous_associated_model = AssociatedModel.new("my-model-guid-3", client)
42
+ model.associated_model = previous_associated_model
43
+
44
+ expect {
45
+ model.associated_model = other_model
46
+ }.to change { model.changes }.to(:associated_model => [previous_associated_model, other_model])
47
+ end
48
+
49
+ it "returns the assigned value" do
50
+ model.send(:associated_model=, other_model).should == other_model
51
+ end
52
+
53
+ context "when there is a default" do
54
+ let(:model) { TestModelBuilder.build("my-model-guid-1", client) { to_one :associated_model, :default => nil } }
55
+
56
+ before do
57
+ model.associated_model = other_model
58
+ end
59
+
60
+ it "allows setting to the default" do
61
+ expect {
62
+ model.associated_model = nil
63
+ }.to change {
64
+ model.manifest[:entity][:associated_model_guid]
65
+ }.from(other_model.guid).to(nil)
66
+ end
67
+ end
57
68
  end
58
- end
59
- end
60
-
61
- describe 'associated create' do
62
- let!(:model) { fake_model { to_one :associated } }
63
- let(:instance) { model.new(nil, client).fake }
64
- let!(:request) { WebMock.stub_request(:post, /v2\/associated/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json) }
65
-
66
- it 'returns a new associated object' do
67
- instance.create_associated.should be_a(Associated)
68
- end
69
-
70
- it 'sets the relation' do
71
- created = instance.create_associated
72
- instance.associated.should == created
73
- end
74
-
75
- context 'with attributes for the association' do
76
- it 'sets these attributes on the association' do
77
- created = instance.create_associated(:attribute => 'value')
78
- created.attribute.should == 'value'
79
- end
80
- end
81
-
82
- it 'calls out to cloud_controller' do
83
- instance.create_associated
84
- request.should have_been_requested
85
- end
86
-
87
- context 'when creation fails' do
88
- let!(:request) { WebMock.stub_request(:post, /v2\/associated/).to_raise(:not_authorized) }
89
69
 
90
- it 'raises an exception' do
91
- expect { instance.create_associated }.to raise_error(StandardError)
70
+ describe "associated create" do
71
+ let(:model) do
72
+ TestModelBuilder.build("my-model-guid-1", client) { to_one :associated_model }
73
+ end
74
+
75
+ before do
76
+ WebMock.stub_request(:post, /v2\/associated_model/).to_return(:body => {:metadata => {:guid => "thing"}}.to_json)
77
+ end
78
+
79
+ it "returns a new associated object" do
80
+ model.create_associated_model.should be_a(AssociatedModel)
81
+ end
82
+
83
+ it "sets the relation" do
84
+ created = model.create_associated_model
85
+ model.associated_model.should == created
86
+ end
87
+
88
+ context "with attributes for the association" do
89
+ it "sets these attributes on the association" do
90
+ created = model.create_associated_model(:attribute => "value")
91
+ created.attribute.should == "value"
92
+ end
93
+ end
94
+
95
+ context "when creation fails" do
96
+ it "raises an exception" do
97
+ WebMock.stub_request(:post, /v2\/associated/).to_raise(:not_authorized)
98
+ expect { instance.create_associated }.to raise_error(StandardError)
99
+ end
100
+ end
92
101
  end
93
102
  end
94
103
  end