schemacop 3.0.17 → 3.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c486c27262569e4a3f3f3b9751aedfab72a15611c457c9748577e2d2625f43ec
4
- data.tar.gz: dc61cc778afc5403904fcc51cb74c81fadb0d5b3142ffb91f0b09b2eb82f4c69
3
+ metadata.gz: d7be04fe24124ae7715ad4bf2ac992d97e0e7fbc924df352ddb09094e02ace5d
4
+ data.tar.gz: c9a21f9cd191d54ad1f56a9434fd47a63a420e4dbe9a890baacfb6a1354b2c1c
5
5
  SHA512:
6
- metadata.gz: 2ad16e54c5d883e62b456718dbb8e086c6e0cad805b88996817876176451fe04b0ababa4410762e2d58adbefbdce34e69a8a0f0ff9499b683dbdfcb3b89185f9
7
- data.tar.gz: b08189742b46257f92dd7e54fd0f917cbb03b95092add3557a90b428f64fdc7ad7428ae96004ee5a645eefec83b70934b3a03f39152fa71d35dc4132bfa9694b
6
+ metadata.gz: 661976d31dc6cfa271cd3347b786e47c7c213f128d36e7431116c5244ae89eff7ad72f25eceead000eb26afd0096bafd39c270f087aea7caac95e23277dc1169
7
+ data.tar.gz: 18f397c6759b4c801a949e310b0cc8c1938972abc08f9e0a59800dab121c7f028143769157969786e61b931973a5f467379290df7103d480dd0d253bbd0987c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.18 (2022-07-27)
4
+
5
+ * Add option `ignore_obsolete_properties` to `HashNode` for Schemacop v3
6
+
3
7
  ## 3.0.17 (2022-06-08)
4
8
 
5
9
  * Add options `filter` and `reject` to array nodes which allow to filter arrays
data/README_V3.md CHANGED
@@ -864,6 +864,13 @@ It consists of key-value-pairs that can be validated using arbitrary nodes.
864
864
  * `max_properties`
865
865
  Specifies the (inclusive) maximum number of properties a hash must contain.
866
866
 
867
+ * `ignore_obsolete_properties`
868
+ Similar to `additional_properties`. If this is set to `true`, all additional
869
+ properties are allowed (i.e. they pass the validation), but they are removed
870
+ from the result hash. This is useful e.g. to validate params coming from the
871
+ controller, as this only allows white-listed params and removes any params
872
+ which are not whitelisted (i.e. similar to strong params from Rails).
873
+
867
874
  #### Specifying properties
868
875
 
869
876
  Hash nodes support a block in which you can specify the required hash contents.
@@ -1071,6 +1078,22 @@ schema.validate!({foo: :bar}) # => Schemacop::Exceptions::ValidationError:
1071
1078
  schema.validate!({Foo: :bar}) # => Schemacop::Exceptions::ValidationError: /: Property name :Foo does not match "^[a-z]+$". /Foo: Invalid type, got type "Symbol", expected "array".
