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.
- 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,11 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
29
|
-
expect(
|
18
|
+
it "returns the value from the manifest" do
|
19
|
+
expect(model.foo).to eq "bar"
|
30
20
|
end
|
31
|
-
end
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
27
|
+
before do
|
28
|
+
model.foo = false
|
29
|
+
end
|
39
30
|
|
40
|
-
|
41
|
-
|
31
|
+
it "returns false" do
|
32
|
+
expect(model.foo).to eq false
|
33
|
+
end
|
42
34
|
end
|
43
|
-
end
|
44
|
-
end
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
41
|
+
before do
|
42
|
+
model.foo = nil
|
43
|
+
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
45
|
+
it "returns nil" do
|
46
|
+
expect(model.foo).to eq nil
|
47
|
+
end
|
48
|
+
end
|
57
49
|
end
|
58
|
-
end
|
59
50
|
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
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
|
-
|
68
|
-
expect(subject.foo).to eq "foo"
|
69
|
-
end
|
70
|
-
end
|
61
|
+
expect(model.foo).to eq "fizz"
|
71
62
|
|
72
|
-
|
73
|
-
let(:mymodel) {
|
74
|
-
fake_model { attribute :foo, :object, :at => :not_foo }
|
75
|
-
}
|
63
|
+
dont_allow(client.base).model.ordered
|
76
64
|
|
77
|
-
|
65
|
+
expect(model.foo).to eq "fizz"
|
66
|
+
end
|
67
|
+
end
|
78
68
|
|
79
|
-
it
|
80
|
-
|
81
|
-
{:entity => {:
|
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
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
84
|
+
before do
|
85
|
+
stub(client.base).test_model("test-model-guid-1") {
|
86
|
+
{:entity => {:not_foo => "fizz"}}
|
87
|
+
}
|
88
|
+
end
|
96
89
|
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
104
|
-
|
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
|
-
|
107
|
-
"v2", :
|
108
|
-
|
109
|
-
|
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
|
-
|
112
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
91
|
-
|
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
|