-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed foreman features to ems_comfiguration and adjusted roles
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class RenameForemanFeatures < ActiveRecord::Migration[5.1] | ||
class MiqProductFeature < ActiveRecord::Base; end | ||
class MiqRolesFeature < ActiveRecord::Base; end | ||
|
||
def up | ||
return if MiqProductFeature.none? | ||
|
||
MiqProductFeature.find_by(:identifier => 'provider_foreman_explorer')&.update(:identifier => 'ems_configuration') | ||
|
||
MiqProductFeature.find_by(:identifier => 'provider_foreman_view')&.update(:identifier => 'ems_configuration_view') | ||
|
||
provider_feature = MiqProductFeature.find_or_create_by!(:identifier => 'ems_configuration') | ||
|
||
profiles_feature = MiqProductFeature.create!(:identifier => 'configuration_profile') | ||
systems_feature = MiqProductFeature.create!(:identifier => 'configured_system') | ||
|
||
MiqRolesFeature.where(:miq_product_feature_id => provider_feature.id).each do |roles_feature| | ||
MiqRolesFeature.create!(:miq_product_feature_id => profiles_feature.id, :miq_user_role_id => roles_feature.miq_user_role_id) | ||
MiqRolesFeature.create!(:miq_product_feature_id => systems_feature.id, :miq_user_role_id => roles_feature.miq_user_role_id) | ||
end | ||
end | ||
|
||
def down | ||
return if MiqProductFeature.none? | ||
|
||
MiqProductFeature.find_by(:identifier => 'ems_configuration')&.update(:identifier => 'provider_foreman_explorer') | ||
|
||
MiqProductFeature.find_by(:identifier => 'ems_configuration_view')&.update(:identifier => 'provider_foreman_view') | ||
|
||
profiles_feature = MiqProductFeature.find_by!(:identifier => 'configuration_profile') | ||
systems_feature = MiqProductFeature.find_by!(:identifier => 'configured_system') | ||
|
||
MiqRolesFeature.where(:miq_product_feature_id => [profiles_feature.id, systems_feature.id]).delete_all | ||
end | ||
end |
58 changes: 58 additions & 0 deletions
58
spec/migrations/20200331150436_rename_foreman_features_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require_migration | ||
|
||
describe RenameForemanFeatures do | ||
class MiqRolesFeature < ActiveRecord::Base; end | ||
|
||
let(:user_role_id) { rand(1..1000) } | ||
let(:feature_stub) { migration_stub :MiqProductFeature } | ||
let(:roles_feature_stub) { migration_stub :MiqRolesFeature } | ||
|
||
migration_context :up do | ||
let!(:explorer_feature) { feature_stub.create!(:identifier => 'provider_foreman_explorer', :name => 'foo') } | ||
|
||
it 'renames the features' do | ||
view_feature = feature_stub.create!(:identifier => 'provider_foreman_view', :name => 'bar') | ||
|
||
migrate | ||
|
||
expect(explorer_feature.reload.identifier).to eq('ems_configuration') | ||
expect(view_feature.reload.identifier).to eq('ems_configuration_view') | ||
end | ||
|
||
it 'appends the extra features for roles' do | ||
roles_feature_stub.create!(:miq_product_feature_id => explorer_feature.id, :miq_user_role_id => user_role_id) | ||
|
||
expect(MiqRolesFeature.where(:miq_user_role_id => user_role_id).count).to eq(1) | ||
|
||
migrate | ||
|
||
expect(MiqRolesFeature.where(:miq_user_role_id => user_role_id).count).to eq(3) | ||
end | ||
end | ||
|
||
migration_context :down do | ||
let!(:explorer_feature) { feature_stub.create!(:identifier => 'ems_configuration', :name => 'foo') } | ||
let!(:profile_feature) { feature_stub.create!(:identifier => 'configuration_profile', :name => 'baz') } | ||
let!(:system_feature) { feature_stub.create!(:identifier => 'configured_system', :name => 'yay') } | ||
let!(:view_feature) { feature_stub.create!(:identifier => 'ems_configuration_view', :name => 'bar') } | ||
|
||
it 'renames the features' do | ||
migrate | ||
|
||
expect(explorer_feature.reload.identifier).to eq('provider_foreman_explorer') | ||
expect(view_feature.reload.identifier).to eq('provider_foreman_view') | ||
end | ||
|
||
it 'removes the extra features for roles' do | ||
roles_feature_stub.create!(:miq_product_feature_id => explorer_feature.id, :miq_user_role_id => user_role_id) | ||
roles_feature_stub.create!(:miq_product_feature_id => profile_feature.id, :miq_user_role_id => user_role_id) | ||
roles_feature_stub.create!(:miq_product_feature_id => system_feature.id, :miq_user_role_id => user_role_id) | ||
|
||
expect(MiqRolesFeature.where(:miq_user_role_id => user_role_id).count).to eq(3) | ||
|
||
migrate | ||
|
||
expect(MiqRolesFeature.where(:miq_user_role_id => user_role_id).count).to eq(1) | ||
end | ||
end | ||
end |