Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix spec warnings #1583

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ 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
when Grape::Http::Headers::DELETE
if @body.present?
if defined?(@body) && @body.present?
200
else
204
Expand Down Expand Up @@ -199,7 +199,7 @@ def body(value = nil)
elsif value == false
@body = ''
status 204
else
elsif defined?(@body)
@body
end
end
Expand Down Expand Up @@ -233,7 +233,7 @@ 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
elsif defined?(@file)
@file
end
end
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?
Expand Down Expand Up @@ -209,8 +209,8 @@ 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 = map_params(params, @element) if @element
params = @parent.params(params) if defined?(@parent) && @parent
params = map_params(params, @element) if defined?(@element) && @element
params
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/grape/dsl/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions lib/grape/validations/validators/values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(attrs, options, required, scope, opts = {})
raise ArgumentError, 'proc must be a Proc' if @proc && [email protected]_a?(Proc)
else
@values = options
@excepts = @proc = nil
end
super
end
Expand Down
8 changes: 5 additions & 3 deletions spec/grape/dsl/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
config.raise_errors_for_deprecations!

config.before(:each) { Grape::Util::InheritableSetting.reset_global! }

config.warnings = true
end

require 'coveralls'
Expand Down