Skip to content
Browse files

fix inverted wildcard logic

Change-Id: Ib75a8eaf6a90e3d31244a8bf8cb5fa6044151a93
  • Loading branch information...
1 parent d27ac1f commit f4b1f434f8ec2046ec10adf5b633a8e7fa448719 @pbozeman pbozeman committed Oct 24, 2012
View
5 lib/cloud_controller/models/domain.rb
@@ -30,7 +30,7 @@ def validate
validates_presence :wildcard
if (!new? && column_changed?(:wildcard) && !wildcard &&
- routes_dataset.filter(:host => nil).count > 0)
+ routes_dataset.filter(~{:host => nil}).count > 0)
@vito
Cloud Foundry member
vito added a note Nov 1, 2012

What adds this ~ method? Pretty clever.

@pbozeman
pbozeman added a note Nov 1, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
errors.add(:wildcard, :wildcard_routes_in_use)
end
@@ -122,7 +122,8 @@ def self.default_serving_domain_name=(name)
@default_serving_domain = Domain[:name => name]
unless @default_serving_domain
logger.info "creating default serving domain: #{name}"
- @default_serving_domain = Domain.new(:name => name)
+ @default_serving_domain = Domain.new(:name => name,
+ :wildcard => true)
@default_serving_domain.save(:validate => false)
else
logger.info "reusing default serving domain: #{name}"
View
5 lib/cloud_controller/models/route.rb
@@ -29,7 +29,10 @@ def fqdn
end
def validate
- validates_presence :host if domain && !domain.wildcard
+ if domain && !domain.wildcard
+ errors.add(:host, :host_not_nil) unless host.nil?
+ end
+
validates_presence :domain
validates_presence :organization
View
15 spec/api/route_spec.rb
@@ -9,7 +9,7 @@ module VCAP::CloudController
:path => "/v2/routes",
:model => Models::Route,
:basic_attributes => [:host, :domain_guid, :organization_guid],
- :required_attributes => [:host, :domain_guid, :organization_guid],
+ :required_attributes => [:domain_guid, :organization_guid],
:update_attributes => [:host],
:unique_attributes => [:host, :domain_guid],
:create_attribute => lambda { |name|
@@ -19,8 +19,11 @@ module VCAP::CloudController
@org.guid
when :domain_guid
Models::Domain.make(
+ :wildcard => true,
:owning_organization => @org
).guid
+ when :host
+ Sham.host
end
},
:create_attribute_reset => lambda { @org = nil }
@@ -159,11 +162,11 @@ module VCAP::CloudController
end
before do
- @domain_a = Models::Domain.make(:owning_organization => @org_a)
+ @domain_a = Models::Domain.make(:wildcard => true, :owning_organization => @org_a)
@space_a.add_domain(@domain_a)
@obj_a = Models::Route.make(:domain => @domain_a, :organization => @org_a)
- @domain_b = Models::Domain.make(:owning_organization => @org_b)
+ @domain_b = Models::Domain.make(:wildcard => true, :owning_organization => @org_b)
@space_b.add_domain(@domain_b)
@obj_b = Models::Route.make(:domain => @domain_b, :organization => @org_b)
end
@@ -190,11 +193,13 @@ module VCAP::CloudController
Models::Domain.default_serving_domain_name = "shared.com"
@obj_a = Models::Route.make(
+ :host => Sham.host,
:domain => Models::Domain.default_serving_domain,
:organization => @org_a
)
@obj_b = Models::Route.make(
+ :host => Sham.host,
:domain => Models::Domain.default_serving_domain,
:organization => @org_b
)
@@ -210,8 +215,8 @@ module VCAP::CloudController
describe "quota" do
let(:cf_admin) { Models::User.make(:admin => true) }
- let(:domain) { Models::Domain.make }
- let(:route) { Models::Route.make }
+ let(:domain) { Models::Domain.make(:wildcard => true) }
+ let(:route) { Models::Route.make(:domain => domain) }
describe "create" do
it "should fetch a quota token" do
View
1 spec/blueprints.rb
@@ -38,7 +38,6 @@ module VCAP::CloudController::Models
end
Route.blueprint do
- host { Sham.host }
domain { Domain.make }
organization { domain.owning_organization }
end
View
8 spec/models/domain_spec.rb
@@ -26,7 +26,8 @@ module VCAP::CloudController
},
:one_to_zero_or_more => {
:routes => lambda { |domain|
- Models::Route.make(:domain => domain)
+ domain.update(:wildcard => true)
+ Models::Route.make(:host => Sham.host, :domain => domain)
}
}
}
@@ -253,7 +254,7 @@ module VCAP::CloudController
it "should not remove the wildcard flag if routes are using it" do
d = Models::Domain.make(:wildcard => true)
- r = Models::Route.make(:host => nil,
+ r = Models::Route.make(:host => Sham.host,
:domain => d,
:organization => d.owning_organization)
expect {
@@ -263,7 +264,8 @@ module VCAP::CloudController
it "should remove the wildcard flag if no routes are using it" do
d = Models::Domain.make(:wildcard => true)
- r = Models::Route.make(:domain => d,
+ r = Models::Route.make(:host => nil,
+ :domain => d,
:organization => d.owning_organization)
d.update(:wildcard => false)
end
View
5 spec/models/helpers/unique_attributes.rb
@@ -73,8 +73,11 @@ module VCAP::CloudController::ModelSpecHelper
let(:dup_opts) do
opts[:create_attribute_reset].call if opts[:create_attribute_reset]
+ new_opts = opts.dup
+ new_opts[:required_attributes] |= new_opts[:unique_attributes]
+
initial_template = described_class.make
- orig_opts = creation_opts_from_obj(initial_template, opts)
+ orig_opts = creation_opts_from_obj(initial_template, new_opts)
initial_template.delete
orig_obj = described_class.make orig_opts
View
21 spec/models/route_spec.rb
@@ -5,7 +5,7 @@
module VCAP::CloudController
describe VCAP::CloudController::Models::Route do
it_behaves_like "a CloudController model", {
- :required_attributes => [:host, :domain, :organization],
+ :required_attributes => [:domain, :organization],
:db_required_attributes => [:domain, :organization],
:unique_attributes => [:host, :domain],
:stripped_string_attributes => :host,
@@ -16,8 +16,11 @@ module VCAP::CloudController
@org
when :domain
Models::Domain.make(
- :owning_organization => @org
+ :owning_organization => @org,
+ :wildcard => true
)
+ when :host
+ Sham.host
end
},
:create_attribute_reset => lambda { @org = nil },
@@ -82,11 +85,17 @@ module VCAP::CloudController
context "with a non-wild card domain" do
let(:domain) { Models::Domain.make(:wildcard => false) }
- it "should not allow an nil host" do
+ it "should allow a nil host" do
+ Models::Route.make(:organization => domain.owning_organization,
+ :domain => domain,
+ :host => nil).should be_valid
+ end
+
+ it "should not allow a valid host" do
expect {
Models::Route.make(:organization => domain.owning_organization,
:domain => domain,
- :host => nil)
+ :host => Sham.host)
}.to raise_error(Sequel::ValidationFailed)
end
@@ -112,9 +121,9 @@ module VCAP::CloudController
describe "#fqdn" do
context "for a non-nil host" do
it "should return the fqdn of for the route" do
- d = Models::Domain.make(:name => "foobar.com")
+ d = Models::Domain.make(:wildcard => true)
r = Models::Route.make(:host => "www", :domain => d)
- r.fqdn.should == "www.foobar.com"
+ r.fqdn.should == "www.#{d.name}"
end
end

0 comments on commit f4b1f43

Please sign in to comment.
Something went wrong with that request. Please try again.