cfoundry 2.2.0rc3 → 2.3.0

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.
@@ -134,6 +134,8 @@ module CFoundry
134
134
 
135
135
  def handle_response(response, options, request)
136
136
  if status_is_successful?(response[:status].to_i)
137
+ uaa.delete_user(options[:params][:user_delete]) if options[:params] && options[:params][:user_delete]
138
+
137
139
  handle_successful_response(response, options)
138
140
  else
139
141
  handle_error_response(response, request)
@@ -2,11 +2,19 @@ require "cfoundry/v2/model"
2
2
 
3
3
  module CFoundry::V2
4
4
  class Domain < Model
5
+ validates_presence_of :name
6
+ validates_format_of :name, :with => /\A([^\.]+\.)+[^\.]+\Z/
7
+ validates_presence_of :owning_organization
8
+
5
9
  attribute :name, :string
6
10
  attribute :wildcard, :boolean
7
11
  to_one :owning_organization, :as => :organization, :default => nil
8
12
  to_many :spaces
9
13
 
10
14
  queryable_by :name, :owning_organization_guid, :space_guid
15
+
16
+ def system?
17
+ guid.present? && !owning_organization.present?
18
+ end
11
19
  end
12
20
  end
@@ -1,64 +1,71 @@
1
1
  require "cfoundry/v2/model"
2
2
 
3
- module CFoundry::V2
4
- class User < Model
5
- to_many :spaces
6
- to_many :organizations
7
- to_many :managed_organizations, :as => :organization
8
- to_many :billing_managed_organizations, :as => :organization
9
- to_many :audited_organizations, :as => :organization
10
- to_many :managed_spaces, :as => :space
11
- to_many :audited_spaces, :as => :space
12
- attribute :admin, :boolean
13
- to_one :default_space, :as => :space
3
+ module CFoundry
4
+ module V2
5
+ class User < Model
6
+ to_many :spaces
7
+ to_many :organizations
8
+ to_many :managed_organizations, :as => :organization
9
+ to_many :billing_managed_organizations, :as => :organization
10
+ to_many :audited_organizations, :as => :organization
11
+ to_many :managed_spaces, :as => :space
12
+ to_many :audited_spaces, :as => :space
13
+ attribute :admin, :boolean
14
+ to_one :default_space, :as => :space
14
15
 
15
- attribute :guid, :string # guid is explicitly set for users
16
+ attribute :guid, :string # guid is explicitly set for users
16
17
 
17
- queryable_by :space_guid, :organization_guid, :managed_organization_guid,
18
- :billing_managed_organization_guid, :audited_organization_guid,
19
- :managed_space_guid, :audited_space_guid
18
+ queryable_by :space_guid, :organization_guid, :managed_organization_guid,
19
+ :billing_managed_organization_guid, :audited_organization_guid,
20
+ :managed_space_guid, :audited_space_guid
20
21
 
21
- def guid
22
- @guid
23
- end
22
+ def guid
23
+ @guid
24
+ end
24
25
 
25
- alias set_guid_attribute guid=
26
+ alias set_guid_attribute guid=
26
27
 
27
- def guid=(x)
28
- @guid = x
29
- set_guid_attribute(x)
30
- end
28
+ def guid=(x)
29
+ @guid = x
30
+ set_guid_attribute(x)
31
+ end
31
32
 
32
- alias :admin? :admin
33
+ alias :admin? :admin
33
34
 
34
- def change_password!(new, old)
35
- @client.base.uaa.change_password(@guid, new, old)
36
- end
35
+ def change_password!(new, old)
36
+ @client.base.uaa.change_password(@guid, new, old)
37
+ end
37
38
 
38
- # optional metadata from UAA
39
- attr_accessor :emails, :name
39
+ # optional metadata from UAA
40
+ attr_accessor :emails, :name
40
41
 
41
- def email
42
- return unless @emails && @emails.first
43
- @emails.first[:value]
44
- end
42
+ def email
43
+ return unless @emails && @emails.first
44
+ @emails.first[:value]
45
+ end
45
46
 
