Skip to content

Commit ce42782

Browse files
committed
Added integration specs for multi_json and multi_xml, don't attempt to require them.
1 parent 094b19a commit ce42782

File tree

12 files changed

+32
-25
lines changed

12 files changed

+32
-25
lines changed

.rubocop_todo.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2017-06-13 11:28:56 -0400 using RuboCop version 0.47.0.
3+
# on 2017-06-13 12:09:49 -0400 using RuboCop version 0.47.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 2
10-
Lint/HandleExceptions:
11-
Exclude:
12-
- 'lib/grape/util/json.rb'
13-
- 'lib/grape/util/xml.rb'
14-
159
# Offense count: 45
1610
Metrics/AbcSize:
1711
Max: 44
1812

1913
# Offense count: 278
2014
# Configuration parameters: CountComments, ExcludedMethods.
2115
Metrics/BlockLength:
22-
Max: 3104
16+
Max: 3117
2317

2418
# Offense count: 8
2519
# Configuration parameters: CountComments.
@@ -30,7 +24,7 @@ Metrics/ClassLength:
3024
Metrics/CyclomaticComplexity:
3125
Max: 14
3226

33-
# Offense count: 1102
27+
# Offense count: 1108
3428
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
3529
# URISchemes: http, https
3630
Metrics/LineLength:

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ matrix:
1919
gemfile: gemfiles/rails_5.gemfile
2020
- rvm: 2.4.1
2121
gemfile: gemfiles/multi_json.gemfile
22+
script:
23+
- bundle exec rake
24+
- bundle exec rspec spec/integration/multi_json
2225
- rvm: 2.4.1
2326
gemfile: gemfiles/multi_xml.gemfile
27+
script:
28+
- bundle exec rake
29+
- bundle exec rspec spec/integration/multi_xml
2430
- rvm: 2.3.4
2531
gemfile: Gemfile
2632
- rvm: 2.3.4

Appraisals

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ appraise 'rack-edge' do
2424
end
2525

2626
appraise 'multi_json' do
27-
gem 'multi_json'
27+
gem 'multi_json', require: 'multi_json'
2828
end
2929

3030
appraise 'multi_xml' do
31-
gem 'multi_xml'
31+
gem 'multi_xml', require: 'multi_xml'
3232
end

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ You can disable parsing for a content-type with `nil`. For example, `parser :jso
25672567

25682568
## JSON and XML Processors
25692569

2570-
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.
2570+
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.
25712571

25722572
## RESTful Model Representations
25732573

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Bundler::GemHelper.install_tasks
77
require 'rspec/core/rake_task'
88
RSpec::Core::RakeTask.new(:spec) do |spec|
99
spec.pattern = 'spec/**/*_spec.rb'
10+
spec.exclude_pattern = 'spec/integration/**/*_spec.rb'
1011
end
1112

1213
RSpec::Core::RakeTask.new(:rcov) do |spec|

UPGRADING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Upgrading Grape
77

88
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`.
99

10-
To restore previous behavior, add `multi_json` or `multi_xml` to your `Gemfile`, Grape will auto-detect it.
10+
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.
11+
12+
To restore previous behavior, add `multi_json` or `multi_xml` to your `Gemfile` and `require` it.
1113

1214
See [#1623](https://github.com/ruby-grape/grape/pull/1623) for more information.
1315

gemfiles/multi_json.gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
gem 'multi_json'
5+
gem 'multi_json', require: 'multi_json'
66

77
group :development, :test do
88
gem 'bundler'

gemfiles/multi_xml.gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
gem 'multi_xml'
5+
gem 'multi_xml', require: 'multi_xml'
66

77
group :development, :test do
88
gem 'bundler'

lib/grape/util/json.rb

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
begin
2-
require 'multi_json'
3-
rescue LoadError
4-
end
5-
61
module Grape
72
if Object.const_defined? :MultiJson
83
Json = ::MultiJson

lib/grape/util/xml.rb

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
begin
2-
require 'multi_xml'
3-
rescue LoadError
4-
end
5-
61
module Grape
72
if Object.const_defined? :MultiXml
83
Xml = ::MultiXml
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper'
2+
3+
describe Grape::Json do
4+
it 'uses multi_json' do
5+
expect(Grape::Json).to eq(::MultiJson)
6+
end
7+
end
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper'
2+
3+
describe Grape::Xml do
4+
it 'uses multi_xml' do
5+
expect(Grape::Xml).to eq(::MultiXml)
6+
end
7+
end

0 commit comments

Comments
 (0)