diff --git a/app/views/users/_customization.html.erb b/app/views/users/_customization.html.erb index f4d163d90..1062329a4 100644 --- a/app/views/users/_customization.html.erb +++ b/app/views/users/_customization.html.erb @@ -14,7 +14,8 @@
Site Theme
- <% Users::Setting.config_themes.keys.each do |theme| %> + <%# This is temporary while we're migrating themes %> + <% %w[light_theme dark_theme].each do |theme| %> <%= render partial: "theme_selector", locals: { f: f, theme: theme } %> <% end %>
diff --git a/db/migrate/20211021063645_add_prefer_os_color_scheme_to_user_settings.rb b/db/migrate/20211021063645_add_prefer_os_color_scheme_to_user_settings.rb new file mode 100644 index 000000000..ec0c33c2b --- /dev/null +++ b/db/migrate/20211021063645_add_prefer_os_color_scheme_to_user_settings.rb @@ -0,0 +1,5 @@ +class AddPreferOsColorSchemeToUserSettings < ActiveRecord::Migration[6.1] + def change + add_column :users_settings, :prefer_os_color_scheme, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 940533ad7..695670f03 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1419,6 +1419,7 @@ ActiveRecord::Schema.define(version: 2021_11_04_161101) do t.string "inbox_guidelines" t.integer "inbox_type", default: 0, null: false t.boolean "permit_adjacent_sponsors", default: true + t.boolean "prefer_os_color_scheme", default: true t.datetime "updated_at", precision: 6, null: false t.bigint "user_id", null: false t.index ["feed_url"], name: "index_users_settings_on_feed_url", where: "((COALESCE(feed_url, ''::character varying))::text <> ''::text)" diff --git a/lib/data_update_scripts/20211019063703_migrate_themes.rb b/lib/data_update_scripts/20211019063703_migrate_themes.rb new file mode 100644 index 000000000..7face4786 --- /dev/null +++ b/lib/data_update_scripts/20211019063703_migrate_themes.rb @@ -0,0 +1,22 @@ +module DataUpdateScripts + class MigrateThemes + FILE_NAME = "20211019063703_migrate_themes".freeze + + def run + # NOTE: I couldn't come up with a better way to make this idempotent. + return if DataUpdateScript.where(file_name: FILE_NAME).any? + + # No OS sync for Dark (2) users + Users::Setting.where(config_theme: 2).update_all(prefer_os_color_scheme: false) + + # Ten X Hacker (4) -> Dark (2), no OS sync + Users::Setting.where(config_theme: 4).update_all(config_theme: 2, prefer_os_color_scheme: false) + + # Minimal (1) -> Light (0), no OS sync + Users::Setting.where(config_theme: 1).update_all(config_theme: 0, prefer_os_color_scheme: false) + + # Pink (3) -> Light (0), OS sync (defaults to true), the + Users::Setting.where(config_theme: 3).update_all(config_theme: 0) + end + end +end diff --git a/spec/lib/data_update_scripts/migrate_themes_spec.rb b/spec/lib/data_update_scripts/migrate_themes_spec.rb new file mode 100644 index 000000000..4f57b78ae --- /dev/null +++ b/spec/lib/data_update_scripts/migrate_themes_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" +require Rails.root.join( + "lib/data_update_scripts/20211019063703_migrate_themes.rb", +) + +describe DataUpdateScripts::MigrateThemes do + let(:user) { create(:user) } + + it "leaves default theme users on light and leaves OS sync enabled" do + user.setting.update_columns(config_theme: 0) + + expect { described_class.new.run } + .to not_change { user.setting.reload.config_theme }.from("light_theme") + .and not_change { user.setting.prefer_os_color_scheme }.from(true) + end + + it "updates minimal theme users to light and disables OS sync" do + user.setting.update_columns(config_theme: 1) + + expect { described_class.new.run } + .to change { user.setting.reload.config_theme }.to("light_theme") + .and change { user.setting.prefer_os_color_scheme }.from(true).to(false) + end + + it "updates night theme users to dark and disables OS sync" do + user.setting.update_columns(config_theme: 2) + + expect { described_class.new.run } + .to not_change { user.setting.reload.config_theme }.from("dark_theme") + .and change { user.setting.prefer_os_color_scheme }.from(true).to(false) + end + + it "updates pink theme users to light and leaves OS sync enabled" do + user.setting.update_columns(config_theme: 3) + + expect { described_class.new.run } + .to change { user.setting.reload.config_theme }.to("light_theme") + .and not_change { user.setting.prefer_os_color_scheme }.from(true) + end + + it "updates ten x hacker theme users to dark and disables OS sync" do + user.setting.update_columns(config_theme: 4) + + expect { described_class.new.run } + .to change { user.setting.reload.config_theme }.to("dark_theme") + .and change { user.setting.prefer_os_color_scheme }.from(true).to(false) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e58e02977..55ec6b233 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,6 +21,7 @@ require "zonebie/rspec" # This makes Rspec fail if there's any output RSpec::Matchers.define_negated_matcher :avoid_outputting, :output RSpec::Matchers.define_negated_matcher :exclude, :include +RSpec::Matchers.define_negated_matcher :not_change, :change ############ RSpec.configure do |config| # makes example fail if there's any output diff --git a/spec/system/user/user_edits_customization_spec.rb b/spec/system/user/user_edits_customization_spec.rb index 57e08b531..cd0bd0c72 100644 --- a/spec/system/user/user_edits_customization_spec.rb +++ b/spec/system/user/user_edits_customization_spec.rb @@ -13,7 +13,7 @@ RSpec.describe "User edits their Customization settings", type: :system do it "makes the 'Save Button' footer sticky once a theme is selected", js: true do expect(page).not_to have_css(".sticky") - choose("Ten X Hacker Theme") + choose("Dark Theme") expect(page).to have_css(".sticky") end