Skip to content

Commit

Permalink
Fix the way in which the conditions are queried and key is set
Browse files Browse the repository at this point in the history
Thanks Ivan!
  • Loading branch information
aaron-contreras committed Sep 10, 2024
1 parent 908e08e commit 16c20ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@
#++

class MigrateLegacyDefaultThemeToLightTheme < ActiveRecord::Migration[7.1]
class MigrationUserPreference < ActiveRecord::Base
self.table_name = "user_preferences"
end

# Migrate legacy `default` theme to `light` theme
#
# Moving from:
# {
# "settings": {
# "theme": "default"
# "theme": "default",
# "foo": "bar"
# }
# }
#
# To:
# {
# "settings": {
# "theme": "light" # current default theme
# "theme": "light", # current default theme
# "foo": "bar"
# }
# }
def up
MigrationUserPreference
.where(settings: { theme: "default" })
.update_all(settings: { theme: "light" })
execute <<-SQL.squish
UPDATE user_preferences
SET settings = jsonb_set(settings, '{theme}', '"light"')
WHERE settings->>'theme' = 'default';
SQL
end

# no-op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
# Silencing migration logs, since we are not interested in that during testing
subject(:run_migration) { ActiveRecord::Migration.suppress_messages { described_class.new.up } }

shared_let(:user_with_default_theme) { create(:user, preferences: { settings: { theme: "default" } }) }
shared_let(:user_with_light_theme) { create(:user, preferences: { settings: { theme: "light" } }) }
shared_let(:user_with_light_high_contrast_theme) { create(:user, preferences: { settings: { theme: "light_high_contrast" } }) }
shared_let(:user_with_dark_theme) { create(:user, preferences: { settings: { theme: "dark" } }) }
shared_let(:user_with_default_theme) { create(:user, preferences: { settings: { theme: "default", foo: "bar" } }) }
shared_let(:user_with_light_theme) { create(:user, preferences: { settings: { theme: "light", foo: "bar" } }) }
shared_let(:user_with_light_high_contrast_theme) do
create(:user, preferences: { settings: { theme: "light_high_contrast", foo: "bar" } })
end
shared_let(:user_with_dark_theme) { create(:user, preferences: { settings: { theme: "dark", foo: "bar" } }) }

it "sets the theme to light for users with the 'default' theme" do
expect { run_migration }
Expand Down

0 comments on commit 16c20ee

Please sign in to comment.