File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
lib/canvas/validators/schema_attributes
spec/lib/canvas/validators/schema_attributes Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class SchemaAttribute
77 # Attribute validations specific to product-type variables.
88 class Product < Base
99 ALLOWED_DEFAULT_VALUES = %w[ random ] . freeze
10+ ALLOWED_RESTRICTIONS = %w[ experiences accommodations extras ] . freeze
1011
1112 def validate
1213 super &&
@@ -43,10 +44,16 @@ def ensure_only_values_are_valid
4344
4445 if attribute [ "only" ] . empty?
4546 @errors << %["only" cannot be empty]
46- false
47- else
48- true
47+ return false
4948 end
49+
50+ usupported_entries = attribute [ "only" ] - ALLOWED_RESTRICTIONS
51+ if usupported_entries . any?
52+ @errors << %["only" contains unsupported entries: #{ usupported_entries } ]
53+ return false
54+ end
55+
56+ true
5057 end
5158
5259 def default_value_is_valid? ( value )
Original file line number Diff line number Diff line change 2626
2727 context "when `only` is provided" do
2828 it "is valid when using an array" do
29+ all_allowed_values = %w[ experiences accommodations extras ]
2930 validator = described_class . new ( {
3031 "name" => "my_product" ,
3132 "type" => "product" ,
32- "only" => [ "Experience" , "Product" ] ,
33+ "only" => all_allowed_values ,
3334 } )
3435 expect ( validator . validate ) . to eq ( true )
3536 end
4445 expect ( validator . errors ) . to include ( %["only" cannot be empty] )
4546 end
4647
48+ it "is invalid when using unsupported option" do
49+ validator = described_class . new ( {
50+ "name" => "my_product" ,
51+ "type" => "product" ,
52+ "only" => [ "unsupported" ] ,
53+ } )
54+ expect ( validator . validate ) . to eq ( false )
55+ expect ( validator . errors ) . to include ( %["only" contains unsupported entries: ["unsupported"]] )
56+ end
57+
4758 it "is invalid when not an array" do
4859 validator = described_class . new ( {
4960 "name" => "my_product" ,
You can’t perform that action at this time.
0 commit comments