docbrown/spec/models/settings/general_spec.rb
Duke Greene cf7847fadb
remove onboarding background image, use gradient based on brand color (#19815)
* remove background image, rename prop to refer to color, pass primary brand color

* create helper method, send calculated gradient values into frontend props

* test new helper method and refine how color is darkened
2023-07-27 07:27:21 -04:00

53 lines
1.7 KiB
Ruby

require "rails_helper"
RSpec.describe Settings::General do
describe "validations" do
describe "validating URLs" do
let(:url_fields) do
%w[
main_social_image logo_png mascot_image_url
]
end
it "accepts valid URLs" do
url_fields.each do |attribute|
expect do
described_class.public_send("#{attribute}=", "https://example.com")
end.not_to raise_error
end
end
it "rejects invalid URLs and accepts valid ones", :aggregate_failures do
url_fields.each do |attribute|
expect do
described_class.public_send("#{attribute}=", "example.com")
end.to raise_error(/is not a valid URL/)
end
end
end
describe "validating :feed_pinned_article_id" do
it "does not accept non numeric values" do
expect { described_class.feed_pinned_article_id = "string" }.to raise_error(ActiveRecord::RecordInvalid)
end
it "does not accept ids of non existing articles" do
expect { described_class.feed_pinned_article_id = 9999 }.to raise_error(ActiveRecord::RecordInvalid)
end
it "accepts nil" do
expect { described_class.feed_pinned_article_id = nil }.not_to raise_error
end
it "does not accept the id of an existing draft article" do
article = create(:article, published: false)
expect { described_class.feed_pinned_article_id = article.id }.to raise_error(ActiveRecord::RecordInvalid)
end
it "accepts the id of an existing published article" do
article = create(:article, published: true)
expect { described_class.feed_pinned_article_id = article.id }.not_to raise_error
end
end
end
end