Skip to content

Commit

Permalink
Make oj adapter ignore global symbol_keys setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Mar 22, 2013
1 parent 46ff924 commit 3695f81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/multi_json/adapters/oj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module MultiJson
module Adapters
# Use the Oj library to dump/load.
class Oj < Adapter
defaults :load, :mode => :strict
defaults :load, :mode => :strict, :symbolize_keys => false
defaults :dump, :mode => :compat, :time_format => :ruby

ParseError = if defined?(::Oj::ParseError)
Expand Down
17 changes: 8 additions & 9 deletions spec/multi_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,22 @@
end
end

context 'with Oj set to symbol_keys by default' do
before(:each) do
@oj_options = Oj.default_options
context 'with Oj.default_settings' do

around do |example|
options = Oj.default_options
Oj.default_options = { :symbol_keys => true }
MultiJson.with_engine(:oj){ example.call }
Oj.default_options = options
end

it "doesn't symbolize keys with :symbolize_keys => false" do
it 'ignores global settings' do
MultiJson.with_engine(:oj) do
example = '{"a": 1, "b": 2}'
expected = { 'a' => 1, 'b' => 2 }
expect(MultiJson.load(example, :symbolize_keys => false)).to eq expected
expect(MultiJson.load(example)).to eq expected
end
end

after(:each) do
Oj.default_options = @oj_options
end
end
end

Expand Down

2 comments on commit 3695f81

@sferik
Copy link
Member

@sferik sferik commented on 3695f81 Mar 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you make this change? It seems like Oj should respect the global settings, just like all the other adapters.

@rwz
Copy link
Member Author

@rwz rwz commented on 3695f81 Mar 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I have a feeling that MultiJson should not depend on any external states.

So if user uses Oj directly in some other part of the app, or if it's used internally in one of the gems, it should never change the behavior of MultiJson.

If user wants to use this option, he/she might set it in global MultiJson settings, or as a per-adapter setting.

Please sign in to comment.