Skip to content

Add support for ActiveModel::Errors. #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 11, 2017
Merged

Add support for ActiveModel::Errors. #22

merged 12 commits into from
Sep 11, 2017

Conversation

beauby
Copy link
Member

@beauby beauby commented May 18, 2017

No description provided.

@@ -16,9 +17,17 @@ def self.render(resources, options)
end
end

class ErrorRenderer
class ErrorsRenderer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.

@@ -1,3 +1,4 @@
require 'jsonapi/rails/active_model_errors'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing frozen string literal comment.

end
end

class ActiveModelErrors

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.

@@ -0,0 +1,39 @@
module JSONAPI
module Rails
class ActiveModelError

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.

@@ -0,0 +1,39 @@
module JSONAPI

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing frozen string literal comment.

@@ -1,3 +1,4 @@
require 'jsonapi/rails/active_model_errors'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

@@ -0,0 +1,39 @@
module JSONAPI

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

@@ -33,13 +33,13 @@ class Railtie < ::Rails::Railtie
RENDERERS[:jsonapi].render(resources, options).to_json
end

::ActionController::Renderers.add(:jsonapi_error) do |errors, options|
::ActionController::Renderers.add(:jsonapi_errors) do |errors, options|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]

@beauby beauby force-pushed the ar-validation-errors branch from f49e9a7 to 57afcdd Compare July 14, 2017 15:19
@beauby beauby force-pushed the ar-validation-errors branch from 57afcdd to ac98273 Compare July 25, 2017 11:24
@@ -0,0 +1,62 @@
require 'rails_helper'

describe ActionController::Base, "#render", type: :controller do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block has too many lines. [49/25]
Prefer single-quoted strings when you don't need string interpolation or special symbols.

{
detail: 'Email must be a valid email',
title: 'Invalid email',
source: { pointer: "/data/attributes/email" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

{
detail: 'Name can\'t be blank',
title: 'Invalid name',
source: { pointer: "/data/attributes/name" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.


context 'when rendering error hashes' do
controller do
def create

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has too many lines. [13/10]

end
end


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

},
{
"detail" => "Email must be a valid email",
"title" => "Invalid email",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

"source" => { "pointer"=>"/data/attributes/name" }
},
{
"detail" => "Email must be a valid email",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

"detail" => "Name can't be blank",
"title" => "Invalid name",
"source" => { "pointer"=>"/data/attributes/name" }
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the start of the line where the left brace is.

"errors" => [{
"detail" => "Name can't be blank",
"title" => "Invalid name",
"source" => { "pointer"=>"/data/attributes/name" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Surrounding space missing for operator =>.

{
"errors" => [{
"detail" => "Name can't be blank",
"title" => "Invalid name",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

@beauby beauby force-pushed the ar-validation-errors branch from 7078321 to e496357 Compare July 27, 2017 13:04
let(:serialized_errors) do
{
'errors' => [{
'detail' => 'Name can\'t be blank',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.

@beauby beauby force-pushed the ar-validation-errors branch 3 times, most recently from 276e7dc to a7e6841 Compare July 27, 2017 13:07
end
end

class ActiveModelErrors

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.

@beauby beauby force-pushed the ar-validation-errors branch from 0811702 to 0e13ab6 Compare July 31, 2017 11:02
options[:expose] =
controller.jsonapi_expose
.merge!(options[:expose] || {})
.merge!(_jsonapi_pointers: controller.jsonapi_pointers)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align .merge! with .jsonapi_expose on line 70.

options.dup.tap do |options|
options[:expose] =
controller.jsonapi_expose
.merge!(options[:expose] || {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align .merge! with .jsonapi_expose on line 70.


# @api private
def default_options(options, controller)
options.dup.tap do |options|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shadowing outer local variable - options.

(options[:links] ||= {}).merge!(pagination_links)
end
options[:expose] = controller.jsonapi_expose
.merge!(options[:expose] || {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align .merge! with .jsonapi_expose on line 27.


# @api private
def default_options(options, controller, resources)
options.dup.tap do |options|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shadowing outer local variable - options.

@beauby beauby force-pushed the ar-validation-errors branch from 0e13ab6 to d012897 Compare July 31, 2017 11:12
@beauby beauby force-pushed the ar-validation-errors branch 2 times, most recently from 49ce233 to cfcf79a Compare September 6, 2017 06:02
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 8, 2017
@beauby beauby force-pushed the ar-validation-errors branch from cfcf79a to 3fe4bad Compare September 9, 2017 16:50
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 9, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 9, 2017
@jsonapi-rb jsonapi-rb deleted a comment from houndci-bot Sep 9, 2017
@jsonapi-rb jsonapi-rb deleted a comment from NullVoxPopuli Sep 9, 2017
@beauby beauby force-pushed the ar-validation-errors branch from 3fe4bad to 9caf4a0 Compare September 10, 2017 20:17
@beauby beauby force-pushed the ar-validation-errors branch 3 times, most recently from 65a3db7 to f98b88b Compare September 11, 2017 00:20
@beauby beauby force-pushed the ar-validation-errors branch from f98b88b to 99a0509 Compare September 11, 2017 00:21
@beauby beauby force-pushed the ar-validation-errors branch from 5d22a0b to 86fde0c Compare September 11, 2017 07:30
@beauby beauby merged commit 0f31cda into master Sep 11, 2017
@beauby beauby deleted the ar-validation-errors branch September 11, 2017 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants