cfoundry 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -36,6 +36,6 @@ end
36
36
 
37
37
  namespace "test" do
38
38
  task "spec" do |t|
39
- sh("cd spec && bundle exec rake spec")
39
+ sh("bundle exec rspec")
40
40
  end
41
41
  end
@@ -0,0 +1 @@
1
+ require File.expand_path("../../../spec/spec_helper", __FILE__)
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.4.10".freeze
3
+ VERSION = "0.4.11".freeze
4
4
  end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe CFoundry::UAAClient do
4
+ let(:target) { "https://uaa.example.com" }
5
+ let(:uaa) { CFoundry::UAAClient.new(target) }
6
+
7
+ describe '#prompts' do
8
+ subject { uaa.prompts }
9
+
10
+ # GET (target)/login
11
+ it "receives the prompts from /login" do
12
+ stub_request(:get, "#{target}/login").to_return :status => 200,
13
+ :body => <<EOF
14
+ {
15
+ "timestamp": "2012-11-08T13:32:18+0000",
16
+ "commit_id": "ebbf817",
17
+ "app": {
18
+ "version": "1.2.6",
19
+ "artifact": "cloudfoundry-identity-uaa",
20
+ "description": "User Account and Authentication Service",
21
+ "name": "UAA"
22
+ },
23
+ "prompts": {
24
+ "username": [
25
+ "text",
26
+ "Email"
27
+ ],
28
+ "password": [
29
+ "password",
30
+ "Password"
31
+ ]
32
+ }
33
+ }
34
+ EOF
35
+
36
+ expect(subject).to eq(
37
+ :username => ["text", "Email"],
38
+ :password => ["password", "Password"])
39
+ end
40
+ end
41
+
42
+ describe '#authorize' do
43
+ let(:username) { "foo@bar.com" }
44
+ let(:password) { "test" }
45
+
46
+ subject { uaa.authorize(:username => username, :password => password) }
47
+
48
+ it 'returns the token on successful authentication' do
49
+ stub_request(
50
+ :post,
51
+ "#{target}/oauth/authorize"
52
+ ).with(
53
+ :query => {
54
+ "client_id" => uaa.client_id,
55
+ "redirect_uri" => uaa.redirect_uri,
56
+ "response_type" => "token"
57
+ }
58
+ ).to_return(
59
+ :status => 302,
60
+ :headers => {
61
+ "Location" => "#{uaa.redirect_uri}#access_token=bar&token_type=foo&fizz=buzz&foo=bar"
62
+ }
63
+ )
64
+
65
+ expect(subject).to eq "foo bar"
66
+ end
67
+
68
+ it 'raises CFoundry::Denied if authentication fails' do
69
+ stub_request(
70
+ :post,
71
+ "#{target}/oauth/authorize"
72
+ ).with(
73
+ :query => {
74
+ "client_id" => uaa.client_id,
75
+ "redirect_uri" => uaa.redirect_uri,
76
+ "response_type" => "token"
77
+ }
78
+ ).to_return(
79
+ :status => 401,
80
+ :headers => {
81
+ "Location" => "#{uaa.redirect_uri}#access_token=bar&token_type=foo&fizz=buzz&foo=bar"
82
+ },
83
+ :body => <<EOF
84
+ {
85
+ "error": "unauthorized",
86
+ "error_description": "Bad credentials"
87
+ }
88
+ EOF
89
+ )
90
+
91
+ expect { subject }.to raise_error(
92
+ CFoundry::Denied, "401: Bad credentials")
93
+ end
94
+ end
95
+
96
+ describe '#users' do
97
+ subject { uaa.users }
98
+
99
+ it 'requests /Users' do
100
+ req = stub_request(:get, "#{target}/Users").to_return(
101
+ :body => '{ "fake_data": "123" }')
102
+ expect(subject).to eq({ :fake_data => "123" })
103
+ expect(req).to have_been_requested
104
+ end
105
+ end
106
+
107
+ describe '#change_password' do
108
+ let(:guid) { "foo-bar-baz" }
109
+ let(:old) { "old-pass" }
110
+ let(:new) { "new-pass" }
111
+
112
+ subject { uaa.change_password(guid, new, old) }
113
+
114
+ it 'sends a password change request' do
115
+ req = stub_request(
116
+ :put,
117
+ "#{target}/User/#{guid}/password"
118
+ ).with(
119
+ :body => {
120
+ :schemas => ["urn:scim:schemas:core:1.0"],
121
+ :password => new,
122
+ :oldPassword => old
123
+ },
124
+ :headers => { "Content-Type" => "application/json" }
125
+ )
126
+
127
+ subject
128
+
129
+ expect(req).to have_been_requested
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,24 @@
1
+ FactoryGirl.define do
2
+ factory :app, :class => CFoundry::V2::App do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+ memory 128
6
+ total_instances 0
7
+ production false
8
+ state "STOPPED"
9
+
10
+ ignore do
11
+ routes []
12
+ service_bindings []
13
+ end
14
+
15
+ initialize_with do
16
+ CFoundry::V2::App.new(nil, nil)
17
+ end
18
+
19
+ after_build do |app, evaluator|
20
+ RR.stub(app).routes { evaluator.routes }
21
+ RR.stub(app).service_bindings { evaluator.service_bindings }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ FactoryGirl.define do
2
+ factory :client, :class => CFoundry::V2::Client do
3
+ ignore do
4
+ routes []
5
+ apps []
6
+ frameworks []
7
+ runtimes []
8
+ service_instances []
9
+ spaces []
10
+ organizations []
11
+ logged_in true
12
+ end
13
+
14
+ after_build do |client, evaluator|
15
+ RR.stub(client).logged_in? { evaluator.logged_in }
16
+ RR.stub(client).routes { evaluator.routes }
17
+ RR.stub(client).apps { evaluator.apps }
18
+ RR.stub(client).frameworks { evaluator.frameworks }
19
+ RR.stub(client).runtimes { evaluator.runtimes }
20
+ RR.stub(client).service_instances { evaluator.service_instances }
21
+ RR.stub(client).spaces { evaluator.spaces }
22
+ RR.stub(client).organizations { evaluator.organizations }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :domain, :class => CFoundry::V2::Domain do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+
6
+ initialize_with do
7
+ CFoundry::V2::Domain.new(nil, nil)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ FactoryGirl.define do
2
+ sequence(:random_string) {|n| "random_#{n}_string" }
3
+ sequence(:guid) {|n| "random_#{n}_guid" }
4
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :framework, :class => CFoundry::V2::Framework do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+
6
+ initialize_with do
7
+ CFoundry::V2::Framework.new(nil, nil)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ FactoryGirl.define do
2
+ factory :organization, :class => CFoundry::V2::Organization do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+
6
+ ignore do
7
+ spaces []
8
+ domains []
9
+ end
10
+
11
+ initialize_with do
12
+ CFoundry::V2::Organization.new(nil, nil)
13
+ end
14
+
15
+ after_build do |org, evaluator|
16
+ evaluator.spaces.each { |s| s.organization = org }
17
+ evaluator.domains.each { |s| s.owning_organization = org }
18
+
19
+ RR.stub(org).spaces { evaluator.spaces }
20
+ RR.stub(org).domains { evaluator.domains }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :route, :class => CFoundry::V2::Route do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ host { FactoryGirl.generate(:random_string) }
5
+ association :domain, :factory => :domain, :strategy => :build
6
+
7
+ initialize_with do
8
+ CFoundry::V2::Route.new(nil, nil)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :runtime, :class => CFoundry::V2::Runtime do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+
6
+ initialize_with do
7
+ CFoundry::V2::Runtime.new(nil, nil)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :service_binding, :class => CFoundry::V2::ServiceBinding do
3
+ guid { FactoryGirl.generate(:guid) }
4
+
5
+ initialize_with do
6
+ CFoundry::V2::ServiceBinding.new(nil, nil)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :service, :class => CFoundry::V2::Service do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ label "redis"
5
+ provider "core"
6
+ url "http://example.com"
7
+ description "small key-value store"
8
+ version "2.8"
9
+ info_url "http://cloudfoundry.com/redis"
10
+ active true
11
+
12
+ initialize_with do
13
+ CFoundry::V2::Service.new(nil, nil)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :service_instance, :class => CFoundry::V2::ServiceInstance do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+
6
+ initialize_with do
7
+ CFoundry::V2::ServiceInstance.new(nil, nil)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :service_plan, :class => CFoundry::V2::ServicePlan do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name "D100"
5
+ description "Filibuster plan"
6
+
7
+ initialize_with do
8
+ CFoundry::V2::ServicePlan.new(nil, nil)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ FactoryGirl.define do
2
+ factory :space, :class => CFoundry::V2::Space do
3
+ guid { FactoryGirl.generate(:guid) }
4
+ name { FactoryGirl.generate(:random_string) }
5
+
6
+ ignore do
7
+ apps []
8
+ service_instances []
9
+ domains []
10
+ end
11
+
12
+ initialize_with do
13
+ CFoundry::V2::Space.new(nil, nil)
14
+ end
15
+
16
+ after_build do |org, evaluator|
17
+ evaluator.apps.each { |s| s.space = org }
18
+ evaluator.service_instances.each { |s| s.space = org }
19
+
20
+ RR.stub(org).apps { evaluator.apps }
21
+ RR.stub(org).service_instances { evaluator.service_instances }
22
+ RR.stub(org).domains { evaluator.domains }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require "rspec"
2
+ require "cfoundry"
3
+ require "factory_girl"
4
+ require "webmock/rspec"
5
+
6
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
7
+ require file
8
+ end
9
+
10
+ FactoryGirl.definition_file_paths = File.expand_path("../factories", __FILE__)
11
+ FactoryGirl.find_definitions
12
+
13
+ RSpec.configure do |c|
14
+ c.mock_with :rr
15
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 10
10
- version: 0.4.10
9
+ - 11
10
+ version: 0.4.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-11 00:00:00 -08:00
18
+ date: 2012-12-14 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,11 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 19
29
+ hash: 13
30
30
  segments:
