Skip to content

Commit

Permalink
Added integration specs for multi_json and multi_xml, don't attempt t…
Browse files Browse the repository at this point in the history
…o require them.
  • Loading branch information
dblock committed Jun 13, 2017
1 parent 094b19a commit 3cb8e74
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
12 changes: 3 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# 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

# Offense count: 278
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 3104
Max: 3117

# Offense count: 8
# Configuration parameters: CountComments.
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 3 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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 `<user>Bobby T.</user>` 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.
If you were using `MultiJson.load`, `MultiJson.dump` or `MultiXml.parse`, you can substitute those with `Grape::Json.load`, `Grape::Json.dump`, `::Grape::Xml.parse`, or directly with `JSON.load`, `JSON.dump`, `XmlMini.parse`, etc.

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.

Expand Down
5 changes: 0 additions & 5 deletions lib/grape/util/json.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
begin
require 'multi_json'
rescue LoadError
end

module Grape
if Object.const_defined? :MultiJson
Json = ::MultiJson
Expand Down
5 changes: 0 additions & 5 deletions lib/grape/util/xml.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
begin
require 'multi_xml'
rescue LoadError
end

module Grape
if Object.const_defined? :MultiXml
Xml = ::MultiXml
Expand Down
7 changes: 7 additions & 0 deletions spec/integration/multi_json/json_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe Grape::Json do
it 'uses multi_json' do
expect(Grape::Json).to eq(::MiltiJson)
end
end
7 changes: 7 additions & 0 deletions spec/integration/multi_xml/xml_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe Grape::Xml do
it 'uses multi_xml' do
expect(Grape::Xml).to eq(::MultiXml)
end
end

0 comments on commit 3cb8e74

Please sign in to comment.