Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope Tenant#name validation to the current region #16506

Merged
merged 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class Tenant < ApplicationRecord
validate :validate_only_one_root
validates :description, :presence => true
validates :name, :presence => true, :unless => :use_config_for_attributes?
validates :name, :uniqueness => {:scope => :ancestry, :message => "should be unique per parent"}
validates :name, :uniqueness => {:scope => :ancestry,
:conditions => -> { in_my_region },
:message => "should be unique per parent"}
validate :validate_default_tenant, :on => :update, :if => :default_miq_group_id_changed?

scope :all_tenants, -> { where(:divisible => true) }
Expand Down
9 changes: 9 additions & 0 deletions spec/models/tenant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@
end
end

context "validate multi region" do
let(:other_region_id) { ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1) }

it "allows same name as tenant in a different region" do
described_class.create(:name => "GT", :description => "GT Tenant in other region", :id => other_region_id)
expect(described_class.new(:name => "GT", :description => "GT Tenant in this region").valid?).to be_truthy
end
end

context "#ensure_can_be_destroyed" do
let(:tenant) { FactoryGirl.create(:tenant) }
let(:cloud_tenant) { FactoryGirl.create(:cloud_tenant) }
Expand Down