31
31
  - 1
32
32
  - 1
33
- - 0
34
- version: 1.1.0
33
+ version: "1.1"
35
34
  type: :runtime
36
35
  version_requirements: *id001
37
36
  - !ruby/object:Gem::Dependency
@@ -42,12 +41,11 @@ dependencies:
42
41
  requirements:
43
42
  - - ~>
44
43
  - !ruby/object:Gem::Version
45
- hash: 7
44
+ hash: 9
46
45
  segments:
47
46
  - 1
48
- - 4
49
- - 0
50
- version: 1.4.0
47
+ - 3
48
+ version: "1.3"
51
49
  type: :runtime
52
50
  version_requirements: *id002
53
51
  - !ruby/object:Gem::Dependency
@@ -58,12 +56,11 @@ dependencies:
58
56
  requirements:
59
57
  - - ~>
60
58
  - !ruby/object:Gem::Version
61
- hash: 41
59
+ hash: 25
62
60
  segments:
63
61
  - 0
64
62
  - 9
65
- - 9
66
- version: 0.9.9
63
+ version: "0.9"
67
64
  type: :runtime
68
65
  version_requirements: *id003
69
66
  - !ruby/object:Gem::Dependency
@@ -74,13 +71,11 @@ dependencies:
74
71
  requirements:
