diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2e4e47db2a..e0d6a1673b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,17 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-06-13 11:28:56 -0400 using RuboCop version 0.47.0. +# on 2017-06-13 12:09:49 -0400 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 # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -Lint/HandleExceptions: - Exclude: - - 'lib/grape/util/json.rb' - - 'lib/grape/util/xml.rb' - # Offense count: 45 Metrics/AbcSize: Max: 44 @@ -19,7 +13,7 @@ Metrics/AbcSize: # Offense count: 278 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: - Max: 3104 + Max: 3117 # Offense count: 8 # Configuration parameters: CountComments. @@ -30,7 +24,7 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 14 -# Offense count: 1102 +# Offense count: 1108 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: diff --git a/.travis.yml b/.travis.yml index 0e07c51d72..4e36118c9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,10 @@ matrix: gemfile: gemfiles/rails_5.gemfile - rvm: 2.4.1 gemfile: gemfiles/multi_json.gemfile + script: bundle exec rspec spec spec/integration/multi_json - rvm: 2.4.1 gemfile: gemfiles/multi_xml.gemfile + script: bundle exec rspec spec spec/integration/multi_xml - rvm: 2.3.4 gemfile: Gemfile - rvm: 2.3.4 diff --git a/README.md b/README.md index 70226be119..3ecf5a7c17 100644 --- a/README.md +++ b/README.md @@ -2567,7 +2567,7 @@ You can disable parsing for a content-type with `nil`. For example, `parser :jso ## JSON and XML Processors -Grape uses `JSON` and `ActiveSupport::XmlMini` for JSON and XML parsing by default. It also detects and supports [multi_json](https://github.com/intridea/multi_json) and [multi_xml](https://github.com/sferik/multi_xml). Adding those gems to your Gemfile will automatically enable them and allow you to swap the JSON and XML back-ends. +Grape uses `JSON` and `ActiveSupport::XmlMini` for JSON and XML parsing by default. It also detects and supports [multi_json](https://github.com/intridea/multi_json) and [multi_xml](https://github.com/sferik/multi_xml). Adding those gems to your Gemfile and requiring them will enable them and allow you to swap the JSON and XML back-ends. ## RESTful Model Representations diff --git a/Rakefile b/Rakefile index f4e330c030..1df4278400 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = 'spec/**/*_spec.rb' + spec.exclude_pattern = 'spec/integration/**/*_spec.rb' end RSpec::Core::RakeTask.new(:rcov) do |spec| diff --git a/UPGRADING.md b/UPGRADING.md index b2ade7a145..f18f0bd84f 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -7,7 +7,7 @@ Upgrading Grape Grape no longer uses `multi_json` or `multi_xml` by default and uses `JSON` and `ActiveSupport::XmlMini` instead. This has no visible impact on JSON processing, but the default behavior of the XML parser has changed. For example, an XML POST containing `Bobby T.` was parsed as `Bobby T.` with `multi_xml`, and as now parsed as `{"__content__"=>"Bobby T."}` with `XmlMini`. -To restore previous behavior, add `multi_json` or `multi_xml` to your `Gemfile`, Grape will auto-detect it. +To restore previous behavior, add `multi_json` or `multi_xml` to your `Gemfile` and `require` it. See [#1623](https://github.com/ruby-grape/grape/pull/1623) for more information. diff --git a/lib/grape/util/json.rb b/lib/grape/util/json.rb index a5686a342f..b0f5addb07 100644 --- a/lib/grape/util/json.rb +++ b/lib/grape/util/json.rb @@ -1,8 +1,3 @@ -begin - require 'multi_json' -rescue LoadError -end - module Grape if Object.const_defined? :MultiJson Json = ::MultiJson diff --git a/lib/grape/util/xml.rb b/lib/grape/util/xml.rb index 34b645a8e2..dd5d296e6b 100644 --- a/lib/grape/util/xml.rb +++ b/lib/grape/util/xml.rb @@ -1,8 +1,3 @@ -begin - require 'multi_xml' -rescue LoadError -end - module Grape if Object.const_defined? :MultiXml Xml = ::MultiXml diff --git a/spec/integration/multi_json/json_spec.rb b/spec/integration/multi_json/json_spec.rb new file mode 100644 index 0000000000..5724c8680a --- /dev/null +++ b/spec/integration/multi_json/json_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Grape::Json do + it 'uses multi_xml' do + expect(Grape::Json).to eq(::MiltiJson) + end +end diff --git a/spec/integration/multi_xml/xml_spec.rb b/spec/integration/multi_xml/xml_spec.rb new file mode 100644 index 0000000000..fce3c51ed8 --- /dev/null +++ b/spec/integration/multi_xml/xml_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Grape::Xml do + it 'uses multi_xml' do + expect(Grape::Xml).to eq(::MultiXml) + end +end