Skip to content

Commit

Permalink
Merge pull request #18286 from lpichler/dont_create_tenant_product_fe…
Browse files Browse the repository at this point in the history
…atures_remote_tenants

Don't seed tenant product features for tenant from remote region

(cherry picked from commit 7909bf7)

https://bugzilla.redhat.com/show_bug.cgi?id=1468795
  • Loading branch information
kbrock authored and simaishi committed Dec 20, 2018
1 parent b6bb060 commit 9d4c1af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/miq_product_feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def self.with_tenant_feature_root_features

def self.seed_tenant_miq_product_features
result = with_tenant_feature_root_features.map.each do |tenant_miq_product_feature|
Tenant.all.map { |tenant| tenant.build_miq_product_feature(tenant_miq_product_feature) }
Tenant.in_my_region.all.map { |tenant| tenant.build_miq_product_feature(tenant_miq_product_feature) }
end.flatten

MiqProductFeature.create(result).map(&:identifier)
Expand Down
26 changes: 26 additions & 0 deletions spec/models/miq_product_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ def traverse_product_features(product_feature, &block)
expect(MiqProductFeature.where(:identifier => "dialog_copy_editor", :name => "Edit").count).to eq(1)
end

context "with tenants from remote region" do
before do
MiqRegion.seed
end

def id_for_model_in_region(model, region)
model.id_in_region(model.count + 1_000_000, region.region)
end

let!(:other_miq_region) { FactoryBot.create(:miq_region) }
let!(:tenant_product_feature_other_region) do
Tenant.skip_callback(:create, :after, :create_miq_product_features_for_tenant_nodes)
tenant = FactoryGirl.create(:tenant, :id => id_for_model_in_region(Tenant, other_miq_region))
Tenant.set_callback(:create, :after, :create_miq_product_features_for_tenant_nodes)

tenant
end

it "doesn't seed tenant features for tenants from remote regions" do
MiqProductFeature.seed_tenant_miq_product_features
expect(tenant_product_feature_other_region.miq_product_features.to_a).to be_empty

expect(tenant.miq_product_features.map(&:identifier)).to match_array(["dialog_copy_editor_tenant_#{tenant.id}"])
end
end

context "add tenant node product features" do
let(:base) do
{
Expand Down

0 comments on commit 9d4c1af

Please sign in to comment.