* schema file undelete description * feat: v1 of the script * Flesh out remaining enums under their categories * complete UsersSettings data update script * complete DUS for relevant attributes in users and profiles tables * complete DUS for users_notification_settings * alphabetize user_settings sql file * safeguard against null values for "null: false" settings * Set up actual UsersSettings DUS and specs files * fix broken DUS script * complete specs for UsersSetting DUS * Address QA of specs * complete specs for users_notification_settings DUS * fix the typos (thanks Julianna!) * begin implementation * still building * add missing attribute "email_membership_newsletter" * complete sync code (except race condition for user profile) * complete implementation, remains tests * Address PR review and fix Travis fails * remove superfluous Profile.new * fix travis fails * feat: update the users_notification_setting attributes from the user model * feat: use the config fonts enums to display the fonts * feat: loop through the keys * fix profile = nil blowing up; add specs for notification_setting model * remove unneeded spec * remove feed validation until after sync code removed; fixes feed_import spec failures * remove spec associated with feed_url validation in user_setting model * fix failing spec 😅 * add TODO * feat: set the user settings in the user controller and use it in the customization form * feat: move some update logic to the users settings controller thats being used from customization * feat: show the updated values form the users_settingd and not the user instance * Generalize redirect back to current tab * still trying to reflect changed theme upon refresh * customizations take effect on refresh * remove 'with_feed' scope from user model Co-authored-by: Jamie Gaskins <jamie@forem.com> * start with takeover for fields previously in profiles table * Takeover code for `publishing_from_rss` section in Settings (#13914) * implement takeover code part 1 * implement takeover code * fix feed fetch * need rhymes help * complete implementation; specs pending * fix STUPID omission that caused so many headaches 😫 * implement profile fields pointing to users_settings 🎉 * run migrations * implement inbox type & guidelines takeover code; specs pending (#13911) * Point changes in notification settings to `users_notification_settings` table (#13910) * implement takeover code; remains specs * address PR feedback; remove related sync code * address PR review feedback * need help with routing and specs * address pr review * addressing pr review * Treat implementation edge cases and omissions 😅 * fix uncommented comment * fixing implementation cases * address more PR review feedback * fixing notifications use-cases * refactor settings controller * more pr review changes * solving bugs * fix broken onboarding * handle eperience_level calls * more fixes * remove unneeded mappings * add To-dos for quety updates * remove done TODO * purge done TODOs * update notification_settings-related queries * start fixing specs * fixing specs * fix notification and lrg_forem specs * fixing broken specs * still fixing * fix line dif and remove reloads from user.rb * run specs * silence bullet and other fixes * remove setting migration scripts and specs, fix more settings for specs * handle missing user for article builder and fix notification specs * fix some final controller specs and re-add incorrectly removed specs * remove deprecated data update scripts and related workers, put travis back * refactor admin tags mods controller, write/move specs for users notifications settings controller * schema cleanup and other small refactors for consistency * set field we can invalidate in spec via active record instead of at the db level * remove I think an uneccessary hook call from subscribe_to_mailchimp_newsletter * use bnefore_create to setup settings, please dont blow up the test suite * mailchimp bot fix * remove decorator in favor of single model method Co-authored-by: Arit Amana <msarit@gmail.com> Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com> Co-authored-by: Arit Amana <32520970+msarit@users.noreply.github.com> Co-authored-by: Jamie Gaskins <jamie@forem.com>
90 lines
3.2 KiB
Ruby
90 lines
3.2 KiB
Ruby
require "rails_helper"
|
|
# rubocop:disable Layout/LineLength
|
|
RSpec.describe Users::Setting, type: :model do
|
|
let(:user) { create(:user) }
|
|
let(:setting) { described_class.find_by(user_id: user.id) }
|
|
|
|
describe "validations" do
|
|
subject { setting }
|
|
|
|
it { is_expected.to validate_length_of(:inbox_guidelines).is_at_most(250).allow_nil }
|
|
it { is_expected.to define_enum_for(:inbox_type).with_values(private: 0, open: 1).with_suffix(:inbox) }
|
|
it { is_expected.to define_enum_for(:config_font).with_values(default: 0, comic_sans: 1, monospace: 2, open_dyslexic: 3, sans_serif: 4, serif: 5).with_suffix(:font) }
|
|
it { is_expected.to define_enum_for(:config_navbar).with_values(default: 0, static: 1).with_suffix(:navbar) }
|
|
it { is_expected.to define_enum_for(:config_theme).with_values(default: 0, minimal_light_theme: 1, night_theme: 2, pink_theme: 3, ten_x_hacker_theme: 4) }
|
|
|
|
describe "#config_theme" do
|
|
it "accepts valid theme" do
|
|
setting.config_theme = 2
|
|
expect(setting).to be_valid
|
|
expect(setting.night_theme?).to be true
|
|
end
|
|
|
|
it "does not accept invalid theme" do
|
|
expect { setting.config_theme = 10 }.to raise_error(ArgumentError)
|
|
end
|
|
end
|
|
|
|
describe "#config_font" do
|
|
it "accepts valid font" do
|
|
setting.config_font = 4
|
|
expect(setting).to be_valid
|
|
expect(setting.sans_serif_font?).to be true
|
|
end
|
|
|
|
it "does not accept invalid font" do
|
|
expect { setting.config_font = 10 }.to raise_error(ArgumentError)
|
|
end
|
|
end
|
|
|
|
describe "#config_navbar" do
|
|
it "accepts valid navbar" do
|
|
setting.config_navbar = 1
|
|
expect(setting).to be_valid
|
|
expect(setting.static_navbar?).to be true
|
|
end
|
|
|
|
it "does not accept invalid navbar" do
|
|
expect { setting.config_navbar = 10 }.to raise_error(ArgumentError)
|
|
end
|
|
end
|
|
|
|
context "when validating feed_url", vcr: true do
|
|
it "is valid with no feed_url" do
|
|
setting.feed_url = nil
|
|
|
|
expect(setting).to be_valid
|
|
end
|
|
|
|
it "is not valid with an invalid feed_url", vcr: { cassette_name: "feeds_validate_url_invalid" } do
|
|
setting.feed_url = "http://example.com"
|
|
|
|
expect(setting).not_to be_valid
|
|
end
|
|
|
|
it "is valid with a valid feed_url", vcr: { cassette_name: "feeds_import_medium_vaidehi" } do
|
|
setting.feed_url = "https://medium.com/feed/@vaidehijoshi"
|
|
|
|
expect(setting).to be_valid
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#resolved_font_name" do
|
|
it "replaces 'default' with font configured for the site in Settings::General" do
|
|
expect(setting.config_font).to eq("default")
|
|
%w[sans_serif serif open_dyslexic].each do |font|
|
|
allow(Settings::UserExperience).to receive(:default_font).and_return(font)
|
|
expect(setting.resolved_font_name).to eq(font)
|
|
end
|
|
end
|
|
|
|
it "doesn't replace the user's custom selected font" do
|
|
user_comic_sans = create(:user)
|
|
user_comic_sans.setting.update(config_font: "comic_sans")
|
|
allow(Settings::UserExperience).to receive(:default_font).and_return("open_dyslexic")
|
|
expect(user_comic_sans.setting.resolved_font_name).to eq("comic_sans")
|
|
end
|
|
end
|
|
end
|
|
# rubocop:enable Layout/LineLength
|