* feat: add the two new models users_setting and users_notification_setting * feat: add the settings and notification_settings table to the schema * feat: add the user and notification models * feat: add the user_id foreign key to the model * chore: sneaky indent * feat: add some fields from the profile attributes * Revert "feat: add some fields from the profile attributes" This reverts commit 376828746ded063a243505d317140fa5339227cf. * chore: add some profile field attributes * chore: remove language_settings * chore: update indent * chore: remove language_settings * feat: changes to the tables * chore: remove validation in favor of the foreign keys * chore: add default for editor version * Address PR review suggestions * setting_spec.rb needs to be fixed; need help * Working on PR review comments * Continue with addressing PR review comments * Remove normalize_config_values method; pass correct values from forms * Address Travis failures * revert some unnecessary changes in spec file Co-authored-by: Arit Amana <msarit@gmail.com>
73 lines
2.5 KiB
Ruby
73 lines
2.5 KiB
Ruby
require "rails_helper"
|
|
# rubocop:disable Layout/LineLength
|
|
RSpec.describe Users::Setting, type: :model do
|
|
describe "validations" do
|
|
subject { setting }
|
|
|
|
let(:setting) { create(:users_setting, user: user) }
|
|
let(:user) { create(:user) }
|
|
|
|
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) }
|
|
it { is_expected.to define_enum_for(:config_navbar).with_values(default_navbar: 0, static_navbar: 1) }
|
|
it { is_expected.to define_enum_for(:config_theme).with_values(default_theme: 0, minimal_light_theme: 1, night_theme: 2, pink_theme: 3, ten_x_hacker_theme: 4) }
|
|
|
|
describe "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
|
|
|
|
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?).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
|
|
end
|
|
end
|
|
# rubocop:enable Layout/LineLength
|