75
72
  - - ~>
76
73
  - !ruby/object:Gem::Version
77
- hash: 11
74
+ hash: 25
78
75
  segments:
79
76
  - 0
80
77
  - 9
81
- - 2
82
- - 2
83
- version: 0.9.2.2
78
+ version: "0.9"
84
79
  type: :development
85
80
  version_requirements: *id004
86
81
  - !ruby/object:Gem::Dependency
@@ -91,14 +86,58 @@ dependencies:
91
86
  requirements:
92
87
  - - ~>
93
88
  - !ruby/object:Gem::Version
94
- hash: 35
89
+ hash: 21
95
90
  segments:
96
91
  - 2
97
92
  - 11
98
- - 0
99
- version: 2.11.0
93
+ version: "2.11"
100
94
  type: :development
101
95
  version_requirements: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ name: webmock
98
+ prerelease: false
99
+ requirement: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ hash: 29
105
+ segments:
106
+ - 1
107
+ - 9
108
+ version: "1.9"
109
+ type: :development
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: rr
113
+ prerelease: false
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ hash: 15
120
+ segments:
121
+ - 1
122
+ - 0
123
+ version: "1.0"
124
+ type: :development
125
+ version_requirements: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ name: factory_girl
128
+ prerelease: false
129
+ requirement: &id008 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ hash: 15
135
+ segments:
136
+ - 2
137
+ - 6
138
+ version: "2.6"
139
+ type: :development
140
+ version_requirements: *id008
102
141
  description:
103
142
  email:
104
143
  - asuraci@vmware.com
@@ -117,6 +156,7 @@ files:
117
156
  - lib/cfoundry/errors.rb
118
157
  - lib/cfoundry/validator.rb
119
158
  - lib/cfoundry/uaaclient.rb
159
+ - lib/cfoundry/spec_helper.rb
120
160
  - lib/cfoundry/v2/service_binding.rb
121
161
  - lib/cfoundry/v2/service.rb
122
162
  - lib/cfoundry/v2/client.rb
@@ -148,9 +188,21 @@ files:
148
188
  - lib/cfoundry/v1/service_instance.rb