1072
1079
  ```
1073
1080
 
1081
+ ##### Ignoring obsolete properties
1082
+
1083
+ By enabling `ignore_obsolete_properties`, you can filter out any unspecified params,
1084
+ while still passing validation:
1085
+
1086
+ ```ruby
1087
+ # This schema will accept any additional properties, but remove them from the result
1088
+ schema = Schemacop::Schema3.new :hash, ignore_obsolete_properties: true do
1089
+ int? :foo
1090
+ end
1091
+
1092
+ schema.validate!({}) # => {}
1093
+ schema.validate!({foo: :bar}) # => {"foo"=>:bar}
1094
+ schema.validate!({foo: :bar, baz: 42}) # => {"foo"=>:bar}
1095
+ ```
1096
+
1074
1097
  ##### Dependencies
1075
1098
 
1076
1099
  Using the DSL method `dep`, you can specifiy (non-nested) property dependencies:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.17
1
+ 3.0.18
@@ -14,7 +14,7 @@ module Schemacop
14
14
  attr_reader :properties
15
15
 
16
16
  def self.allowed_options
17
- super + ATTRIBUTES - %i[dependencies] + %i[additional_properties]
17
+ super + ATTRIBUTES - %i[dependencies] + %i[additional_properties ignore_obsolete_properties]
18
18
  end
19
19
 
20
20
  def self.dsl_methods
@@ -141,7 +141,7 @@ module Schemacop
141
141
  result.in_path(name) do
142
142
  property_patterns[match]._validate(additional_property, result: result)
143
143
  end
144
- else
144
+ elsif !options[:ignore_obsolete_properties]
145
145
  result.error "Obsolete property #{name.to_s.inspect}."
146
146
  end
147
147
  elsif options[:additional_properties].is_a?(Node)
@@ -235,10 +235,20 @@ module Schemacop
235
235
  fail Schemacop::Exceptions::InvalidSchemaError, 'Option "additional_properties" must be a boolean value'
236
236
  end
237
237
 
238
+ # Cannot set additional_properties and ignore_obsolete_properties option to true at the same time
239
+ if @options[:additional_properties].is_a?(TrueClass) && options[:ignore_obsolete_properties].is_a?(TrueClass)
240
+ fail Schemacop::Exceptions::InvalidSchemaError, 'Cannot set "additional_properties" and "ignore_obsolete_properties" to true at the same time'
241
+ end
242
+
238
243
  # Default the additional_properties option to false if it's not given
239
244
  if @options[:additional_properties].nil?
240
245
  @options[:additional_properties] = false
241
246
  end
247
+
248
+ # Default the ignore_obsolete_properties option to false if it's not given
249
+ if @options[:ignore_obsolete_properties].nil?
250
+ @options[:ignore_obsolete_properties] = false
251
+ end
242
252
  end
243
253
 
244
254
  def validate_self
data/schemacop.gemspec CHANGED
@@ -1,49 +1,37 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 3.0.17 ruby lib
2
+ # stub: schemacop 3.0.18 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.17"
6
+ s.version = "3.0.18"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2022-06-08"
11
+ s.date = "2022-07-27"
12
12
  s.files = [".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/validator/array_validator.rb".freeze, "lib/schemacop/v2/validator/boolean_validator.rb".freeze, "lib/schemacop/v2/validator/float_validator.rb".freeze, "lib/schemacop/v2/validator/hash_validator.rb".freeze, "lib/schemacop/v2/validator/integer_validator.rb".freeze, "lib/schemacop/v2/validator/nil_validator.rb".freeze, "lib/schemacop/v2/validator/number_validator.rb".freeze, "lib/schemacop/v2/validator/object_validator.rb".freeze, "lib/schemacop/v2/validator/string_validator.rb".freeze, "lib/schemacop/v2/validator/symbol_validator.rb".freeze, "lib/schemacop/v3.rb".freeze, "lib/schemacop/v3/all_of_node.rb".freeze, "lib/schemacop/v3/any_of_node.rb".freeze, "lib/schemacop/v3/array_node.rb".freeze, "lib/schemacop/v3/boolean_node.rb".freeze, "lib/schemacop/v3/combination_node.rb".freeze, "lib/schemacop/v3/context.rb".freeze, "lib/schemacop/v3/dsl_scope.rb".freeze, "lib/schemacop/v3/global_context.rb".freeze, "lib/schemacop/v3/hash_node.rb".freeze, "lib/schemacop/v3/integer_node.rb".freeze, "lib/schemacop/v3/is_not_node.rb".freeze, "lib/schemacop/v3/node.rb".freeze, "lib/schemacop/v3/node_registry.rb".freeze, "lib/schemacop/v3/number_node.rb".freeze, "lib/schemacop/v3/numeric_node.rb".freeze, "lib/schemacop/v3/object_node.rb".freeze, "lib/schemacop/v3/one_of_node.rb".freeze, "lib/schemacop/v3/reference_node.rb".freeze, "lib/schemacop/v3/result.rb".freeze, "lib/schemacop/v3/string_node.rb".freeze, "lib/schemacop/v3/symbol_node.rb".freeze, "schemacop.gemspec".freeze, "test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
13
13
  s.homepage = "https://github.com/sitrox/schemacop".freeze
14
14
  s.licenses = ["MIT".freeze]
15
- s.rubygems_version = "3.0.3".freeze
15
+ s.rubygems_version = "3.2.15".freeze
16
16
  s.summary = "Schemacop validates ruby structures consisting of nested hashes and arrays against simple schema definitions.".freeze
17
17
  s.test_files = ["test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
18
18
 
19
19
  if s.respond_to? :specification_version then
20
20
  s.specification_version = 4
21
+ end
21
22
 
22
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
- s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
24
- s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
25
- s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
26
- s.add_development_dependency(%q<rake>.freeze, [">= 0"])
27
- s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
28
- s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
29
- s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
30
- s.add_development_dependency(%q<rubocop>.freeze, ["= 1.24.1"])
31
- s.add_development_dependency(%q<pry>.freeze, [">= 0"])
32
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
33
- s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
34
- else
35
- s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
36
- s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
37
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
38
- s.add_dependency(%q<rake>.freeze, [">= 0"])
39
- s.add_dependency(%q<minitest>.freeze, [">= 0"])
40
- s.add_dependency(%q<minitest-reporters>.freeze, [">= 0"])
41
- s.add_dependency(%q<colorize>.freeze, [">= 0"])
42
- s.add_dependency(%q<rubocop>.freeze, ["= 1.24.1"])
43
- s.add_dependency(%q<pry>.freeze, [">= 0"])
44
- s.add_dependency(%q<byebug>.freeze, [">= 0"])
45
- s.add_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
46
- end
23
+ if s.respond_to? :add_runtime_dependency then
24
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
25
+ s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
26
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
27
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
28
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
29
+ s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
30
+ s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
31
+ s.add_development_dependency(%q<rubocop>.freeze, ["= 1.24.1"])
32
+ s.add_development_dependency(%q<pry>.freeze, [">= 0"])
33
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
34
+ s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
47
35
  else
48
36
  s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
49
37
  s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
@@ -1005,6 +1005,133 @@ module Schemacop
1005
1005
  assert_validation({ active: '', id: '' })
1006
1006
  assert_cast({ active: '', id: '' }, { active: nil, id: nil }.with_indifferent_access)
1007
1007
  end
1008
+
1009
+ def test_ignore_obsolete_properties_true
1010
+ schema :hash, ignore_obsolete_properties: true do
1011
+ int? :foo
1012
+ str? :bar
1013
+ end
1014
+
1015
+ # Some standard validations first
1016
+ assert_validation({})
1017
+ assert_validation({ foo: 1 })
1018
+ assert_validation({ bar: 'baz' })
1019
+ assert_validation({ foo: 1, bar: 'baz' })
1020
+
1021
+ assert_cast({}, {}.with_indifferent_access)
1022
+ assert_cast({ foo: 1 }, { foo: 1 }.with_indifferent_access)
1023
+ assert_cast({ bar: 'baz' }, { bar: 'baz' }.with_indifferent_access)
1024
+ assert_cast({ foo: 1, bar: 'baz' }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1025
+
1026
+ # Should allow obsolete properties and remove them from the result
1027
+ assert_validation({ obsolete_key: 42 })
1028
+ assert_validation({ foo: 1, obsolete_key: 42 })
1029
+ assert_validation({ bar: 'baz', obsolete_key: 42 })
1030
+ assert_validation({ foo: 1, bar: 'baz', obsolete_key: 42 })
1031
+
1032
+ assert_cast({ obsolete_key: 42 }, {}.with_indifferent_access)
1033
+ assert_cast({ foo: 1, obsolete_key: 42 }, { foo: 1 }.with_indifferent_access)
1034
+ assert_cast({ bar: 'baz', obsolete_key: 42 }, { bar: 'baz' }.with_indifferent_access)
1035
+ assert_cast({ foo: 1, bar: 'baz', obsolete_key: 42 }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1036
+ end
1037
+
1038
+ def test_ignore_obsolete_properties_false
1039
+ schema :hash, ignore_obsolete_properties: false do
1040
+ int? :foo
1041
+ str? :bar
1042
+ end
1043
+
1044
+ # Some standard validations first
1045
+ assert_validation({})
1046
+ assert_validation({ foo: 1 })
1047
+ assert_validation({ bar: 'baz' })
1048
+ assert_validation({ foo: 1, bar: 'baz' })
1049
+
1050
+ assert_cast({}, {}.with_indifferent_access)
1051
+ assert_cast({ foo: 1 }, { foo: 1 }.with_indifferent_access)
1052
+ assert_cast({ bar: 'baz' }, { bar: 'baz' }.with_indifferent_access)
1053
+ assert_cast({ foo: 1, bar: 'baz' }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1054
+
1055
+ # Should not allow obsolete properties as the option is set to false
1056
+ assert_validation({ obsolete_key: 42 }) do
1057
+ error '/', 'Obsolete property "obsolete_key".'
1058
+ end
1059
+ assert_validation({ foo: 1, obsolete_key: 42 }) do
1060
+ error '/', 'Obsolete property "obsolete_key".'
1061
+ end
1062
+ assert_validation({ bar: 'baz', obsolete_key: 42 }) do
1063
+ error '/', 'Obsolete property "obsolete_key".'
1064
+ end
1065
+ assert_validation({ foo: 1, bar: 'baz', obsolete_key: 42 }) do
1066
+ error '/', 'Obsolete property "obsolete_key".'
1067
+ end
1068
+ end
1069
+
1070
+ def test_ignore_obsolete_properties_true_and_additional_properties_true
1071
+ # Cannot set both options to true at the same time
1072
+ assert_raises_with_message Exceptions::InvalidSchemaError,
1073
+ 'Cannot set "additional_properties" and "ignore_obsolete_properties" to true at the same time' do
1074
+ schema :hash, ignore_obsolete_properties: true, additional_properties: true
1075
+ end
1076
+ end
1077
+
1078
+ def test_ignore_obsolete_properties_false_and_additional_properties_true
1079
+ # This should allow any additional properties and keep them in the hash
1080
+ schema :hash, ignore_obsolete_properties: false, additional_properties: true do
1081
+ int? :foo
1082
+ str? :bar
1083
+ end
1084
+
1085
+ assert_validation({ obsolete_key: 42 })
1086
+ assert_validation({ foo: 1, obsolete_key: 42 })
1087
+ assert_validation({ bar: 'baz', obsolete_key: 42 })
1088
+ assert_validation({ foo: 1, bar: 'baz', obsolete_key: 42 })
1089
+
1090
+ assert_cast({ obsolete_key: 42 }, { obsolete_key: 42 }.with_indifferent_access)
1091
+ assert_cast({ foo: 1, obsolete_key: 42 }, { foo: 1, obsolete_key: 42 }.with_indifferent_access)
1092
+ assert_cast({ bar: 'baz', obsolete_key: 42 }, { bar: 'baz', obsolete_key: 42 }.with_indifferent_access)
1093
+ assert_cast({ foo: 1, bar: 'baz', obsolete_key: 42 }, { foo: 1, bar: 'baz', obsolete_key: 42 }.with_indifferent_access)
1094
+ end
1095
+
1096
+ def test_ignore_obsolete_properties_true_and_additional_properties_false
1097
+ # This should allow any additional properties and keep them in the hash
1098
+ schema :hash, ignore_obsolete_properties: true, additional_properties: false do
1099
+ int? :foo
1100
+ str? :bar
1101
+ end
1102
+
1103
+ # Should allow obsolete properties and remove them from the result
1104
+ assert_validation({ obsolete_key: 42 })
1105
+ assert_validation({ foo: 1, obsolete_key: 42 })
1106
+ assert_validation({ bar: 'baz', obsolete_key: 42 })
1107
+ assert_validation({ foo: 1, bar: 'baz', obsolete_key: 42 })
1108
+
1109
+ assert_cast({ obsolete_key: 42 }, {}.with_indifferent_access)
1110
+ assert_cast({ foo: 1, obsolete_key: 42 }, { foo: 1 }.with_indifferent_access)
1111
+ assert_cast({ bar: 'baz', obsolete_key: 42 }, { bar: 'baz' }.with_indifferent_access)
1112
+ assert_cast({ foo: 1, bar: 'baz', obsolete_key: 42 }, { foo: 1, bar: 'baz' }.with_indifferent_access)
1113
+ end
1114
+
1115
+ def test_ignore_obsolete_properties_false_and_additional_properties_false
1116
+ # This should not allow any additional properties
1117
+ schema :hash, ignore_obsolete_properties: false, additional_properties: false do
1118
+ int? :foo
1119
+ str? :bar
1120
+ end
1121
+
1122
+ assert_validation({ obsolete_key: 42 }) do
1123
+ error '/', 'Obsolete property "obsolete_key".'
1124
+ end
1125
+ assert_validation({ foo: 1, obsolete_key: 42 }) do
1126
+ error '/', 'Obsolete property "obsolete_key".'
1127
+ end
1128
+ assert_validation({ bar: 'baz', obsolete_key: 42 }) do
1129
+ error '/', 'Obsolete property "obsolete_key".'
1130
+ end
1131
+ assert_validation({ foo: 1, bar: 'baz', obsolete_key: 42 }) do
1132
+ error '/', 'Obsolete property "obsolete_key".'
1133
+ end
1134
+ end
1008
1135
  end
1009
1136
  end
1010
1137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemacop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.17
4
+ version: 3.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,8 +164,8 @@ dependencies:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.21.2
167
- description:
168
- email:
167
+ description:
168
+ email:
169
169
  executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
@@ -277,7 +277,7 @@ homepage: https://github.com/sitrox/schemacop
277
277
  licenses:
278
278
  - MIT
279
279
  metadata: {}
280
- post_install_message:
280
+ post_install_message:
281
281
  rdoc_options: []
282
282
  require_paths:
283
283
  - lib
@@ -292,8 +292,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  - !ruby/object:Gem::Version
293
293
  version: '0'
294
294
  requirements: []
295
- rubygems_version: 3.3.11
296
- signing_key:
295
+ rubygems_version: 3.2.15
296
+ signing_key:
297
297
  specification_version: 4
298
298
  summary: Schemacop validates ruby structures consisting of nested hashes and arrays
299
299
  against simple schema definitions.