Skip to content

Commit

Permalink
Spec for subclassing resource_pools
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Nov 18, 2019
1 parent 53d6de2 commit 8c92acb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
12 changes: 6 additions & 6 deletions db/migrate/20191118161319_subclass_resource_pools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def up
'Vmware',
].each do |provider|
ems_class_name = "ManageIQ::Providers::#{provider}::InfraManager"
cluster_class_name = "#{ems_class_name}::ResourcePool"
EmsCluster.in_my_region.
joins(:ext_management_system).
where(:ext_management_systems => {:type => ems_class_name}).
update_all(:type => cluster_class_name)
respool_class_name = "#{ems_class_name}::ResourcePool"
ResourcePool.in_my_region
.joins(:ext_management_system)
.where(:ext_management_systems => {:type => ems_class_name})
.update_all(:type => respool_class_name)
end
end

def down
EmsCluster.in_my_region.update_all(:type => nil)
ResourcePool.in_my_region.update_all(:type => nil)
end
end
42 changes: 42 additions & 0 deletions spec/migrations/20191118161319_subclass_resource_pools_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_migration

describe SubclassResourcePools do
let(:ext_management_system_stub) { migration_stub(:ExtManagementSystem) }
let(:resource_pool_stub) { migration_stub(:ResourcePool) }

migration_context :up do
it "migrates resource pools from all supported providers" do
emss = %w[Microsoft Redhat Vmware].map do |vendor|
ext_management_system_stub.create!(:type => "ManageIQ::Providers::#{vendor}::InfraManager")
end

resource_pools = emss.map do |ems|
resource_pool_stub.create!(:ext_management_system => ems)
end

migrate

resource_pools.each do |respool|
expect(respool.reload.type).to eq("#{respool.ext_management_system.type}::ResourcePool")
end
end
end

migration_context :down do
it "migrates resource pools from all supported providers" do
emss = %w[Microsoft Redhat Vmware].map do |vendor|
ext_management_system_stub.create!(:type => "ManageIQ::Providers::#{vendor}::InfraManager")
end

resource_pools = emss.map do |ems|
resource_pool_stub.create!(:ext_management_system => ems, :type => "#{ems.type}::ResourcePool")
end

migrate

resource_pools.each do |respool|
expect(respool.reload.type).to be_nil
end
end
end
end

0 comments on commit 8c92acb

Please sign in to comment.