Skip to content

Commit

Permalink
Merge pull request #197 from eregon/fix-detection-json-gem
Browse files Browse the repository at this point in the history
Fix detection for the json_gem adapter
  • Loading branch information
rwz committed Jul 10, 2020
2 parents db64069 + 401362d commit 62d5401
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/multi_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def default_adapter
return :oj if defined?(::Oj)
return :yajl if defined?(::Yajl)
return :jr_jackson if defined?(::JrJackson)
return :json_gem if defined?(::JSON::JSON_LOADED)
return :json_gem if defined?(::JSON::Ext::Parser)
return :gson if defined?(::Gson)

REQUIREMENT_MAP.each do |adapter, library|
Expand Down
18 changes: 18 additions & 0 deletions spec/multi_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
end
end

context 'when JSON pure is already loaded' do
it 'default_adapter tries to require each adapter in turn and does not assume :json_gem is already loaded' do
require 'json/pure'
expect(JSON::JSON_LOADED).to be_truthy

undefine_constants :Oj, :Yajl, :Gson, :JrJackson do
# simulate that the json_gem is not loaded
ext = defined?(JSON::Ext::Parser) ? JSON::Ext.send(:remove_const, :Parser) : nil
begin
expect(MultiJson).to receive(:require)
MultiJson.default_adapter
ensure
JSON::Ext::Parser = ext if ext
end
end
end
end

context 'caching' do
before { MultiJson.use adapter }
let(:adapter) { MultiJson::Adapters::JsonGem }
Expand Down

0 comments on commit 62d5401

Please sign in to comment.