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,30 +1,28 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::V2::Organization do
4
- let(:client) { fake_client }
3
+ module CFoundry
4
+ module V2
5
+ describe Organization do
6
+ let(:client) { build(:client) }
7
+ let(:organization) { build(:organization, :client => client) }
5
8
 
6
- subject { CFoundry::V2::Organization.new("organization-1", client) }
9
+ it_behaves_like "a summarizeable model" do
10
+ subject { organization }
11
+ let(:summary_attributes) { {:name => "fizzbuzz"} }
12
+ end
7
13
 
8
- describe "summarization" do
9
- let(:mymodel) { CFoundry::V2::Organization }
10
- let(:myobject) { fake(:organization) }
11
- let(:summary_attributes) { { :name => "fizzbuzz" } }
14
+ it "has quota_definition" do
15
+ quota = build(:quota_definition)
16
+ organization.quota_definition = quota
17
+ expect(organization.quota_definition).to eq(quota)
18
+ end
12
19
 
13
- subject { myobject }
14
-
15
- it_behaves_like "a summarizeable model"
16
- end
17
-
18
- it "has quota_definition" do
19
- quota = fake(:quota_definition)
20
- subject.quota_definition = quota
21
- expect(subject.quota_definition).to eq(quota)
22
- end
23
-
24
- it "has billing_enabled" do
25
- [true, false].each do |v|
26
- subject.billing_enabled = v
27
- expect(subject.billing_enabled).to eq(v)
20
+ it "has billing_enabled" do
21
+ [true, false].each do |v|
22
+ organization.billing_enabled = v
23
+ expect(organization.billing_enabled).to eq(v)
24
+ end
25
+ end
28
26
  end
29
27
  end
30
28
  end
@@ -1,52 +1,50 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::V2::QuotaDefinition do
4
- let(:client) { fake_client }
5
-
6
- subject { CFoundry::V2::QuotaDefinition.new("quota-definition-1", client) }
7
-
8
- it "has guid" do
9
- expect(subject.guid).to eq("quota-definition-1")
10
- end
11
-
12
- it "has name" do
13
- subject.name = "name"
14
- expect(subject.name).to eq("name")
15
- end
16
-
17
- it "has non_basic_services_allowed" do
18
- [true, false].each do |v|
19
- subject.non_basic_services_allowed = v
20
- expect(subject.non_basic_services_allowed).to eq(v)
21
- end
22
- end
23
-
24
- it "has total_services" do
25
- [0, 1].each do |v|
26
- subject.total_services = v
27
- expect(subject.total_services).to eq(v)
28
- end
29
- end
30
-
31
- it "has total_services" do
32
- [0, 1].each do |v|
33
- subject.total_services = v
34
- expect(subject.total_services).to eq(v)
35
- end
36
- end
37
-
38
- describe "querying" do
39
- let(:foo) { fake(:quota_definition, :name => "foo") }
40
- let(:bar) { fake(:quota_definition, :name => "bar") }
41
- let(:baz) { fake(:quota_definition, :name => "baz") }
42
-
43
- let(:quota_definitions) { [foo, bar, baz] }
44
-
45
- let(:client) { fake_client :quota_definitions => quota_definitions }
46
-
47
- it "is queryable by name" do
48
- quota = quota_definitions.last
49
- expect(client.quota_definition_by_name("bar")).to eq(bar)
3
+ module CFoundry
4
+ module V2
5
+ describe QuotaDefinition do
6
+ let(:quota_definition) { build(:quota_definition) }
7
+
8
+ it "has guid" do
9
+ quota_definition.guid = "quota-definition-1"
10
+ expect(quota_definition.guid).to eq("quota-definition-1")
11
+ end
12
+
13
+ it "has name" do
14
+ quota_definition.name = "name"
15
+ expect(quota_definition.name).to eq("name")
16
+ end
17
+
18
+ it "has non_basic_services_allowed" do
19
+ [true, false].each do |v|
20
+ quota_definition.non_basic_services_allowed = v
21
+ expect(quota_definition.non_basic_services_allowed).to eq(v)
22
+ end
23
+ end
24
+
25
+ it "has total_services" do
26
+ [0, 1].each do |v|
27
+ quota_definition.total_services = v
28
+ expect(quota_definition.total_services).to eq(v)
29
+ end
30
+ end
31
+
32
+ it "has total_services" do
33
+ [0, 1].each do |v|
34
+ quota_definition.total_services = v
35
+ expect(quota_definition.total_services).to eq(v)
36
+ end
37
+ end
38
+
39
+ describe "querying" do
40
+ let(:client) { build(:client) }
41
+
42
+ it "is queryable by name" do
43
+ mock(client).quota_definitions({:query=>[:name, "quota-name"]}) {[]}
44
+
45
+ client.quota_definition_by_name("quota-name")
46
+ end
47
+ end
50
48
  end
