Skip to content

Commit

Permalink
Add Ruby 2.4.0 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
marshall-lee authored and iainbeeston committed Feb 7, 2017
1 parent 0993575 commit 7f42797
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rvm:
- "2.1"
- "2.2"
- "2.3.3"
- "2.4.0"
- "jruby-9.1.7.0"

sudo: false
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- Ruby 2.4 support

### Changed
- Made the `:clear_cache` option for `validate` also clear the URI parse cache
- Moved `JSON::Validator.absolutize_ref` and the ref manipulating code in
Expand Down
8 changes: 4 additions & 4 deletions lib/json-schema/util/array_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class ArraySet < Array
def include?(obj)
if !defined? @values
@values = Set.new
self.each { |x| @values << convert_to_float_if_fixnum(x) }
self.each { |x| @values << convert_to_float_if_numeric(x) }
end
@values.include?(convert_to_float_if_fixnum(obj))
@values.include?(convert_to_float_if_numeric(obj))
end

private

def convert_to_float_if_fixnum(value)
value.is_a?(Fixnum) ? value.to_f : value
def convert_to_float_if_numeric(value)
value.is_a?(Numeric) ? value.to_f : value
end
end
1 change: 0 additions & 1 deletion lib/json-schema/util/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def to_uri
alias urn to_uri

# Convert into 128-bit unsigned integer
# Typically a Bignum instance, but can be a Fixnum.
def to_int
tmp = self.raw_bytes.unpack "C*"
tmp.inject do |r, i|
Expand Down
6 changes: 4 additions & 2 deletions test/custom_format_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ def test_format_validation
assert(!JSON::Validator.validate(schema, data), "#{prefix} fails with 'custom' format validator and wrong data")

errors = JSON::Validator.fully_validate(schema, data)
assert(errors.count == 1 && errors.first.match(/The property '#\/a' must be 42 in schema/), "#{prefix} records fromat error")
assert_equal(errors.count, 1)
assert_match(/The property '#\/a' must be 42 in schema/, errors.first, "#{prefix} records format error")

data["a"] = 23
errors = JSON::Validator.fully_validate(schema, data)
assert(errors.count == 1 && errors.first.match(/The property '#\/a' of type (?:integer|Fixnum) did not match the following type: string/), "#{prefix} records no fromat error on type mismatch")
assert_equal(errors.count, 1)
assert_match(/The property '#\/a' of type (?:Integer|Fixnum) did not match the following type: string/i, errors.first, "#{prefix} records no format error on type mismatch")
end
end

Expand Down
7 changes: 4 additions & 3 deletions test/one_of_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_one_of_sub_errors
errors = JSON::Validator.fully_validate(schema, { "a" => 5 }, :errors_as_objects => true)
nested_errors = errors[0][:errors]
assert_equal([:oneof_0,:oneof_1,:oneof_2], nested_errors.keys, 'should have nested errors for each allOf subschema')
assert_match(/the property '#\/a' of type Fixnum did not match the following type: string/i, nested_errors[:oneof_0][0][:message])
assert_match(/the property '#\/a' of type (?:Integer|Fixnum) did not match the following type: string/i, nested_errors[:oneof_0][0][:message])
assert_match(/the property '#\/a' did not have a minimum value of 10, inclusively/i, nested_errors[:oneof_2][0][:message])
end

Expand All @@ -69,12 +69,13 @@ def test_one_of_sub_errors_message
}

errors = JSON::Validator.fully_validate(schema, { "a" => 5 })
integer_type = RUBY_VERSION.to_f >= 2.4 ? 'Integer' : 'Fixnum'
expected_message = """The property '#/' of type Hash did not match any of the required schemas. The schema specific errors were:
- oneOf #0:
- The property '#/a' of type Fixnum did not match the following type: string
- The property '#/a' of type #{integer_type} did not match the following type: string
- oneOf #1:
- The property '#/a' of type Fixnum did not match the following type: string
- The property '#/a' of type #{integer_type} did not match the following type: string
- oneOf #2:
- The property '#/a' did not have a minimum value of 10, inclusively"""

Expand Down

0 comments on commit 7f42797

Please sign in to comment.