Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #58 from sriedel/ruby/cooperate_with_yajl

Be YAJL friendly
  • Loading branch information...
commit 88f4c44b1349a647475e960c6d036590b52a1575 2 parents 049ade7 + 3ada3c7
@SamSaffron authored
View
2  Ruby/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- rack-mini-profiler (0.1.8)
+ rack-mini-profiler (0.1.9)
rack (>= 1.1.3)
GEM
View
7 Ruby/lib/mini_profiler/timer_struct.rb
@@ -22,7 +22,12 @@ def []=(name, val)
end
def to_json(*a)
- ::JSON.generate(@attributes, a[0])
+ if a[0] == nil
+ # YAJL doesnt like nil as options
+ ::JSON.generate( @attributes )
+ else
+ ::JSON.generate(@attributes, a[0])
+ end
end
end
View
14 Ruby/spec/components/timer_struct_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
require 'mini_profiler/timer_struct'
+require 'json'
+
describe Rack::MiniProfiler::TimerStruct do
before do
@@ -27,6 +29,16 @@
@json.should_not be_nil
end
+ it 'should not add a second (nil) argument if no arguments were passed' do
+ ::JSON.should_receive( :generate ).once.with( @timer.attributes ).and_return( nil )
+ @timer.to_json
+ end
+
+ it 'should pass given arguments' do
+ ::JSON.should_receive( :generate ).once.with( @timer.attributes, :foo => true ).and_return( nil )
+ @timer.to_json( :foo => true )
+ end
+
describe 'deserialized' do
before do
@@ -44,4 +56,4 @@
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.