File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,7 +87,9 @@ def adapter
8787 # * <tt>:gson</tt> (JRuby only)
8888 # * <tt>:jr_jackson</tt> (JRuby only)
8989 def use ( new_adapter )
90- @adapter = load_adapter ( new_adapter )
90+ adapter = load_adapter ( new_adapter )
91+ adapter . activate! if adapter . respond_to? ( :activate! )
92+ @adapter = adapter
9193 end
9294 alias adapter = use
9395 alias engine = use
Original file line number Diff line number Diff line change @@ -5,6 +5,16 @@ module Adapters
55 class JsonCommon < Adapter
66 defaults :load , :create_additions => false , :quirks_mode => true
77
8+ GEM_VERSION = '1.7.7'
9+
10+ def self . activate!
11+ if JSON ::VERSION < GEM_VERSION
12+ Kernel . warn "You are using an old or stdlib version of #{ gem_name } gem\n " +
13+ "Please upgrade to the recent version by adding this to your Gemfile:\n \n " +
14+ " gem '#{ gem_name } ', '~> #{ GEM_VERSION } '\n "
15+ end
16+ end
17+
818 def load ( string , options = { } )
919 string = string . read if string . respond_to? ( :read )
1020
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ module Adapters
66 # Use the JSON gem to dump/load.
77 class JsonGem < JsonCommon
88 ParseError = ::JSON ::ParserError
9+
10+ def self . gem_name
11+ 'json'
12+ end
913 end
1014 end
1115end
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ module Adapters
66 # Use JSON pure to dump/load.
77 class JsonPure < JsonCommon
88 ParseError = ::JSON ::ParserError
9+
10+ def self . gem_name
11+ 'json_pure'
12+ end
913 end
1014 end
1115end
Original file line number Diff line number Diff line change 5050 end
5151 end
5252
53+ context 'with stdlib version' do
54+ around do |example |
55+ version = JSON ::VERSION
56+ silence_warnings { JSON ::VERSION = '1.5.5' }
57+ example . call
58+ silence_warnings { JSON ::VERSION = version }
59+ end
60+
61+ it 'should warn about json' do
62+ Kernel . should_receive ( :warn ) . with ( /'json', '~> 1.7.7'/ )
63+ MultiJson . use :json_gem
64+ end
65+
66+ it 'should warb about json/pure' do
67+ Kernel . should_receive ( :warn ) . with ( /'json_pure', '~> 1.7.7'/ )
68+ MultiJson . use :json_pure
69+ end
70+ end
71+
5372 it 'defaults to the best available gem' do
5473 # Clear cache variable already set by previous tests
5574 MultiJson . send ( :remove_instance_variable , :@adapter )
You can’t perform that action at this time.
0 commit comments