Skip to content

Commit

Permalink
Oj expects indent as a Fixnum.
Browse files Browse the repository at this point in the history
When using multi_json with Oj, and also the json lib happens to be laoded, there's a case the json lib sets indent as a String (see https://github.com/ruby/ruby/blob/v2_1_0/ext/json/lib/json/common.rb), making Oj crash with ArgumentError: :indent must be a Fixnum.
  • Loading branch information
oriolgual committed Apr 8, 2014
1 parent 3b62e64 commit b3db833
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/multi_json/adapters/oj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def load(string, options={})

def dump(object, options={})
options.merge!(:indent => 2) if options[:pretty]
options[:indent] = options[:indent].to_i if options[:indent]
::Oj.dump(object, options)
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/oj_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@

describe MultiJson::Adapters::Oj do
it_behaves_like 'an adapter', described_class

describe '.dump' do
describe '#dump_options' do
before{ MultiJson.use :oj }
before{ MultiJson.dump_options = MultiJson.adapter.dump_options = {} }
after{ MultiJson.dump_options = MultiJson.adapter.dump_options = {} }

it 'ensures indent is a Fixnum' do
expect { MultiJson.dump(42, :indent => '')}.not_to raise_error
end
end
end
end

0 comments on commit b3db833

Please sign in to comment.