Add lambda to the validations that use model constants
In this way when we need modify the constants model value in the model/custom folder, adding lambda it will be possible load the new values.
This commit is contained in:
@@ -17,4 +17,14 @@ RSpec.describe SiteCustomization::ContentBlock, type: :model do
|
||||
valid_block = build(:site_customization_content_block, name: "top_links", locale: "es")
|
||||
expect(valid_block).to be_valid
|
||||
end
|
||||
|
||||
it "dynamically validates the valid blocks" do
|
||||
stub_const("#{SiteCustomization::ContentBlock}::VALID_BLOCKS", %w[custom])
|
||||
|
||||
block.name = "custom"
|
||||
expect(block).to be_valid
|
||||
|
||||
block.name = "top_links"
|
||||
expect(block).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,5 +33,15 @@ describe SiteCustomization::Image do
|
||||
|
||||
expect(image).not_to be_valid
|
||||
end
|
||||
|
||||
it "dynamically validates the valid images" do
|
||||
stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "custom" => [223, 80] })
|
||||
|
||||
custom = build(:site_customization_image, name: "custom", image: fixture_file_upload("logo_header.png"))
|
||||
expect(custom).to be_valid
|
||||
|
||||
map = build(:site_customization_image, name: "map", image: fixture_file_upload("custom_map.jpg"))
|
||||
expect(map).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,4 +13,14 @@ RSpec.describe SiteCustomization::Page, type: :model do
|
||||
custom_page = build(:site_customization_page, slug: "as/as*la")
|
||||
expect(custom_page).to be_invalid
|
||||
end
|
||||
|
||||
it "dynamically validates the valid statuses" do
|
||||
stub_const("#{SiteCustomization::Page}::VALID_STATUSES", %w[custom])
|
||||
|
||||
custom_page.status = "custom"
|
||||
expect(custom_page).to be_valid
|
||||
|
||||
custom_page.status = "published"
|
||||
expect(custom_page).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user