From a639d9744e88e569e1a6671491e96fc9d8823ea1 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:28:58 +0000 Subject: [PATCH 01/17] Enable warnings while running specs --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e00fba2281..cdd0b742c4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,6 +20,8 @@ config.raise_errors_for_deprecations! config.before(:each) { Grape::Util::InheritableSetting.reset_global! } + + config.warnings = true end require 'coveralls' From 7affe49ad3106f326654721ab34c1b9bb65db073 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:29:25 +0000 Subject: [PATCH 02/17] Fix "warning: instance variable @namespace_description not initialized" --- lib/grape/dsl/routing.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/grape/dsl/routing.rb b/lib/grape/dsl/routing.rb index 24b9d5f3a5..0cd90525ec 100644 --- a/lib/grape/dsl/routing.rb +++ b/lib/grape/dsl/routing.rb @@ -159,8 +159,8 @@ def route(methods, paths = ['/'], route_options = {}, &block) def namespace(space = nil, options = {}, &block) if space || block_given? within_namespace do - previous_namespace_description = @namespace_description - @namespace_description = (@namespace_description || {}).deep_merge(namespace_setting(:description) || {}) + previous_namespace_description = defined?(@namespace_description) && @namespace_description + @namespace_description = ((defined?(@namespace_description) && @namespace_description) || {}).deep_merge(namespace_setting(:description) || {}) nest(block) do if space namespace_stackable(:namespace, Namespace.new(space, options)) From d0c87aadd92f13430ed95dee8469bc93a99157e9 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:39:36 +0000 Subject: [PATCH 03/17] Fix "warning: instance variable @file not initialized" --- lib/grape/dsl/inside_route.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 0e771504aa..037b37aed6 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -234,7 +234,7 @@ def file(value = nil) warn '[DEPRECATION] Argument as FileStreamer-like object is deprecated. Use path to file instead.' @file = Grape::ServeFile::FileResponse.new(value) else - @file + @file if defined?(@file) end end From b0c8ec1d953c1a48bb93671a0b833fd780a35e2c Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:42:31 +0000 Subject: [PATCH 04/17] Fix "warning: instance variable @status not initialized" --- lib/grape/dsl/inside_route.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 037b37aed6..b6b1d977ae 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -144,7 +144,7 @@ def status(status = nil) when Integer @status = status when nil - return @status if @status + return @status if defined?(@status) && @status case request.request_method.to_s.upcase when Grape::Http::Headers::POST 201 From 7b6f9e97c85d35f14fe5d8bb965f8a7736035b10 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:46:35 +0000 Subject: [PATCH 05/17] Fix "warning: instance variable @excepts not initialized" --- lib/grape/validations/validators/values.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/grape/validations/validators/values.rb b/lib/grape/validations/validators/values.rb index 1926bc9020..13730bc307 100644 --- a/lib/grape/validations/validators/values.rb +++ b/lib/grape/validations/validators/values.rb @@ -9,6 +9,7 @@ def initialize(attrs, options, required, scope, opts = {}) raise ArgumentError, 'proc must be a Proc' if @proc && !@proc.is_a?(Proc) else @values = options + @excepts = nil end super end From 76bbd8c2cf0ef58c54064b796444d2087910932f Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:49:13 +0000 Subject: [PATCH 06/17] Fix "warning: instance variable @proc not initialized" --- lib/grape/validations/validators/values.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/validations/validators/values.rb b/lib/grape/validations/validators/values.rb index 13730bc307..e4269c3fd1 100644 --- a/lib/grape/validations/validators/values.rb +++ b/lib/grape/validations/validators/values.rb @@ -9,7 +9,7 @@ def initialize(attrs, options, required, scope, opts = {}) raise ArgumentError, 'proc must be a Proc' if @proc && !@proc.is_a?(Proc) else @values = options - @excepts = nil + @excepts = @proc = nil end super end From 03d1fd556da8732a2086473d5bd2719af1a59ab2 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:50:32 +0000 Subject: [PATCH 07/17] Fix "warning: instance variable @named_params not initialized" --- lib/grape/dsl/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/dsl/helpers.rb b/lib/grape/dsl/helpers.rb index 9d2200a7cd..c28b89925b 100644 --- a/lib/grape/dsl/helpers.rb +++ b/lib/grape/dsl/helpers.rb @@ -78,7 +78,7 @@ def api_changed(new_api) protected def process_named_params - return unless @named_params && @named_params.any? + return unless defined?(@named_params) && @named_params && @named_params.any? api.namespace_stackable(:named_params, @named_params) end end From 512d1af8949025afd2038939c6d45b9635da5bea Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 16:57:50 +0000 Subject: [PATCH 08/17] Fix "warning: instance variable @body not initialized" --- lib/grape/dsl/inside_route.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index b6b1d977ae..9e410d9db7 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -149,7 +149,7 @@ def status(status = nil) when Grape::Http::Headers::POST 201 when Grape::Http::Headers::DELETE - if @body.present? + if defined?(@body) && @body.present? 200 else 204 @@ -200,7 +200,7 @@ def body(value = nil) @body = '' status 204 else - @body + @body if defined?(@body) end end @@ -294,8 +294,8 @@ def present(*args) representation = { root => representation } if root if key - representation = (@body || {}).merge(key => representation) - elsif entity_class.present? && @body + representation = ((defined?(@body) && @body) || {}).merge(key => representation) + elsif entity_class.present? && defined?(@body) && @body raise ArgumentError, "Representation of type #{representation.class} cannot be merged." unless representation.respond_to?(:merge) representation = @body.merge(representation) end From 183f60b66fbb2163b9b9343d1256b6a21ff64022 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 17:00:18 +0000 Subject: [PATCH 09/17] Fix "warning: instance variable @parent not initialized" --- lib/grape/dsl/parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/dsl/parameters.rb b/lib/grape/dsl/parameters.rb index 7d3986ac09..58c3403ff8 100644 --- a/lib/grape/dsl/parameters.rb +++ b/lib/grape/dsl/parameters.rb @@ -209,7 +209,7 @@ def map_params(params, element) # @return hash of parameters relevant for the current scope # @api private def params(params) - params = @parent.params(params) if @parent + params = @parent.params(params) if defined?(@parent) && @parent params = map_params(params, @element) if @element params end From 6860336d619d7f89f1c867f01477b8ff63be12d1 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 17:00:50 +0000 Subject: [PATCH 10/17] Fix "warning: instance variable @element not initialized" --- lib/grape/dsl/parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/dsl/parameters.rb b/lib/grape/dsl/parameters.rb index 58c3403ff8..7675acb8f9 100644 --- a/lib/grape/dsl/parameters.rb +++ b/lib/grape/dsl/parameters.rb @@ -210,7 +210,7 @@ def map_params(params, element) # @api private def params(params) params = @parent.params(params) if defined?(@parent) && @parent - params = map_params(params, @element) if @element + params = map_params(params, @element) if defined?(@element) && @element params end end From a538955dd7dfd444c80f3d4af26c055359a70548 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 17:02:23 +0000 Subject: [PATCH 11/17] Fix "warning: instance variable @group not initialized" --- lib/grape/dsl/parameters.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/grape/dsl/parameters.rb b/lib/grape/dsl/parameters.rb index 7675acb8f9..4fd2e7afcf 100644 --- a/lib/grape/dsl/parameters.rb +++ b/lib/grape/dsl/parameters.rb @@ -99,7 +99,7 @@ def requires(*attrs, &block) opts = attrs.extract_options!.clone opts[:presence] = { value: true, message: opts[:message] } - opts = @group.merge(opts) if @group + opts = @group.merge(opts) if defined?(@group) && @group if opts[:using] require_required_and_optional_fields(attrs.first, opts) @@ -119,7 +119,7 @@ def optional(*attrs, &block) opts = attrs.extract_options!.clone type = opts[:type] - opts = @group.merge(opts) if @group + opts = @group.merge(opts) if defined?(@group) && @group # check type for optional parameter group if attrs && block_given? From 47e6114e84bce0929395b1d5d719c9ca8c6db45d Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 17:14:42 +0000 Subject: [PATCH 12/17] Fix "warning: instance variable @versions not initialized" --- lib/grape/dsl/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grape/dsl/routing.rb b/lib/grape/dsl/routing.rb index 0cd90525ec..3695976286 100644 --- a/lib/grape/dsl/routing.rb +++ b/lib/grape/dsl/routing.rb @@ -49,7 +49,7 @@ def version(*args, &block) end end - @versions.last unless @versions.nil? + @versions.last if defined?(@versions) && @versions end # Define a root URL prefix for your entire API. From a535103859e4a2ab952be886e67afea94a5b634c Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 17:24:24 +0000 Subject: [PATCH 13/17] Fix "warning: instance variable @api not initialized" --- spec/grape/dsl/parameters_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/grape/dsl/parameters_spec.rb b/spec/grape/dsl/parameters_spec.rb index a0fae5f669..d1a6af581a 100644 --- a/spec/grape/dsl/parameters_spec.rb +++ b/spec/grape/dsl/parameters_spec.rb @@ -50,19 +50,21 @@ def extract_message_option(attrs) describe '#use' do before do allow_message_expectations_on_nil - allow(subject.api).to receive(:namespace_stackable).with(:named_params) + subject.api = api + allow(api).to receive(:namespace_stackable).with(:named_params) end + let(:api) { double("api") } let(:options) { { option: 'value' } } let(:named_params) { { params_group: proc {} } } it 'calls processes associated with named params' do - allow(subject.api).to receive(:namespace_stackable_with_hash).and_return(named_params) + allow(api).to receive(:namespace_stackable_with_hash).and_return(named_params) expect(subject).to receive(:instance_exec).with(options).and_yield subject.use :params_group, options end it 'raises error when non-existent named param is called' do - allow(subject.api).to receive(:namespace_stackable_with_hash).and_return({}) + allow(api).to receive(:namespace_stackable_with_hash).and_return({}) expect { subject.use :params_group }.to raise_error('Params :params_group not found!') end end From af93f8efc16b2c60cfd173dd47215b3ce24bf1dd Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 17:56:18 +0000 Subject: [PATCH 14/17] Fix rubocop single quote offense --- spec/grape/dsl/parameters_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/grape/dsl/parameters_spec.rb b/spec/grape/dsl/parameters_spec.rb index d1a6af581a..ee45c18684 100644 --- a/spec/grape/dsl/parameters_spec.rb +++ b/spec/grape/dsl/parameters_spec.rb @@ -53,7 +53,7 @@ def extract_message_option(attrs) subject.api = api allow(api).to receive(:namespace_stackable).with(:named_params) end - let(:api) { double("api") } + let(:api) { double('api') } let(:options) { { option: 'value' } } let(:named_params) { { params_group: proc {} } } From 718c0b7c77b2742acda61cef429d293a50e0fe63 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 18:03:18 +0000 Subject: [PATCH 15/17] Fix rubocop conflict C: Convert if nested inside else to elsif. --- lib/grape/dsl/inside_route.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 9e410d9db7..681f6d127c 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -199,8 +199,8 @@ def body(value = nil) elsif value == false @body = '' status 204 - else - @body if defined?(@body) + elsif defined?(@body) + @body end end @@ -233,8 +233,8 @@ def file(value = nil) elsif !value.is_a?(NilClass) warn '[DEPRECATION] Argument as FileStreamer-like object is deprecated. Use path to file instead.' @file = Grape::ServeFile::FileResponse.new(value) - else - @file if defined?(@file) + elsif defined?(@file) + @file end end From aca29d3d1b7d1b2875e16d56cc7a9ab316b4171a Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 18:06:22 +0000 Subject: [PATCH 16/17] Update rubocop todo --- .rubocop_todo.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1d7f66c286..67503bab13 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-02-19 15:40:46 -0500 using RuboCop version 0.47.1. +# on 2017-02-27 18:05:03 +0000 using RuboCop version 0.47.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 @@ -25,11 +25,11 @@ Metrics/BlockNesting: Metrics/ClassLength: Max: 281 -# Offense count: 26 +# Offense count: 28 Metrics/CyclomaticComplexity: Max: 14 -# Offense count: 993 +# Offense count: 994 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: @@ -45,9 +45,9 @@ Metrics/MethodLength: Metrics/ModuleLength: Max: 212 -# Offense count: 16 +# Offense count: 19 Metrics/PerceivedComplexity: - Max: 14 + Max: 16 # Offense count: 2 Style/IdenticalConditionalBranches: From b835c9444bfb10ea96d714d9127bcc6fac6ac861 Mon Sep 17 00:00:00 2001 From: axfcampos Date: Mon, 27 Feb 2017 18:14:49 +0000 Subject: [PATCH 17/17] Update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd1576850f..b9ada4619a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * [#1561](https://github.com/ruby-grape/grape/pull/1561): Fix performance issue introduced by duplicated calls in StackableValue#[] - [@brucehsu](https://github.com/brucehsu). * [#1564](https://github.com/ruby-grape/grape/pull/1564): Fix declared params bug with nested namespaces - [@bmarini](https://github.com/bmarini). * [#1567](https://github.com/ruby-grape/grape/pull/1567): Fix values validator when value is empty array and apply except to input array - [@jlfaber](https://github.com/jlfaber). +* [#1583](https://github.com/ruby-grape/grape/pull/1583): Fix spec warnings - [@axfcampos](https://github.com/axfcampos). * Your contribution here. ### 0.19.1 (1/9/2017)