Theme data update script, remove theme choices from UI (#15225)
* Add prefer_os_color_scheme to users_settings * Add data update script * Update theme selector view * Update spec wording * Fix spec Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com>
This commit is contained in:
parent
0cf6d7616d
commit
bff7cd1118
7 changed files with 80 additions and 2 deletions
|
|
@ -14,7 +14,8 @@
|
|||
<fieldset class="crayons-field">
|
||||
<legend class="crayons-field__label">Site Theme</legend>
|
||||
<div class="theme-selector-field grid gap-4 grid-cols-2 l:grid-cols-3">
|
||||
<% 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 %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)"
|
||||
|
|
|
|||
22
lib/data_update_scripts/20211019063703_migrate_themes.rb
Normal file
22
lib/data_update_scripts/20211019063703_migrate_themes.rb
Normal file
|
|
@ -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
|
||||
48
spec/lib/data_update_scripts/migrate_themes_spec.rb
Normal file
48
spec/lib/data_update_scripts/migrate_themes_spec.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue