Skip to content

Commit

Permalink
Merge pull request #18025 from kbrock/bz_1625788
Browse files Browse the repository at this point in the history
Properly create tenant default group for population
  • Loading branch information
bdunne authored Sep 26, 2018
2 parents cc6e263 + bea02fc commit 88c3637
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ def self.create_tenant_group(tenant)

create_with(
:description => "Tenant #{tenant_full_name} access",
:group_type => TENANT_GROUP,
:default_tenant_role => MiqUserRole.default_tenant_role
).find_or_create_by!(:tenant_id => tenant.id)
).find_or_create_by!(
:group_type => TENANT_GROUP,
:tenant_id => tenant.id,
)
end

def self.sort_by_desc
Expand Down
21 changes: 21 additions & 0 deletions spec/models/tenant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,25 @@
expect(sub_tenant.parent_id = tenant.id).to eq(tenant.id)
end
end

describe "#create" do
it "properly creates a default group" do
# create a tenant, but one that doesn't have a default_miq_group
# this is only possibly during an upgrade
tenant.save!
tenant.default_miq_group.delete
# We are using update_attribute to create an invalid tenant.
# rubocop:disable Rails/SkipsModelValidations
tenant.update_attribute(:default_miq_group_id, nil)
# rubocop:enable Rails/SkipsModelValidations
# lets make sure the tenant doesn't get assigned this user created group (the bug)
false_group = FactoryGirl.create(:miq_group, :tenant_id => tenant.id)

# 20151021174140_assign_tenant_default_group.rb
tenant.send(:create_tenant_group)

expect(tenant.default_miq_group).not_to eq(false_group)
expect(tenant.default_miq_group).to be_tenant_group
end
end
end

0 comments on commit 88c3637

Please sign in to comment.