Skip to content

Commit

Permalink
Add scope to list providers from ancestor tenants
Browse files Browse the repository at this point in the history
  • Loading branch information
lpichler committed May 6, 2019
1 parent fdc1b6d commit 4967ab5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ class ExtManagementSystem < ApplicationRecord
include CustomActionsMixin
include SupportsFeatureMixin

def self.with_tenant(tenant_id)
tenant = Tenant.find(tenant_id)
where(:tenant_id => tenant.ancestor_ids + [tenant_id])
end

def self.types
leaf_subclasses.collect(&:ems_type)
end
Expand Down
28 changes: 28 additions & 0 deletions spec/models/ext_management_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
describe ExtManagementSystem do
describe ".with_tenant" do
# tenant_root
# \___ tenant_eye_bee_em (service_template_eye_bee_em)
# \__ subtenant_tenant_eye_bee_em_1 (ems_1)
# \__ subtenant_tenant_eye_bee_em_1_1 (ems_1_1, ems_1_1_a)
# \__ subtenant_tenant_eye_bee_em_3 (ems_3, ems_3_a)

let!(:tenant_root) { Tenant.seed }

let!(:tenant_eye_bee_em) { FactoryBot.create(:tenant, :parent => tenant_root) }
let!(:subtenant_tenant_eye_bee_em_1) { FactoryBot.create(:tenant, :parent => tenant_eye_bee_em) }
let!(:subtenant_tenant_eye_bee_em_3) { FactoryBot.create(:tenant, :parent => tenant_eye_bee_em) }

let!(:subtenant_tenant_eye_bee_em_1_1) { FactoryBot.create(:tenant, :parent => subtenant_tenant_eye_bee_em_1) }

let!(:ems_eye_bee_em) { FactoryBot.create(:ext_management_system, :tenant => tenant_eye_bee_em) }
let!(:ems_1) { FactoryBot.create(:ext_management_system, :tenant => subtenant_tenant_eye_bee_em_1) }
let!(:ems_3) { FactoryBot.create(:ext_management_system, :tenant => subtenant_tenant_eye_bee_em_3) }
let!(:ems_3_a) { FactoryBot.create(:ext_management_system, :tenant => subtenant_tenant_eye_bee_em_3) }
let!(:ems_1_1) { FactoryBot.create(:ext_management_system, :tenant => subtenant_tenant_eye_bee_em_1_1) }
let!(:ems_1_1_a) { FactoryBot.create(:ext_management_system, :tenant => subtenant_tenant_eye_bee_em_1_1) }

it "lists ancestor service templates" do
expect(ExtManagementSystem.with_tenant(subtenant_tenant_eye_bee_em_1_1.id).ids).to match_array([ems_1_1.id, ems_1_1_a.id, ems_1.id, ems_eye_bee_em.id])
expect(ExtManagementSystem.with_tenant(subtenant_tenant_eye_bee_em_3.id).ids).to match_array([ems_3.id, ems_3_a.id, ems_eye_bee_em.id])
end
end

it ".model_name_from_emstype" do
described_class.leaf_subclasses.each do |klass|
expect(described_class.model_name_from_emstype(klass.ems_type)).to eq(klass.name)
Expand Down

0 comments on commit 4967ab5

Please sign in to comment.