diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 04940c0fe..d0d40c872 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,54 +1,117 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-07-11 00:59:31 +0100 using RuboCop version 0.47.0. +# on 2017-12-10 01:00:44 +0900 using RuboCop version 0.51.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 45 +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent +Layout/IndentHeredoc: + Exclude: + - 'lib/grape/router/route.rb' + - 'spec/grape/api_spec.rb' + - 'spec/grape/entity_spec.rb' + +# Offense count: 2 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'lib/grape/middleware/stack.rb' + - 'spec/grape/dsl/routing_spec.rb' + +# Offense count: 1 +Lint/RescueWithoutErrorClass: + Exclude: + - 'lib/grape/validations/validators/coerce.rb' + +# Offense count: 49 Metrics/AbcSize: Max: 44 -# Offense count: 279 +# Offense count: 285 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 3117 -# Offense count: 8 +# Offense count: 9 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 288 -# Offense count: 28 +# Offense count: 32 Metrics/CyclomaticComplexity: Max: 14 -# Offense count: 1114 +# Offense count: 1160 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 215 -# Offense count: 56 +# Offense count: 57 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 33 -# Offense count: 10 +# Offense count: 11 # Configuration parameters: CountComments. Metrics/ModuleLength: Max: 212 -# Offense count: 17 +# Offense count: 21 Metrics/PerceivedComplexity: Max: 14 -# Offense count: 2 +# Offense count: 4 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'Appraisals' + - 'Gemfile' + - 'Guardfile' + - 'Rakefile' + +# Offense count: 1 +# Configuration parameters: Blacklist. +# Blacklist: END, (?-mix:EO[A-Z]{1}) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/grape/router/route.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Performance/HashEachMethods: + Exclude: + - 'lib/grape/api.rb' + - 'lib/grape/middleware/versioner/header.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it Style/BlockDelimiters: Exclude: - 'spec/grape/middleware/formatter_spec.rb' +# Offense count: 1 +Style/CommentedKeyword: + Exclude: + - 'spec/grape/validations_spec.rb' + +# Offense count: 2 +# Configuration parameters: SupportedStyles. +# SupportedStyles: annotated, template +Style/FormatStringToken: + EnforcedStyle: template + # Offense count: 2 Style/IdenticalConditionalBranches: Exclude: @@ -58,3 +121,8 @@ Style/IdenticalConditionalBranches: Style/MethodMissing: Exclude: - 'lib/grape/router/attribute_translator.rb' + +# Offense count: 1 +Style/MultipleComparison: + Exclude: + - 'lib/grape/validations/types/custom_type_coercer.rb' diff --git a/Appraisals b/Appraisals index 5ceb072bc..5bb876782 100644 --- a/Appraisals +++ b/Appraisals @@ -1,6 +1,6 @@ appraise 'rails-3' do gem 'rails', '3.2.19' - gem 'rack-cache', '<= 1.2' # Pin as next rack-cache version (1.3) removes Ruby1.9 support + gem 'rack-cache', '<= 1.2' # Pin as next rack-cache version (1.3) removes Ruby1.9 support end appraise 'rails-4' do diff --git a/Gemfile b/Gemfile index 2c95e4d45..b1a41e2c9 100644 --- a/Gemfile +++ b/Gemfile @@ -6,28 +6,28 @@ gemspec group :development, :test do gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' gem 'hashie' + gem 'rake' + gem 'rubocop', '0.51.0' end group :development do + gem 'appraisal' + gem 'benchmark-ips' gem 'guard' gem 'guard-rspec' gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' end group :test do + gem 'cookiejar' + gem 'coveralls', '~> 0.8.17', require: false + gem 'danger-toc', '~> 0.1.0' gem 'grape-entity', '~> 0.6' gem 'maruku' + gem 'mime-types' + gem 'rack-jsonp', require: 'rack/jsonp' gem 'rack-test', '~> 0.6.3' gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false - gem 'danger-toc', '~> 0.1.0' end diff --git a/Rakefile b/Rakefile index a62ec8562..2beb99875 100644 --- a/Rakefile +++ b/Rakefile @@ -22,5 +22,4 @@ require 'rainbow/ext/string' unless String.respond_to?(:color) require 'rubocop/rake_task' RuboCop::RakeTask.new -task default: [:rubocop, :spec] - +task default: %i[rubocop spec] diff --git a/gemfiles/multi_json.gemfile b/gemfiles/multi_json.gemfile index 231ee1697..495befbf2 100644 --- a/gemfiles/multi_json.gemfile +++ b/gemfiles/multi_json.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'multi_json', require: 'multi_json' +gem "multi_json", :require => "multi_json" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/multi_xml.gemfile b/gemfiles/multi_xml.gemfile index b551d9dc0..13cb4a570 100644 --- a/gemfiles/multi_xml.gemfile +++ b/gemfiles/multi_xml.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'multi_xml', require: 'multi_xml' +gem "multi_xml", :require => "multi_xml" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/rack_1.5.2.gemfile b/gemfiles/rack_1.5.2.gemfile index 7207360b5..753f7d5b4 100644 --- a/gemfiles/rack_1.5.2.gemfile +++ b/gemfiles/rack_1.5.2.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'rack', '1.5.2' +gem "rack", "1.5.2" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/rack_edge.gemfile b/gemfiles/rack_edge.gemfile index 11c2d0652..fedd2f681 100644 --- a/gemfiles/rack_edge.gemfile +++ b/gemfiles/rack_edge.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'rack', github: 'rack/rack' +gem "rack", :github => "rack/rack" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/rails_3.gemfile b/gemfiles/rails_3.gemfile index 1137e17df..5b5b8ac3a 100644 --- a/gemfiles/rails_3.gemfile +++ b/gemfiles/rails_3.gemfile @@ -1,35 +1,36 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'rails', '3.2.19' -gem 'rack-cache', '<= 1.2' +gem "rails", "3.2.19" +gem "rack-cache", "<= 1.2" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/rails_4.gemfile b/gemfiles/rails_4.gemfile index e115c6cb9..d0b4262cd 100644 --- a/gemfiles/rails_4.gemfile +++ b/gemfiles/rails_4.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'rails', '4.1.6' +gem "rails", "4.1.6" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/rails_5.gemfile b/gemfiles/rails_5.gemfile index a477347e9..f374975ed 100644 --- a/gemfiles/rails_5.gemfile +++ b/gemfiles/rails_5.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'rails', '5.0.0' +gem "rails", "5.0.0" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile index 0b788b331..f8a5f8d71 100644 --- a/gemfiles/rails_edge.gemfile +++ b/gemfiles/rails_edge.gemfile @@ -1,34 +1,35 @@ # This file was generated by Appraisal -source 'https://rubygems.org' +source "https://rubygems.org" -gem 'arel', github: 'rails/arel' +gem "arel", :github => "rails/arel" group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '0.47.0' - gem 'hashie' + gem "bundler" + gem "hashie" + gem "rake" + gem "rubocop", "0.51.0" end group :development do - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' - gem 'appraisal' - gem 'benchmark-ips' + gem "appraisal" + gem "benchmark-ips" + gem "guard" + gem "guard-rspec" + gem "guard-rubocop" end group :test do - gem 'grape-entity', '~> 0.6' - gem 'maruku' - gem 'rack-test', '~> 0.6.3' - gem 'rspec', '~> 3.0' - gem 'cookiejar' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'mime-types' - gem 'ruby-grape-danger', '~> 0.1.0', require: false - gem 'coveralls', '~> 0.8.17', require: false + gem "cookiejar" + gem "coveralls", "~> 0.8.17", :require => false + gem "danger-toc", "~> 0.1.0" + gem "grape-entity", "~> 0.6" + gem "maruku" + gem "mime-types" + gem "rack-jsonp", :require => "rack/jsonp" + gem "rack-test", "~> 0.6.3" + gem "rspec", "~> 3.0" + gem "ruby-grape-danger", "~> 0.1.0", :require => false end -gemspec path: '../' +gemspec :path => "../" diff --git a/grape.gemspec b/grape.gemspec index e2f43592a..176efd1f7 100644 --- a/grape.gemspec +++ b/grape.gemspec @@ -12,12 +12,12 @@ Gem::Specification.new do |s| s.description = 'A Ruby framework for rapid API development with great conventions.' s.license = 'MIT' - s.add_runtime_dependency 'rack', '>= 1.3.0' + s.add_runtime_dependency 'activesupport' + s.add_runtime_dependency 'builder' s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0' + s.add_runtime_dependency 'rack', '>= 1.3.0' s.add_runtime_dependency 'rack-accept' - s.add_runtime_dependency 'activesupport' s.add_runtime_dependency 'virtus', '>= 1.0.0' - s.add_runtime_dependency 'builder' s.files = Dir['**/*'].keep_if { |file| File.file?(file) } s.test_files = Dir['spec/**/*'] diff --git a/lib/grape/api.rb b/lib/grape/api.rb index 4e4f79bd7..70114859d 100644 --- a/lib/grape/api.rb +++ b/lib/grape/api.rb @@ -161,7 +161,7 @@ def add_head_not_allowed_methods_and_options_methods route_settings[:endpoint] = route.app # using the :any shorthand produces [nil] for route methods, substitute all manually - route_settings[:methods] = %w(GET PUT POST DELETE PATCH HEAD OPTIONS) if route_settings[:methods].include?('*') + route_settings[:methods] = %w[GET PUT POST DELETE PATCH HEAD OPTIONS] if route_settings[:methods].include?('*') end end @@ -195,7 +195,7 @@ def add_head_not_allowed_methods_and_options_methods # Generate a route that returns an HTTP 405 response for a user defined # path on methods not specified def generate_not_allowed_method(pattern, allowed_methods: [], **attributes) - not_allowed_methods = %w(GET PUT POST DELETE PATCH HEAD) - allowed_methods + not_allowed_methods = %w[GET PUT POST DELETE PATCH HEAD] - allowed_methods not_allowed_methods << Grape::Http::Headers::OPTIONS if self.class.namespace_inheritable(:do_not_route_options) return if not_allowed_methods.empty? diff --git a/lib/grape/dsl/routing.rb b/lib/grape/dsl/routing.rb index 2f3236d7d..fcde3dbda 100644 --- a/lib/grape/dsl/routing.rb +++ b/lib/grape/dsl/routing.rb @@ -136,7 +136,7 @@ def route(methods, paths = ['/'], route_options = {}, &block) reset_validations! end - %w(get post put head delete options patch).each do |meth| + %w[get post put head delete options patch].each do |meth| define_method meth do |*args, &block| options = args.extract_options! paths = args.first || ['/'] diff --git a/lib/grape/exceptions/incompatible_option_values.rb b/lib/grape/exceptions/incompatible_option_values.rb index 5f42ea43a..a5e40b5b4 100644 --- a/lib/grape/exceptions/incompatible_option_values.rb +++ b/lib/grape/exceptions/incompatible_option_values.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class IncompatibleOptionValues < Base diff --git a/lib/grape/exceptions/invalid_accept_header.rb b/lib/grape/exceptions/invalid_accept_header.rb index 544201607..d9e04cc89 100644 --- a/lib/grape/exceptions/invalid_accept_header.rb +++ b/lib/grape/exceptions/invalid_accept_header.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class InvalidAcceptHeader < Base diff --git a/lib/grape/exceptions/invalid_formatter.rb b/lib/grape/exceptions/invalid_formatter.rb index 5d069b91f..21f1a473f 100644 --- a/lib/grape/exceptions/invalid_formatter.rb +++ b/lib/grape/exceptions/invalid_formatter.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class InvalidFormatter < Base diff --git a/lib/grape/exceptions/invalid_message_body.rb b/lib/grape/exceptions/invalid_message_body.rb index c0f05281e..6c2ae2b26 100644 --- a/lib/grape/exceptions/invalid_message_body.rb +++ b/lib/grape/exceptions/invalid_message_body.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class InvalidMessageBody < Base diff --git a/lib/grape/exceptions/invalid_version_header.rb b/lib/grape/exceptions/invalid_version_header.rb index 6b93ea7e9..7a903eebb 100644 --- a/lib/grape/exceptions/invalid_version_header.rb +++ b/lib/grape/exceptions/invalid_version_header.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class InvalidVersionHeader < Base diff --git a/lib/grape/exceptions/invalid_versioner_option.rb b/lib/grape/exceptions/invalid_versioner_option.rb index 14aea1684..8549a3fc2 100644 --- a/lib/grape/exceptions/invalid_versioner_option.rb +++ b/lib/grape/exceptions/invalid_versioner_option.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class InvalidVersionerOption < Base diff --git a/lib/grape/exceptions/invalid_with_option_for_represent.rb b/lib/grape/exceptions/invalid_with_option_for_represent.rb index 521a1e019..3d8530348 100644 --- a/lib/grape/exceptions/invalid_with_option_for_represent.rb +++ b/lib/grape/exceptions/invalid_with_option_for_represent.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class InvalidWithOptionForRepresent < Base diff --git a/lib/grape/exceptions/method_not_allowed.rb b/lib/grape/exceptions/method_not_allowed.rb index 378cf034c..2fc1fd91d 100644 --- a/lib/grape/exceptions/method_not_allowed.rb +++ b/lib/grape/exceptions/method_not_allowed.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class MethodNotAllowed < Base diff --git a/lib/grape/exceptions/missing_group_type.rb b/lib/grape/exceptions/missing_group_type.rb index 31faa6887..96ce63a98 100644 --- a/lib/grape/exceptions/missing_group_type.rb +++ b/lib/grape/exceptions/missing_group_type.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class MissingGroupTypeError < Base diff --git a/lib/grape/exceptions/missing_mime_type.rb b/lib/grape/exceptions/missing_mime_type.rb index faaef5b53..880ba310a 100644 --- a/lib/grape/exceptions/missing_mime_type.rb +++ b/lib/grape/exceptions/missing_mime_type.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class MissingMimeType < Base diff --git a/lib/grape/exceptions/missing_option.rb b/lib/grape/exceptions/missing_option.rb index 19d2aa61d..fad838dd1 100644 --- a/lib/grape/exceptions/missing_option.rb +++ b/lib/grape/exceptions/missing_option.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class MissingOption < Base diff --git a/lib/grape/exceptions/missing_vendor_option.rb b/lib/grape/exceptions/missing_vendor_option.rb index b30ec42c6..a06110c8c 100644 --- a/lib/grape/exceptions/missing_vendor_option.rb +++ b/lib/grape/exceptions/missing_vendor_option.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class MissingVendorOption < Base diff --git a/lib/grape/exceptions/unknown_options.rb b/lib/grape/exceptions/unknown_options.rb index fc92fab79..4e5d535e0 100644 --- a/lib/grape/exceptions/unknown_options.rb +++ b/lib/grape/exceptions/unknown_options.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class UnknownOptions < Base diff --git a/lib/grape/exceptions/unknown_parameter.rb b/lib/grape/exceptions/unknown_parameter.rb index 7ed3b19af..30e8ef111 100644 --- a/lib/grape/exceptions/unknown_parameter.rb +++ b/lib/grape/exceptions/unknown_parameter.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class UnknownParameter < Base diff --git a/lib/grape/exceptions/unknown_validator.rb b/lib/grape/exceptions/unknown_validator.rb index 3a6bf4220..3acea5304 100644 --- a/lib/grape/exceptions/unknown_validator.rb +++ b/lib/grape/exceptions/unknown_validator.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class UnknownValidator < Base diff --git a/lib/grape/exceptions/unsupported_group_type.rb b/lib/grape/exceptions/unsupported_group_type.rb index 2ebada66e..36dfc2fc4 100644 --- a/lib/grape/exceptions/unsupported_group_type.rb +++ b/lib/grape/exceptions/unsupported_group_type.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + module Grape module Exceptions class UnsupportedGroupTypeError < Base diff --git a/lib/grape/router/pattern.rb b/lib/grape/router/pattern.rb index c563b76e2..9f326ecc0 100644 --- a/lib/grape/router/pattern.rb +++ b/lib/grape/router/pattern.rb @@ -5,7 +5,7 @@ module Grape class Router class Pattern DEFAULT_PATTERN_OPTIONS = { uri_decode: true, type: :grape }.freeze - DEFAULT_SUPPORTED_CAPTURE = [:format, :version].freeze + DEFAULT_SUPPORTED_CAPTURE = %i[format version].freeze attr_reader :origin, :path, :capture, :pattern diff --git a/lib/grape/router/route.rb b/lib/grape/router/route.rb index 9026665a3..bf6e47b88 100644 --- a/lib/grape/router/route.rb +++ b/lib/grape/router/route.rb @@ -8,7 +8,7 @@ class Router class Route ROUTE_ATTRIBUTE_REGEXP = /route_([_a-zA-Z]\w*)/ SOURCE_LOCATION_REGEXP = /^(.*?):(\d+?)(?::in `.+?')?$/ - FIXED_NAMED_CAPTURES = %w(format version).freeze + FIXED_NAMED_CAPTURES = %w[format version].freeze attr_accessor :pattern, :translator, :app, :index, :regexp, :options @@ -32,19 +32,19 @@ def respond_to_missing?(method_id, _) ROUTE_ATTRIBUTE_REGEXP.match(method_id.to_s) end - [ - :prefix, - :version, - :settings, - :format, - :description, - :http_codes, - :headers, - :entity, - :details, - :requirements, - :request_method, - :namespace + %i[ + prefix + version + settings + format + description + http_codes + headers + entity + details + requirements + request_method + namespace ].each do |method_name| define_method method_name do attributes.public_send method_name diff --git a/lib/grape/validations/validators/allow_blank.rb b/lib/grape/validations/validators/allow_blank.rb index e22a511cb..d0c314e7a 100644 --- a/lib/grape/validations/validators/allow_blank.rb +++ b/lib/grape/validations/validators/allow_blank.rb @@ -7,7 +7,7 @@ def validate_param!(attr_name, params) value = params[attr_name] value = value.strip if value.respond_to?(:strip) - return if false == value || value.present? + return if value == false || value.present? raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:blank) end diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 9b5db5a47..48bb0f415 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -209,7 +209,7 @@ def app expect(last_response.body).to eq('outer') end - %w(group resource resources segment).each do |als| + %w[group resource resources segment].each do |als| it "`.#{als}` is an alias" do inner_namespace = nil subject.send(als, :awesome) do @@ -318,7 +318,7 @@ def subject.enable_root_route! end context 'when array of versions provided' do - let(:version) { %w(v1 v2) } + let(:version) { %w[v1 v2] } it { versioned_get '/', 'v1', using: :path } it { versioned_get '/', 'v2', using: :path } @@ -333,7 +333,7 @@ def subject.enable_root_route! end it 'header versioned APIs with multiple headers' do - subject.version %w(v1 v2), using: :header, vendor: 'test' + subject.version %w[v1 v2], using: :header, vendor: 'test' subject.enable_root_route! versioned_get '/', 'v1', using: :header, vendor: 'test' @@ -421,7 +421,7 @@ class DummyFormatClass end it 'allows for multiple verbs' do - subject.route([:get, :post], '/abc') do + subject.route(%i[get post], '/abc') do 'hiya' end @@ -435,7 +435,7 @@ class DummyFormatClass expect(last_response.body).to eql 'hiya' end - [:put, :post].each do |verb| + %i[put post].each do |verb| context verb do ['string', :symbol, 1, -1.1, {}, [], true, false, nil].each do |object| it "allows a(n) #{object.class} json object in params" do @@ -473,14 +473,14 @@ class DummyFormatClass end it 'allows for multipart paths' do - subject.route([:get, :post], '/:id/first') do + subject.route(%i[get post], '/:id/first') do 'first' end - subject.route([:get, :post], '/:id') do + subject.route(%i[get post], '/:id') do 'ola' end - subject.route([:get, :post], '/:id/first/second') do + subject.route(%i[get post], '/:id/first/second') do 'second' end @@ -501,7 +501,7 @@ class DummyFormatClass 'lol' end - %w(get post put delete options patch).each do |m| + %w[get post put delete options patch].each do |m| send(m, '/abc') expect(last_response.body).to eql 'lol' end @@ -538,7 +538,7 @@ class DummyFormatClass expect(last_response.body).to eql 'catch-all' end - verbs = %w(post get head delete put options patch) + verbs = %w[post get head delete put options patch] verbs.each do |verb| it "allows and properly constrain a #{verb.upcase} method" do subject.send(verb, '/example') do @@ -2393,7 +2393,7 @@ def static expect(subject.version).to eq('v2') end it 'returns versions' do - expect(subject.versions).to eq(%w(v1 v2)) + expect(subject.versions).to eq(%w[v1 v2]) end it 'sets route paths' do expect(subject.routes.size).to be >= 2 @@ -3368,7 +3368,7 @@ def serializable_hash end it 'array' do subject.get '/example' do - %w(example1 example2) + %w[example1 example2] end get '/example' expect(last_response.status).to eq(200) diff --git a/spec/grape/dsl/inside_route_spec.rb b/spec/grape/dsl/inside_route_spec.rb index f48ba0d8b..928510f75 100644 --- a/spec/grape/dsl/inside_route_spec.rb +++ b/spec/grape/dsl/inside_route_spec.rb @@ -91,7 +91,7 @@ def initialize end describe '#status' do - %w(GET PUT OPTIONS).each do |method| + %w[GET PUT OPTIONS].each do |method| it 'defaults to 200 on GET' do request = Grape::Request.new(Rack::MockRequest.env_for('/', method: method)) expect(subject).to receive(:request).and_return(request) diff --git a/spec/grape/dsl/parameters_spec.rb b/spec/grape/dsl/parameters_spec.rb index f6ffd433b..27af242a2 100644 --- a/spec/grape/dsl/parameters_spec.rb +++ b/spec/grape/dsl/parameters_spec.rb @@ -110,7 +110,7 @@ def extract_message_option(attrs) it 'adds an mutally exclusive parameter validation' do subject.mutually_exclusive :media, :audio - expect(subject.validates_reader).to eq([[:media, :audio], { mutual_exclusion: { value: true, message: nil } }]) + expect(subject.validates_reader).to eq([%i[media audio], { mutual_exclusion: { value: true, message: nil } }]) end end @@ -118,7 +118,7 @@ def extract_message_option(attrs) it 'adds an exactly of one parameter validation' do subject.exactly_one_of :media, :audio - expect(subject.validates_reader).to eq([[:media, :audio], { exactly_one_of: { value: true, message: nil } }]) + expect(subject.validates_reader).to eq([%i[media audio], { exactly_one_of: { value: true, message: nil } }]) end end @@ -126,7 +126,7 @@ def extract_message_option(attrs) it 'adds an at least one of parameter validation' do subject.at_least_one_of :media, :audio - expect(subject.validates_reader).to eq([[:media, :audio], { at_least_one_of: { value: true, message: nil } }]) + expect(subject.validates_reader).to eq([%i[media audio], { at_least_one_of: { value: true, message: nil } }]) end end @@ -134,7 +134,7 @@ def extract_message_option(attrs) it 'adds an all or none of parameter validation' do subject.all_or_none_of :media, :audio - expect(subject.validates_reader).to eq([[:media, :audio], { all_or_none_of: { value: true, message: nil } }]) + expect(subject.validates_reader).to eq([%i[media audio], { all_or_none_of: { value: true, message: nil } }]) end end @@ -155,7 +155,7 @@ def extract_message_option(attrs) describe 'when params argument is an array of hashes' do it 'returns values of each hash for @element key' do subject.element = :foo - expect(subject.params([{ foo: 'bar' }, { foo: 'baz' }])).to eq(%w(bar baz)) + expect(subject.params([{ foo: 'bar' }, { foo: 'baz' }])).to eq(%w[bar baz]) end end diff --git a/spec/grape/dsl/settings_spec.rb b/spec/grape/dsl/settings_spec.rb index 556e353ff..1620c4f7d 100644 --- a/spec/grape/dsl/settings_spec.rb +++ b/spec/grape/dsl/settings_spec.rb @@ -166,7 +166,7 @@ def reset_validations!; end subject.namespace_stackable(:some_thing, :foo_bar_2) - expect(subject.namespace_stackable(:some_thing)).to eq [:foo_bar, :foo_bar_2] + expect(subject.namespace_stackable(:some_thing)).to eq %i[foo_bar foo_bar_2] subject.namespace_end expect(subject.namespace_stackable(:some_thing)).to eq [:foo_bar] @@ -253,7 +253,7 @@ def reset_validations!; end obj1.top_level_setting.inherit_from obj2_copy.point_in_time_copy obj2.top_level_setting.inherit_from obj3_copy.point_in_time_copy - expect(obj1_copy.namespace_stackable[:some_thing]).to eq [:obj3, :obj2, :obj1] + expect(obj1_copy.namespace_stackable[:some_thing]).to eq %i[obj3 obj2 obj1] end end end diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index dbe1d2cab..659766f2a 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -215,7 +215,7 @@ def app [cookie.name, cookie] end] expect(cookies.size).to eq(2) - %w(and_this delete_this_cookie).each do |cookie_name| + %w[and_this delete_this_cookie].each do |cookie_name| cookie = cookies[cookie_name] expect(cookie).not_to be_nil expect(cookie.value).to eq('deleted') @@ -239,7 +239,7 @@ def app [cookie.name, cookie] end] expect(cookies.size).to eq(2) - %w(and_this delete_this_cookie).each do |cookie_name| + %w[and_this delete_this_cookie].each do |cookie_name| cookie = cookies[cookie_name] expect(cookie).not_to be_nil expect(cookie.value).to eq('deleted') @@ -528,9 +528,9 @@ def app json = JSON.parse(last_response.body) expect(last_response.status).to eq(200) expect(json['first']).to eq 'present' - expect(json['nested'].keys).to eq %w(fourth fifth nested_nested) + expect(json['nested'].keys).to eq %w[fourth fifth nested_nested] expect(json['nested']['fourth']).to eq '' - expect(json['nested']['nested_nested'].keys).to eq %w(sixth seven) + expect(json['nested']['nested_nested'].keys).to eq %w[sixth seven] expect(json['nested']['nested_nested']['sixth']).to eq 'sixth' end @@ -556,7 +556,7 @@ def app json = JSON.parse(last_response.body) expect(last_response.status).to eq(200) expect(json['first']).to eq 'present' - expect(json['nested'].keys).to eq %w(fourth) + expect(json['nested'].keys).to eq %w[fourth] expect(json['nested']['fourth']).to eq '4' end end @@ -1224,7 +1224,7 @@ def memoized get '/all_filters' json = JSON.parse(last_response.body) - expect(json.keys).to match_array %w(before before_validation after_validation endpoint after) + expect(json.keys).to match_array %w[before before_validation after_validation endpoint after] end context 'when terminating the response with error!' do @@ -1241,7 +1241,7 @@ def memoized get '/error_filters' expect(last_response.status).to eql 500 - expect(called).to match_array %w(before before_validation) + expect(called).to match_array %w[before before_validation] end it 'allows prior and parent filters of same type to run' do @@ -1259,7 +1259,7 @@ def memoized get '/parent/hello' expect(last_response.status).to eql 500 - expect(called).to match_array %w(parent prior) + expect(called).to match_array %w[parent prior] end end end @@ -1326,7 +1326,7 @@ def memoized end describe 'all other' do - %w(post get head put options patch).each do |verb| + %w[post get head put options patch].each do |verb| it "allows for the anchoring option with a #{verb.upcase} method" do subject.send(verb, '/example', anchor: true) do verb diff --git a/spec/grape/entity_spec.rb b/spec/grape/entity_spec.rb index 4748d1467..35299dfb9 100644 --- a/spec/grape/entity_spec.rb +++ b/spec/grape/entity_spec.rb @@ -169,7 +169,7 @@ def first expect(inner_body).to eql(root: { abc: 'def' }) end - [:json, :serializable_hash].each do |format| + %i[json serializable_hash].each do |format| it "presents with #{format}" do entity = Class.new(Grape::Entity) entity.root 'examples', 'example' diff --git a/spec/grape/exceptions/invalid_formatter_spec.rb b/spec/grape/exceptions/invalid_formatter_spec.rb index e98ab75a6..01ac0439b 100644 --- a/spec/grape/exceptions/invalid_formatter_spec.rb +++ b/spec/grape/exceptions/invalid_formatter_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + require 'spec_helper' describe Grape::Exceptions::InvalidFormatter do diff --git a/spec/grape/exceptions/invalid_versioner_option_spec.rb b/spec/grape/exceptions/invalid_versioner_option_spec.rb index 1e0dde002..2778b793f 100644 --- a/spec/grape/exceptions/invalid_versioner_option_spec.rb +++ b/spec/grape/exceptions/invalid_versioner_option_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + require 'spec_helper' describe Grape::Exceptions::InvalidVersionerOption do diff --git a/spec/grape/exceptions/missing_option_spec.rb b/spec/grape/exceptions/missing_option_spec.rb index 2aaac32cd..54e750695 100644 --- a/spec/grape/exceptions/missing_option_spec.rb +++ b/spec/grape/exceptions/missing_option_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + require 'spec_helper' describe Grape::Exceptions::MissingOption do diff --git a/spec/grape/exceptions/unknown_options_spec.rb b/spec/grape/exceptions/unknown_options_spec.rb index ca49321c4..c94e81c9f 100644 --- a/spec/grape/exceptions/unknown_options_spec.rb +++ b/spec/grape/exceptions/unknown_options_spec.rb @@ -1,10 +1,10 @@ -# encoding: utf-8 + require 'spec_helper' describe Grape::Exceptions::UnknownOptions do describe '#message' do let(:error) do - described_class.new([:a, :b]) + described_class.new(%i[a b]) end it 'contains the problem in the message' do diff --git a/spec/grape/exceptions/unknown_validator_spec.rb b/spec/grape/exceptions/unknown_validator_spec.rb index 8015ba9fd..9411b50c0 100644 --- a/spec/grape/exceptions/unknown_validator_spec.rb +++ b/spec/grape/exceptions/unknown_validator_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + require 'spec_helper' describe Grape::Exceptions::UnknownValidator do diff --git a/spec/grape/exceptions/validation_errors_spec.rb b/spec/grape/exceptions/validation_errors_spec.rb index e0ee3883b..bbbcc10cc 100644 --- a/spec/grape/exceptions/validation_errors_spec.rb +++ b/spec/grape/exceptions/validation_errors_spec.rb @@ -69,7 +69,7 @@ def app get '/exactly_one_of', beer: 'string', wine: 'anotherstring' expect(last_response.status).to eq(400) expect(JSON.parse(last_response.body)).to eq([ - 'params' => %w(beer wine), + 'params' => %w[beer wine], 'messages' => ['are mutually exclusive'] ]) end diff --git a/spec/grape/middleware/formatter_spec.rb b/spec/grape/middleware/formatter_spec.rb index aeab1c4e1..dafef25a8 100644 --- a/spec/grape/middleware/formatter_spec.rb +++ b/spec/grape/middleware/formatter_spec.rb @@ -223,7 +223,7 @@ def to_xml end context 'input' do - %w(POST PATCH PUT DELETE).each do |method| + %w[POST PATCH PUT DELETE].each do |method| ['application/json', 'application/json; charset=utf-8'].each do |content_type| context content_type do it "parses the body from #{method} and copies values into rack.request.form_hash" do diff --git a/spec/grape/middleware/versioner/header_spec.rb b/spec/grape/middleware/versioner/header_spec.rb index 498fe50a6..5befcc6a7 100644 --- a/spec/grape/middleware/versioner/header_spec.rb +++ b/spec/grape/middleware/versioner/header_spec.rb @@ -241,7 +241,7 @@ context 'when multiple versions are specified' do before do - @options[:versions] = %w(v1 v2) + @options[:versions] = %w[v1 v2] end it 'succeeds with v1' do diff --git a/spec/grape/middleware/versioner/param_spec.rb b/spec/grape/middleware/versioner/param_spec.rb index 98bb0710a..cdf3d23a8 100644 --- a/spec/grape/middleware/versioner/param_spec.rb +++ b/spec/grape/middleware/versioner/param_spec.rb @@ -35,7 +35,7 @@ end context 'with specified versions' do - let(:options) { { versions: %w(v1 v2) } } + let(:options) { { versions: %w[v1 v2] } } it 'throws an error if a non-allowed version is specified' do env = Rack::MockRequest.env_for('/awesome', params: { 'apiver' => 'v3' }) expect(catch(:error) { subject.call(env) }[:status]).to eq(404) diff --git a/spec/grape/middleware/versioner/path_spec.rb b/spec/grape/middleware/versioner/path_spec.rb index 686be9393..c5e9995d8 100644 --- a/spec/grape/middleware/versioner/path_spec.rb +++ b/spec/grape/middleware/versioner/path_spec.rb @@ -28,7 +28,7 @@ end end - [%w(v1 v2), [:v1, :v2], [:v1, 'v2'], ['v1', :v2]].each do |versions| + [%w[v1 v2], %i[v1 v2], [:v1, 'v2'], ['v1', :v2]].each do |versions| context "with specified versions as #{versions}" do let(:options) { { versions: versions } } diff --git a/spec/grape/path_spec.rb b/spec/grape/path_spec.rb index 88ffd8793..721b69f24 100644 --- a/spec/grape/path_spec.rb +++ b/spec/grape/path_spec.rb @@ -31,8 +31,8 @@ module Grape end it 'splits the mount path' do - path = Path.new(anything, anything, mount_path: %w(foo bar)) - expect(path.mount_path).to eql(%w(foo bar)) + path = Path.new(anything, anything, mount_path: %w[foo bar]) + expect(path.mount_path).to eql(%w[foo bar]) end end @@ -49,7 +49,7 @@ module Grape it 'splits the mount path' do path = Path.new(anything, anything, root_prefix: 'hello/world') - expect(path.root_prefix).to eql(%w(hello world)) + expect(path.root_prefix).to eql(%w[hello world]) end end diff --git a/spec/grape/util/inheritable_setting_spec.rb b/spec/grape/util/inheritable_setting_spec.rb index 4caa7606f..866a7bbd3 100644 --- a/spec/grape/util/inheritable_setting_spec.rb +++ b/spec/grape/util/inheritable_setting_spec.rb @@ -192,7 +192,7 @@ module Util expect(cloned_obj.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar] subject.namespace_stackable[:namespace_stackable_thing] = :other_thing - expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar, :other_thing] + expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq %i[namespace_stackable_foo_bar other_thing] expect(cloned_obj.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar] end @@ -200,7 +200,7 @@ module Util expect(cloned_obj.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar] subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing] = :other_thing - expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:other_thing, :namespace_reverse_stackable_foo_bar] + expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq %i[other_thing namespace_reverse_stackable_foo_bar] expect(cloned_obj.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar] end diff --git a/spec/grape/util/reverse_stackable_values_spec.rb b/spec/grape/util/reverse_stackable_values_spec.rb index 2fc623664..6c2d6b543 100644 --- a/spec/grape/util/reverse_stackable_values_spec.rb +++ b/spec/grape/util/reverse_stackable_values_spec.rb @@ -9,7 +9,7 @@ module Util it 'returns all keys' do subject[:some_thing] = :foo_bar subject[:some_thing_else] = :foo_bar - expect(subject.keys).to eq [:some_thing, :some_thing_else].sort + expect(subject.keys).to eq %i[some_thing some_thing_else].sort end it 'returns merged keys with parent' do @@ -19,7 +19,7 @@ module Util subject[:some_thing] = :foo_bar subject[:some_thing_more] = :foo_bar - expect(subject.keys).to eq [:some_thing, :some_thing_else, :some_thing_more].sort + expect(subject.keys).to eq %i[some_thing some_thing_else some_thing_more].sort end end @@ -52,7 +52,7 @@ module Util it 'combines parent and actual values (actual first)' do parent[:some_thing] = :foo subject[:some_thing] = :foo_bar - expect(subject[:some_thing]).to eq [:foo_bar, :foo] + expect(subject[:some_thing]).to eq %i[foo_bar foo] end it 'parent values are not changed' do @@ -71,28 +71,28 @@ module Util it 'pushes further values' do subject[:some_thing] = :foo subject[:some_thing] = :bar - expect(subject[:some_thing]).to eq [:foo, :bar] + expect(subject[:some_thing]).to eq %i[foo bar] end it 'can handle array values' do subject[:some_thing] = :foo - subject[:some_thing] = [:bar, :more] - expect(subject[:some_thing]).to eq [:foo, [:bar, :more]] + subject[:some_thing] = %i[bar more] + expect(subject[:some_thing]).to eq [:foo, %i[bar more]] - parent[:some_thing_else] = [:foo, :bar] - subject[:some_thing_else] = [:some, :bar, :foo] + parent[:some_thing_else] = %i[foo bar] + subject[:some_thing_else] = %i[some bar foo] - expect(subject[:some_thing_else]).to eq [[:some, :bar, :foo], [:foo, :bar]] + expect(subject[:some_thing_else]).to eq [%i[some bar foo], %i[foo bar]] end end describe '#to_hash' do it 'returns a Hash representation' do parent[:some_thing] = :foo - subject[:some_thing] = [:bar, :more] + subject[:some_thing] = %i[bar more] subject[:some_thing_more] = :foo_bar expect(subject.to_hash).to eq( - some_thing: [[:bar, :more], :foo], + some_thing: [%i[bar more], :foo], some_thing_more: [:foo_bar] ) end @@ -106,12 +106,12 @@ module Util grandchild = described_class.new child parent[:some_thing] = :foo - child[:some_thing] = [:bar, :more] + child[:some_thing] = %i[bar more] grandchild[:some_thing] = :grand_foo_bar grandchild[:some_thing_more] = :foo_bar expect(grandchild.clone.to_hash).to eq( - some_thing: [:grand_foo_bar, [:bar, :more], :foo], + some_thing: [:grand_foo_bar, %i[bar more], :foo], some_thing_more: [:foo_bar] ) end diff --git a/spec/grape/util/stackable_values_spec.rb b/spec/grape/util/stackable_values_spec.rb index 6f2982dfb..82a327a56 100644 --- a/spec/grape/util/stackable_values_spec.rb +++ b/spec/grape/util/stackable_values_spec.rb @@ -9,7 +9,7 @@ module Util it 'returns all key' do subject[:some_thing] = :foo_bar subject[:some_thing_else] = :foo_bar - expect(subject.keys).to eq [:some_thing, :some_thing_else].sort + expect(subject.keys).to eq %i[some_thing some_thing_else].sort end it 'returns merged keys with parent' do @@ -19,7 +19,7 @@ module Util subject[:some_thing] = :foo_bar subject[:some_thing_more] = :foo_bar - expect(subject.keys).to eq [:some_thing, :some_thing_else, :some_thing_more].sort + expect(subject.keys).to eq %i[some_thing some_thing_else some_thing_more].sort end end @@ -52,7 +52,7 @@ module Util it 'combines parent and actual values' do parent[:some_thing] = :foo subject[:some_thing] = :foo_bar - expect(subject[:some_thing]).to eq [:foo, :foo_bar] + expect(subject[:some_thing]).to eq %i[foo foo_bar] end it 'parent values are not changed' do @@ -71,27 +71,27 @@ module Util it 'pushes further values' do subject[:some_thing] = :foo subject[:some_thing] = :bar - expect(subject[:some_thing]).to eq [:foo, :bar] + expect(subject[:some_thing]).to eq %i[foo bar] end it 'can handle array values' do subject[:some_thing] = :foo - subject[:some_thing] = [:bar, :more] - expect(subject[:some_thing]).to eq [:foo, [:bar, :more]] + subject[:some_thing] = %i[bar more] + expect(subject[:some_thing]).to eq [:foo, %i[bar more]] - parent[:some_thing_else] = [:foo, :bar] - subject[:some_thing_else] = [:some, :bar, :foo] + parent[:some_thing_else] = %i[foo bar] + subject[:some_thing_else] = %i[some bar foo] - expect(subject[:some_thing_else]).to eq [[:foo, :bar], [:some, :bar, :foo]] + expect(subject[:some_thing_else]).to eq [%i[foo bar], %i[some bar foo]] end end describe '#to_hash' do it 'returns a Hash representation' do parent[:some_thing] = :foo - subject[:some_thing] = [:bar, :more] + subject[:some_thing] = %i[bar more] subject[:some_thing_more] = :foo_bar - expect(subject.to_hash).to eq(some_thing: [:foo, [:bar, :more]], some_thing_more: [:foo_bar]) + expect(subject.to_hash).to eq(some_thing: [:foo, %i[bar more]], some_thing_more: [:foo_bar]) end end @@ -103,11 +103,11 @@ module Util grandchild = StackableValues.new child parent[:some_thing] = :foo - child[:some_thing] = [:bar, :more] + child[:some_thing] = %i[bar more] grandchild[:some_thing] = :grand_foo_bar grandchild[:some_thing_more] = :foo_bar - expect(grandchild.clone.to_hash).to eq(some_thing: [:foo, [:bar, :more], :grand_foo_bar], some_thing_more: [:foo_bar]) + expect(grandchild.clone.to_hash).to eq(some_thing: [:foo, %i[bar more], :grand_foo_bar], some_thing_more: [:foo_bar]) end context 'complex (i.e. not primitive) data types (ex. middleware, please see bug #930)' do diff --git a/spec/grape/util/strict_hash_configuration_spec.rb b/spec/grape/util/strict_hash_configuration_spec.rb index 428d1f5e0..8798d095f 100644 --- a/spec/grape/util/strict_hash_configuration_spec.rb +++ b/spec/grape/util/strict_hash_configuration_spec.rb @@ -4,7 +4,7 @@ module Util describe 'StrictHashConfiguration' do subject do Class.new do - include Grape::Util::StrictHashConfiguration.module(:config1, :config2, config3: [:config4], config5: [config6: [:config7, :config8]]) + include Grape::Util::StrictHashConfiguration.module(:config1, :config2, config3: [:config4], config5: [config6: %i[config7 config8]]) end end diff --git a/spec/grape/validations/params_scope_spec.rb b/spec/grape/validations/params_scope_spec.rb index e048496ed..075db2195 100644 --- a/spec/grape/validations/params_scope_spec.rb +++ b/spec/grape/validations/params_scope_spec.rb @@ -74,7 +74,7 @@ def app end context 'setting description' do - [:desc, :description].each do |description_type| + %i[desc description].each do |description_type| it "allows setting #{description_type}" do subject.params do requires :int, type: Integer, description_type => 'My very nice integer' @@ -160,18 +160,18 @@ def initialize(value) context 'array without coerce type explicitly given' do it 'sets the type based on first element' do subject.params do - requires :periods, type: Array, values: -> { %w(day month) } + requires :periods, type: Array, values: -> { %w[day month] } end subject.get('/required') { 'required works' } - get '/required', periods: %w(day month) + get '/required', periods: %w[day month] expect(last_response.status).to eq(200) expect(last_response.body).to eq('required works') end it 'fails to call API without Array type' do subject.params do - requires :periods, type: Array, values: -> { %w(day month) } + requires :periods, type: Array, values: -> { %w[day month] } end subject.get('/required') { 'required works' } @@ -468,7 +468,7 @@ def initialize(value) it 'does not validate nested requires when given is false' do subject.params do - requires :a, type: String, allow_blank: false, values: %w(x y z) + requires :a, type: String, allow_blank: false, values: %w[x y z] given a: ->(val) { val == 'x' } do requires :inner1, type: Hash, allow_blank: false do requires :foo, type: Integer, allow_blank: false @@ -586,8 +586,8 @@ def initialize(value) context 'when validations are dependent on a parameter with specific value' do # build test cases from all combinations of declarations and options - a_decls = %i(optional requires) - a_options = [{}, { values: %w(x y z) }] + a_decls = %i[optional requires] + a_options = [{}, { values: %w[x y z] }] b_options = [{}, { type: String }, { allow_blank: false }, { type: String, allow_blank: false }] combinations = a_decls.product(a_options, b_options) combinations.each_with_index do |combination, i| diff --git a/spec/grape/validations/validators/all_or_none_spec.rb b/spec/grape/validations/validators/all_or_none_spec.rb index 0e6e9b40e..98d82ce8f 100644 --- a/spec/grape/validations/validators/all_or_none_spec.rb +++ b/spec/grape/validations/validators/all_or_none_spec.rb @@ -11,7 +11,7 @@ def params(arg) def required?; end end end - let(:all_or_none_params) { [:beer, :wine, :grapefruit] } + let(:all_or_none_params) { %i[beer wine grapefruit] } let(:validator) { described_class.new(all_or_none_params, {}, false, scope.new) } context 'when all restricted params are present' do diff --git a/spec/grape/validations/validators/at_least_one_of_spec.rb b/spec/grape/validations/validators/at_least_one_of_spec.rb index 6a0a05fea..7a331fe9b 100644 --- a/spec/grape/validations/validators/at_least_one_of_spec.rb +++ b/spec/grape/validations/validators/at_least_one_of_spec.rb @@ -11,7 +11,7 @@ def params(arg) def required?; end end end - let(:at_least_one_of_params) { [:beer, :wine, :grapefruit] } + let(:at_least_one_of_params) { %i[beer wine grapefruit] } let(:validator) { described_class.new(at_least_one_of_params, {}, false, scope.new) } context 'when all restricted params are present' do diff --git a/spec/grape/validations/validators/coerce_spec.rb b/spec/grape/validations/validators/coerce_spec.rb index c3eaaf0ad..b21ec8cf2 100644 --- a/spec/grape/validations/validators/coerce_spec.rb +++ b/spec/grape/validations/validators/coerce_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 + require 'spec_helper' describe Grape::Validations::CoerceValidator do @@ -136,11 +136,11 @@ class User 'array int works' end - get 'array', ids: %w(1 2 az) + get 'array', ids: %w[1 2 az] expect(last_response.status).to eq(400) expect(last_response.body).to eq('ids is invalid') - get 'array', ids: %w(1 2 890) + get 'array', ids: %w[1 2 890] expect(last_response.status).to eq(200) expect(last_response.body).to eq('array int works') end @@ -187,7 +187,7 @@ class User params[:arry][0].class end - get '/array', arry: %w(1 2 3) + get '/array', arry: %w[1 2 3] expect(last_response.status).to eq(200) expect(last_response.body).to eq(integer_class_name) end @@ -444,11 +444,11 @@ def self.parsed?(value) get '/ints', values: '1 2 3 4' expect(last_response.status).to eq(200) - expect(JSON.parse(last_response.body)).to eq(%w(1 2 3 4)) + expect(JSON.parse(last_response.body)).to eq(%w[1 2 3 4]) get '/ints', values: 'a b c d' expect(last_response.status).to eq(200) - expect(JSON.parse(last_response.body)).to eq(%w(0 0 0 0)) + expect(JSON.parse(last_response.body)).to eq(%w[0 0 0 0]) end it 'parses parameters with Array[Integer] type' do @@ -480,7 +480,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(JSON.parse(last_response.body)).to eq([2, 3, 4, 5]) - get '/ints', values: %w(a b c d) + get '/ints', values: %w[a b c d] expect(last_response.status).to eq(200) expect(JSON.parse(last_response.body)).to eq([1, 1, 1, 1]) end @@ -742,7 +742,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(last_response.body).to eq('"one way"') - get '/', a: %w(the other) + get '/', a: %w[the other] expect(last_response.status).to eq(200) expect(last_response.body).to eq('["the", "other"]') @@ -760,7 +760,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(last_response.body).to eq('[1, 2, 3]') - get '/', b: %w(1 2 3) + get '/', b: %w[1 2 3] expect(last_response.status).to eq(200) expect(last_response.body).to eq('[1, 2, 3]') @@ -782,7 +782,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(last_response.body).to eq('"one"') - get '/', d: %w(1 two) + get '/', d: %w[1 two] expect(last_response.status).to eq(200) expect(last_response.body).to eq('#') end @@ -813,7 +813,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(last_response.body).to eq('"one way"') - get '/', a: %w(the other) + get '/', a: %w[the other] expect(last_response.status).to eq(200) expect(last_response.body).to eq('#') @@ -831,7 +831,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(last_response.body).to eq('#') - get '/', b: %w(1 2 3) + get '/', b: %w[1 2 3] expect(last_response.status).to eq(200) expect(last_response.body).to eq('#') @@ -853,7 +853,7 @@ def self.parsed?(value) expect(last_response.status).to eq(200) expect(last_response.body).to eq('"one"') - get '/', d: %w(1 two) + get '/', d: %w[1 two] expect(last_response.status).to eq(200) expect(last_response.body).to eq('#') end diff --git a/spec/grape/validations/validators/exactly_one_of_spec.rb b/spec/grape/validations/validators/exactly_one_of_spec.rb index 166bb0627..8bdb23073 100644 --- a/spec/grape/validations/validators/exactly_one_of_spec.rb +++ b/spec/grape/validations/validators/exactly_one_of_spec.rb @@ -11,7 +11,7 @@ def params(arg) def required?; end end end - let(:exactly_one_of_params) { [:beer, :wine, :grapefruit] } + let(:exactly_one_of_params) { %i[beer wine grapefruit] } let(:validator) { described_class.new(exactly_one_of_params, {}, false, scope.new) } context 'when all restricted params are present' do diff --git a/spec/grape/validations/validators/mutual_exclusion_spec.rb b/spec/grape/validations/validators/mutual_exclusion_spec.rb index f06778054..9fa6375b5 100644 --- a/spec/grape/validations/validators/mutual_exclusion_spec.rb +++ b/spec/grape/validations/validators/mutual_exclusion_spec.rb @@ -9,7 +9,7 @@ def params(arg) end end end - let(:mutually_exclusive_params) { [:beer, :wine, :grapefruit] } + let(:mutually_exclusive_params) { %i[beer wine grapefruit] } let(:validator) { described_class.new(mutually_exclusive_params, {}, false, scope.new) } context 'when all mutually exclusive params are present' do diff --git a/spec/grape/validations/validators/values_spec.rb b/spec/grape/validations/validators/values_spec.rb index 4e7cecf07..2317cf555 100644 --- a/spec/grape/validations/validators/values_spec.rb +++ b/spec/grape/validations/validators/values_spec.rb @@ -159,7 +159,7 @@ class API < Grape::API params do optional :optional, type: Array do - requires :type, values: %w(a b) + requires :type, values: %w[a b] end end get '/optional_with_required_values' @@ -207,7 +207,7 @@ class API < Grape::API end params do - optional :optional, type: Array[String], values: %w(a b c) + optional :optional, type: Array[String], values: %w[a b c] end put '/optional_with_array_of_string_values' @@ -555,7 +555,7 @@ def app end it 'rejects an array of values if any of them matches except' do - get '/except/exclusive', type: %w(valid1 valid2 invalid-type1 valid4) + get '/except/exclusive', type: %w[valid1 valid2 invalid-type1 valid4] expect(last_response.status).to eq 400 expect(last_response.body).to eq({ error: 'type has a value not allowed' }.to_json) end diff --git a/spec/grape/validations_spec.rb b/spec/grape/validations_spec.rb index 2c5e90e58..a5b79be9e 100644 --- a/spec/grape/validations_spec.rb +++ b/spec/grape/validations_spec.rb @@ -63,7 +63,7 @@ def define_optional_using it 'adds entity documentation to declared params' do define_optional_using - expect(subject.route_setting(:declared_params)).to eq([:field_a, :field_b]) + expect(subject.route_setting(:declared_params)).to eq(%i[field_a field_b]) end it 'works when field_a and field_b are not present' do @@ -139,7 +139,7 @@ def define_requires_all it 'adds entity documentation to declared params' do define_requires_all - expect(subject.route_setting(:declared_params)).to eq([:required_field, :optional_field]) + expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field]) end it 'errors when required_field is not present' do @@ -174,7 +174,7 @@ def define_requires_none it 'adds entity documentation to declared params' do define_requires_none - expect(subject.route_setting(:declared_params)).to eq([:required_field, :optional_field]) + expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field]) end it 'errors when required_field is not present' do @@ -204,7 +204,7 @@ def define_requires_all it 'adds only the entity documentation to declared params, nothing more' do define_requires_all - expect(subject.route_setting(:declared_params)).to eq([:required_field, :optional_field]) + expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field]) end end @@ -350,7 +350,7 @@ def define_requires_none before do subject.params do requires :items, type: Hash do - requires :key, type: String, values: %w(a b) + requires :key, type: String, values: %w[a b] end end subject.get '/required' do @@ -1058,14 +1058,14 @@ def validate_param!(attr_name, params) subject.params do use :pagination end - expect(subject.route_setting(:declared_params)).to eq [:page, :per_page] + expect(subject.route_setting(:declared_params)).to eq %i[page per_page] end it 'by #use with multiple params' do subject.params do use :pagination, :period end - expect(subject.route_setting(:declared_params)).to eq [:page, :per_page, :start_date, :end_date] + expect(subject.route_setting(:declared_params)).to eq %i[page per_page start_date end_date] end end @@ -1073,13 +1073,13 @@ def validate_param!(attr_name, params) before do subject.helpers do params :order do |options| - optional :order, type: Symbol, values: [:asc, :desc], default: options[:default_order] + optional :order, type: Symbol, values: %i[asc desc], default: options[:default_order] optional :order_by, type: Symbol, values: options[:order_by], default: options[:default_order_by] end end subject.format :json subject.params do - use :order, default_order: :asc, order_by: [:name, :created_at], default_order_by: :created_at + use :order, default_order: :asc, order_by: %i[name created_at], default_order_by: :created_at end subject.get '/order' do { diff --git a/spec/support/content_type_helpers.rb b/spec/support/content_type_helpers.rb index 1ec1851b3..5a23f0260 100644 --- a/spec/support/content_type_helpers.rb +++ b/spec/support/content_type_helpers.rb @@ -1,7 +1,7 @@ module Spec module Support module Helpers - %w(put patch post delete).each do |method| + %w[put patch post delete].each do |method| define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block| params = params.to_json env['CONTENT_TYPE'] ||= 'application/json'