cfoundry 1.0.0 → 1.1.0.rc1
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.rb +3 -0
- data/lib/cfoundry/client.rb +1 -0
- data/lib/cfoundry/v2/app.rb +4 -30
- data/lib/cfoundry/v2/app_event.rb +12 -0
- data/lib/cfoundry/v2/model.rb +41 -5
- data/lib/cfoundry/v2/route.rb +9 -0
- data/lib/cfoundry/validator.rb +3 -1
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/v2/app_event_spec.rb +78 -0
- data/spec/cfoundry/v2/app_spec.rb +19 -0
- data/spec/cfoundry/v2/model_spec.rb +132 -6
- data/spec/cfoundry/v2/route_spec.rb +37 -0
- data/spec/cfoundry/validator_spec.rb +92 -0
- data/spec/fixtures/fake_cc_route.json +16 -0
- data/spec/spec_helper.rb +1 -0
- metadata +35 -10
data/lib/cfoundry.rb
CHANGED
data/lib/cfoundry/client.rb
CHANGED
data/lib/cfoundry/v2/app.rb
CHANGED
@@ -31,6 +31,7 @@ module CFoundry::V2
|
|
31
31
|
attribute :debug, :string, :default => nil
|
32
32
|
to_many :service_bindings
|
33
33
|
to_many :routes
|
34
|
+
to_many :app_events
|
34
35
|
|
35
36
|
scoped_to_space
|
36
37
|
|
@@ -46,6 +47,9 @@ module CFoundry::V2
|
|
46
47
|
|
47
48
|
private :environment_json
|
48
49
|
|
50
|
+
alias :events :app_events
|
51
|
+
alias :events= :app_events=
|
52
|
+
|
49
53
|
def instances
|
50
54
|
@client.base.instances(@guid).collect do |i, m|
|
51
55
|
Instance.new(self, i.to_s, @client, m)
|
@@ -99,36 +103,6 @@ module CFoundry::V2
|
|
99
103
|
end
|
100
104
|
alias :urls= :uris=
|
101
105
|
|
102
|
-
def create_routes(*uris)
|
103
|
-
uris.each do |uri|
|
104
|
-
host, domain_name = uri.split(".", 2)
|
105
|
-
|
106
|
-
domain =
|
107
|
-
@client.current_space.domains.find { |d|
|
108
|
-
d.name == domain_name
|
109
|
-
}
|
110
|
-
|
111
|
-
unless domain
|
112
|
-
raise CFoundry::Error, "Invalid domain '#{domain_name}'"
|
113
|
-
end
|
114
|
-
|
115
|
-
route = @client.routes.find { |r|
|
116
|
-
r.host == host && r.domain == domain
|
117
|
-
}
|
118
|
-
|
119
|
-
unless route
|
120
|
-
route = @client.route
|
121
|
-
route.host = host
|
122
|
-
route.domain = domain
|
123
|
-
route.space = space
|
124
|
-
route.create!
|
125
|
-
end
|
126
|
-
|
127
|
-
add_route(route)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
alias :create_route :create_routes
|
131
|
-
|
132
106
|
def uri
|
133
107
|
if uris = @cache[:uris]
|
134
108
|
return uris.first
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "cfoundry/v2/model"
|
2
|
+
|
3
|
+
module CFoundry::V2
|
4
|
+
class AppEvent < Model
|
5
|
+
to_one :app
|
6
|
+
|
7
|
+
attribute :instance_guid, :string
|
8
|
+
attribute :instance_index, :integer
|
9
|
+
attribute :exit_status, :integer
|
10
|
+
attribute :exit_description, :string, :default => ""
|
11
|
+
end
|
12
|
+
end
|
data/lib/cfoundry/v2/model.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require "multi_json"
|
2
|
-
|
3
2
|
require "cfoundry/v2/model_magic"
|
4
3
|
|
5
|
-
|
6
4
|
module CFoundry::V2
|
7
5
|
class Model
|
6
|
+
include ActiveModel::Validations
|
7
|
+
|
8
8
|
@@objects = {}
|
9
9
|
|
10
10
|
extend ModelMagic
|
@@ -64,6 +64,22 @@ module CFoundry::V2
|
|
64
64
|
@changes = {}
|
65
65
|
end
|
66
66
|
|
67
|
+
def create
|
68
|
+
create!
|
69
|
+
true
|
70
|
+
rescue CFoundry::APIError => e
|
71
|
+
if e.instance_of? CFoundry::APIError
|
72
|
+
errors.add(:base, :cc_client)
|
73
|
+
else
|
74
|
+
errors.add(attribute_for_error(e), e.message)
|
75
|
+
end
|
76
|
+
false
|
77
|
+
end
|
78
|
+
|
79
|
+
def attribute_for_error(error)
|
80
|
+
:base
|
81
|
+
end
|
82
|
+
|
67
83
|
# this does a bit of extra processing to allow for
|
68
84
|
# `delete!' followed by `create!'
|
69
85
|
def create!
|
@@ -76,8 +92,8 @@ module CFoundry::V2
|
|
76
92
|
if v.is_a?(Hash) && v.key?(:metadata)
|
77
93
|
# skip; there's a _guid attribute already
|
78
94
|
elsif v.is_a?(Array) && !v.empty? && v.all? { |x|
|
79
|
-
|
80
|
-
|
95
|
+
x.is_a?(Hash) && x.key?(:metadata)
|
96
|
+
}
|
81
97
|
singular = k.to_s.sub(/s$/, "")
|
82
98
|
|
83
99
|
payload[:"#{singular}_guids"] = v.collect do |x|
|
@@ -118,10 +134,21 @@ module CFoundry::V2
|
|
118
134
|
true
|
119
135
|
end
|
120
136
|
|
137
|
+
def delete
|
138
|
+
delete!
|
139
|
+
rescue CFoundry::APIError => e
|
140
|
+
if e.instance_of? CFoundry::APIError
|
141
|
+
errors.add(:base, :cc_client)
|
142
|
+
else
|
143
|
+
errors.add(attribute_for_error(e), e.message)
|
144
|
+
end
|
145
|
+
false
|
146
|
+
end
|
147
|
+
|
121
148
|
def delete!(options = {})
|
122
149
|
@client.base.delete("v2", plural_object_name, guid, :params => options)
|
123
150
|
|
124
|
-
@
|
151
|
+
@deleted = true
|
125
152
|
|
126
153
|
@diff.clear
|
127
154
|
|
@@ -132,6 +159,14 @@ module CFoundry::V2
|
|
132
159
|
true
|
133
160
|
end
|
134
161
|
|
162
|
+
def to_key
|
163
|
+
persisted? ? [@guid] : nil
|
164
|
+
end
|
165
|
+
|
166
|
+
def persisted?
|
167
|
+
@guid && !@deleted
|
168
|
+
end
|
169
|
+
|
135
170
|
def exists?
|
136
171
|
invalidate!
|
137
172
|
manifest
|
@@ -147,6 +182,7 @@ module CFoundry::V2
|
|
147
182
|
def eql?(other)
|
148
183
|
other.is_a?(self.class) && @guid == other.guid
|
149
184
|
end
|
185
|
+
|
150
186
|
alias :== :eql?
|
151
187
|
|
152
188
|
def hash
|
data/lib/cfoundry/v2/route.rb
CHANGED
@@ -3,6 +3,9 @@ require "cfoundry/v2/model"
|
|
3
3
|
module CFoundry::V2
|
4
4
|
class Route < Model
|
5
5
|
attribute :host, :string
|
6
|
+
validates_format_of :host, :with => /\A[a-z]+([a-z0-9\-]*[a-z0-9]+)?\Z/i
|
7
|
+
validates_length_of :host, :maximum => 63
|
8
|
+
validates_presence_of :domain
|
6
9
|
to_one :domain
|
7
10
|
to_one :space
|
8
11
|
|
@@ -11,5 +14,11 @@ module CFoundry::V2
|
|
11
14
|
def name
|
12
15
|
"#{host}.#{domain.name}"
|
13
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def attribute_for_error(error)
|
21
|
+
error.is_a?(CFoundry::RouteHostTaken) ? :host : :base
|
22
|
+
end
|
14
23
|
end
|
15
24
|
end
|
data/lib/cfoundry/validator.rb
CHANGED
@@ -2,11 +2,13 @@ module CFoundry
|
|
2
2
|
module Validator
|
3
3
|
class << self
|
4
4
|
def value_matches?(val, type)
|
5
|
+
return true if val.nil?
|
6
|
+
|
5
7
|
case type
|
6
8
|
when Class
|
7
9
|
val.is_a?(type)
|
8
10
|
when Regexp
|
9
|
-
val.is_a?(String) && val =~ type
|
11
|
+
val.is_a?(String) && !!(val =~ type)
|
10
12
|
when :url
|
11
13
|
value_matches?(val, URI::regexp(%w(http https)))
|
12
14
|
when :https_url
|
data/lib/cfoundry/version.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe CFoundry::V2::AppEvent do
|
4
|
+
let(:client) { fake_client }
|
5
|
+
|
6
|
+
let(:app) { fake :app }
|
7
|
+
|
8
|
+
subject { described_class.new("app-event-1", client) }
|
9
|
+
|
10
|
+
it "has an app" do
|
11
|
+
subject.app = app
|
12
|
+
expect(subject.app).to eq(app)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#instance_guid" do
|
16
|
+
it "has an instance guid" do
|
17
|
+
subject.instance_guid = "foo"
|
18
|
+
expect(subject.instance_guid).to eq("foo")
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when an invalid value is assigned" do
|
22
|
+
it "raises a Mismatch exception" do
|
23
|
+
expect {
|
24
|
+
subject.instance_guid = 123
|
25
|
+
}.to raise_error(CFoundry::Mismatch)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#instance_index" do
|
31
|
+
it "has an instance index" do
|
32
|
+
subject.instance_index = 123
|
33
|
+
expect(subject.instance_index).to eq(123)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when an invalid value is assigned" do
|
37
|
+
it "raises a Mismatch exception" do
|
38
|
+
expect {
|
39
|
+
subject.instance_index = "wrong"
|
40
|
+
}.to raise_error(CFoundry::Mismatch)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#exit_status" do
|
46
|
+
it "has an instance index" do
|
47
|
+
subject.exit_status = 123
|
48
|
+
expect(subject.exit_status).to eq(123)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when an invalid value is assigned" do
|
52
|
+
it "raises a Mismatch exception" do
|
53
|
+
expect {
|
54
|
+
subject.exit_status = "wrong"
|
55
|
+
}.to raise_error(CFoundry::Mismatch)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#exit_description" do
|
61
|
+
it "defaults to an empty string" do
|
62
|
+
expect(subject.fake.exit_description).to eq("")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has an instance guid" do
|
66
|
+
subject.exit_description = "foo"
|
67
|
+
expect(subject.exit_description).to eq("foo")
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when an invalid value is assigned" do
|
71
|
+
it "raises a Mismatch exception" do
|
72
|
+
expect {
|
73
|
+
subject.exit_description = 123
|
74
|
+
}.to raise_error(CFoundry::Mismatch)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -3,6 +3,25 @@ require "spec_helper"
|
|
3
3
|
describe CFoundry::V2::App do
|
4
4
|
let(:client) { fake_client }
|
5
5
|
|
6
|
+
subject { described_class.new("app-1", client) }
|
7
|
+
|
8
|
+
describe "#events" do
|
9
|
+
let(:events) { [fake(:app_event)] }
|
10
|
+
|
11
|
+
it "has events" do
|
12
|
+
subject.events = events
|
13
|
+
expect(subject.events).to eq(events)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when an invalid value is assigned" do
|
17
|
+
it "raises a Mismatch exception" do
|
18
|
+
expect {
|
19
|
+
subject.events = [fake(:organization)]
|
20
|
+
}.to raise_error(CFoundry::Mismatch)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
6
25
|
describe "environment" do
|
7
26
|
let(:app) { fake :app, :env => { "FOO" => "1" } }
|
8
27
|
|
@@ -7,11 +7,58 @@ describe CFoundry::V2::Model do
|
|
7
7
|
let(:klass) {
|
8
8
|
fake_model do
|
9
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
|
10
14
|
end
|
11
15
|
}
|
12
16
|
|
13
17
|
subject { klass.new(guid, client, manifest) }
|
14
18
|
|
19
|
+
describe "create" do
|
20
|
+
it "uses #create!" do
|
21
|
+
mock(subject).create!
|
22
|
+
subject.create
|
23
|
+
end
|
24
|
+
|
25
|
+
context "without errors" do
|
26
|
+
it "returns true" do
|
27
|
+
mock(subject).create!
|
28
|
+
subject.create.should == true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
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
|
37
|
+
|
38
|
+
it "does not raise an exception" do
|
39
|
+
expect { subject.create }.to_not raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns false" do
|
43
|
+
subject.create.should == false
|
44
|
+
end
|
45
|
+
|
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
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
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
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
15
62
|
describe "#create!" do
|
16
63
|
before do
|
17
64
|
stub(client.base).post {
|
@@ -68,6 +115,49 @@ describe CFoundry::V2::Model do
|
|
68
115
|
end
|
69
116
|
end
|
70
117
|
|
118
|
+
describe "delete" do
|
119
|
+
it "uses #delete!" do
|
120
|
+
mock(subject).delete! { true }
|
121
|
+
subject.delete
|
122
|
+
end
|
123
|
+
|
124
|
+
context "without errors" do
|
125
|
+
it "returns true" do
|
126
|
+
mock(subject).delete! { true }
|
127
|
+
subject.delete.should == true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "with errors" do
|
132
|
+
before do
|
133
|
+
stub(subject.class).model_name { ActiveModel::Name.new(subject, nil, "abstract_model") }
|
134
|
+
stub(subject).delete! { raise CFoundry::APIError.new("HELP") }
|
135
|
+
end
|
136
|
+
|
137
|
+
it "does not raise an exception" do
|
138
|
+
expect { subject.delete }.to_not raise_error
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns false" do
|
142
|
+
subject.delete.should == false
|
143
|
+
end
|
144
|
+
|
145
|
+
context "without model-specific errors" do
|
146
|
+
it "adds generic base error " do
|
147
|
+
subject.delete
|
148
|
+
subject.errors.full_messages.first.should =~ /cloud controller reported an error/i
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "with model-specific errors" do
|
153
|
+
it "does not set the generic error on base" do
|
154
|
+
subject.delete
|
155
|
+
subject.errors.size.should == 1
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
71
161
|
describe "#delete!" do
|
72
162
|
before { stub(client.base).delete }
|
73
163
|
|
@@ -87,12 +177,6 @@ describe CFoundry::V2::Model do
|
|
87
177
|
end
|
88
178
|
end
|
89
179
|
|
90
|
-
it "clears its guid" do
|
91
|
-
subject.guid.should be_present
|
92
|
-
subject.delete!
|
93
|
-
subject.guid.should_not be_present
|
94
|
-
end
|
95
|
-
|
96
180
|
it "clears its manifest metadata" do
|
97
181
|
subject.manifest.should have_key(:metadata)
|
98
182
|
subject.delete!
|
@@ -113,6 +197,48 @@ describe CFoundry::V2::Model do
|
|
113
197
|
ex.message.should_not =~ /\?/
|
114
198
|
end
|
115
199
|
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#to_key" do
|
203
|
+
context "when persisted" do
|
204
|
+
it "returns an enumerable containing the guid" do
|
205
|
+
subject.to_key.should respond_to(:each)
|
206
|
+
subject.to_key.first.should == guid
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "when not persisted" do
|
211
|
+
let(:guid) { nil }
|
116
212
|
|
213
|
+
it "returns nil" do
|
214
|
+
subject.to_key.should be_nil
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#persisted?" do
|
220
|
+
context "on a new object" do
|
221
|
+
let(:guid) { nil }
|
222
|
+
it "returns false" do
|
223
|
+
subject.should_not be_persisted
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "on an object with a guid" do
|
228
|
+
it "returns false" do
|
229
|
+
subject.should be_persisted
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context "on an object that has been deleted" do
|
234
|
+
before do
|
235
|
+
stub(client.base).delete
|
236
|
+
subject.delete
|
237
|
+
end
|
238
|
+
|
239
|
+
it "returns false" do
|
240
|
+
subject.should_not be_persisted
|
241
|
+
end
|
242
|
+
end
|
117
243
|
end
|
118
244
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module CFoundry::V2
|
4
|
+
describe Route do
|
5
|
+
subject { Route.new(nil, nil) }
|
6
|
+
|
7
|
+
describe "validations" do
|
8
|
+
it { should validate_presence_of(:domain) }
|
9
|
+
|
10
|
+
# http://tools.ietf.org/html/rfc1035
|
11
|
+
it "only allows host names according to RFC1035" do
|
12
|
+
message = "can only include a-z, 0-9 and -"
|
13
|
+
|
14
|
+
subject.should allow_value("a", "starts-with-letter", "includes-9-digits", "ends-with-letter",
|
15
|
+
"ends-with-digit-9", "can--have--consecutive---dashes", "allows-UPPERCASE-chars").for(:host)
|
16
|
+
|
17
|
+
["-must-start-with-letter", "9must-start-with-letter", "must-not-end-with-dash-", "must-not-include-punctuation-chars-@\#$%^&*()",
|
18
|
+
"must-not-include-special-chars-ä", "must.not.include.dots"].each do |bad_value|
|
19
|
+
subject.should_not allow_value(bad_value).for(:host).with_message(message)
|
20
|
+
end
|
21
|
+
|
22
|
+
subject.should ensure_length_of(:host).is_at_most(63)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "errors" do
|
27
|
+
before do
|
28
|
+
stub(subject).create! { raise CFoundry::RouteHostTaken.new("the host is taken", 210003) }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "populates errors on host" do
|
32
|
+
subject.create
|
33
|
+
subject.errors[:host].first.should =~ /the host is taken/i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CFoundry::Validator do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
describe 'value_matches?' do
|
7
|
+
it 'returns true on nil values' do
|
8
|
+
subject.value_matches?(nil, :something).should be_true
|
9
|
+
end
|
10
|
+
|
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with a Regex' do
|
18
|
+
it 'returns true when the regex matches' do
|
19
|
+
subject.value_matches?('value', /lue/).should == true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
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
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
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
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
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
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
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
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
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
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns true when type is nil' do
|
62
|
+
subject.value_matches?('some value', nil).should be_true
|
63
|
+
end
|
64
|
+
|
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
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
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
|
79
|
+
|
80
|
+
it 'passes validation when the value matches' do
|
81
|
+
expect {
|
82
|
+
subject.validate_type('string', :string)
|
83
|
+
}.to_not raise_error
|
84
|
+
end
|
85
|
+
|
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)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"metadata": {
|
3
|
+
"guid": "route-id-1",
|
4
|
+
"url": "/v2/routes/route-id-1",
|
5
|
+
"created_at": "2013-05-16 20:03:48 +0000",
|
6
|
+
"updated_at": null
|
7
|
+
},
|
8
|
+
"entity": {
|
9
|
+
"host": "route-1",
|
10
|
+
"domain_guid": "domain-id-1",
|
11
|
+
"space_guid": "space-id-1",
|
12
|
+
"apps_url": "/v2/routes/route-id-1/apps",
|
13
|
+
"domain_url": "/v2/domains/domain-id-1",
|
14
|
+
"space_url": "/v2/spaces/space-id-1"
|
15
|
+
}
|
16
|
+
}
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,7 @@ require "timecop"
|
|
8
8
|
require "active_support"
|
9
9
|
require "active_support/core_ext"
|
10
10
|
require "cc_api_stub"
|
11
|
+
require "shoulda/matchers/integrations/rspec" # requiring all of shoulda matchers makes test unit run
|
11
12
|
|
12
13
|
Dir[File.expand_path('../{support,fakes}/**/*.rb', __FILE__)].each do |file|
|
13
14
|
require file
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0.rc1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Cloud Foundry Team
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-05-
|
13
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multipart-post
|
@@ -76,6 +76,22 @@ dependencies:
|
|
76
76
|
- - ~>
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: 1.3.10
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: activemodel
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 3.2.13
|
87
|
+
type: :runtime
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 3.2.13
|
79
95
|
- !ruby/object:Gem::Dependency
|
80
96
|
name: rake
|
81
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,13 +205,13 @@ dependencies:
|
|
189
205
|
- !ruby/object:Gem::Version
|
190
206
|
version: 1.7.7
|
191
207
|
- !ruby/object:Gem::Dependency
|
192
|
-
name:
|
208
|
+
name: shoulda-matchers
|
193
209
|
requirement: !ruby/object:Gem::Requirement
|
194
210
|
none: false
|
195
211
|
requirements:
|
196
212
|
- - ~>
|
197
213
|
- !ruby/object:Gem::Version
|
198
|
-
version:
|
214
|
+
version: 1.5.6
|
199
215
|
type: :development
|
200
216
|
prerelease: false
|
201
217
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -203,7 +219,7 @@ dependencies:
|
|
203
219
|
requirements:
|
204
220
|
- - ~>
|
205
221
|
- !ruby/object:Gem::Version
|
206
|
-
version:
|
222
|
+
version: 1.5.6
|
207
223
|
description:
|
208
224
|
email:
|
209
225
|
- vcap-dev@googlegroups.com
|
@@ -240,6 +256,7 @@ files:
|
|
240
256
|
- lib/cfoundry/uaaclient.rb
|
241
257
|
- lib/cfoundry/upload_helpers.rb
|
242
258
|
- lib/cfoundry/v2/app.rb
|
259
|
+
- lib/cfoundry/v2/app_event.rb
|
243
260
|
- lib/cfoundry/v2/base.rb
|
244
261
|
- lib/cfoundry/v2/client.rb
|
245
262
|
- lib/cfoundry/v2/domain.rb
|
@@ -284,6 +301,7 @@ files:
|
|
284
301
|
- spec/cfoundry/trace_helpers_spec.rb
|
285
302
|
- spec/cfoundry/uaaclient_spec.rb
|
286
303
|
- spec/cfoundry/upload_helpers_spec.rb
|
304
|
+
- spec/cfoundry/v2/app_event_spec.rb
|
287
305
|
- spec/cfoundry/v2/app_spec.rb
|
288
306
|
- spec/cfoundry/v2/base_spec.rb
|
289
307
|
- spec/cfoundry/v2/client_spec.rb
|
@@ -292,7 +310,9 @@ files:
|
|
292
310
|
- spec/cfoundry/v2/model_spec.rb
|
293
311
|
- spec/cfoundry/v2/organization_spec.rb
|
294
312
|
- spec/cfoundry/v2/quota_definition_spec.rb
|
313
|
+
- spec/cfoundry/v2/route_spec.rb
|
295
314
|
- spec/cfoundry/v2/space_spec.rb
|
315
|
+
- spec/cfoundry/validator_spec.rb
|
296
316
|
- spec/fakes/app_fake.rb
|
297
317
|
- spec/fakes/domain_fake.rb
|
298
318
|
- spec/fakes/framework_fake.rb
|
@@ -336,6 +356,7 @@ files:
|
|
336
356
|
- spec/fixtures/fake_cc_organization_search.json
|
337
357
|
- spec/fixtures/fake_cc_organization_summary.json
|
338
358
|
- spec/fixtures/fake_cc_organization_users.json
|
359
|
+
- spec/fixtures/fake_cc_route.json
|
339
360
|
- spec/fixtures/fake_cc_runtimes.json
|
340
361
|
- spec/fixtures/fake_cc_service_binding.json
|
341
362
|
- spec/fixtures/fake_cc_service_bindings.json
|
@@ -369,16 +390,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
369
390
|
version: '0'
|
370
391
|
segments:
|
371
392
|
- 0
|
372
|
-
hash: -
|
393
|
+
hash: -1889885215026340519
|
373
394
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
374
395
|
none: false
|
375
396
|
requirements:
|
376
|
-
- - ! '
|
397
|
+
- - ! '>'
|
377
398
|
- !ruby/object:Gem::Version
|
378
|
-
version:
|
399
|
+
version: 1.3.1
|
379
400
|
requirements: []
|
380
401
|
rubyforge_project: cfoundry
|
381
|
-
rubygems_version: 1.8.
|
402
|
+
rubygems_version: 1.8.25
|
382
403
|
signing_key:
|
383
404
|
specification_version: 3
|
384
405
|
summary: High-level library for working with the Cloud Foundry API.
|
@@ -404,6 +425,7 @@ test_files:
|
|
404
425
|
- spec/cfoundry/trace_helpers_spec.rb
|
405
426
|
- spec/cfoundry/uaaclient_spec.rb
|
406
427
|
- spec/cfoundry/upload_helpers_spec.rb
|
428
|
+
- spec/cfoundry/v2/app_event_spec.rb
|
407
429
|
- spec/cfoundry/v2/app_spec.rb
|
408
430
|
- spec/cfoundry/v2/base_spec.rb
|
409
431
|
- spec/cfoundry/v2/client_spec.rb
|
@@ -412,7 +434,9 @@ test_files:
|
|
412
434
|
- spec/cfoundry/v2/model_spec.rb
|
413
435
|
- spec/cfoundry/v2/organization_spec.rb
|
414
436
|
- spec/cfoundry/v2/quota_definition_spec.rb
|
437
|
+
- spec/cfoundry/v2/route_spec.rb
|
415
438
|
- spec/cfoundry/v2/space_spec.rb
|
439
|
+
- spec/cfoundry/validator_spec.rb
|
416
440
|
- spec/fakes/app_fake.rb
|
417
441
|
- spec/fakes/domain_fake.rb
|
418
442
|
- spec/fakes/framework_fake.rb
|
@@ -456,6 +480,7 @@ test_files:
|
|
456
480
|
- spec/fixtures/fake_cc_organization_search.json
|
457
481
|
- spec/fixtures/fake_cc_organization_summary.json
|
458
482
|
- spec/fixtures/fake_cc_organization_users.json
|
483
|
+
- spec/fixtures/fake_cc_route.json
|
459
484
|
- spec/fixtures/fake_cc_runtimes.json
|
460
485
|
- spec/fixtures/fake_cc_service_binding.json
|
461
486
|
- spec/fixtures/fake_cc_service_bindings.json
|