Hello community, here is the log from the commit of package rubygem-grape for openSUSE:Factory checked in at 2018-07-18 22:49:49 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-grape (Old) and /work/SRC/openSUSE:Factory/.rubygem-grape.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-grape" Wed Jul 18 22:49:49 2018 rev:3 rq:621004 version:1.0.3 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-grape/rubygem-grape.changes 2018-02-16 21:43:36.273398196 +0100 +++ /work/SRC/openSUSE:Factory/.rubygem-grape.new/rubygem-grape.changes 2018-07-18 22:49:52.383770000 +0200 @@ -1,0 +2,19 @@ +Tue Apr 24 00:05:37 UTC 2018 - [email protected] + +- updated to version 1.0.3 + see installed CHANGELOG.md + + ### 1.0.3 (4/23/2018) + + #### Fixes + + * [#1755](https://github.com/ruby-grape/grape/pull/1755): Fix shared params with exactly_one_of - [@milgner](https://github.com/milgner). + * [#1740](https://github.com/ruby-grape/grape/pull/1740): Fix dependent parameter validation using `given` when parameter is a `Hash` - [@jvortmann](https://github.com/jvortmann). + * [#1737](https://github.com/ruby-grape/grape/pull/1737): Fix translating error when passing symbols as params in custom validations - [@mlzhuyi](https://github.com/mlzhuyi). + * [#1749](https://github.com/ruby-grape/grape/pull/1749): Allow rescue from non-`StandardError` exceptions - [@dm1try](https://github.com/dm1try). + * [#1750](https://github.com/ruby-grape/grape/pull/1750): Fix a circular dependency warning due to router being loaded by API - [@salasrod](https://github.com/salasrod). + * [#1752](https://github.com/ruby-grape/grape/pull/1752): Fix `include_missing` behavior for aliased parameters - [@jonasoberschweiber](https://github.com/jonasoberschweiber). + * [#1754](https://github.com/ruby-grape/grape/pull/1754): Allow rescue from non-`StandardError` exceptions to use default error handling - [@jelkster](https://github.com/jelkster). + * [#1756](https://github.com/ruby-grape/grape/pull/1756): Allow custom Grape exception handlers when the built-in exception handling is enabled - [@soylent](https://github.com/soylent). + +------------------------------------------------------------------- Old: ---- grape-1.0.2.gem New: ---- grape-1.0.3.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-grape.spec ++++++ --- /var/tmp/diff_new_pack.OtI2Xw/_old 2018-07-18 22:49:53.747765478 +0200 +++ /var/tmp/diff_new_pack.OtI2Xw/_new 2018-07-18 22:49:53.747765478 +0200 @@ -24,7 +24,7 @@ # Name: rubygem-grape -Version: 1.0.2 +Version: 1.0.3 Release: 0 %define mod_name grape %define mod_full_name %{mod_name}-%{version} ++++++ grape-1.0.2.gem -> grape-1.0.3.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2018-01-10 23:03:42.000000000 +0100 +++ new/CHANGELOG.md 2018-04-24 01:36:45.000000000 +0200 @@ -1,3 +1,16 @@ +### 1.0.3 (4/23/2018) + +#### Fixes + +* [#1755](https://github.com/ruby-grape/grape/pull/1755): Fix shared params with exactly_one_of - [@milgner](https://github.com/milgner). +* [#1740](https://github.com/ruby-grape/grape/pull/1740): Fix dependent parameter validation using `given` when parameter is a `Hash` - [@jvortmann](https://github.com/jvortmann). +* [#1737](https://github.com/ruby-grape/grape/pull/1737): Fix translating error when passing symbols as params in custom validations - [@mlzhuyi](https://github.com/mlzhuyi). +* [#1749](https://github.com/ruby-grape/grape/pull/1749): Allow rescue from non-`StandardError` exceptions - [@dm1try](https://github.com/dm1try). +* [#1750](https://github.com/ruby-grape/grape/pull/1750): Fix a circular dependency warning due to router being loaded by API - [@salasrod](https://github.com/salasrod). +* [#1752](https://github.com/ruby-grape/grape/pull/1752): Fix `include_missing` behavior for aliased parameters - [@jonasoberschweiber](https://github.com/jonasoberschweiber). +* [#1754](https://github.com/ruby-grape/grape/pull/1754): Allow rescue from non-`StandardError` exceptions to use default error handling - [@jelkster](https://github.com/jelkster). +* [#1756](https://github.com/ruby-grape/grape/pull/1756): Allow custom Grape exception handlers when the built-in exception handling is enabled - [@soylent](https://github.com/soylent). + ### 1.0.2 (1/10/2018) #### Features diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Gemfile new/Gemfile --- old/Gemfile 2018-01-10 23:03:42.000000000 +0100 +++ new/Gemfile 2018-04-24 01:36:45.000000000 +0200 @@ -22,7 +22,7 @@ group :test do gem 'cookiejar' gem 'coveralls', '~> 0.8.17', require: false - gem 'danger-toc', '~> 0.1.0' + gem 'danger-toc', '~> 0.1.2' gem 'grape-entity', '~> 0.6' gem 'maruku' gem 'mime-types' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Gemfile.lock new/Gemfile.lock --- old/Gemfile.lock 2018-01-10 23:03:42.000000000 +0100 +++ new/Gemfile.lock 2018-04-24 01:36:45.000000000 +0200 @@ -1,7 +1,7 @@ PATH remote: . specs: - grape (1.0.2) + grape (1.0.3) activesupport builder mustermann-grape (~> 1.0.0) @@ -23,7 +23,7 @@ bundler rake thor (>= 0.14.0) - ast (2.3.0) + ast (2.4.0) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) @@ -65,7 +65,7 @@ danger-plugin-api (~> 1.0) danger-plugin-api (1.0.0) danger (> 2.0) - danger-toc (0.1.0) + danger-toc (0.1.2) activesupport danger-plugin-api (~> 1.0) kramdown @@ -74,15 +74,15 @@ diff-lcs (1.3) docile (1.1.5) equalizer (0.0.11) - faraday (0.13.1) + faraday (0.14.0) multipart-post (>= 1.2, < 3) faraday-http-cache (1.3.1) faraday (~> 0.8) - ffi (1.9.18) + ffi (1.9.21) formatador (0.2.5) git (1.3.0) - grape-entity (0.6.1) - activesupport (>= 5.0.0) + grape-entity (0.7.1) + activesupport (>= 4.0) multi_json (>= 1.3.2) guard (2.14.2) formatador (>= 0.2.4) @@ -102,7 +102,7 @@ guard (~> 2.0) rubocop (~> 0.20) hashie (3.5.7) - i18n (0.9.1) + i18n (0.9.4) concurrent-ruby (~> 1.0) ice_nine (0.11.2) json (2.1.0) @@ -117,7 +117,7 @@ mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - minitest (5.11.1) + minitest (5.11.3) multi_json (1.13.1) multipart-post (2.0.0) mustermann (1.0.1) @@ -139,7 +139,7 @@ coderay (~> 1.1.0) method_source (~> 0.9.0) public_suffix (3.0.1) - rack (2.0.3) + rack (2.0.4) rack-accept (0.4.5) rack (>= 0.4) rack-jsonp (1.3.1) @@ -164,7 +164,7 @@ rspec-mocks (3.7.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.7.0) - rspec-support (3.7.0) + rspec-support (3.7.1) rubocop (0.51.0) parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) @@ -193,7 +193,7 @@ thor (0.19.4) thread_safe (0.3.6) tins (1.16.3) - tzinfo (1.2.4) + tzinfo (1.2.5) thread_safe (~> 0.1) unicode-display_width (1.3.0) virtus (1.0.5) @@ -211,7 +211,7 @@ bundler cookiejar coveralls (~> 0.8.17) - danger-toc (~> 0.1.0) + danger-toc (~> 0.1.2) grape! grape-entity (~> 0.6) guard @@ -228,4 +228,4 @@ ruby-grape-danger (~> 0.1.0) BUNDLED WITH - 1.16.0 + 1.15.3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2018-01-10 23:03:42.000000000 +0100 +++ new/README.md 2018-04-24 01:36:45.000000000 +0200 @@ -45,24 +45,31 @@ - [Group Options](#group-options) - [Alias](#alias) - [Built-in Validators](#built-in-validators) - - [`allow_blank`](#allowblank) + - [`allow_blank`](#allow_blank) - [`values`](#values) - - [`except_values`](#exceptvalues) + - [`except_values`](#except_values) - [`regexp`](#regexp) - - [`mutually_exclusive`](#mutuallyexclusive) - - [`exactly_one_of`](#exactlyoneof) - - [`at_least_one_of`](#atleastoneof) - - [`all_or_none_of`](#allornoneof) - - [Nested `mutually_exclusive`, `exactly_one_of`, `at_least_one_of`, `all_or_none_of`](#nested-mutuallyexclusive-exactlyoneof-atleastoneof-allornoneof) + - [`mutually_exclusive`](#mutually_exclusive) + - [`exactly_one_of`](#exactly_one_of) + - [`at_least_one_of`](#at_least_one_of) + - [`all_or_none_of`](#all_or_none_of) + - [Nested `mutually_exclusive`, `exactly_one_of`, `at_least_one_of`, `all_or_none_of`](#nested-mutually_exclusive-exactly_one_of-at_least_one_of-all_or_none_of) - [Namespace Validation and Coercion](#namespace-validation-and-coercion) - [Custom Validators](#custom-validators) - [Validation Errors](#validation-errors) - [I18n](#i18n) - [Custom Validation messages](#custom-validation-messages) - - [`presence`, `allow_blank`, `values`, `regexp`](#presence-allowblank-values-regexp) - - [`mutually_exclusive`](#mutuallyexclusive-1) + - [`presence`, `allow_blank`, `values`, `regexp`](#presence-allow_blank-values-regexp) + - [`all_or_none_of`](#all_or_none_of-1) + - [`mutually_exclusive`](#mutually_exclusive-1) + - [`exactly_one_of`](#exactly_one_of-1) + - [`at_least_one_of`](#at_least_one_of-1) + - [`Coerce`](#coerce) + - [`With Lambdas`](#with-lambdas) + - [`Pass symbols for i18n translations`](#pass-symbols-for-i18n-translations) - [Overriding Attribute Names](#overriding-attribute-names) - [With Default](#with-default) +- [Headers](#headers) - [Routes](#routes) - [Helpers](#helpers) - [Path Helpers](#path-helpers) @@ -78,6 +85,7 @@ - [Exception Handling](#exception-handling) - [Rescuing exceptions inside namespaces](#rescuing-exceptions-inside-namespaces) - [Unrescuable Exceptions](#unrescuable-exceptions) + - [Exceptions that should be rescued explicitly](#exceptions-that-should-be-rescued-explicitly) - [Rails 3.x](#rails-3x) - [Logging](#logging) - [API Formats](#api-formats) @@ -117,10 +125,10 @@ - [Reloading in Rails Applications](#reloading-in-rails-applications) - [Performance Monitoring](#performance-monitoring) - [Active Support Instrumentation](#active-support-instrumentation) - - [endpoint_run.grape](#endpointrungrape) - - [endpoint_render.grape](#endpointrendergrape) - - [endpoint_run_filters.grape](#endpointrunfiltersgrape) - - [endpoint_run_validators.grape](#endpointrunvalidatorsgrape) + - [endpoint_run.grape](#endpoint_rungrape) + - [endpoint_render.grape](#endpoint_rendergrape) + - [endpoint_run_filters.grape](#endpoint_run_filtersgrape) + - [endpoint_run_validators.grape](#endpoint_run_validatorsgrape) - [Monitoring Products](#monitoring-products) - [Contributing to Grape](#contributing-to-grape) - [License](#license) @@ -136,7 +144,7 @@ ## Stable Release -You're reading the documentation for the stable release of Grape, **1.0.2**. +You're reading the documentation for the stable release of Grape, **1.0.3**. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. ## Project Resources @@ -1548,6 +1556,7 @@ requires :name, values: { value: 1..10, message: 'not in range from 1 to 10' }, allow_blank: { value: false, message: 'cannot be blank' }, regexp: { value: /^[a-z]+$/, message: 'format is invalid' }, message: 'is required' end ``` + #### `all_or_none_of` ```ruby @@ -1569,6 +1578,7 @@ mutually_exclusive :beer, :wine, :juice, message: "are mutually exclusive cannot pass both params" end ``` + #### `exactly_one_of` ```ruby @@ -1579,6 +1589,7 @@ exactly_one_of :beer, :wine, :juice, message: {exactly_one: "are missing, exactly one parameter is required", mutual_exclusion: "are mutually exclusive, exactly one parameter is required"} end ``` + #### `at_least_one_of` ```ruby @@ -1589,6 +1600,7 @@ at_least_one_of :beer, :wine, :juice, message: "are missing, please specify at least one param" end ``` + #### `Coerce` ```ruby @@ -1596,6 +1608,7 @@ requires :int, type: {value: Integer, message: "type cast is invalid" } end ``` + #### `With Lambdas` ```ruby @@ -1603,6 +1616,7 @@ requires :name, values: { value: -> { (1..10).to_a }, message: 'not in range from 1 to 10' } end ``` + #### `Pass symbols for i18n translations` You can pass a symbol if you want i18n translations for your custom validation messages. @@ -1650,6 +1664,7 @@ requires :name, values: { value: -> { (1..10).to_a }, message: 'not in range from 1 to 10' }, default: 5 end ``` + ## Headers Request headers are available through the `headers` helper or from `env` in their original form. @@ -2078,6 +2093,9 @@ end ``` +This mimics [default `rescue` behaviour](https://ruby-doc.org/core/StandardError.html) when an exception type is not provided. +Any other exception should be rescued explicitly, see [below](#exceptions-that-should-be-rescued-explicitly). + Grape can also rescue from all exceptions and still use the built-in exception handing. This will give the same behavior as `rescue_from :all` with the addition that Grape will use the exception handling defined by all Exception classes that inherit `Grape::Exceptions::Base`. @@ -2280,6 +2298,12 @@ `Grape::Exceptions::InvalidVersionHeader`, which is raised when the version in the request header doesn't match the currently evaluated version for the endpoint, will _never_ be rescued from a `rescue_from` block (even a `rescue_from :all`) This is because Grape relies on Rack to catch that error and try the next versioned-route for cases where there exist identical Grape endpoints with different versions. +#### Exceptions that should be rescued explicitly + +Any exception that is not subclass of `StandardError` should be rescued explicitly. +Usually it is not a case for an application logic as such errors point to problems in Ruby runtime. +This is following [standard recommendations for exceptions handling](https://ruby-doc.org/core/Exception.html). + ### Rails 3.x When mounted inside containers, such as Rails 3.x, errors such as "404 Not Found" or Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape/dsl/inside_route.rb new/lib/grape/dsl/inside_route.rb --- old/lib/grape/dsl/inside_route.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape/dsl/inside_route.rb 2018-04-24 01:36:45.000000000 +0200 @@ -64,7 +64,7 @@ has_alias = route_setting(:aliased_params) && route_setting(:aliased_params).find { |current| current[declared_param] } param_alias = has_alias[declared_param] if has_alias - next unless options[:include_missing] || passed_params.key?(declared_param) || param_alias + next unless options[:include_missing] || passed_params.key?(declared_param) || (param_alias && passed_params.key?(param_alias)) if param_alias memo[optioned_param_key(param_alias, options)] = passed_params[param_alias] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape/dsl/parameters.rb new/lib/grape/dsl/parameters.rb --- old/lib/grape/dsl/parameters.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape/dsl/parameters.rb 2018-04-24 01:36:45.000000000 +0200 @@ -201,7 +201,7 @@ # @yield a parameter definition DSL def given(*attrs, &block) attrs.each do |attr| - proxy_attr = attr.is_a?(Hash) ? attr.keys[0] : attr + proxy_attr = first_hash_key_or_param(attr) raise Grape::Exceptions::UnknownParameter.new(proxy_attr) unless declared_param?(proxy_attr) end new_lateral_scope(dependent_on: attrs, &block) @@ -213,7 +213,9 @@ def declared_param?(param) # @declared_params also includes hashes of options and such, but those # won't be flattened out. - @declared_params.flatten.include?(param) + @declared_params.flatten.any? do |declared_param| + first_hash_key_or_param(declared_param) == param + end end alias group requires @@ -238,6 +240,12 @@ params = map_params(params, @element) if @element params end + + private + + def first_hash_key_or_param(parameter) + parameter.is_a?(Hash) ? parameter.keys.first : parameter + end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape/exceptions/base.rb new/lib/grape/exceptions/base.rb --- old/lib/grape/exceptions/base.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape/exceptions/base.rb 2018-04-24 01:36:45.000000000 +0200 @@ -71,6 +71,8 @@ end def translate(key, **options) + options = options.dup + options[:default] &&= options[:default].to_s message = ::I18n.translate(key, **options) message.present? ? message : ::I18n.translate(key, locale: FALLBACK_LOCALE, **options) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape/middleware/error.rb new/lib/grape/middleware/error.rb --- old/lib/grape/middleware/error.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape/middleware/error.rb 2018-04-24 01:36:45.000000000 +0200 @@ -36,47 +36,15 @@ error_response(catch(:error) do return @app.call(@env) end) - rescue StandardError => e - is_rescuable = rescuable?(e.class) - if e.is_a?(Grape::Exceptions::Base) && (!is_rescuable || rescuable_by_grape?(e.class)) - handler = ->(arg) { error_response(arg) } - else - raise unless is_rescuable - handler = find_handler(e.class) - end + rescue Exception => error # rubocop:disable Lint/RescueException + handler = + rescue_handler_for_base_only_class(error.class) || + rescue_handler_for_class_or_its_ancestor(error.class) || + rescue_handler_for_grape_exception(error.class) || + rescue_handler_for_any_class(error.class) || + raise - handler.nil? ? handle_error(e) : exec_handler(e, &handler) - end - end - - def find_handler(klass) - handler = options[:rescue_handlers].find(-> { [] }) { |error, _| klass <= error }[1] - handler ||= options[:base_only_rescue_handlers][klass] - handler ||= options[:all_rescue_handler] - - if handler.instance_of?(Symbol) - raise NoMethodError, "undefined method `#{handler}'" unless respond_to?(handler) - handler = self.class.instance_method(handler).bind(self) - end - - handler - end - - def rescuable?(klass) - return false if klass == Grape::Exceptions::InvalidVersionHeader - rescue_all? || rescue_class_or_its_ancestor?(klass) || rescue_with_base_only_handler?(klass) - end - - def rescuable_by_grape?(klass) - return false if klass == Grape::Exceptions::InvalidVersionHeader - options[:rescue_grape_exceptions] - end - - def exec_handler(e, &handler) - if handler.lambda? && handler.arity.zero? - instance_exec(&handler) - else - instance_exec(e, &handler) + run_rescue_handler(handler, error) end end @@ -85,7 +53,7 @@ rack_response(format_message(message, backtrace, original_exception), status, headers) end - def handle_error(e) + def default_rescue_handler(e) error_response(message: e.message, backtrace: e.backtrace, original_exception: e) end @@ -117,16 +85,45 @@ private - def rescue_all? - options[:rescue_all] + def rescue_handler_for_base_only_class(klass) + error, handler = options[:base_only_rescue_handlers].find { |err, _handler| klass == err } + + return unless error + + handler || :default_rescue_handler + end + + def rescue_handler_for_class_or_its_ancestor(klass) + error, handler = options[:rescue_handlers].find { |err, _handler| klass <= err } + + return unless error + + handler || :default_rescue_handler + end + + def rescue_handler_for_grape_exception(klass) + return unless klass <= Grape::Exceptions::Base + return :error_response if klass == Grape::Exceptions::InvalidVersionHeader + return unless options[:rescue_grape_exceptions] || !options[:rescue_all] + + :error_response end - def rescue_class_or_its_ancestor?(klass) - (options[:rescue_handlers] || []).any? { |error, _handler| klass <= error } + def rescue_handler_for_any_class(klass) + return unless klass <= StandardError + return unless options[:rescue_all] || options[:rescue_grape_exceptions] + + options[:all_rescue_handler] || :default_rescue_handler end - def rescue_with_base_only_handler?(klass) - (options[:base_only_rescue_handlers] || []).include?(klass) + def run_rescue_handler(handler, error) + if handler.instance_of?(Symbol) + raise NoMethodError, "undefined method `#{handler}'" unless respond_to?(handler) + + handler = public_method(handler) + end + + handler.arity.zero? ? instance_exec(&handler) : instance_exec(error, &handler) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape/validations/params_scope.rb new/lib/grape/validations/params_scope.rb --- old/lib/grape/validations/params_scope.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape/validations/params_scope.rb 2018-04-24 01:36:45.000000000 +0200 @@ -40,7 +40,7 @@ # validated def should_validate?(parameters) return false if @optional && (params(parameters).blank? || all_element_blank?(parameters)) - + return false unless meets_dependency?(params(parameters), parameters) return true if parent.nil? parent.should_validate?(parameters) end @@ -51,7 +51,7 @@ end return true unless @dependent_on - + return params.any? { |param| meets_dependency?(param, request_params) } if params.is_a?(Array) params = params.with_indifferent_access @dependent_on.each do |dependency| diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape/version.rb new/lib/grape/version.rb --- old/lib/grape/version.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape/version.rb 2018-04-24 01:36:45.000000000 +0200 @@ -1,4 +1,4 @@ module Grape # The current version of Grape. - VERSION = '1.0.2'.freeze + VERSION = '1.0.3'.freeze end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/grape.rb new/lib/grape.rb --- old/lib/grape.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/lib/grape.rb 2018-04-24 01:36:45.000000000 +0200 @@ -30,7 +30,6 @@ eager_autoload do autoload :API autoload :Endpoint - autoload :Router autoload :Namespace diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2018-01-10 23:03:42.000000000 +0100 +++ new/metadata 2018-04-24 01:36:45.000000000 +0200 @@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: grape version: !ruby/object:Gem::Version - version: 1.0.2 + version: 1.0.3 platform: ruby authors: - Michael Bleigh autorequire: bindir: bin cert_chain: [] -date: 2018-01-10 00:00:00.000000000 Z +date: 2018-04-23 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: activesupport @@ -250,8 +250,7 @@ - lib/grape/validations/validators/regexp.rb - lib/grape/validations/validators/values.rb - lib/grape/version.rb -- pkg/grape-0.19.1.gem -- pkg/grape-1.0.1.gem +- pkg/grape-1.0.0.gem - spec/grape/api/custom_validations_spec.rb - spec/grape/api/deeply_included_options_spec.rb - spec/grape/api/inherited_helpers_spec.rb @@ -264,6 +263,7 @@ - spec/grape/api/recognize_path_spec.rb - spec/grape/api/required_parameters_in_route_spec.rb - spec/grape/api/required_parameters_with_invalid_method_spec.rb +- spec/grape/api/shared_helpers_exactly_one_of_spec.rb - spec/grape/api/shared_helpers_spec.rb - spec/grape/api_spec.rb - spec/grape/dsl/callbacks_spec.rb @@ -368,104 +368,105 @@ version: '0' requirements: [] rubyforge_project: -rubygems_version: 2.7.3 +rubygems_version: 2.6.12 signing_key: specification_version: 4 summary: A simple Ruby framework for building REST-like APIs. test_files: -- spec/grape/api/custom_validations_spec.rb -- spec/grape/api/deeply_included_options_spec.rb -- spec/grape/api/inherited_helpers_spec.rb -- spec/grape/api/invalid_format_spec.rb -- spec/grape/api/namespace_parameters_in_route_spec.rb -- spec/grape/api/nested_helpers_spec.rb -- spec/grape/api/optional_parameters_in_route_spec.rb -- spec/grape/api/parameters_modification_spec.rb -- spec/grape/api/patch_method_helpers_spec.rb -- spec/grape/api/recognize_path_spec.rb -- spec/grape/api/required_parameters_in_route_spec.rb -- spec/grape/api/required_parameters_with_invalid_method_spec.rb -- spec/grape/api/shared_helpers_spec.rb -- spec/grape/api_spec.rb -- spec/grape/dsl/callbacks_spec.rb -- spec/grape/dsl/configuration_spec.rb -- spec/grape/dsl/desc_spec.rb -- spec/grape/dsl/headers_spec.rb -- spec/grape/dsl/helpers_spec.rb -- spec/grape/dsl/inside_route_spec.rb -- spec/grape/dsl/logger_spec.rb -- spec/grape/dsl/middleware_spec.rb -- spec/grape/dsl/parameters_spec.rb -- spec/grape/dsl/request_response_spec.rb -- spec/grape/dsl/routing_spec.rb -- spec/grape/dsl/settings_spec.rb -- spec/grape/dsl/validations_spec.rb -- spec/grape/endpoint_spec.rb -- spec/grape/entity_spec.rb -- spec/grape/exceptions/body_parse_errors_spec.rb -- spec/grape/exceptions/invalid_accept_header_spec.rb -- spec/grape/exceptions/invalid_formatter_spec.rb -- spec/grape/exceptions/invalid_versioner_option_spec.rb -- spec/grape/exceptions/missing_mime_type_spec.rb -- spec/grape/exceptions/missing_option_spec.rb -- spec/grape/exceptions/unknown_options_spec.rb -- spec/grape/exceptions/unknown_validator_spec.rb -- spec/grape/exceptions/validation_errors_spec.rb -- spec/grape/exceptions/validation_spec.rb -- spec/grape/extensions/param_builders/hash_spec.rb -- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb -- spec/grape/extensions/param_builders/hashie/mash_spec.rb -- spec/grape/integration/global_namespace_function_spec.rb -- spec/grape/integration/rack_sendfile_spec.rb -- spec/grape/integration/rack_spec.rb -- spec/grape/loading_spec.rb -- spec/grape/middleware/auth/base_spec.rb -- spec/grape/middleware/auth/dsl_spec.rb -- spec/grape/middleware/auth/strategies_spec.rb -- spec/grape/middleware/base_spec.rb +- spec/spec_helper.rb +- spec/integration/multi_xml/xml_spec.rb +- spec/integration/multi_json/json_spec.rb +- spec/shared/versioning_examples.rb +- spec/support/basic_auth_encode_helpers.rb +- spec/support/endpoint_faker.rb +- spec/support/file_streamer.rb +- spec/support/versioned_helpers.rb +- spec/support/content_type_helpers.rb +- spec/support/integer_helpers.rb - spec/grape/middleware/error_spec.rb -- spec/grape/middleware/exception_spec.rb -- spec/grape/middleware/formatter_spec.rb - spec/grape/middleware/globals_spec.rb +- spec/grape/middleware/formatter_spec.rb +- spec/grape/middleware/auth/strategies_spec.rb +- spec/grape/middleware/auth/dsl_spec.rb +- spec/grape/middleware/auth/base_spec.rb - spec/grape/middleware/stack_spec.rb +- spec/grape/middleware/exception_spec.rb +- spec/grape/middleware/versioner_spec.rb - spec/grape/middleware/versioner/accept_version_header_spec.rb - spec/grape/middleware/versioner/header_spec.rb -- spec/grape/middleware/versioner/param_spec.rb - spec/grape/middleware/versioner/path_spec.rb -- spec/grape/middleware/versioner_spec.rb -- spec/grape/parser_spec.rb -- spec/grape/path_spec.rb -- spec/grape/presenters/presenter_spec.rb -- spec/grape/request_spec.rb -- spec/grape/util/inheritable_setting_spec.rb -- spec/grape/util/inheritable_values_spec.rb +- spec/grape/middleware/versioner/param_spec.rb +- spec/grape/middleware/base_spec.rb +- spec/grape/loading_spec.rb +- spec/grape/endpoint_spec.rb +- spec/grape/api_spec.rb - spec/grape/util/reverse_stackable_values_spec.rb - spec/grape/util/stackable_values_spec.rb +- spec/grape/util/inheritable_setting_spec.rb - spec/grape/util/strict_hash_configuration_spec.rb +- spec/grape/util/inheritable_values_spec.rb +- spec/grape/integration/rack_spec.rb +- spec/grape/integration/rack_sendfile_spec.rb +- spec/grape/integration/global_namespace_function_spec.rb +- spec/grape/validations_spec.rb +- spec/grape/entity_spec.rb +- spec/grape/exceptions/validation_spec.rb +- spec/grape/exceptions/invalid_accept_header_spec.rb +- spec/grape/exceptions/missing_option_spec.rb +- spec/grape/exceptions/body_parse_errors_spec.rb +- spec/grape/exceptions/invalid_formatter_spec.rb +- spec/grape/exceptions/missing_mime_type_spec.rb +- spec/grape/exceptions/unknown_options_spec.rb +- spec/grape/exceptions/validation_errors_spec.rb +- spec/grape/exceptions/unknown_validator_spec.rb +- spec/grape/exceptions/invalid_versioner_option_spec.rb +- spec/grape/presenters/presenter_spec.rb - spec/grape/validations/attributes_iterator_spec.rb -- spec/grape/validations/instance_behaivour_spec.rb - spec/grape/validations/params_scope_spec.rb +- spec/grape/validations/instance_behaivour_spec.rb - spec/grape/validations/types_spec.rb -- spec/grape/validations/validators/all_or_none_spec.rb -- spec/grape/validations/validators/allow_blank_spec.rb -- spec/grape/validations/validators/at_least_one_of_spec.rb -- spec/grape/validations/validators/coerce_spec.rb -- spec/grape/validations/validators/default_spec.rb +- spec/grape/validations/validators/regexp_spec.rb +- spec/grape/validations/validators/mutual_exclusion_spec.rb - spec/grape/validations/validators/exactly_one_of_spec.rb - spec/grape/validations/validators/except_values_spec.rb -- spec/grape/validations/validators/mutual_exclusion_spec.rb - spec/grape/validations/validators/presence_spec.rb -- spec/grape/validations/validators/regexp_spec.rb +- spec/grape/validations/validators/all_or_none_spec.rb +- spec/grape/validations/validators/allow_blank_spec.rb +- spec/grape/validations/validators/default_spec.rb - spec/grape/validations/validators/values_spec.rb +- spec/grape/validations/validators/at_least_one_of_spec.rb +- spec/grape/validations/validators/coerce_spec.rb - spec/grape/validations/validators/zh-CN.yml -- spec/grape/validations_spec.rb -- spec/integration/multi_json/json_spec.rb -- spec/integration/multi_xml/xml_spec.rb -- spec/shared/versioning_examples.rb -- spec/spec_helper.rb -- spec/support/basic_auth_encode_helpers.rb -- spec/support/content_type_helpers.rb -- spec/support/endpoint_faker.rb -- spec/support/file_streamer.rb -- spec/support/integer_helpers.rb -- spec/support/versioned_helpers.rb +- spec/grape/extensions/param_builders/hashie/mash_spec.rb +- spec/grape/extensions/param_builders/hash_spec.rb +- spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +- spec/grape/parser_spec.rb +- spec/grape/request_spec.rb +- spec/grape/api/parameters_modification_spec.rb +- spec/grape/api/patch_method_helpers_spec.rb +- spec/grape/api/required_parameters_with_invalid_method_spec.rb +- spec/grape/api/nested_helpers_spec.rb +- spec/grape/api/invalid_format_spec.rb +- spec/grape/api/required_parameters_in_route_spec.rb +- spec/grape/api/namespace_parameters_in_route_spec.rb +- spec/grape/api/recognize_path_spec.rb +- spec/grape/api/shared_helpers_exactly_one_of_spec.rb +- spec/grape/api/inherited_helpers_spec.rb +- spec/grape/api/shared_helpers_spec.rb +- spec/grape/api/deeply_included_options_spec.rb +- spec/grape/api/custom_validations_spec.rb +- spec/grape/api/optional_parameters_in_route_spec.rb +- spec/grape/dsl/request_response_spec.rb +- spec/grape/dsl/desc_spec.rb +- spec/grape/dsl/logger_spec.rb +- spec/grape/dsl/configuration_spec.rb +- spec/grape/dsl/validations_spec.rb +- spec/grape/dsl/parameters_spec.rb +- spec/grape/dsl/helpers_spec.rb +- spec/grape/dsl/middleware_spec.rb +- spec/grape/dsl/headers_spec.rb +- spec/grape/dsl/callbacks_spec.rb +- spec/grape/dsl/settings_spec.rb +- spec/grape/dsl/routing_spec.rb +- spec/grape/dsl/inside_route_spec.rb +- spec/grape/path_spec.rb Binary files old/pkg/grape-0.19.1.gem and new/pkg/grape-0.19.1.gem differ Binary files old/pkg/grape-1.0.0.gem and new/pkg/grape-1.0.0.gem differ Binary files old/pkg/grape-1.0.1.gem and new/pkg/grape-1.0.1.gem differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/grape/api/shared_helpers_exactly_one_of_spec.rb new/spec/grape/api/shared_helpers_exactly_one_of_spec.rb --- old/spec/grape/api/shared_helpers_exactly_one_of_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/grape/api/shared_helpers_exactly_one_of_spec.rb 2018-04-24 01:36:45.000000000 +0200 @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Grape::API::Helpers do + subject do + shared_params = Module.new do + extend Grape::API::Helpers + + params :drink do + optional :beer + optional :wine + exactly_one_of :beer, :wine + end + end + + Class.new(Grape::API) do + helpers shared_params + format :json + + params do + requires :orderType, type: String, values: %w[food drink] + given orderType: ->(val) { val == 'food' } do + optional :pasta + optional :pizza + exactly_one_of :pasta, :pizza + end + given orderType: ->(val) { val == 'drink' } do + use :drink + end + end + get do + declared(params, include_missing: true) + end + end + end + + def app + subject + end + + it 'defines parameters' do + get '/', orderType: 'food', pizza: 'mista' + expect(last_response.status).to eq 200 + expect(last_response.body).to eq({ orderType: 'food', + pasta: nil, pizza: 'mista', + beer: nil, wine: nil }.to_json) + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/grape/api_spec.rb new/spec/grape/api_spec.rb --- old/spec/grape/api_spec.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/spec/grape/api_spec.rb 2018-04-24 01:36:45.000000000 +0200 @@ -1946,6 +1946,40 @@ end end + describe '.rescue_from :grape_exceptions' do + before do + subject.rescue_from :grape_exceptions + end + + let(:grape_exception) do + Grape::Exceptions::Base.new(status: 400, message: 'Grape Error') + end + + it 'rescues grape exceptions' do + exception = grape_exception + subject.get('/grape_exception') { raise exception } + + get '/grape_exception' + + expect(last_response.status).to eq(exception.status) + expect(last_response.body).to eq(exception.message) + end + + it 'rescues grape exceptions with a user-defined handler' do + subject.rescue_from grape_exception.class do |_error| + rack_response('Redefined Error', 403) + end + + exception = grape_exception + subject.get('/grape_exception') { raise exception } + + get '/grape_exception' + + expect(last_response.status).to eq(403) + expect(last_response.body).to eq('Redefined Error') + end + end + describe '.error_format' do it 'rescues all errors and return :txt' do subject.rescue_from :all diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/grape/endpoint_spec.rb new/spec/grape/endpoint_spec.rb --- old/spec/grape/endpoint_spec.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/spec/grape/endpoint_spec.rb 2018-04-24 01:36:45.000000000 +0200 @@ -464,7 +464,20 @@ it 'does not include missing attributes if that option is passed' do subject.get '/declared' do - error! 400, 'expected nil' if declared(params, include_missing: false)[:second] + error! 'expected nil', 400 if declared(params, include_missing: false).key?(:second) + '' + end + + get '/declared?first=one&other=two' + expect(last_response.status).to eq(200) + end + + it 'does not include aliased missing attributes if that option is passed' do + subject.params do + optional :aliased_original, as: :aliased + end + subject.get '/declared' do + error! 'expected nil', 400 if declared(params, include_missing: false).key?(:aliased) '' end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/grape/exceptions/validation_errors_spec.rb new/spec/grape/exceptions/validation_errors_spec.rb --- old/spec/grape/exceptions/validation_errors_spec.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/spec/grape/exceptions/validation_errors_spec.rb 2018-04-24 01:36:45.000000000 +0200 @@ -43,6 +43,15 @@ expect(subject).to contain_exactly('id is missing', 'name is missing') end end + + context 'when attributes is an array of symbols' do + let(:validation_error) { Grape::Exceptions::Validation.new(params: [:admin_field], message: 'Can not set admin-only field') } + subject { described_class.new(errors: [validation_error]).full_messages } + + it 'returns an array with an error full message' do + expect(subject.first).to eq('admin_field Can not set admin-only field') + end + end end context 'api' do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/grape/middleware/exception_spec.rb new/spec/grape/middleware/exception_spec.rb --- old/spec/grape/middleware/exception_spec.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/spec/grape/middleware/exception_spec.rb 2018-04-24 01:36:45.000000000 +0200 @@ -109,6 +109,36 @@ end end + context 'Non-StandardError exception with a provided rescue handler' do + context 'default error response' do + subject do + Rack::Builder.app do + use Spec::Support::EndpointFaker + use Grape::Middleware::Error, rescue_handlers: { NotImplementedError => nil } + run ExceptionSpec::OtherExceptionApp + end + end + it 'rescues the exception using the default handler' do + get '/' + expect(last_response.body).to eq('snow!') + end + end + + context 'custom error response' do + subject do + Rack::Builder.app do + use Spec::Support::EndpointFaker + use Grape::Middleware::Error, rescue_handlers: { NotImplementedError => -> { [200, {}, 'rescued'] } } + run ExceptionSpec::OtherExceptionApp + end + end + it 'rescues the exception using the provided handler' do + get '/' + expect(last_response.body).to eq('rescued') + end + end + end + context do subject do Rack::Builder.app do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/grape/validations/params_scope_spec.rb new/spec/grape/validations/params_scope_spec.rb --- old/spec/grape/validations/params_scope_spec.rb 2018-01-10 23:03:42.000000000 +0100 +++ new/spec/grape/validations/params_scope_spec.rb 2018-04-24 01:36:45.000000000 +0200 @@ -466,6 +466,19 @@ end.to raise_error(Grape::Exceptions::UnknownParameter) end + it 'does not raise an error if the dependent parameter is a Hash' do + expect do + subject.params do + optional :a, type: Hash do + requires :b + end + given :a do + requires :c + end + end + end.to_not raise_error + end + 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]
