2024-02-08 12:59:52 +08:00
# frozen_string_literal: true
RSpec . describe ThemeSettingsManager :: Objects do
fab! ( :theme )
2024-02-28 10:33:22 +08:00
let ( :objects_setting ) do
yaml = File . read ( " #{ Rails . root } /spec/fixtures/theme_settings/objects_settings.yaml " )
field = theme . set_field ( target : :settings , name : " yaml " , value : yaml )
theme . save!
theme . settings [ :objects_setting ]
end
2024-02-08 12:59:52 +08:00
before { SiteSetting . experimental_objects_type_for_theme_settings = true }
it " can store a list of objects " do
2024-02-28 10:33:22 +08:00
new_value = [
{
" name " = > " section 3 " ,
" links " = > [
{ " name " = > " section 3 link 1 " , " url " = > " https://section3link1.com " } ,
{ " name " = > " section 3 link 2 " } ,
] ,
} ,
{
" name " = > " section 4 " ,
" links " = > [ { " name " = > " section 4 link 1 " , " url " = > " https://section4link1.com " } ] ,
} ,
]
2024-02-08 12:59:52 +08:00
2024-02-28 10:33:22 +08:00
objects_setting . value = new_value
2024-02-08 12:59:52 +08:00
2024-02-28 10:33:22 +08:00
expect ( theme . reload . settings [ :objects_setting ] . value ) . to eq ( new_value )
end
it " raises the right error when there are objects which are not valid " do
new_value = [
{ " name " = > " section 3 " , " links " = > [ { " url " = > " https://some.url.no.name " } ] } ,
{
" links " = > [
{
" name " = > " some name that exceeds the max length of 20 characters " ,
" url " = > " https://some.url " ,
} ,
] ,
} ,
]
2024-02-08 12:59:52 +08:00
2024-02-28 10:33:22 +08:00
expect { objects_setting . value = new_value } . to raise_error (
Discourse :: InvalidParameters ,
" The property at JSON Pointer '/0/links/0/name' must be present. The property at JSON Pointer '/1/name' must be present. The property at JSON Pointer '/1/links/0/name' must be at most 20 characters long. " ,
2024-02-08 12:59:52 +08:00
)
end
end