46
- def given_name
47
- return unless @name && @name[:givenName] != email
48
- @name[:givenName]
49
- end
47
+ def given_name
48
+ return unless @name && @name[:givenName] != email
49
+ @name[:givenName]
50
+ end
50
51
 
51
- def family_name
52
- return unless @name && @name[:familyName] != email
53
- @name[:familyName]
54
- end
52
+ def family_name
53
+ return unless @name && @name[:familyName] != email
54
+ @name[:familyName]
55
+ end
56
+
57
+ def full_name
58
+ if @name && @name[:fullName]
59
+ @name[:fullName]
60
+ elsif given_name && family_name
61
+ "#{given_name} #{family_name}"
62
+ end
63
+ end
55
64
 
56
- def full_name
57
- if @name && @name[:fullName]
58
- @name[:fullName]
59
- elsif given_name && family_name
60
- "#{given_name} #{family_name}"
65
+ def delete! (options = {})
66
+ options[:user_delete] = guid
67
+ super (options)
61
68
  end
62
69
  end
63
70
  end
64
- end
71
+ end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "2.2.0rc3".freeze
3
+ VERSION = "2.3.0".freeze
4
4
  end
@@ -9,6 +9,43 @@ module CFoundry
9
9
  it "should have a spaces association" do
10
10
  expect(domain.spaces).to eq([space])
11
11
  end
12
+
13
+ describe "validations" do
14
+ subject { build(:domain) }
15
+ it { should validate_presence_of(:name) }
16
+ it { should allow_value("run.pivotal.io").for(:name) }
17
+ it { should_not allow_value("not-a-url").for(:name) }
18
+ it { should validate_presence_of(:owning_organization) }
19
+ end
20
+
21
+ describe "#system?" do
22
+ let(:params) { {} }
23
+ let(:domain) { build(:domain, {:owning_organization => nil, client: client}.merge(params)) }
24
+ let(:client) { build(:client) }
25
+
26
+ context "when the domain is persisted and has no owning organization" do
27
+ it "returns true" do
28
+ expect(domain.system?).to be_true
29
+ end
30
+ end
31
+
32
+ context "when the domain is not persisted" do
33
+ let(:params) { {:guid => nil} }
34
+
35
+ it "returns false" do
36
+ expect(domain.system?).to be_false
37
+ end
38
+ end
39
+
40
+ context "when the domain has an owning org" do
41
+ let(:params) { {:owning_organization => org} }
42
+ let(:org) { build(:organization) }
43
+
44
+ it "returns false" do
45
+ expect(domain.system?).to be_false
46
+ end
47
+ end
48
+ end
12
49
  end
13
50
  end
14
51
  end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe User do
6
+ let(:client) { build(:client) }
7
+ subject { build(:user, client: client) }
8
+
9
+ describe '#delete!' do
10
+ describe 'when cloud controller was able to delete the user' do
11
+ before do
12
+ stub_request(:delete, /v2\/users\/.*/).to_return(:status => 200, :body => "", :headers => {})
13
+ client.base.stub(:info).and_return({:authorization_endpoint => 'some_endpoint'})
14
+ end
15
+
16
+ it "also removes the user from uaa" do
17
+ CFoundry::UAAClient.any_instance.should_receive(:delete_user)
18
+
19
+ subject.delete!({})
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,7 +1,10 @@
1
1
  FactoryGirl.define do
2
2
  factory :domain, :class => CFoundry::V2::Domain do
3
3
  sequence(:guid) { |n| "domain-guid-#{n}" }
4
+ ignore do
5
+ client build(:client)
6
+ end
4
7
 
5
- initialize_with { new(guid, build(:client)) }
8
+ initialize_with { new(guid, client) }
6
9
  end
7
10
  end
