2022-06-30 01:54:20 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe SidebarSectionLink do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
describe "Validations" do
|
2023-01-09 05:18:21 -06:00
|
|
|
it "is not valid when linkable already exists for the current user" do
|
2022-06-30 01:54:20 -05:00
|
|
|
category_sidebar_section_link = Fabricate(:category_sidebar_section_link, user: user)
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
sidebar_section_link =
|
|
|
|
SidebarSectionLink.new(user: user, linkable: category_sidebar_section_link.linkable)
|
2022-06-30 01:54:20 -05:00
|
|
|
|
|
|
|
expect(sidebar_section_link.valid?).to eq(false)
|
|
|
|
expect(sidebar_section_link.errors.details[:user_id][0][:error]).to eq(:taken)
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe "#linkable_type" do
|
2022-06-30 01:54:20 -05:00
|
|
|
it "is not valid when linkable_type is not supported" do
|
2023-01-09 05:18:21 -06:00
|
|
|
sidebar_section_link =
|
|
|
|
SidebarSectionLink.new(user: user, linkable_id: 1, linkable_type: "sometype")
|
2022-06-30 01:54:20 -05:00
|
|
|
|
|
|
|
expect(sidebar_section_link.valid?).to eq(false)
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(sidebar_section_link.errors[:linkable_type]).to eq(
|
|
|
|
[
|
|
|
|
I18n.t(
|
|
|
|
"activerecord.errors.models.sidebar_section_link.attributes.linkable_type.invalid",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2022-06-30 01:54:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is not valid when linkable_type is Tag and SiteSetting.tagging_enabled is false" do
|
|
|
|
SiteSetting.tagging_enabled = false
|
2023-01-09 05:18:21 -06:00
|
|
|
sidebar_section_link =
|
|
|
|
SidebarSectionLink.new(user: user, linkable_id: 1, linkable_type: "Tag")
|
2022-06-30 01:54:20 -05:00
|
|
|
|
|
|
|
expect(sidebar_section_link.valid?).to eq(false)
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(sidebar_section_link.errors[:linkable_type]).to eq(
|
|
|
|
[
|
|
|
|
I18n.t(
|
|
|
|
"activerecord.errors.models.sidebar_section_link.attributes.linkable_type.invalid",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2022-06-30 01:54:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|