51
49
  end
52
50
  end
@@ -1,38 +1,41 @@
1
1
  # encoding: UTF-8
2
- require 'spec_helper'
2
+ require "spec_helper"
3
3
 
4
- module CFoundry::V2
5
- describe Route do
6
- subject { Route.new(nil, fake_client) }
4
+ module CFoundry
5
+ module V2
6
+ describe Route do
7
+ let(:route) { build(:route) }
8
+ subject { route }
7
9
 
8
- describe "validations" do
9
- it { should validate_presence_of(:domain) }
10
- it { should validate_presence_of(:space) }
10
+ describe "validations" do
11
+ it { should validate_presence_of(:domain) }
12
+ it { should validate_presence_of(:space) }
11
13
 
12
- # http://tools.ietf.org/html/rfc1035
13
- it "only allows host names according to RFC1035" do
14
- message = "can only include a-z, 0-9 and -"
14
+ # http://tools.ietf.org/html/rfc1035
15
+ it "only allows host names according to RFC1035" do
16
+ message = "can only include a-z, 0-9 and -"
15
17
 
16
- subject.should allow_value("a", "starts-with-letter", "includes-9-digits", "ends-with-letter",
17
- "ends-with-digit-9", "can--have--consecutive---dashes", "allows-UPPERCASE-chars").for(:host)
18
+ route.should allow_value("a", "starts-with-letter", "includes-9-digits", "ends-with-letter",
19
+ "ends-with-digit-9", "can--have--consecutive---dashes", "allows-UPPERCASE-chars").for(:host)
18
20
 
19
- ["-must-start-with-letter", "9must-start-with-letter", "must-not-end-with-dash-", "must-not-include-punctuation-chars-@\#$%^&*()",
20
- "must-not-include-special-chars-ä", "must.not.include.dots"].each do |bad_value|
21
- subject.should_not allow_value(bad_value).for(:host).with_message(message)
22
- end
21
+ ["-must-start-with-letter", "9must-start-with-letter", "must-not-end-with-dash-", "must-not-include-punctuation-chars-@\#$%^&*()",
22
+ "must-not-include-special-chars-ä", "must.not.include.dots"].each do |bad_value|
23
+ route.should_not allow_value(bad_value).for(:host).with_message(message)
24
+ end
23
25
 
24
- subject.should ensure_length_of(:host).is_at_most(63)
26
+ route.should ensure_length_of(:host).is_at_most(63)
27
+ end
25
28
  end
26
- end
27
29
 
28
- describe "errors" do
29
- before do
30
- stub(subject).create! { raise CFoundry::RouteHostTaken.new("the host is taken", 210003) }
31
- end
30
+ describe "errors" do
31
+ before do
32
+ stub(route).create! { raise CFoundry::RouteHostTaken.new("the host is taken", 210003) }
33
+ end
32
34
 
33
- it "populates errors on host" do
34
- subject.create
35
- subject.errors[:host].first.should =~ /the host is taken/i
35
+ it "populates errors on host" do
36
+ route.create
37
+ route.errors[:host].first.should =~ /the host is taken/i
38
+ end
36
39
  end
37
40
  end
38
41
  end
