cfoundry 0.5.1.rc4 → 0.5.1.rc5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cfoundry/errors.rb +1 -0
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cc_api_stub/organizations_spec.rb +33 -39
- data/spec/support/fake_helper.rb +35 -0
- data/vendor/errors/v2.yml +1 -6
- metadata +3 -3
data/lib/cfoundry/errors.rb
CHANGED
data/lib/cfoundry/version.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
2
4
|
|
3
5
|
describe CcApiStub::Organizations do
|
4
6
|
let(:client) { CFoundry::V2::Client.new }
|
5
7
|
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
8
|
+
describe ".succeed_to_create" do
|
9
|
+
let(:url) { "http://example.com/v2/organizations/" }
|
10
|
+
subject { CcApiStub::Organizations.succeed_to_create }
|
9
11
|
|
10
|
-
|
11
|
-
org.create!.should be_true
|
12
|
-
org.guid.should == 'created-organization-id-1'
|
13
|
-
end
|
12
|
+
it_behaves_like "a stubbed post request"
|
14
13
|
end
|
15
14
|
|
15
|
+
|
16
16
|
describe '.summary_fixture' do
|
17
17
|
it 'returns the fake org' do
|
18
18
|
CcApiStub::Organizations.summary_fixture.should be_a(Hash)
|
@@ -20,41 +20,37 @@ describe CcApiStub::Organizations do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '.fail_to_find' do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
23
|
+
let(:url) { "http://example.com/v2/organizations/9234" }
|
24
|
+
subject { CcApiStub::Organizations.fail_to_find(9234) }
|
25
|
+
|
26
|
+
it_behaves_like "a stubbed get request", :code => 404
|
28
27
|
end
|
29
28
|
|
30
29
|
describe '.succeed_to_load_summary' do
|
31
|
-
|
32
|
-
|
30
|
+
let(:url) { "http://example.com/v2/organizations/9234/summary" }
|
31
|
+
subject { CcApiStub::Organizations.succeed_to_load_summary }
|
32
|
+
|
33
|
+
it_behaves_like "a stubbed get request"
|
34
|
+
|
35
|
+
context "when passed a no_spaces option" do
|
36
|
+
subject { CcApiStub::Organizations.succeed_to_load_summary(:no_spaces => true) }
|
33
37
|
|
34
|
-
|
35
|
-
org.summarize!
|
36
|
-
org.spaces[0].should be_a(CFoundry::V2::Space)
|
38
|
+
it_behaves_like "a stubbed get request", :including_json => { "spaces" => [] }
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
describe '.succeed_to_search' do
|
41
|
-
|
42
|
-
|
43
|
-
CcApiStub::Organizations.succeed_to_search(org_name)
|
43
|
+
let(:url) { "http://example.com/v2/organizations?inline-relations-depth=1&q=name:orgname" }
|
44
|
+
subject { CcApiStub::Organizations.succeed_to_search("orgname") }
|
44
45
|
|
45
|
-
|
46
|
-
org.guid.should == 'organization-id-1'
|
47
|
-
end
|
46
|
+
it_behaves_like "a stubbed get request"
|
48
47
|
end
|
49
48
|
|
50
49
|
describe '.succeed_to_search_none' do
|
51
|
-
|
52
|
-
|
53
|
-
CcApiStub::Organizations.succeed_to_search_none
|
50
|
+
let(:url) { "http://example.com/v2/organizations?inline-relations-depth=1&q=name:orgname" }
|
51
|
+
subject { CcApiStub::Organizations.succeed_to_search_none }
|
54
52
|
|
55
|
-
|
56
|
-
org.should be_nil
|
57
|
-
end
|
53
|
+
it_behaves_like "a stubbed get request"
|
58
54
|
end
|
59
55
|
|
60
56
|
describe '.domains_fixture' do
|
@@ -72,11 +68,10 @@ describe CcApiStub::Organizations do
|
|
72
68
|
end
|
73
69
|
|
74
70
|
describe '.succeed_to_load_domains' do
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
71
|
+
let(:url) { "http://example.com/v2/organizations/3434/domains?inline-relations-depth=1" }
|
72
|
+
subject { CcApiStub::Organizations.succeed_to_load_domains }
|
73
|
+
|
74
|
+
it_behaves_like "a stubbed get request"
|
80
75
|
end
|
81
76
|
|
82
77
|
describe '.users_fixture' do
|
@@ -94,10 +89,9 @@ describe CcApiStub::Organizations do
|
|
94
89
|
end
|
95
90
|
|
96
91
|
describe '.succeed_to_load_users' do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
92
|
+
let(:url) { "http://example.com/v2/organizations/2342/users?inline-relations-depth=1" }
|
93
|
+
subject { CcApiStub::Organizations.succeed_to_load_users }
|
94
|
+
|
95
|
+
it_behaves_like "a stubbed get request"
|
102
96
|
end
|
103
97
|
end
|
data/spec/support/fake_helper.rb
CHANGED
@@ -39,6 +39,7 @@ module Fake
|
|
39
39
|
def fake(attributes = {})
|
40
40
|
fake_attributes(attributes).each do |k, v|
|
41
41
|
send(:"#{k}=", v)
|
42
|
+
setup_reverse_relationship(v)
|
42
43
|
end
|
43
44
|
|
44
45
|
self
|
@@ -114,6 +115,28 @@ module CFoundry::V2
|
|
114
115
|
:guid => random_string("fake-#{object_name}-guid"))
|
115
116
|
end
|
116
117
|
|
118
|
+
def setup_reverse_relationship(v)
|
119
|
+
if v.is_a?(Array)
|
120
|
+
v.each do |x|
|
121
|
+
setup_reverse_relationship(x)
|
122
|
+
end
|
123
|
+
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
return unless v.is_a?(Model)
|
128
|
+
|
129
|
+
relation, type = find_reverse_relationship(v)
|
130
|
+
|
131
|
+
v.client = @client
|
132
|
+
|
133
|
+
if type == :one
|
134
|
+
v.send(:"#{relation}=", self)
|
135
|
+
elsif type == :many
|
136
|
+
v.send(:"#{relation}=", v.send(relation) + [self])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
117
140
|
def find_reverse_relationship(v)
|
118
141
|
singular = object_name
|
119
142
|
plural = plural_object_name
|
@@ -198,4 +221,16 @@ module CFoundry::V2
|
|
198
221
|
end
|
199
222
|
end
|
200
223
|
|
224
|
+
Model.objects.each_value do |klass|
|
225
|
+
klass.to_many_relations.each do |plural, _|
|
226
|
+
Fake.define_many_association(klass, plural)
|
227
|
+
end
|
228
|
+
|
229
|
+
FakeClient.class_eval do
|
230
|
+
plural = klass.plural_object_name
|
231
|
+
|
232
|
+
attr_writer plural
|
233
|
+
Fake.define_many_association(self, plural)
|
234
|
+
end
|
235
|
+
end
|
201
236
|
end
|
data/vendor/errors/v2.yml
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -2275817692
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
9
|
- 1
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 0.5.1.
|
11
|
+
- 5
|
12
|
+
version: 0.5.1.rc5
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Cloud Foundry Team
|