Skip to content

Commit

Permalink
Include actual exception message with custom exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed May 17, 2016
1 parent d0d7af4 commit 93cad82
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Breaking changes:
- [#1662](https://github.com/rails-api/active_model_serializers/pull/1662) Drop support for Rails 4.0 and Ruby 2.0.0. (@remear)

Features:
- [#1697](https://github.com/rails-api/active_model_serializers/pull/1697) Include actual exception message with custom exceptions;
`Test::Schema` exceptions are now `Minitest::Assertion`s. (@bf4)
- [#1699](https://github.com/rails-api/active_model_serializers/pull/1699) String/Lambda support for conditional attributes/associations (@mtsmfm)
- [#1687](https://github.com/rails-api/active_model_serializers/pull/1687) Only calculate `_cache_digest` (in `cache_key`) when `skip_digest` is false. (@bf4)
- [#1647](https://github.com/rails-api/active_model_serializers/pull/1647) Restrict usage of `serializable_hash` options
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model_serializers/test/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(schema_path, response, message)
def call
json_schema.expand_references!(store: document_store)
status, errors = json_schema.validate(response_body)
@message ||= errors.map(&:to_s).to_sentence
@message = [message, errors.map(&:to_s).to_sentence].compact.join(': ')
status
end

Expand Down
8 changes: 5 additions & 3 deletions test/active_model_serializers/test/schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ def test_that_raises_a_minitest_error_with_a_invalid_schema

def test_that_raises_error_with_a_custom_message_with_a_invalid_schema
message = 'oh boy the show is broken'
exception_message = "#/name: failed schema #/properties/name: For 'properties/name', \"Name 1\" is not an integer. and #/description: failed schema #/properties/description: For 'properties/description', \"Description 1\" is not a boolean."
expected_message = "#{message}: #{exception_message}"

get :show

error = assert_raises Minitest::Assertion do
assert_response_schema(nil, message)
end
assert_equal(message, error.message)
assert_equal(expected_message, error.message)
end

def test_that_assert_with_a_custom_schema
Expand Down Expand Up @@ -102,14 +104,14 @@ def test_that_assert_with_a_custom_schema_directory
end

def test_with_a_non_existent_file
expected_message = 'No Schema file at test/support/schemas/non-existent.json'
message = 'No Schema file at test/support/schemas/non-existent.json'

get :show

error = assert_raises ActiveModelSerializers::Test::Schema::MissingSchema do
assert_response_schema('non-existent.json')
end
assert_equal(expected_message, error.message)
assert_equal(message, error.message)
end

def test_that_raises_with_a_invalid_json_body
Expand Down

0 comments on commit 93cad82

Please sign in to comment.