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.
@@ -1,5 +1,6 @@
1
1
  require "net/https"
2
2
  require "multi_json"
3
+ require "yaml"
3
4
 
4
5
  module CFoundry
5
6
  # Base class for CFoundry errors (not from the server).
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.5.1.rc4".freeze
3
+ VERSION = "0.5.1.rc5".freeze
4
4
  end
@@ -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 '.succeed_to_create' do
7
- it 'stubs creation of an organization' do
8
- CcApiStub::Organizations.succeed_to_create
8
+ describe ".succeed_to_create" do
9
+ let(:url) { "http://example.com/v2/organizations/" }
10
+ subject { CcApiStub::Organizations.succeed_to_create }
9
11
 
10
- org = client.organization
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
- it 'fails to find the org' do
24
- guid = 'organization-id-1'
25
- CcApiStub::Organizations.fail_to_find(guid)
26
- client.organization(guid).exists?.should be_false
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
- it 'stubs loading the organization summary' do
32
- CcApiStub::Organizations.succeed_to_load_summary
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
- org = client.organization('organization-id-1')
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
- it 'stubs searching' do
42
- org_name = 'yoda'
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
- org = client.organization_by_name(org_name)
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
- it 'stubs searching' do
52
- org_name = 'yoda'
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
- org = client.organization_by_name(org_name)
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
- it 'stubs domain loading' do
76
- CcApiStub::Organizations.succeed_to_load_domains
77
- org = client.organization('organization-id-1')
78
- org.domains[0].should be_a(CFoundry::V2::Domain)
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
- it 'stubs users loading' do
98
- CcApiStub::Organizations.succeed_to_load_users
99
- org = client.organization('organization-id-1')
100
- org.users[0].should be_a(CFoundry::V2::User)
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
@@ -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
@@ -1,13 +1,8 @@
1
- 100:
1
+ 1000:
2
2
  name: InvalidAuthToken
3
3
  http_code: 401
4
4
  message: "Invalid Auth Token"
5
5
 
6
- 1000:
7
- name: QuotaDeclined
8
- http_code: 400
9
- message: "Quota declined: %s"
10
-
11
6
  1001:
12
7
  name: MessageParseError
13
8
  http_code: 400
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: -2707842676
4
+ hash: -2275817692
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
9
  - 1
10
10
  - rc
11
- - 4
12
- version: 0.5.1.rc4
11
+ - 5
12
+ version: 0.5.1.rc5
13
13
  platform: ruby
14
14
  authors:
15
15
  - Cloud Foundry Team