Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgraded Rubocop to 0.15.0.

  • Loading branch information...
commit 90a1f89d539f1ab9ba2f6cb40f21c804f79c941e 1 parent a401b52
@dblock dblock authored
Showing with 267 additions and 304 deletions.
  1. +4 −0 .rubocop.yml
  2. +1 −1  Gemfile
  3. +8 −8 lib/grape/api.rb
  4. +0 −2  lib/grape/cookies.rb
  5. +6 −6 lib/grape/endpoint.rb
  6. +0 −3  lib/grape/error_formatter/base.rb
  7. +0 −2  lib/grape/error_formatter/json.rb
  8. +0 −2  lib/grape/error_formatter/txt.rb
  9. +0 −2  lib/grape/error_formatter/xml.rb
  10. +0 −2  lib/grape/exceptions/base.rb
  11. +0 −3  lib/grape/exceptions/incompatible_option_values.rb
  12. +0 −3  lib/grape/exceptions/invalid_formatter.rb
  13. +0 −4 lib/grape/exceptions/invalid_versioner_option.rb
  14. +0 −2  lib/grape/exceptions/invalid_with_option_for_represent.rb
  15. +0 −4 lib/grape/exceptions/missing_mime_type.rb
  16. +0 −3  lib/grape/exceptions/missing_option.rb
  17. +0 −3  lib/grape/exceptions/missing_vendor_option.rb
  18. +0 −4 lib/grape/exceptions/unknown_options.rb
  19. +0 −2  lib/grape/exceptions/unknown_validator.rb
  20. +5 −4 lib/grape/exceptions/validation_errors.rb
  21. +0 −3  lib/grape/formatter/base.rb
  22. +0 −2  lib/grape/formatter/json.rb
  23. +15 −16 lib/grape/formatter/serializable_hash.rb
  24. +0 −2  lib/grape/formatter/txt.rb
  25. +0 −2  lib/grape/formatter/xml.rb
  26. +0 −2  lib/grape/http/request.rb
  27. +0 −1  lib/grape/middleware/base.rb
  28. +0 −2  lib/grape/middleware/error.rb
  29. +80 −82 lib/grape/middleware/formatter.rb
  30. +0 −2  lib/grape/middleware/versioner/accept_version_header.rb
  31. +0 −2  lib/grape/middleware/versioner/header.rb
  32. +0 −1  lib/grape/middleware/versioner/param.rb
  33. +3 −4 lib/grape/middleware/versioner/path.rb
  34. +0 −1  lib/grape/namespace.rb
  35. +0 −3  lib/grape/parser/base.rb
  36. +0 −2  lib/grape/parser/json.rb
  37. +0 −2  lib/grape/parser/xml.rb
  38. +0 −2  lib/grape/path.rb
  39. +0 −3  lib/grape/route.rb
  40. +0 −6 lib/grape/validations.rb
  41. +0 −4 lib/grape/validations/coerce.rb
  42. +0 −2  lib/grape/validations/regexp.rb
  43. +20 −24 spec/grape/api_spec.rb
  44. +12 −12 spec/grape/endpoint_spec.rb
  45. +1 −1  spec/grape/middleware/auth/oauth2_spec.rb
  46. +7 −7 spec/grape/middleware/versioner/param_spec.rb
  47. +21 −11 spec/grape/path_spec.rb
  48. +8 −8 spec/grape/util/hash_stack_spec.rb
  49. +74 −32 spec/grape/validations/coerce_spec.rb
  50. +0 −1  spec/grape/validations/values_spec.rb
  51. +2 −2 spec/grape/validations_spec.rb
