Skip to content

Commit 3c32d35

Browse files
johvetTate Thurston
authored andcommitted
Try to make Rubocop happy
1 parent 0f80179 commit 3c32d35

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

lib/jsonapi/active_model_error_serializer.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ module JSONAPI
55
class ActiveModelErrorSerializer < ErrorSerializer
66
class << self
77
##
8-
# Get the status code to render for the serializer, considering an
9-
# eventual status provided through the serializer parameters
8+
# Get the status code to render for the serializer
9+
#
10+
# This considers an optional status provided through the serializer
11+
# parameters, as either a symbol or a number.
1012
#
1113
# @param params [Hash]
1214
# The serializer parameters
@@ -72,7 +74,7 @@ def status_code(params)
7274
elsif rels.include?(error_key)
7375
{ pointer: "/data/relationships/#{error_key}" }
7476
elsif error_key == :base
75-
{ pointer: "/data" }
77+
{ pointer: '/data' }
7678
else
7779
{ pointer: nil }
7880
end

lib/jsonapi/rails.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def self.add_errors_renderer!
7373

7474
details[attr] << current
7575
else
76-
details[attr] << error.merge(message: resource.messages[attr][index])
76+
message = resource.messages[attr][index]
77+
details[attr] << error.merge(message: message)
7778
end
7879
end
7980
end
@@ -92,7 +93,11 @@ def self.add_errors_renderer!
9293

9394
JSONAPI::Rails.serializer_to_json(
9495
JSONAPI::ActiveModelErrorSerializer.new(
95-
errors, params: { model: model, model_serializer: model_serializer, status: options[:status] }
96+
errors, params: {
97+
model: model,
98+
model_serializer: model_serializer,
99+
status: options[:status]
100+
}
96101
)
97102
)
98103
end

spec/dummy.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def self.ransackable_attributes(auth_object = nil)
5757

5858
# Provide a validation adding an error to the model's base
5959
def title_check
60-
errors.add(:base, :model_invalid, errors: 'The record has an unacceptable title.') if title == 'n/a'
60+
return unless title == 'n/a'
61+
62+
message = 'The record has an unacceptable title.'
63+
errors.add(:base, :model_invalid, errors: message)
6164
end
6265

6366
def deletable?

0 commit comments

Comments
 (0)