Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate one more feature renamed previously #580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker < ActiveRecord::Migration[6.0]
class MiqProductFeature < ActiveRecord::Base; end

FEATURE_MAPPING = {'automation_manager_add_provider' => 'ems_automation_add_provider'}.freeze

def up
return if MiqProductFeature.none?

say_with_time 'Adjusting Automation Provider add provider feature' do
FEATURE_MAPPING.each do |from, to|
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to)
end
end
end

def down
return if MiqProductFeature.none?

say_with_time 'Adjusting Automation Provider add provider feature' do
FEATURE_MAPPING.each do |to, from|
MiqProductFeature.find_by(:identifier => from)&.update!(:identifier => to)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require_migration

class UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker
class MiqRolesFeature < ActiveRecord::Base; end
end

describe UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker do
let(:user_role_id) { anonymous_class_with_id_regions.id_in_region(1, anonymous_class_with_id_regions.my_region_number) }
let(:feature_stub) { migration_stub :MiqProductFeature }
let(:roles_feature_stub) { migration_stub :MiqRolesFeature }

migration_context :up do
describe 'product features update' do
it "renamed features aren't removed from user roles" do
features = {}
UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker::FEATURE_MAPPING.each do |before, _|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-de-dooper minor, but this can be described_class::FEATURE_MAPPING to save yourself from the long class names.

features[before] = feature_stub.create!(:identifier => before)
roles_feature_stub.create!(:miq_product_feature_id => features[before].id, :miq_user_role_id => user_role_id)
end

migrate

UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker::FEATURE_MAPPING.each do |before, after|
after_feature = features[before].reload
expect(after_feature.identifier).to eq(after)
end
expect(roles_feature_stub.where(:miq_user_role_id => user_role_id).count).to eq(features.keys.length)
end
end
end

migration_context :down do
describe 'product features update' do
it "renamed features aren't removed from user roles" do
features = {}
UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker::FEATURE_MAPPING.each do |_, after|
features[after] = feature_stub.create!(:identifier => after)
roles_feature_stub.create!(:miq_product_feature_id => features[after].id, :miq_user_role_id => user_role_id)
end

migrate

UpdateProductFeaturesWhereIdentifierWasRenamedSinceLasker::FEATURE_MAPPING.each do |before, after|
before_feature = features[after].reload
expect(before_feature.identifier).to eq(before)
end
expect(roles_feature_stub.where(:miq_user_role_id => user_role_id).count).to eq(features.keys.length)
end
end
end
end