@@ -1,15 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
- describe CFoundry::V2::Space do
4
- let(:client) { fake_client }
5
-
6
- describe 'summarization' do
7
- let(:mymodel) { CFoundry::V2::Space }
8
- let(:myobject) { fake(:space) }
9
- let(:summary_attributes) { { :name => "fizzbuzz" } }
10
-
11
- subject { myobject }
12
-
13
- it_behaves_like 'a summarizeable model'
3
+ module CFoundry
4
+ module V2
5
+ describe Space do
6
+ it_behaves_like "a summarizeable model" do
7
+ let(:summary_attributes) { {:name => "fizzbuzz"} }
8
+ let(:client) { build(:client) }
9
+ subject { build(:space, :client => client) }
10
+ end
11
+ end
14
12
  end
15
13
  end
@@ -1,92 +1,94 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe CFoundry::Validator do
4
- subject { described_class }
3
+ module CFoundry
4
+ describe Validator do
5
+ let(:validator) { described_class }
5
6
 
6
- describe 'value_matches?' do
7
- it 'returns true on nil values' do
8
- subject.value_matches?(nil, :something).should be_true
9
- end
7
+ describe "value_matches?" do
8
+ it "returns true on nil values" do
9
+ validator.value_matches?(nil, :something).should be_true
10
+ end
10
11
 
11
- context 'with a type of Class' do
12
- it 'returns true when value is of type class' do
13
- subject.value_matches?(1, Integer).should be_true
12
+ context "with a type of Class" do
13
+ it "returns true when value is of type class" do
14
+ validator.value_matches?(1, Integer).should be_true
15
+ end
14
16
  end
15
- end
16
17
 
17
- context 'with a Regex' do
18
- it 'returns true when the regex matches' do
19
- subject.value_matches?('value', /lue/).should == true
18
+ context "with a Regex" do
19
+ it "returns true when the regex matches" do
20
+ validator.value_matches?("value", /lue/).should == true
21
+ end
20
22
  end
21
- end
22
23
 
23
- context 'with type of url' do
24
- it 'requires http or https urls' do
25
- subject.value_matches?('http:whatever', :url).should be_true
26
- subject.value_matches?('https:whatever', :url).should be_true
27
- subject.value_matches?('htt_no:whatever', :url).should be_false
24
+ context "with type of url" do
25
+ it "requires http or https urls" do
26
+ validator.value_matches?("http:whatever", :url).should be_true
27
+ validator.value_matches?("https:whatever", :url).should be_true
28
+ validator.value_matches?("htt_no:whatever", :url).should be_false
29
+ end
28
30
  end
29
- end
30
31
 
31
- context 'with type of https_url' do
32
- it 'requires http or https urls' do
33
- subject.value_matches?('https:whatever', :https_url).should be_true
34
- subject.value_matches?('http:whatever', :https_url).should be_false
32
+ context "with type of https_url" do
33
+ it "requires http or https urls" do
34
+ validator.value_matches?("https:whatever", :https_url).should be_true
35
+ validator.value_matches?("http:whatever", :https_url).should be_false
36
+ end
35
37
  end
36
- end
37
38
 
38
- context 'with type boolean' do
39
- it 'returns true on presence of true or false' do
40
- subject.value_matches?(true, :boolean).should be_true
41
- subject.value_matches?(false, :boolean).should be_true
42
- subject.value_matches?('no boolean', :boolean).should be_false
39
+ context "with type boolean" do
40
+ it "returns true on presence of true or false" do
41
+ validator.value_matches?(true, :boolean).should be_true
42
+ validator.value_matches?(false, :boolean).should be_true
43
+ validator.value_matches?("no boolean", :boolean).should be_false
44
+ end
43
45
  end
44
- end
45
46
 
46
- context 'with an Array' do
47
- it 'returns true when all elements are of same type' do
48
- subject.value_matches?(['https:whatever'], [String]).should be_true
49
- subject.value_matches?(['https:whatever'], [Integer]).should be_false
47
+ context "with an Array" do
48
+ it "returns true when all elements are of same type" do
49
+ validator.value_matches?(["https:whatever"], [String]).should be_true
50
+ validator.value_matches?(["https:whatever"], [Integer]).should be_false
51
+ end
50
52
  end
