Skip to content

Commit

Permalink
Use string instead of symbols for hash keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mtnstar committed Sep 21, 2023
1 parent 601cb5f commit b53f39e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
23 changes: 10 additions & 13 deletions db/migrate/20230919124243_migrate_group_settings_die_mitte.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ class LegacyGroupSetting < ActiveRecord::Base
private

def migrate_settings
LegacyGroupSetting.find_each do |setting|
group = setting.target if setting.target_type == 'Group'

next unless group

LegacyGroupSetting.where(target_type: 'Group').find_each do |setting|
group = setting.target
setting.value.each do |key, value|
case key
when :footer_column_1
when 'footer_column_1'
group.letter_footer_column_1 = value
when :footer_column_2
when 'footer_column_2'
group.letter_footer_column_2 = value
when :footer_column_3
when 'footer_column_3'
group.letter_footer_column_3 = value
when :footer_column_4
when 'footer_column_4'
group.letter_footer_column_4 = value
end
end
Expand All @@ -74,10 +71,10 @@ def revert_mounted_attributes
Group.where(id: relevant_group_ids).find_each do |group|
values_for_var = {
messages_letter: {
footer_column_1: group.letter_footer_column_1,
footer_column_2: group.letter_footer_column_2,
footer_column_3: group.letter_footer_column_3,
footer_column_4: group.letter_footer_column_4
'footer_column_1' => group.letter_footer_column_1,
'footer_column_2' => group.letter_footer_column_2,
'footer_column_3' => group.letter_footer_column_3,
'footer_column_4' => group.letter_footer_column_4
}
}

Expand Down
18 changes: 9 additions & 9 deletions spec/migrations/migrate_group_settings_die_mitte_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
var: :messages_letter,
target: group,
value: {
footer_column_1: 'bla',
footer_column_2: 'bli',
footer_column_3: 'blö',
footer_column_4: 'ble'
'footer_column_1' => 'bla',
'footer_column_2' => 'bli',
'footer_column_3' => 'blö',
'footer_column_4' => 'ble'
}
})
end
Expand All @@ -43,7 +43,7 @@

it 'migrates group settings' do
group_settings.each do |s|
value = s.value[:footer_column_3]
value = s.value['footer_column_3']

expect(value).to be_present
expect(value).to eq('blö')
Expand Down Expand Up @@ -84,10 +84,10 @@
layers.each do |group|
setting = MigrateGroupSettingsDieMitte::LegacyGroupSetting.find_by(target: group,
var: :messages_letter)
expect(setting.value[:footer_column_1]).to eq('bla')
expect(setting.value[:footer_column_2]).to eq('bli')
expect(setting.value[:footer_column_3]).to eq('blö')
expect(setting.value[:footer_column_4]).to eq('ble')
expect(setting.value['footer_column_1']).to eq('bla')
expect(setting.value['footer_column_2']).to eq('bli')
expect(setting.value['footer_column_3']).to eq('blö')
expect(setting.value['footer_column_4']).to eq('ble')
end
end
end
Expand Down

0 comments on commit b53f39e

Please sign in to comment.