149
189
  - lib/cfoundry/zip.rb
150
190
  - lib/cfoundry/chatty_hash.rb
151
- - spec/helpers.rb
152
- - spec/Rakefile
153
- - spec/client_spec.rb
191
+ - spec/factories/service_instance_factory.rb
192
+ - spec/factories/service_binding_factory.rb
193
+ - spec/factories/service_factory.rb
194
+ - spec/factories/route_factory.rb
195
+ - spec/factories/factory.rb
196
+ - spec/factories/runtime_factory.rb
197
+ - spec/factories/space_factory.rb
198
+ - spec/factories/organization_factory.rb
199
+ - spec/factories/framework_factory.rb
200
+ - spec/factories/domain_factory.rb
201
+ - spec/factories/client_factory.rb
202
+ - spec/factories/app_factory.rb
203
+ - spec/factories/service_plan_factory.rb
204
+ - spec/spec_helper.rb
205
+ - spec/cfoundry/uaaclient_spec.rb
154
206
  has_rdoc: true
155
207
  homepage: http://cloudfoundry.com/
156
208
  licenses: []
@@ -186,6 +238,18 @@ signing_key:
186
238
  specification_version: 3
187
239
  summary: High-level library for working with the Cloud Foundry API.
188
240
  test_files:
189
- - spec/helpers.rb
190
- - spec/Rakefile
191
- - spec/client_spec.rb
241
+ - spec/factories/service_instance_factory.rb
242
+ - spec/factories/service_binding_factory.rb
243
+ - spec/factories/service_factory.rb
244
+ - spec/factories/route_factory.rb
245
+ - spec/factories/factory.rb
246
+ - spec/factories/runtime_factory.rb
247
+ - spec/factories/space_factory.rb
248
+ - spec/factories/organization_factory.rb
249
+ - spec/factories/framework_factory.rb
250
+ - spec/factories/domain_factory.rb
251
+ - spec/factories/client_factory.rb
252
+ - spec/factories/app_factory.rb
253
+ - spec/factories/service_plan_factory.rb
254
+ - spec/spec_helper.rb
255
+ - spec/cfoundry/uaaclient_spec.rb
@@ -1,14 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- Bundler.require(:default, :development)
4
-
5
- require 'rake/dsl_definition'
6
- require 'rake'
7
- require 'rspec'
8
- require 'rspec/core/rake_task'
9
-
10
- RSpec::Core::RakeTask.new do |t|
11
- t.pattern = "**/*_spec.rb"
12
- t.rspec_opts = ["--format", "documentation", "--colour"]
13
- end
14
-
@@ -1,206 +0,0 @@
1
- require "cfoundry"
2
- require "./helpers"
3
-
4
- RSpec.configure do |c|
5
- c.include CFoundryHelpers
6
- end
7
-
8
- describe CFoundry::Client do
9
- TARGET = ENV["CFOUNDRY_TEST_TARGET"] || "http://api.vcap.me"
10
- USER = ENV["CFOUNDRY_TEST_USER"] || "dev@cloudfoundry.org"
11
- PASSWORD = ENV["CFOUNDRY_TEST_PASSWORD"] || "test"
12
-
13
- before(:all) do
14
- @client = CFoundry::Client.new(TARGET)
15
- @client.login(USER, PASSWORD)
16
- end
17
-
18
- describe :target do
19
- it "returns the current API target" do
20
- @client.target.should == TARGET
21
- end
22
- end
23
-
24
- describe "metadata" do
25
- describe :info do
26
- it "returns the cloud meta-info" do
27
- @client.info.should be_a(Hash)
28
- end
29
- end
30
-
31
- describe :system_services do
32
- it "returns the service vendors" do
33
- @client.system_services.should be_a(Hash)
34
- end
35
-
36
- it "denies if not authenticated" do
37
- without_auth do
38
- proc {
39
- @client.system_services
40
- }.should raise_error(CFoundry::Denied)
41
- end
42
- end
43
- end
44
-
45
- describe :system_runtimes do
46
- it "returns the supported runtime information" do
47
- @client.system_runtimes.should be_a(Hash)
48
- end
49
-
50
- it "works if not authenticated" do
51
- without_auth do
52
- proc {
53
- @client.system_runtimes
54
- }.should_not raise_error(CFoundry::Denied)
55
- end
56
- end
57
- end
58
- end
59
-
60
- describe :user do
61
- it "creates a lazy User object" do
62
- with_new_user do
63
- @client.user(@user.email).should be_a(CFoundry::User)
64
- end
65
- end
66
- end
67
-
68
- describe :register do
69
- it "registers an account and returns the User" do
70
- email = random_user
71
-
72
- user = @client.register(email, "test")
73
-
74
- begin
75
- @client.user(email).should satisfy(&:exists?)
76
- ensure
77
- user.delete!
78
- end
79
- end
80
-
81
- it "fails if a user by that name already exists" do
82
- proc {
83
- @client.register(USER, PASSWORD)
84
- }.should raise_error(CFoundry::Denied)
85
- end
86
- end
87
-
88
- describe :login do
89
- it "authenticates and sets the client token" do
90
- client = CFoundry::Client.new(TARGET)
91
- email = random_user
92
- pass = random_str
93
-
94
- client.register(email, pass)
95
- begin
96
- client.login(email, pass)
97
- client.should satisfy(&:logged_in?)
98
- ensure
99
- @client.user(email).delete!
100
- end
101
- end
102
-
103
- it "fails with invalid credentials" do
104
- client = CFoundry::Client.new(TARGET)
105
- email = random_user
106
-
107
- client.register(email, "right")
108
- begin
109
- proc {
110
- client.login(email, "wrong")
111
- }.should raise_error(CFoundry::Denied)
112
- ensure
113
- @client.user(email).delete!
114
- end
115
- end
116
- end
117
-
118
- describe :logout do
119
- it "clears the login token" do
120
- client = CFoundry::Client.new(TARGET)
121
- email = random_user
122
- pass = random_str
123
-
124
- client.register(email, pass)
125
-
126
- begin
127
- client.login(email, pass)
128
- client.should satisfy(&:logged_in?)
129
-
130
- client.logout
131
- client.should_not satisfy(&:logged_in?)
132
- ensure
133
- @client.user(email).delete!
134
- end
135
- end
136
- end
137
-
138
- describe :app do
139
- it "creates a lazy App object" do
140
- @client.app("foo").should be_a(CFoundry::App)
141
- @client.app("foo").name.should == "foo"
142
- end
143
- end
144
-
145
- describe :apps do
146
- it "returns an empty array if a user has no apps" do
147
- with_new_user do
148
- @client.apps.should == []
149
- end
150
- end
151
-
152
- it "returns an array of App objects if a user has any" do
153
- with_new_user do
154
- name = random_str
155
-
156
- new = @client.app(name)
157
- new.total_instances = 1
158
- new.urls = []
159
- new.framework = "sinatra"
160
- new.runtime = "ruby18"
161
- new.memory = 64
162
- new.create!
163
-
164
- apps = @client.apps
165
- apps.should be_a(Array)
166
- apps.size.should == 1
167
- apps.first.should be_a(CFoundry::App)
168
- apps.first.name.should == name
169
- end
170
- end
171
- end
172
-
173
- describe :service do
174
- it "creates a lazy Service object" do
175
- @client.service("foo").should be_a(CFoundry::Service)
176
- @client.service("foo").name.should == "foo"
177
- end
178
- end
179
-
180
- describe :services do
181
- it "returns an empty array if a user has no apps" do
182
- with_new_user do
183
- @client.services.should == []
184
- end
185
- end
186
-
187
- it "returns an array of Service objects if a user has any" do
188
- with_new_user do
189
- name = random_str
190
-
191
- new = @client.service(name)
192
- new.type = "key-value"
193
- new.vendor = "redis"
194
- new.version = "2.2"
195
- new.tier = "free"
196
- new.create!
197
-
198
- svcs = @client.services
199
- svcs.should be_a(Array)
200
- svcs.size.should == 1
201
- svcs.first.should be_a(CFoundry::Service)
202
- svcs.first.name.should == name
203
- end
204
- end
205
- end
206
- end
@@ -1,29 +0,0 @@
1
- module CFoundryHelpers
2
- def random_str
3
- format("%x", rand(1000000))
4
- end
5
-
6
- def random_user
7
- "#{random_str}@cfoundry-spec.com"
8
- end
9
-
10
- def without_auth
11
- proxy = @client.proxy
12
- @client.logout
13
- @client.proxy = nil
14
- yield
15
- ensure
16
- @client.login(USER, PASSWORD)
17
- @client.proxy = proxy
18
- end
19
-
20
- def with_new_user
21
- @user = @client.register(random_user, "test")
22
- @client.proxy = @user.email
23
- yield
24
- ensure
25
- @client.proxy = nil
26
- @user.delete!
27
- @user = nil
28
- end
29
- end