cfoundry 4.5.2 → 4.5.3

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/cc_api_stub.rb CHANGED
@@ -12,6 +12,7 @@ require "cc_api_stub/service_bindings"
12
12
  require "cc_api_stub/service_instances"
13
13
  require "cc_api_stub/services"
14
14
  require "cc_api_stub/spaces"
15
+ require "cc_api_stub/space_users"
15
16
  require "cc_api_stub/users"
16
17
 
17
18
  module CcApiStub
@@ -4,6 +4,12 @@ module CcApiStub
4
4
 
5
5
  class << self
6
6
  def succeed_to_delete(options = {})
7
+ if options.has_key? :roles
8
+ options[:roles].each do |role|
9
+ stub_delete(object_endpoint(options[:id], role.to_s.pluralize), {}, response(200, ""))
10
+ end
11
+ end
12
+
7
13
  stub_delete(object_endpoint(options[:id]), {}, response(200, ""))
8
14
  end
9
15
 
@@ -13,8 +19,8 @@ module CcApiStub
13
19
 
14
20
  private
15
21
 
16
- def object_endpoint(id = nil)
17
- %r{/v2/organizations/[^/]+/users/#{id}[^/]+$}
22
+ def object_endpoint(id = nil, role="users")
23
+ %r{/v2/organizations/[^/]+/#{role}/#{id}[^/]+$}
18
24
  end
19
25
  end
20
26
  end
@@ -56,6 +56,18 @@ module CcApiStub
56
56
  stub_get(%r{/v2/organizations/[^\/]+/users\?inline-relations-depth=1}, {}, response(200, users_fixture))
57
57
  end
58
58
 
59
+ def spaces_fixture
60
+ Helper.load_fixtures("fake_cc_organization_spaces")
61
+ end
62
+
63
+ def space_fixture_hash
64
+ MultiJson.load(spaces_fixture["resources"].first.to_json, :symbolize_keys => true)
65
+ end
66
+
67
+ def succeed_to_load_spaces
68
+ stub_get(%r{/v2/organizations/[^\/]+/spaces\?inline-relations-depth=1}, {}, response(200, spaces_fixture))
69
+ end
70
+
59
71
  private
60
72
 
61
73
  def object_endpoint(id = nil)
@@ -0,0 +1,27 @@
1
+ module CcApiStub
2
+ module SpaceUsers
3
+ extend Helper
4
+
5
+ class << self
6
+ def succeed_to_delete(options = {})
7
+ if options.has_key? :roles
8
+ options[:roles].each do |role|
9
+ stub_delete(object_endpoint(options[:id], role.to_s.pluralize), {}, response(200, ""))
10
+ end
11
+ end
12
+
13
+ stub_delete(object_endpoint(options[:id]), {}, response(200, ""))
14
+ end
15
+
16
+ def fail_to_delete(options = {})
17
+ stub_delete(object_endpoint(options[:id]), {}, response(500))
18
+ end
19
+
20
+ private
21
+
22
+ def object_endpoint(id = nil, role="users")
23
+ %r{/v2/spaces/[^/]+/#{role}/#{id}[^/]+$}
24
+ end
25
+ end
26
+ end
27
+ end
@@ -17,5 +17,18 @@ module CFoundry::V2
17
17
 
18
18
  queryable_by :name, :space_guid, :user_guid, :manager_guid,
19
19
  :billing_manager_guid, :auditor_guid
20
+
21
+ def delete_user_from_all_roles(user)
22
+ remove_user(user)
23
+ remove_manager(user)
24
+ remove_billing_manager(user)
25
+ remove_auditor(user)
26
+
27
+ spaces.each do |space|
28
+ space.remove_developer(user)
29
+ space.remove_auditor(user)
30
+ space.remove_manager(user)
31
+ end
32
+ end
20
33
  end
21
34
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "4.5.2".freeze
3
+ VERSION = "4.5.3".freeze
4
4
  end
@@ -9,6 +9,22 @@ describe CcApiStub::OrganizationUsers do
9
9
  subject { CcApiStub::OrganizationUsers.succeed_to_delete }
10
10
 
11
11
  it_behaves_like "a stubbed delete request"
12
+
13
+ context "when the :roles option is provided" do
14
+ let(:roles) { [:user, :managers, :auditor] }
15
+ it "deletes the user from each specified role" do
16
+ CcApiStub::OrganizationUsers.succeed_to_delete(roles: roles)
17
+ roles.each do |role|
18
+ url = "http://example.com/v2/organizations/123/#{role.to_s.pluralize}/94087"
19
+ uri = URI.parse(url)
20
+ Net::HTTP.start(uri.host, uri.port) do |http|
21
+ request = Net::HTTP::Delete.new(url)
22
+ response = http.request(request)
23
+ check_response(response, code: 200, ignore_response: true)
24
+ end
25
+ end
26
+ end
27
+ end
12
28
  end
13
29
 
14
30
  describe ".fail_to_delete" do
@@ -16,4 +32,4 @@ describe CcApiStub::OrganizationUsers do
16
32
 
17
33
  it_behaves_like "a stubbed delete request", :code => 500, :ignore_response => true
18
34
  end
19
- end
35
+ end
@@ -94,4 +94,25 @@ describe CcApiStub::Organizations do
94
94
 
95
95
  it_behaves_like "a stubbed get request"
96
96
  end
97
+
98
+ describe '.spaces_fixture' do
99
+ it "returns the fake spaces" do
100
+ CcApiStub::Organizations.spaces_fixture.should be_a(Hash)
101
+ end
102
+ end
103
+
104
+ describe '.space_fixture_hash' do
105
+ it 'returns the fake space' do
106
+ fixture = CcApiStub::Organizations.space_fixture_hash
107
+ fixture.should be_a(Hash)
108
+ fixture.should == fixture.symbolize_keys
109
+ end
110
+ end
111
+
112
+ describe '.succeed_to_load_spaces' do
113
+ let(:url) { "http://example.com/v2/organizations/2342/spaces?inline-relations-depth=1" }
114
+ subject { CcApiStub::Organizations.succeed_to_load_spaces }
115
+
116
+ it_behaves_like "a stubbed get request"
117
+ end
97
118
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ describe CcApiStub::SpaceUsers do
6
+ let(:url) { "http://example.com/v2/spaces/123/users/94087" }
7
+
8
+ describe ".succeed_to_delete" do
9
+ subject { CcApiStub::SpaceUsers.succeed_to_delete }
10
+
11
+ it_behaves_like "a stubbed delete request"
12
+
13
+ context "when the :roles option is provided" do
14
+ let(:roles) { [:developer, :managers, :auditor] }
15
+ it "deletes the user from each specified role" do
16
+ CcApiStub::SpaceUsers.succeed_to_delete(roles: roles)
17
+ roles.each do |role|
18
+ url = "http://example.com/v2/spaces/123/#{role.to_s.pluralize}/94087"
19
+ uri = URI.parse(url)
20
+ Net::HTTP.start(uri.host, uri.port) do |http|
21
+ request = Net::HTTP::Delete.new(url)
22
+ response = http.request(request)
23
+ check_response(response, code: 200, ignore_response: true)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ describe ".fail_to_delete" do
31
+ subject { CcApiStub::SpaceUsers.fail_to_delete }
32
+
33
+ it_behaves_like "a stubbed delete request", :code => 500, :ignore_response => true
34
+ end
35
+ end
@@ -23,6 +23,113 @@ module CFoundry
23
23
  expect(organization.billing_enabled).to eq(v)
24
24
  end
25
25
  end
26
+
27
+ describe "#delete_user_from_all_roles" do
28
+ let(:user) { build(:user) }
29
+ let(:organization) do
30
+ build(:organization, client: client, users: [user],
31
+ managers: [user], billing_managers: [user], auditors: [user])
32
+ end
33
+
34
+ let(:status) { 201 }
35
+
36
+ let(:delete_from_org_response) do
37
+ <<-json
38
+ {
39
+ "metadata": {
40
+ "guid": "24113d03-204b-4d23-b320-4127ee9c0006",
41
+ "url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006",
42
+ "created_at": "2013-08-17T00:47:03+00:00",
43
+ "updated_at": "2013-08-17T00:47:04+00:00"
44
+ },
45
+ "entity": {
46
+ "name": "dsabeti-the-org",
47
+ "billing_enabled": false,
48
+ "quota_definition_guid": "b72b1acb-ff4f-468d-99c0-05cd91012b62",
49
+ "status": "active",
50
+ "quota_definition_url": "/v2/quota_definitions/b72b1acb-ff4f-468d-99c0-05cd91012b62",
51
+ "spaces_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/spaces",
52
+ "domains_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/domains",
53
+ "users_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/users",
54
+ "managers_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/managers",
55
+ "billing_managers_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/billing_managers",
56
+ "auditors_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/auditors",
57
+ "app_events_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006/app_events"
58
+ }
59
+ }
60
+ json
61
+ end
62
+
63
+ let(:delete_from_space_response) do
64
+ <<-json
65
+ {
66
+ "metadata": {
67
+ "guid": "6825e318-7a3f-4d50-a2a9-dd7088c95347",
68
+ "url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347",
69
+ "created_at": "2013-10-18T00:54:34+00:00",
70
+ "updated_at": null
71
+ },
72
+ "entity": {
73
+ "name": "asdf",
74
+ "organization_guid": "24113d03-204b-4d23-b320-4127ee9c0006",
75
+ "organization_url": "/v2/organizations/24113d03-204b-4d23-b320-4127ee9c0006",
76
+ "developers_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/developers",
77
+ "managers_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/managers",
78
+ "auditors_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/auditors",
79
+ "apps_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/apps",
80
+ "domains_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/domains",
81
+ "service_instances_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/service_instances",
82
+ "app_events_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/app_events",
83
+ "events_url": "/v2/spaces/6825e318-7a3f-4d50-a2a9-dd7088c95347/events"
84
+ }
85
+ }
86
+ json
87
+ end
88
+
89
+ let(:space1) do
90
+ build(:space, organization: organization,
91
+ developers: [user], auditors: [user], managers: [user])
92
+ end
93
+
94
+ let(:space2) do
95
+ build(:space, organization: organization,
96
+ developers: [user], auditors: [user], managers: [user])
97
+ end
98
+
99
+ before do
100
+ organization.stub(:spaces).and_return([space1, space2])
101
+
102
+ stub_request(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/users/#{user.guid}").to_return(status: status, body: delete_from_org_response)
103
+ stub_request(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/managers/#{user.guid}").to_return(status: status, body: delete_from_org_response)
104
+ stub_request(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/billing_managers/#{user.guid}").to_return(status: status, body: delete_from_org_response)
105
+ stub_request(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/auditors/#{user.guid}").to_return(status: status, body: delete_from_org_response)
106
+
107
+ stub_request(:delete, "http://api.example.com/v2/spaces/#{space1.guid}/developers/#{user.guid}").to_return(status: status, body: delete_from_space_response)
108
+ stub_request(:delete, "http://api.example.com/v2/spaces/#{space1.guid}/managers/#{user.guid}").to_return(status: status, body: delete_from_space_response)
109
+ stub_request(:delete, "http://api.example.com/v2/spaces/#{space1.guid}/auditors/#{user.guid}").to_return(status: status, body: delete_from_space_response)
110
+
111
+ stub_request(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/developers/#{user.guid}").to_return(status: status, body: delete_from_space_response)
112
+ stub_request(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/managers/#{user.guid}").to_return(status: status, body: delete_from_space_response)
113
+ stub_request(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/auditors/#{user.guid}").to_return(status: status, body: delete_from_space_response)
114
+ end
115
+
116
+ it "removes the given user from all roles in the org and all its spaces" do
117
+ organization.delete_user_from_all_roles(user)
118
+
119
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/users/#{user.guid}")
120
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/managers/#{user.guid}")
121
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/billing_managers/#{user.guid}")
122
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/organizations/#{organization.guid}/auditors/#{user.guid}")
123
+
124
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space1.guid}/auditors/#{user.guid}")
125
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space1.guid}/managers/#{user.guid}")
126
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space1.guid}/developers/#{user.guid}")
127
+
128
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/auditors/#{user.guid}")
129
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/managers/#{user.guid}")
130
+ expect(WebMock).to have_requested(:delete, "http://api.example.com/v2/spaces/#{space2.guid}/developers/#{user.guid}")
131
+ end
132
+ end
26
133
  end
27
134
  end
28
135
  end
@@ -0,0 +1,99 @@
1
+
2
+ {
3
+ "total_results": 2,
4
+ "total_pages": 1,
5
+ "prev_url": null,
6
+ "next_url": null,
7
+ "resources": [
8
+ {
9
+ "metadata": {
10
+ "guid": "space-id-1",
11
+ "url": "/v2/spaces/space-id-1",
12
+ "created_at": "2012-10-25 14:10:45 -0700",
13
+ "updated_at": null
14
+ },
15
+ "entity": {
16
+ "name": "space-name-1",
17
+ "organization_guid": "organization-id-1",
18
+ "domains_url": "/v2/spaces/space-id-1/domains",
19
+ "domains": [
20
+ {
21
+ "metadata": {
22
+ "guid": "domain-id-1",
23
+ "url": "/v2/domains/domain-id-1",
24
+ "created_at": "2012-10-25 14:08:38 -0700",
25
+ "updated_at": null
26
+ },
27
+ "entity": {
28
+ "name": "vcap.me",
29
+ "owning_organization_guid": null
30
+ }
31
+ }
32
+ ],
33
+ "organization_url": "/v2/organizations/organization-id-1",
34
+ "organization": {
35
+ "metadata": {
36
+ "guid": "organization-id-1",
37
+ "url": "/v2/organizations/organization-id-1",
38
+ "created_at": "2012-10-25 14:10:41 -0700",
39
+ "updated_at": null
40
+ },
41
+ "entity": {
42
+ "name": "organization-name-1",
43
+ "spaces_url": "/v2/organizations/organization-id-1/spaces",
44
+ "domains_url": "/v2/organizations/organization-id-1/domains",
45
+ "users_url": "/v2/organizations/organization-id-1/users",
46
+ "managers_url": "/v2/organizations/organization-id-1/managers",
47
+ "billing_managers_url": "/v2/organizations/organization-id-1/billing_managers",
48
+ "auditors_url": "/v2/organizations/organization-id-1/auditors"
49
+ }
50
+ }
51
+ }
52
+ },
53
+ {
54
+ "metadata": {
55
+ "guid": "space-id-2",
56
+ "url": "/v2/spaces/space-id-2",
57
+ "created_at": "2012-10-25 14:10:45 -0700",
58
+ "updated_at": null
59
+ },
60
+ "entity": {
61
+ "name": "space-name-2",
62
+ "organization_guid": "organization-id-1",
63
+ "domains_url": "/v2/spaces/space-id-2/domains",
64
+ "domains": [
65
+ {
66
+ "metadata": {
67
+ "guid": "domain-id-1",
68
+ "url": "/v2/domains/domain-id-1",
69
+ "created_at": "2012-10-25 14:08:38 -0700",
70
+ "updated_at": null
71
+ },
72
+ "entity": {
73
+ "name": "vcap.me",
74
+ "owning_organization_guid": null
75
+ }
76
+ }
77
+ ],
78
+ "organization_url": "/v2/organizations/organization-id-1",
79
+ "organization": {
80
+ "metadata": {
81
+ "guid": "organization-id-1",
82
+ "url": "/v2/organizations/organization-id-1",
83
+ "created_at": "2012-10-25 14:10:41 -0700",
84
+ "updated_at": null
85
+ },
86
+ "entity": {
87
+ "name": "organization-name-1",
88
+ "spaces_url": "/v2/organizations/organization-id-1/spaces",
89
+ "domains_url": "/v2/organizations/organization-id-1/domains",
90
+ "users_url": "/v2/organizations/organization-id-1/users",
91
+ "managers_url": "/v2/organizations/organization-id-1/managers",
92
+ "billing_managers_url": "/v2/organizations/organization-id-1/billing_managers",
93
+ "auditors_url": "/v2/organizations/organization-id-1/auditors"
94
+ }
95
+ }
96
+ }
97
+ }
98
+ ]
99
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.2
4
+ version: 4.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-21 00:00:00.000000000 Z
13
+ date: 2013-10-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -280,6 +280,7 @@ files:
280
280
  - lib/cc_api_stub/service_bindings.rb
281
281
  - lib/cc_api_stub/service_instances.rb
282
282
  - lib/cc_api_stub/services.rb
283
+ - lib/cc_api_stub/space_users.rb
283
284
  - lib/cc_api_stub/spaces.rb
284
285
  - lib/cc_api_stub/users.rb
285
286
  - lib/cc_api_stub.rb
@@ -344,6 +345,7 @@ files:
344
345
  - spec/cc_api_stub/service_bindings_spec.rb
345
346
  - spec/cc_api_stub/service_instances_spec.rb
346
347
  - spec/cc_api_stub/services_spec.rb
348
+ - spec/cc_api_stub/space_users_spec.rb
347
349
  - spec/cc_api_stub/spaces_spec.rb
348
350
  - spec/cc_api_stub/users_spec.rb
349
351
  - spec/cfoundry/auth_token_spec.rb
@@ -422,6 +424,7 @@ files:
422
424
  - spec/fixtures/fake_cc_organization.json
423
425
  - spec/fixtures/fake_cc_organization_domains.json
424
426
  - spec/fixtures/fake_cc_organization_search.json
427
+ - spec/fixtures/fake_cc_organization_spaces.json
425
428
  - spec/fixtures/fake_cc_organization_summary.json
426
429
  - spec/fixtures/fake_cc_organization_users.json
427
430
  - spec/fixtures/fake_cc_route.json
@@ -462,7 +465,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
462
465
  version: '0'
463
466
  segments:
464
467
  - 0
465
- hash: 2988206602408192095
468
+ hash: -2392374929846355282
466
469
  required_rubygems_version: !ruby/object:Gem::Requirement
467
470
  none: false
468
471
  requirements:
@@ -471,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
471
474
  version: '0'
472
475
  segments:
473
476
  - 0
474
- hash: 2988206602408192095
477
+ hash: -2392374929846355282
475
478
  requirements: []
476
479
  rubyforge_project: cfoundry
477
480
  rubygems_version: 1.8.25
@@ -491,6 +494,7 @@ test_files:
491
494
  - spec/cc_api_stub/service_bindings_spec.rb
492
495
  - spec/cc_api_stub/service_instances_spec.rb
493
496
  - spec/cc_api_stub/services_spec.rb
497
+ - spec/cc_api_stub/space_users_spec.rb
494
498
  - spec/cc_api_stub/spaces_spec.rb
495
499
  - spec/cc_api_stub/users_spec.rb
496
500
  - spec/cfoundry/auth_token_spec.rb
@@ -569,6 +573,7 @@ test_files:
569
573
  - spec/fixtures/fake_cc_organization.json
570
574
  - spec/fixtures/fake_cc_organization_domains.json
571
575
  - spec/fixtures/fake_cc_organization_search.json
576
+ - spec/fixtures/fake_cc_organization_spaces.json
572
577
  - spec/fixtures/fake_cc_organization_summary.json
573
578
  - spec/fixtures/fake_cc_organization_users.json
574
579
  - spec/fixtures/fake_cc_route.json