51
- end
52
53
 
53
- context 'with a hash' do
54
- it 'returns true when specified types match' do
55
- subject.value_matches?({:name => "thing"}, {:name => String}).should be_true
56
- subject.value_matches?({:name => "thing", :unspecified => 1}, {:name => String}).should be_true
57
- subject.value_matches?({:name => 1}, {:name => String}).should be_false
54
+ context "with a hash" do
55
+ it "returns true when specified types match" do
56
+ validator.value_matches?({:name => "thing"}, {:name => String}).should be_true
57
+ validator.value_matches?({:name => "thing", :unspecified => 1}, {:name => String}).should be_true
58
+ validator.value_matches?({:name => 1}, {:name => String}).should be_false
59
+ end
58
60
  end
59
- end
60
61
 
61
- it 'returns true when type is nil' do
62
- subject.value_matches?('some value', nil).should be_true
63
- end
62
+ it "returns true when type is nil" do
63
+ validator.value_matches?("some value", nil).should be_true
64
+ end
64
65
 
65
- context 'with a symbol' do
66
- it 'returns true when the value is of specified type' do
67
- subject.value_matches?('some value', :string).should be_true
68
- subject.value_matches?('some value', :integer).should be_false
66
+ context "with a symbol" do
67
+ it "returns true when the value is of specified type" do
68
+ validator.value_matches?("some value", :string).should be_true
69
+ validator.value_matches?("some value", :integer).should be_false
70
+ end
69
71
  end
70
72
  end
71
- end
72
73
 
73
- describe 'validate_type' do
74
- it 'passes validation with a nil value' do
75
- expect {
76
- subject.validate_type(nil, :whatever)
77
- }.to_not raise_error
78
- end
74
+ describe "validate_type" do
75
+ it "passes validation with a nil value" do
76
+ expect {
77
+ validator.validate_type(nil, :whatever)
78
+ }.to_not raise_error
79
+ end
79
80
 
80
- it 'passes validation when the value matches' do
81
- expect {
82
- subject.validate_type('string', :string)
83
- }.to_not raise_error
84
- end
81
+ it "passes validation when the value matches" do
82
+ expect {
83
+ validator.validate_type("string", :string)
84
+ }.to_not raise_error
85
+ end
85
86
 
86
- it 'raises a validation error when value does not match' do
87
- expect {
88
- subject.validate_type('string', :integer)
89
- }.to raise_error(CFoundry::Mismatch)
87
+ it "raises a validation error when value does not match" do
88
+ expect {
89
+ validator.validate_type("string", :integer)
90
+ }.to raise_error(CFoundry::Mismatch)
91
+ end
90
92
  end
91
93
  end
92
- end
94
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :app_event, :class => CFoundry::V2::AppEvent do
3
+ sequence(:guid) { |n| "app-event-guid-#{n}" }
4
+
5
+ initialize_with { new(guid, build(:client)) }
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :app, :class => CFoundry::V2::App do
3
+ sequence(:guid) { |n| "app-guid-#{n}" }
4
+ ignore do
5
+ manifest { {} }
6
+ client { FactoryGirl.build(:client) }
7
+ end
8
+
9
+ initialize_with { new(guid, client, manifest) }
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :client, :class => CFoundry::V2::Client do
3
+
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :domain, :class => CFoundry::V2::Domain do
3
+ sequence(:guid) { |n| "domain-guid-#{n}" }
4
+
5
+ initialize_with { new(guid, build(:client)) }
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :organization, :class => CFoundry::V2::Organization do
3
+ sequence(:guid) { |n| "organization-guid-#{n}" }
4
+
5
+ ignore do
6
+ client { FactoryGirl.build(:client) }
7
+ end
8
+
9
+ initialize_with { new(guid, client) }
10
+ end
11
+ end