@@ -7,11 +7,21 @@
7
7
  "routes":[
8
8
  { "guid": "route-id",
9
9
  "host": "host",
10
- "domain": { "guid": "domain-id", "name": "app-domain.com", "owning_organization_guid": "organization-id"}
10
+ "domain": {
11
+ "guid": "domain-id",
12
+ "name": "app-domain.com",
13
+ "owning_organization_guid": "organization-id",
14
+ "owning_organization_url": "/v2/organizations/organization-id"
15
+ }
11
16
  },
12
17
  { "guid": "route-id-2",
13
18
  "host": null,
14
- "domain": { "guid": "domain-id", "name": "app-domain.com", "owning_organization_guid": "organization-id"}
19
+ "domain": {
20
+ "guid": "domain-id",
21
+ "name": "app-domain.com",
22
+ "owning_organization_guid": "organization-id",
23
+ "owning_organization_url": "/v2/organizations/organization-id"
24
+ }
15
25
  },
16
26
  { "guid": "route-id-3",
17
27
  "host": "host-3",
@@ -39,8 +49,8 @@
39
49
  "file_descriptors":256,
40
50
  "disk_quota":256,
41
51
  "available_domains":[
42
- {"guid":"domain-id", "name":"app-domain.com", "owning_organization_guid":"organization-id"},
43
- {"guid":"domain-id-2", "name":"app-domain-2.com", "owning_organization_guid":"organization-id"},
52
+ {"guid":"domain-id", "name":"app-domain.com", "owning_organization_guid":"organization-id", "owning_organization_url": "/v2/organizations/organization-id"},
53
+ {"guid":"domain-id-2", "name":"app-domain-2.com", "owning_organization_guid":"organization-id", "owning_organization_url": "/v2/organizations/organization-id"},
44
54
  {"guid":"domain-id-3", "name":"vcap.me", "owning_organization_guid":null}
45
55
  ]
46
56
  }
@@ -8,6 +8,7 @@
8
8
  "entity": {
9
9
  "name": "domain.com",
10
10
  "owning_organization_guid": "organization-id-1",
11
+ "owning_organization_url": "/v2/organizations/organization-id-1",
11
12
  "wildcard": true,
12
13
  "spaces_url": "/v2/domains/domain-id-1/spaces",
13
14
  "spaces": [
@@ -29,6 +29,7 @@
29
29
  "entity": {
30
30
  "name": "domain2.com",
31
31
  "owning_organization_guid": "organization-id-1",
32
+ "owning_organization_url": "/v2/organizations/organization-id-1",
32
33
  "wildcard": true,
33
34
  "spaces_url": "/v2/domains/domain-id-2/spaces",
34
35
  "spaces": [
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: 2.2.0rc3
5
- prerelease: 5
4
+ version: 2.3.0
5
+ prerelease:
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-06-22 00:00:00.000000000 Z
13
+ date: 2013-07-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -337,6 +337,7 @@ files:
337
337
  - spec/cfoundry/v2/quota_definition_spec.rb
338
338
  - spec/cfoundry/v2/route_spec.rb
339
339
  - spec/cfoundry/v2/space_spec.rb
340
+ - spec/cfoundry/v2/user_spec.rb
340
341
  - spec/cfoundry/validator_spec.rb
341
342
  - spec/factories/app_events_factory.rb
342
343
  - spec/factories/apps_factory.rb
@@ -414,9 +415,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
414
415
  required_rubygems_version: !ruby/object:Gem::Requirement
415
416
  none: false
416
417
  requirements:
417
- - - ! '>'
418
+ - - ! '>='
418
419
  - !ruby/object:Gem::Version
419
- version: 1.3.1
420
+ version: '0'
420
421
  requirements: []
421
422
  rubyforge_project: cfoundry
422
423
  rubygems_version: 1.8.25
@@ -459,6 +460,7 @@ test_files:
459
460
  - spec/cfoundry/v2/quota_definition_spec.rb
460
461
  - spec/cfoundry/v2/route_spec.rb
461
462
  - spec/cfoundry/v2/space_spec.rb
463
+ - spec/cfoundry/v2/user_spec.rb
462
464
  - spec/cfoundry/validator_spec.rb
463
465
  - spec/factories/app_events_factory.rb
464
466
  - spec/factories/apps_factory.rb