View
4 .rubocop.yml
@@ -64,3 +64,7 @@ Blocks:
WordArray:
# %w vs. [ '', ... ]
Enabled: false
+
+CyclomaticComplexity:
+ Enabled: false
+
View
2  Gemfile
@@ -16,5 +16,5 @@ group :development, :test do
gem 'cookiejar'
gem 'rack-contrib'
gem 'redcarpet', :platforms => :ruby
- gem 'rubocop', '~> 0.14.1'
+ gem 'rubocop', '~> 0.15.0'
end
View
16 lib/grape/api.rb
@@ -213,7 +213,7 @@ def rescue_from(*args, &block)
if handler
args.each do |arg|
- imbue(:rescue_handlers, { arg => handler })
+ imbue :rescue_handlers, arg => handler
end
end
@@ -324,11 +324,12 @@ def mount(mounts)
app_settings.set :mount_path, mount_path
app.inherit_settings(app_settings)
end
- endpoints << Grape::Endpoint.new(settings.clone, {
+ endpoints << Grape::Endpoint.new(
+ settings.clone,
method: :any,
path: path,
app: app
- })
+ )
end
end
@@ -567,21 +568,20 @@ def add_head_not_allowed_methods_and_options_methods
end
allow_header = (['OPTIONS'] | methods).join(', ')
if methods.include?('OPTIONS') || !self.class.settings[:do_not_route_options]
- self.class.options(path, {}) {
+ self.class.options(path, {}) do
header 'Allow', allow_header
status 204
''
- }
+ end
end
not_allowed_methods = %w(GET PUT POST DELETE PATCH HEAD) - methods
not_allowed_methods << 'OPTIONS' if self.class.settings[:do_not_route_options]
- self.class.route(not_allowed_methods, path) {
+ self.class.route(not_allowed_methods, path) do
header 'Allow', allow_header
status 405
''
- }
+ end
end
end
-
end
end
View
2  lib/grape/cookies.rb
@@ -1,6 +1,5 @@
module Grape
class Cookies
-
def initialize
@cookies = {}
@send_cookies = {}
@@ -36,6 +35,5 @@ def delete(name, opts = {})
options = opts.merge(value: 'deleted', expires: Time.at(0))
self.[]=(name, options)
end
-
end
end
View
12 lib/grape/endpoint.rb
@@ -80,7 +80,7 @@ def mount_in(route_set)
route_set.add_route(self, {
path_info: route.route_compiled,
request_method: method,
- }, { route_info: route })
+ }, route_info: route)
end
end
end
@@ -427,11 +427,11 @@ def build_middleware
b.use Rack::Auth::Digest::MD5, settings[:auth][:realm], settings[:auth][:opaque], &settings[:auth][:proc] if settings[:auth] && settings[:auth][:type] == :http_digest
if settings[:version]
- b.use Grape::Middleware::Versioner.using(settings[:version_options][:using]), {
- versions: settings[:version] ? settings[:version].flatten : nil,
- version_options: settings[:version_options],
- prefix: settings[:root_prefix]
- }
+ b.use Grape::Middleware::Versioner.using(settings[:version_options][:using]),
+ versions: settings[:version] ? settings[:version].flatten : nil,
+ version_options: settings[:version_options],
+ prefix: settings[:root_prefix]
+
end
b.use Grape::Middleware::Formatter,
View
3  lib/grape/error_formatter/base.rb
@@ -1,9 +1,7 @@
module Grape
module ErrorFormatter
module Base
-
class << self
-
FORMATTERS = {
serializable_hash: Grape::ErrorFormatter::Json,
json: Grape::ErrorFormatter::Json,
@@ -27,7 +25,6 @@ def formatter_for(api_format, options = {})
spec
end
end
-
end
end
end
View
2  lib/grape/error_formatter/json.rb
@@ -2,7 +2,6 @@ module Grape
module ErrorFormatter
module Json
class << self
-
def call(message, backtrace, options = {}, env = nil)
result = message.is_a?(Hash) ? message : { error: message }
if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
@@ -10,7 +9,6 @@ def call(message, backtrace, options = {}, env = nil)
end
MultiJson.dump(result)
end
-
end
end
end
View
2  lib/grape/error_formatter/txt.rb
@@ -2,7 +2,6 @@ module Grape
module ErrorFormatter
module Txt
class << self
-
def call(message, backtrace, options = {}, env = nil)
result = message.is_a?(Hash) ? MultiJson.dump(message) : message
if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
@@ -11,7 +10,6 @@ def call(message, backtrace, options = {}, env = nil)
end
result
end
-
end
end
end
View
2  lib/grape/error_formatter/xml.rb
@@ -2,7 +2,6 @@ module Grape
module ErrorFormatter
module Xml
class << self
-
def call(message, backtrace, options = {}, env = nil)
result = message.is_a?(Hash) ? message : { message: message }
if (options[:rescue_options] || {})[:backtrace] && backtrace && !backtrace.empty?
@@ -10,7 +9,6 @@ def call(message, backtrace, options = {}, env = nil)
end
result.respond_to?(:to_xml) ? result.to_xml(root: :error) : result.to_s
end
-
end
end
end
View
2  lib/grape/exceptions/base.rb
@@ -1,7 +1,6 @@
module Grape
module Exceptions
class Base < StandardError
-
BASE_MESSAGES_KEY = 'grape.errors.messages'
BASE_ATTRIBUTES_KEY = 'grape.errors.attributes'
FALLBACK_LOCALE = :en
@@ -62,7 +61,6 @@ def translate(key, options = {})
message = ::I18n.translate(key, options)
message.present? ? message : ::I18n.translate(key, options.merge(locale: FALLBACK_LOCALE))
end
-
end
end
end
View
3  lib/grape/exceptions/incompatible_option_values.rb
@@ -2,12 +2,9 @@
module Grape
module Exceptions
class IncompatibleOptionValues < Base
-
def initialize(option1, value1, option2, value2)
super(message: compose_message("incompatible_option_values", option1: option1, value1: value1, option2: option2, value2: value2))
end
-
end
-
end
end
View
3  lib/grape/exceptions/invalid_formatter.rb
@@ -2,12 +2,9 @@
module Grape
module Exceptions
class InvalidFormatter < Base
-
def initialize(klass, to_format)
super(message: compose_message("invalid_formatter", klass: klass, to_format: to_format))
end
-
end
-
end
end
View
4 lib/grape/exceptions/invalid_versioner_option.rb
@@ -1,14 +1,10 @@
# encoding: utf-8
module Grape
module Exceptions
-
class InvalidVersionerOption < Base
-
def initialize(strategy)
super(message: compose_message("invalid_versioner_option", strategy: strategy))
end
-
end
-
end
end
View
2  lib/grape/exceptions/invalid_with_option_for_represent.rb
@@ -2,11 +2,9 @@
module Grape
module Exceptions
class InvalidWithOptionForRepresent < Base
-
def initialize
super(message: compose_message("invalid_with_option_for_represent"))
end
-
end
end
end
View
4 lib/grape/exceptions/missing_mime_type.rb
@@ -2,13 +2,9 @@
module Grape
module Exceptions
class MissingMimeType < Base
-
def initialize(new_format)
super(message: compose_message("missing_mime_type", new_format: new_format))
end
-
end
-
end
-
end
View
3  lib/grape/exceptions/missing_option.rb
@@ -2,12 +2,9 @@
module Grape
module Exceptions
class MissingOption < Base
-
def initialize(option)
super(message: compose_message("missing_option", option: option))
end
-
end
-
end
end
View
3  lib/grape/exceptions/missing_vendor_option.rb
@@ -2,12 +2,9 @@
module Grape
module Exceptions
class MissingVendorOption < Base
-
def initialize
super(message: compose_message("missing_vendor_option"))
end
-
end
-
end
end
View
4 lib/grape/exceptions/unknown_options.rb
@@ -2,13 +2,9 @@
module Grape
module Exceptions
class UnknownOptions < Base
-
def initialize(options)
super(message: compose_message("unknown_options", options: options))
end
-
end
-
end
-
end
View
2  lib/grape/exceptions/unknown_validator.rb
@@ -2,11 +2,9 @@
module Grape
module Exceptions
class UnknownValidator < Base
-
def initialize(validator_type)
super(message: compose_message("unknown_validator", validator_type: validator_type))
end
-
end
end
end
View
9 lib/grape/exceptions/validation_errors.rb
@@ -31,11 +31,12 @@ def full_messages
end
def full_message(attribute, error)
- I18n.t("grape.errors.format".to_sym, {
- default: "%{attribute} %{message}",
+ I18n.t(
+ "grape.errors.format".to_sym,
+ default: "%{attribute} %{message}",
attribute: translate_attribute(attribute),
- message: error.message
- })
+ message: error.message
+ )
end
end
end
View
3  lib/grape/formatter/base.rb
@@ -1,9 +1,7 @@
module Grape
module Formatter
module Base
-
class << self
-
FORMATTERS = {
json: Grape::Formatter::Json,
jsonapi: Grape::Formatter::Json,
@@ -27,7 +25,6 @@ def formatter_for(api_format, options = {})
spec
end
end
-
end
end
end
View
2  lib/grape/formatter/json.rb
@@ -2,12 +2,10 @@ module Grape
module Formatter
module Json
class << self
-
def call(object, env)
return object.to_json if object.respond_to?(:to_json)
MultiJson.dump(object)
end
-
end
end
end
View
31 lib/grape/formatter/serializable_hash.rb
@@ -2,7 +2,6 @@ module Grape
module Formatter
module SerializableHash
class << self
-
def call(object, env)
return object if object.is_a?(String)
return MultiJson.dump(serialize(object)) if serializable?(object)
@@ -12,24 +11,24 @@ def call(object, env)
private
- def serializable?(object)
- object.respond_to?(:serializable_hash) || object.kind_of?(Array) && !object.map { |o| o.respond_to? :serializable_hash }.include?(false) || object.kind_of?(Hash)
- end
+ def serializable?(object)
+ object.respond_to?(:serializable_hash) || object.kind_of?(Array) && !object.map { |o| o.respond_to? :serializable_hash }.include?(false) || object.kind_of?(Hash)
+ end
- def serialize(object)
- if object.respond_to? :serializable_hash
- object.serializable_hash
- elsif object.kind_of?(Array) && !object.map { |o| o.respond_to? :serializable_hash }.include?(false)
- object.map { |o| o.serializable_hash }
- elsif object.kind_of?(Hash)
- object.inject({}) do |h, (k, v)|
- h[k] = serialize(v)
- h
- end
- else
- object
+ def serialize(object)
+ if object.respond_to? :serializable_hash
+ object.serializable_hash
+ elsif object.kind_of?(Array) && !object.map { |o| o.respond_to? :serializable_hash }.include?(false)
+ object.map { |o| o.serializable_hash }
+ elsif object.kind_of?(Hash)
+ object.inject({}) do |h, (k, v)|
+ h[k] = serialize(v)
+ h
end
+ else
+ object
end
+ end
end
end
end
View
2  lib/grape/formatter/txt.rb
@@ -2,11 +2,9 @@ module Grape
module Formatter
module Txt
class << self
-
def call(object, env)
object.respond_to?(:to_txt) ? object.to_txt : object.to_s
end
-
end
end
end
View
2  lib/grape/formatter/xml.rb
@@ -2,12 +2,10 @@ module Grape
module Formatter
module Xml
class << self
-
def call(object, env)
return object.to_xml if object.respond_to?(:to_xml)
raise Grape::Exceptions::InvalidFormatter.new(object.class, 'xml')
end
-
end
end
end
View
2  lib/grape/http/request.rb
@@ -1,6 +1,5 @@
module Grape
class Request < Rack::Request
-
def params
@params ||= begin
params = Hashie::Mash.new(super)
@@ -23,6 +22,5 @@ def headers
h
end
end
-
end
end
View
1  lib/grape/middleware/base.rb
@@ -57,7 +57,6 @@ def mime_types
types_without_params[k] = v.split(';').first
}.invert
end
-
end
end
end
View
2  lib/grape/middleware/error.rb
@@ -3,7 +3,6 @@
module Grape
module Middleware
class Error < Base
-
def default_options
{
default_status: 403, # default status returned on error
@@ -73,7 +72,6 @@ def format_message(message, backtrace)
throw :error, status: 406, message: "The requested format '#{format}' is not supported." unless formatter
formatter.call(message, backtrace, options, env)
end
-
end
end
end
View
162 lib/grape/middleware/formatter.rb
@@ -3,7 +3,6 @@
module Grape
module Middleware
class Formatter < Base
-
def default_options
{
default_format: :txt,
@@ -42,111 +41,110 @@ def after
private
- def request
- @request ||= Rack::Request.new(env)
- end
-
- # store read input in env['api.request.input']
- def read_body_input
- if (request.post? || request.put? || request.patch? || request.delete?) &&
- (!request.form_data? || !request.media_type) &&
- (!request.parseable_data?) &&
- (request.content_length.to_i > 0 || request.env['HTTP_TRANSFER_ENCODING'] == 'chunked')
+ def request
+ @request ||= Rack::Request.new(env)
+ end
- if (input = env['rack.input'])
+ # store read input in env['api.request.input']
+ def read_body_input
+ if (request.post? || request.put? || request.patch? || request.delete?) &&
+ (!request.form_data? || !request.media_type) &&
+ (!request.parseable_data?) &&
+ (request.content_length.to_i > 0 || request.env['HTTP_TRANSFER_ENCODING'] == 'chunked')
+
+ if (input = env['rack.input'])
+ input.rewind
+ body = env['api.request.input'] = input.read
+ begin
+ read_rack_input(body) if body && body.length > 0
+ ensure
input.rewind
- body = env['api.request.input'] = input.read
- begin
- read_rack_input(body) if body && body.length > 0
- ensure
- input.rewind
- end
end
end
end
+ end
- # store parsed input in env['api.request.body']
- def read_rack_input(body)
- fmt = mime_types[request.media_type] if request.media_type
- fmt ||= options[:default_format]
- if content_type_for(fmt)
- parser = Grape::Parser::Base.parser_for fmt, options
- if parser
- begin
- body = (env['api.request.body'] = parser.call(body, env))
- if body.is_a?(Hash)
- if env['rack.request.form_hash']
- env['rack.request.form_hash'] = env['rack.request.form_hash'].merge(body)
- else
- env['rack.request.form_hash'] = body
- end
- env['rack.request.form_input'] = env['rack.input']
+ # store parsed input in env['api.request.body']
+ def read_rack_input(body)
+ fmt = mime_types[request.media_type] if request.media_type
+ fmt ||= options[:default_format]
+ if content_type_for(fmt)
+ parser = Grape::Parser::Base.parser_for fmt, options
+ if parser
+ begin
+ body = (env['api.request.body'] = parser.call(body, env))
+ if body.is_a?(Hash)
+ if env['rack.request.form_hash']
+ env['rack.request.form_hash'] = env['rack.request.form_hash'].merge(body)
+ else
+ env['rack.request.form_hash'] = body
end
- rescue StandardError => e
- throw :error, status: 400, message: e.message
+ env['rack.request.form_input'] = env['rack.input']
end
- else
- env['api.request.body'] = body
+ rescue StandardError => e
+ throw :error, status: 400, message: e.message
end
else
- throw :error, status: 406, message: "The requested content-type '#{request.media_type}' is not supported."
+ env['api.request.body'] = body
end
+ else
+ throw :error, status: 406, message: "The requested content-type '#{request.media_type}' is not supported."
end
+ end
- def negotiate_content_type
- fmt = format_from_extension || format_from_params || options[:format] || format_from_header || options[:default_format]
- if content_type_for(fmt)
- env['api.format'] = fmt
- else
- throw :error, status: 406, message: "The requested format '#{fmt}' is not supported."
- end
+ def negotiate_content_type
+ fmt = format_from_extension || format_from_params || options[:format] || format_from_header || options[:default_format]
+ if content_type_for(fmt)
+ env['api.format'] = fmt
+ else
+ throw :error, status: 406, message: "The requested format '#{fmt}' is not supported."
end
+ end
- def format_from_extension
- parts = request.path.split('.')
+ def format_from_extension
+ parts = request.path.split('.')
- if parts.size > 1
- extension = parts.last
- # avoid symbol memory leak on an unknown format
- return extension.to_sym if content_type_for(extension)
- end
- nil
- end
-
- def format_from_params
- fmt = Rack::Utils.parse_nested_query(env['QUERY_STRING'])["format"]
+ if parts.size > 1
+ extension = parts.last
# avoid symbol memory leak on an unknown format
- return fmt.to_sym if content_type_for(fmt)
- fmt
+ return extension.to_sym if content_type_for(extension)
end
+ nil
+ end
- def format_from_header
- mime_array.each do |t|
- return mime_types[t] if mime_types.key?(t)
- end
- nil
- end
+ def format_from_params
+ fmt = Rack::Utils.parse_nested_query(env['QUERY_STRING'])["format"]
+ # avoid symbol memory leak on an unknown format
+ return fmt.to_sym if content_type_for(fmt)
+ fmt
+ end
- def mime_array
- accept = headers['accept']
- return [] unless accept
+ def format_from_header
+ mime_array.each do |t|
+ return mime_types[t] if mime_types.key?(t)
+ end
+ nil
+ end
- accept_into_mime_and_quality = %r(
- (
- \w+/[\w+.-]+) # eg application/vnd.example.myformat+xml
- (?:
- (?:;[^,]*?)? # optionally multiple formats in a row
- ;\s*q=([\d.]+) # optional "quality" preference (eg q=0.5)
- )?
- )x
+ def mime_array
+ accept = headers['accept']
+ return [] unless accept
- vendor_prefix_pattern = /vnd\.[^+]+\+/
+ accept_into_mime_and_quality = %r(
+ (
+ \w+/[\w+.-]+) # eg application/vnd.example.myformat+xml
+ (?:
+ (?:;[^,]*?)? # optionally multiple formats in a row
+ ;\s*q=([\d.]+) # optional "quality" preference (eg q=0.5)
+ )?
+ )x
- accept.scan(accept_into_mime_and_quality)
- .sort_by { |_, quality_preference| -quality_preference.to_f }
- .map { |mime, _| mime.sub(vendor_prefix_pattern, '') }
- end
+ vendor_prefix_pattern = /vnd\.[^+]+\+/
+ accept.scan(accept_into_mime_and_quality)
+ .sort_by { |_, quality_preference| -quality_preference.to_f }
+ .map { |mime, _| mime.sub(vendor_prefix_pattern, '') }
+ end
end
end
end
View
2  lib/grape/middleware/versioner/accept_version_header.rb
@@ -17,7 +17,6 @@ module Versioner
# X-Cascade header to alert Rack::Mount to attempt the next matched
# route.
class AcceptVersionHeader < Base
-
def before
potential_version = (env['HTTP_ACCEPT_VERSION'] || '').strip
@@ -62,7 +61,6 @@ def cascade?
def error_headers
cascade? ? { 'X-Cascade' => 'pass' } : {}
end
-
end
end
end
View
2  lib/grape/middleware/versioner/header.rb
@@ -22,7 +22,6 @@ module Versioner
# X-Cascade header to alert Rack::Mount to attempt the next matched
# route.
class Header < Base
-
def before
header = Rack::Accept::MediaType.new env['HTTP_ACCEPT']
@@ -123,7 +122,6 @@ def has_version?(media_type)
_, subtype = Rack::Accept::Header.parse_media_type media_type
subtype[/\Avnd\.[a-z0-9*.]+-[a-z0-9*\-.]+/]
end
-
end
end
end
View
1  lib/grape/middleware/versioner/param.rb
@@ -36,7 +36,6 @@ def before
env['rack.request.query_hash'].delete(paramkey) if env.key? 'rack.request.query_hash'
end
end
-
end
end
end
View
7 lib/grape/middleware/versioner/path.rb
@@ -43,10 +43,9 @@ def before
private
- def prefix
- Rack::Mount::Utils.normalize_path(options[:prefix].to_s) if options[:prefix]
- end
-
+ def prefix
+ Rack::Mount::Utils.normalize_path(options[:prefix].to_s) if options[:prefix]
+ end
end
end
end
View
1  lib/grape/namespace.rb
@@ -19,6 +19,5 @@ def self.joined_space(settings)
def self.joined_space_path(settings)
Rack::Mount::Utils.normalize_path(joined_space(settings))
end
-
end
end
View
3  lib/grape/parser/base.rb
@@ -1,9 +1,7 @@
module Grape
module Parser
module Base
-
class << self
-
PARSERS = {
json: Grape::Parser::Json,
jsonapi: Grape::Parser::Json,
@@ -25,7 +23,6 @@ def parser_for(api_format, options = {})
spec
end
end
-
end
end
end
View
2  lib/grape/parser/json.rb
@@ -2,11 +2,9 @@ module Grape
module Parser
module Json
class << self
-
def call(object, env)
MultiJson.load(object)
end
-
end
end
end
View
2  lib/grape/parser/xml.rb
@@ -2,11 +2,9 @@ module Grape
module Parser
module Xml
class << self
-
def call(object, env)
MultiXml.parse(object)
end
-
end
end
end
View
2  lib/grape/path.rb
@@ -1,6 +1,5 @@
module Grape
class Path
-
def self.prepare(raw_path, namespace, settings)
Path.new(raw_path, namespace, settings).path_with_suffix
end
@@ -67,6 +66,5 @@ def split_setting(key, delimiter)
return if settings[key].nil?
settings[key].to_s.split("/")
end
-
end
end
View
3  lib/grape/route.rb
@@ -1,8 +1,6 @@
module Grape
-
# A compiled route for inspection.
class Route
-
def initialize(options = {})
@options = options || {}
end
@@ -25,6 +23,5 @@ def to_s
def to_ary
nil
end
-
end
end
View
6 lib/grape/validations.rb
@@ -1,7 +1,5 @@
module Grape
-
module Validations
-
##
# All validators must inherit from this class.
#
@@ -64,7 +62,6 @@ def initialize(attrs, options, required, scope)
@option = options
super
end
-
end
# We define Validator::inherited here so SingleOptionValidator
@@ -230,7 +227,6 @@ def validate(type, options, attrs, doc_attrs)
raise Grape::Exceptions::UnknownValidator.new(type)
end
end
-
end
# This module is mixed into the API Class.
@@ -252,9 +248,7 @@ def document_attribute(names, opts)
@last_description[:params][name[:full_name].to_s].merge!(opts)
end
end
-
end
-
end
end
View
4 lib/grape/validations/coerce.rb
@@ -1,11 +1,9 @@
module Grape
-
class API
Boolean = Virtus::Attribute::Boolean # rubocop:disable ConstantName
end
module Validations
-
class CoerceValidator < SingleOptionValidator
def validate_param!(attr_name, params)
new_value = coerce_value(@option, params[attr_name])
@@ -55,8 +53,6 @@ def coerce_value(type, val)
rescue
InvalidValue.new
end
-
end
-
end
end
View
2  lib/grape/validations/regexp.rb
@@ -1,6 +1,5 @@
module Grape
module Validations
-
class RegexpValidator < SingleOptionValidator
def validate_param!(attr_name, params)
if params[attr_name] && !(params[attr_name].to_s =~ @option)
@@ -8,6 +7,5 @@ def validate_param!(attr_name, params)
end
end
end
-
end
end
View
44 spec/grape/api_spec.rb
@@ -383,7 +383,7 @@ def subject.enable_root_route!
subject.send(verb) do
env['api.request.body']
end
- send verb, '/', MultiJson.dump(object), { 'CONTENT_TYPE' => 'application/json' }
+ send verb, '/', MultiJson.dump(object), 'CONTENT_TYPE' => 'application/json'
last_response.status.should == (verb == :post ? 201 : 200)
last_response.body.should eql MultiJson.dump(object)
last_request.params.should eql Hash.new
@@ -393,7 +393,7 @@ def subject.enable_root_route!
subject.send(verb) do
env['api.request.input']
end
- send verb, '/', MultiJson.dump(object), { 'CONTENT_TYPE' => 'application/json' }
+ send verb, '/', MultiJson.dump(object), 'CONTENT_TYPE' => 'application/json'
last_response.status.should == (verb == :post ? 201 : 200)
last_response.body.should eql MultiJson.dump(object).to_json
end
@@ -403,7 +403,7 @@ def subject.enable_root_route!
subject.send(verb) do
env['api.request.input']
end
- send verb, '/', MultiJson.dump(object), { 'CONTENT_TYPE' => 'application/json', 'HTTP_TRANSFER_ENCODING' => 'chunked', 'CONTENT_LENGTH' => nil }
+ send verb, '/', MultiJson.dump(object), 'CONTENT_TYPE' => 'application/json', 'HTTP_TRANSFER_ENCODING' => 'chunked', 'CONTENT_LENGTH' => nil
last_response.status.should == (verb == :post ? 201 : 200)
last_response.body.should eql MultiJson.dump(object).to_json
end
@@ -742,13 +742,13 @@ def call(env)
end
it 'adds a block if one is given' do
- block = lambda { }
+ block = lambda {}
subject.use ApiSpec::PhonyMiddleware, &block
subject.middleware.should eql [[ApiSpec::PhonyMiddleware, block]]
end
it 'uses a block if one is given' do
- block = lambda { }
+ block = lambda {}
subject.use ApiSpec::PhonyMiddleware, &block
subject.get '/' do
env['phony.block'].inspect
@@ -759,7 +759,7 @@ def call(env)
end
it 'does not destroy the middleware settings on multiple runs' do
- block = lambda { }
+ block = lambda {}
subject.use ApiSpec::PhonyMiddleware, &block
subject.get '/' do
env['phony.block'].inspect
@@ -1337,7 +1337,7 @@ def self.call(message, backtrace, option, env)
last_response.body.should eql '{"some":"hash"}'
end
it 'uses custom formatter' do
- get '/simple.custom', { 'HTTP_ACCEPT' => 'application/custom' }
+ get '/simple.custom', 'HTTP_ACCEPT' => 'application/custom'
last_response.body.should eql '{"custom_formatter":"hash"}'
end
end
@@ -1360,7 +1360,7 @@ def self.call(object, env)
last_response.body.should eql '{"some":"hash"}'
end
it 'uses custom formatter' do
- get '/simple.custom', { 'HTTP_ACCEPT' => 'application/custom' }
+ get '/simple.custom', 'HTTP_ACCEPT' => 'application/custom'
last_response.body.should eql '{"custom_formatter":"hash"}'
end
end
@@ -1372,7 +1372,7 @@ def self.call(object, env)
subject.post '/data' do
{ x: params[:x] }
end
- post "/data", '{"x":42}', { 'CONTENT_TYPE' => 'application/json' }
+ post "/data", '{"x":42}', 'CONTENT_TYPE' => 'application/json'
last_response.status.should == 201
last_response.body.should == '{"x":42}'
end
@@ -1542,7 +1542,7 @@ def self.call(object, env)
end
describe 'api structure with additional parameters' do
before(:each) do
- subject.get 'split/:string', { params: { "token" => "a token" }, optional_params: { "limit" => "the limit" } } do
+ subject.get 'split/:string', params: { "token" => "a token" }, optional_params: { "limit" => "the limit" } do
params[:string].split(params[:token], (params[:limit] || 0).to_i)
end
end
@@ -1579,7 +1579,7 @@ def self.call(object, env)
route = subject.routes.first
route.route_description.should == "first method"
route.route_foo.should be_nil
- route.route_params.should == { }
+ route.route_params.should == {}
end
it 'describes methods separately' do
subject.desc "first method"
@@ -1626,9 +1626,7 @@ def self.call(object, env)
]
end
it 'describes a method with parameters' do
- subject.desc "Reverses a string.", { params:
- { "s" => { desc: "string to reverse", type: "string" } }
- }
+ subject.desc "Reverses a string.", params: { "s" => { desc: "string to reverse", type: "string" } }
subject.get 'reverse' do
params[:s].reverse
end
@@ -1749,9 +1747,7 @@ def self.call(object, env)
]
end
it 'does not symbolize params' do
- subject.desc "Reverses a string.", { params:
- { "s" => { desc: "string to reverse", type: "string" } }
- }
+ subject.desc "Reverses a string.", params: { "s" => { desc: "string to reverse", type: "string" } }
subject.get 'reverse/:s' do
params[:s].reverse
end
@@ -1764,7 +1760,7 @@ def self.call(object, env)
end
describe '.mount' do
- let(:mounted_app) { lambda { |env| [200, { }, ["MOUNTED"]] } }
+ let(:mounted_app) { lambda { |env| [200, {}, ["MOUNTED"]] } }
context 'with a bare rack app' do
before do
@@ -1856,8 +1852,8 @@ def self.call(object, env)
it 'collects the routes of the mounted api' do
subject.namespace :cool do
app = Class.new(Grape::API)
- app.get('/awesome') { }
- app.post('/sauce') { }
+ app.get('/awesome') {}
+ app.post('/sauce') {}
mount app
end
subject.routes.size.should == 2
@@ -1961,7 +1957,7 @@ def self.call(object, env)
subject.get '/description' do
route.route_description
end
- subject.desc 'returns parameters', { params: { "x" => "y" } }
+ subject.desc 'returns parameters', params: { "x" => "y" }
subject.get '/params/:id' do
route.route_params[params[:id]]
end
@@ -1994,7 +1990,7 @@ def self.call(object, env)
last_response.body.should == { meaning_of_life: 42 }.to_json
end
it 'forces txt from a non-accepting header' do
- get '/meaning_of_life', {}, { 'HTTP_ACCEPT' => 'application/json' }
+ get '/meaning_of_life', {}, 'HTTP_ACCEPT' => 'application/json'
last_response.body.should == { meaning_of_life: 42 }.to_s
end
end
@@ -2014,7 +2010,7 @@ def self.call(object, env)
last_response.body.should == { meaning_of_life: 42 }.to_s
end
it 'forces txt from a non-accepting header' do
- get '/meaning_of_life', {}, { 'HTTP_ACCEPT' => 'application/json' }
+ get '/meaning_of_life', {}, 'HTTP_ACCEPT' => 'application/json'
last_response.body.should == { meaning_of_life: 42 }.to_s
end
end
@@ -2035,7 +2031,7 @@ def self.call(object, env)
last_response.body.should == { meaning_of_life: 42 }.to_s
end
it 'forces json from a non-accepting header' do
- get '/meaning_of_life', {}, { 'HTTP_ACCEPT' => 'text/html' }
+ get '/meaning_of_life', {}, 'HTTP_ACCEPT' => 'text/html'
last_response.body.should == { meaning_of_life: 42 }.to_json
end
it 'can be overwritten with an explicit content type' do
View
24 spec/grape/endpoint_spec.rb
@@ -9,7 +9,7 @@ def app
describe '#initialize' do
it 'takes a settings stack, options, and a block' do
- p = proc { }
+ p = proc {}
expect {
Grape::Endpoint.new(Grape::Util::HashStack.new, {
path: '/',
@@ -64,7 +64,7 @@ def app
}
end
it 'includes additional request headers' do
- get '/headers', nil, { "HTTP_X_GRAPE_CLIENT" => "1" }
+ get '/headers', nil, "HTTP_X_GRAPE_CLIENT" => "1"
JSON.parse(last_response.body)["X-Grape-Client"].should == "1"
end
it 'includes headers passed as symbols' do
@@ -150,7 +150,7 @@ def app
sum = 0
cookies.each do |name, val|
sum += val.to_i
- cookies.delete name, { path: '/test' }
+ cookies.delete name, path: '/test'
end
sum
end
@@ -354,22 +354,22 @@ def app
end
it 'converts JSON bodies to params' do
- post '/request_body', MultiJson.dump(user: 'Bobby T.'), { 'CONTENT_TYPE' => 'application/json' }
+ post '/request_body', MultiJson.dump(user: 'Bobby T.'), 'CONTENT_TYPE' => 'application/json'
last_response.body.should == 'Bobby T.'
end
it 'does not convert empty JSON bodies to params' do
- put '/request_body', '', { 'CONTENT_TYPE' => 'application/json' }
+ put '/request_body', '', 'CONTENT_TYPE' => 'application/json'
last_response.body.should == ''
end
it 'converts XML bodies to params' do
- post '/request_body', '<user>Bobby T.</user>', { 'CONTENT_TYPE' => 'application/xml' }
+ post '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
last_response.body.should == 'Bobby T.'
end
it 'converts XML bodies to params' do
- put '/request_body', '<user>Bobby T.</user>', { 'CONTENT_TYPE' => 'application/xml' }
+ put '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
last_response.body.should == 'Bobby T.'
end
@@ -378,7 +378,7 @@ def app
error! 400, "expected nil" if params[:version]
params[:user]
end
- post '/omitted_params', MultiJson.dump(user: 'Bob'), { 'CONTENT_TYPE' => 'application/json' }
+ post '/omitted_params', MultiJson.dump(user: 'Bob'), 'CONTENT_TYPE' => 'application/json'
last_response.status.should == 201
last_response.body.should == "Bob"
end
@@ -390,7 +390,7 @@ def app
subject.put '/request_body' do
params[:user]
end
- put '/request_body', '<user>Bobby T.</user>', { 'CONTENT_TYPE' => 'application/xml' }
+ put '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
last_response.status.should == 406
last_response.body.should == '{"error":"The requested content-type \'application/xml\' is not supported."}'
end
@@ -403,7 +403,7 @@ def app
subject.post do
params[:data]
end
- post '/', MultiJson.dump(data: { some: 'payload' }), { 'CONTENT_TYPE' => 'application/json' }
+ post '/', MultiJson.dump(data: { some: 'payload' }), 'CONTENT_TYPE' => 'application/json'
end
it "should not response with 406 for same type without params" do
@@ -562,7 +562,7 @@ def memoized
describe '.generate_api_method' do
it 'raises NameError if the method name is already in use' do
expect {
- Grape::Endpoint.generate_api_method("version", &proc { })
+ Grape::Endpoint.generate_api_method("version", &proc {})
}.to raise_error(NameError)
end
it 'raises ArgumentError if a block is not given' do
@@ -571,7 +571,7 @@ def memoized
}.to raise_error(ArgumentError)
end
it 'returns a Proc' do
- Grape::Endpoint.generate_api_method("GET test for a proc", &proc { }).should be_a Proc
+ Grape::Endpoint.generate_api_method("GET test for a proc", &proc {}).should be_a Proc
end
end
View
2  spec/grape/middleware/auth/oauth2_spec.rb
@@ -73,7 +73,7 @@ def app
end
context 'with the token in the POST body' do
- before { post '/awesome', { 'oauth_token' => 'g123' } }
+ before { post '/awesome', 'oauth_token' => 'g123' }
it { last_response.body.should == 'g123' }
end
View
14 spec/grape/middleware/versioner/param_spec.rb
@@ -6,12 +6,12 @@
subject { Grape::Middleware::Versioner::Param.new(app, @options || {}) }
it 'sets the API version based on the default param (apiver)' do
- env = Rack::MockRequest.env_for("/awesome", { params: { "apiver" => "v1" } })
+ env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1" })
subject.call(env)[1]["api.version"].should == 'v1'
end
it 'cuts (only) the version out of the params', focus: true do
- env = Rack::MockRequest.env_for("/awesome", { params: { "apiver" => "v1", "other_param" => "5" } })
+ env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1", "other_param" => "5" })
env['rack.request.query_hash'] = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
subject.call(env)[1]['rack.request.query_hash']["apiver"].should be_nil
subject.call(env)[1]['rack.request.query_hash']["other_param"].should == "5"
@@ -25,11 +25,11 @@
context 'with specified parameter name' do
before { @options = { parameter: 'v' } }
it 'sets the API version based on the custom parameter name' do
- env = Rack::MockRequest.env_for("/awesome", { params: { "v" => "v1" } })
+ env = Rack::MockRequest.env_for("/awesome", params: { "v" => "v1" })
subject.call(env)[1]["api.version"].should == "v1"
end
it 'does not set the API version based on the default param' do
- env = Rack::MockRequest.env_for("/awesome", { params: { "apiver" => "v1" } })
+ env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1" })
subject.call(env)[1]["api.version"].should be_nil
end
end
@@ -37,11 +37,11 @@
context 'with specified versions' do
before { @options = { versions: ['v1', 'v2'] } }
it 'throws an error if a non-allowed version is specified' do
- env = Rack::MockRequest.env_for("/awesome", { params: { "apiver" => "v3" } })
+ env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v3" })
catch(:error) { subject.call(env) }[:status].should == 404
end
it 'allows versions that have been specified' do
- env = Rack::MockRequest.env_for("/awesome", { params: { "apiver" => "v1" } })
+ env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1" })
subject.call(env)[1]["api.version"].should == 'v1'
end
end
@@ -51,7 +51,7 @@
versions: ['v1'],
version_options: { using: :header }
}
- env = Rack::MockRequest.env_for("/awesome", { params: {} })
+ env = Rack::MockRequest.env_for("/awesome", params: {})
subject.call(env).first.should == 200
end
View
32 spec/grape/path_spec.rb
@@ -61,19 +61,23 @@ module Grape
end
it "is false when the version option is header" do
- path = Path.new(anything, anything, {
+ path = Path.new(
+ anything,
+ anything,
version: 'v1',
version_options: { using: :header }
- })
+ )
expect(path.uses_path_versioning?).to be_false
end
it "is true when the version option is path" do
- path = Path.new(anything, anything, {
+ path = Path.new(
+ anything,
+ anything,
version: 'v1',
version_options: { using: :path }
- })
+ )
expect(path.uses_path_versioning?).to be_true
end
@@ -126,7 +130,7 @@ module Grape
describe "#path" do
context "mount_path" do
it "is not included when it is nil" do
- path = Path.new(nil, nil, { mount_path: '/foo/bar' })
+ path = Path.new(nil, nil, mount_path: '/foo/bar')
expect(path.path).to eql '/foo/bar'
end
@@ -143,29 +147,35 @@ module Grape
end
it "is included after the mount path" do
- path = Path.new(nil, nil, {
+ path = Path.new(
+ nil,
+ nil,
mount_path: '/foo',
root_prefix: '/hello'
- })
+ )
expect(path.path).to eql('/foo/hello')
end
end
it "uses the namespace after the mount path and root prefix" do
- path = Path.new(nil, 'namespace', {
+ path = Path.new(
+ nil,
+ 'namespace',
mount_path: '/foo',
root_prefix: '/hello'
- })
+ )
expect(path.path).to eql('/foo/hello/namespace')
end
it "uses the raw path after the namespace" do
- path = Path.new('raw_path', 'namespace', {
+ path = Path.new(
+ 'raw_path',
+ 'namespace',
mount_path: '/foo',
root_prefix: '/hello'
- })
+ )
expect(path.path).to eql('/foo/hello/namespace/raw_path')
end
View
16 spec/grape/util/hash_stack_spec.rb
@@ -25,31 +25,31 @@
describe '#imbue' do
it 'pushes a new value onto the end of an array' do
subject[:abc] = []
- subject.imbue(:abc, [123])
- subject.imbue(:abc, [456])
+ subject.imbue :abc, [123]
+ subject.imbue :abc, [456]
subject[:abc].should == [123, 456]
end
it 'merges a hash that is passed' do
subject[:abc] = { foo: 'bar' }
- subject.imbue(:abc, { baz: 'wich' })
+ subject.imbue :abc, baz: 'wich'
subject[:abc].should == { foo: 'bar', baz: 'wich' }
end
it 'sets the value if not a hash or array' do
- subject.imbue(:abc, 123)
+ subject.imbue :abc, 123
subject[:abc].should == 123
end
it 'is able to imbue an array without explicit setting' do
- subject.imbue(:arr, [1])
- subject.imbue(:arr, [2])
+ subject.imbue :arr, [1]
+ subject.imbue :arr, [2]
subject[:arr].should == [1, 2]
end
it 'is able to imbue a hash without explicit setting' do
- subject.imbue(:hash, foo: 'bar')
- subject.imbue(:hash, baz: 'wich')
+ subject.imbue :hash, foo: 'bar'
+ subject.imbue :hash, baz: 'wich'
subject[:hash].should == { foo: 'bar', baz: 'wich' }
end
end
View
106 spec/grape/validations/coerce_spec.rb
@@ -22,8 +22,12 @@ def app
I18n.load_path << File.expand_path('../zh-CN.yml', __FILE__)
I18n.reload!
I18n.locale = 'zh-CN'.to_sym
- subject.params { requires :age, type: Integer }
- subject.get '/single' do 'int works'; end
+ subject.params do
+ requires :age, type: Integer
+ end
+ subject.get '/single' do
+ 'int works'
+ end
get '/single', age: '43a'
last_response.status.should == 400
@@ -32,8 +36,12 @@ def app
it 'gives an english fallback error when default locale message is blank' do
I18n.locale = 'pt-BR'.to_sym
- subject.params { requires :age, type: Integer }
- subject.get '/single' do 'int works'; end
+ subject.params do
+ requires :age, type: Integer
+ end
+ subject.get '/single' do
+ 'int works'
+ end
get '/single', age: '43a'
last_response.status.should == 400
@@ -43,8 +51,12 @@ def app
end
it 'error on malformed input' do
- subject.params { requires :int, type: Integer }
- subject.get '/single' do 'int works'; end
+ subject.params do
+ requires :int, type: Integer
+ end
+ subject.get '/single' do
+ 'int works'
+ end
get '/single', int: '43a'
last_response.status.should == 400
@@ -56,14 +68,18 @@ def app
end
it 'error on malformed input (Array)' do
- subject.params { requires :ids, type: Array[Integer] }
- subject.get '/array' do 'array int works'; end
+ subject.params do
+ requires :ids, type: Array[Integer]
+ end
+ subject.get '/array' do
+ 'array int works'
+ end
- get 'array', { ids: ['1', '2', 'az'] }
+ get 'array', ids: ['1', '2', 'az']
last_response.status.should == 400
last_response.body.should == 'ids is invalid'
- get 'array', { ids: ['1', '2', '890'] }
+ get 'array', ids: ['1', '2', '890']
last_response.status.should == 200
last_response.body.should == 'array int works'
end
@@ -78,8 +94,12 @@ class User
end
it 'error on malformed input for complex objects' do
- subject.params { requires :user, type: CoerceValidatorSpec::User }
- subject.get '/user' do 'complex works'; end
+ subject.params do
+ requires :user, type: CoerceValidatorSpec::User
+ end
+ subject.get '/user' do
+ 'complex works'
+ end
get '/user', user: "32"
last_response.status.should == 400
@@ -93,58 +113,78 @@ class User
context 'coerces' do
it 'Integer' do
- subject.params { requires :int, coerce: Integer }
- subject.get '/int' do params[:int].class; end
+ subject.params do
+ requires :int, coerce: Integer
+ end
+ subject.get '/int' do
+ params[:int].class
+ end
- get '/int', { int: "45" }
+ get '/int', int: "45"
last_response.status.should == 200
last_response.body.should == 'Fixnum'
end
it 'Array of Integers' do
- subject.params { requires :arry, coerce: Array[Integer] }
- subject.get '/array' do params[:arry][0].class; end
+ subject.params do
+ requires :arry, coerce: Array[Integer]
+ end
+ subject.get '/array' do
+ params[:arry][0].class
+ end
- get '/array', { arry: ['1', '2', '3'] }
+ get '/array', arry: ['1', '2', '3']
last_response.status.should == 200
last_response.body.should == 'Fixnum'
end
it 'Array of Bools' do
- subject.params { requires :arry, coerce: Array[Virtus::Attribute::Boolean] }
- subject.get '/array' do params[:arry][0].class; end
+ subject.params do
+ requires :arry, coerce: Array[Virtus::Attribute::Boolean]
+ end
+ subject.get '/array' do
+ params[:arry][0].class
+ end
- get 'array', { arry: [1, 0] }
+ get 'array', arry: [1, 0]
last_response.status.should == 200
last_response.body.should == 'TrueClass'
end
it 'Bool' do
- subject.params { requires :bool, coerce: Virtus::Attribute::Boolean }
- subject.get '/bool' do params[:bool].class; end
+ subject.params do
+ requires :bool, coerce: Virtus::Attribute::Boolean
+ end
+ subject.get '/bool' do
+ params[:bool].class
+ end
- get '/bool', { bool: 1 }
+ get '/bool', bool: 1
last_response.status.should == 200
last_response.body.should == 'TrueClass'
- get '/bool', { bool: 0 }
+ get '/bool', bool: 0
last_response.status.should == 200
last_response.body.should == 'FalseClass'
- get '/bool', { bool: 'false' }
+ get '/bool', bool: 'false'
last_response.status.should == 200
last_response.body.should == 'FalseClass'
- get '/bool', { bool: 'true' }
+ get '/bool', bool: 'true'
last_response.status.should == 200
last_response.body.should == 'TrueClass'
end
it 'file' do
- subject.params { requires :file, coerce: Rack::Multipart::UploadedFile }
- subject.post '/upload' do params[:file].filename; end
+ subject.params do
+ requires :file, coerce: Rack::Multipart::UploadedFile
+ end
+ subject.post '/upload' do
+ params[:file].filename
+ end
- post '/upload', { file: Rack::Test::UploadedFile.new(__FILE__) }
+ post '/upload', file: Rack::Test::UploadedFile.new(__FILE__)
last_response.status.should == 201
last_response.body.should == File.basename(__FILE__).to_s
end
@@ -155,9 +195,11 @@ class User
requires :int, coerce: Integer
end
end
- subject.get '/int' do params[:integers][:int].class; end
+ subject.get '/int' do
+ params[:integers][:int].class
+ end
- get '/int', { integers: { int: "45" } }
+ get '/int', integers: { int: "45" }
last_response.status.should == 200
last_response.body.should == 'Fixnum'
end
View
1  spec/grape/validations/values_spec.rb
@@ -20,7 +20,6 @@ class API < Grape::API
get '/default/valid' do
{ type: params[:type] }
end
-
end
end
end
View
4 spec/grape/validations_spec.rb
@@ -344,11 +344,11 @@ def validate_param!(attr_name, params)
end
it 'validates when param is present' do
- get '/optional_custom', { custom: 'im custom' }
+ get '/optional_custom', custom: 'im custom'
last_response.status.should == 200
last_response.body.should == 'optional with custom works!'
- get '/optional_custom', { custom: 'im wrong' }
+ get '/optional_custom', custom: 'im wrong'
last_response.status.should == 400
last_response.body.should == 'custom is not custom!'
end
Please sign in to comment.
Something went wrong with that request. Please try again.