Permalink
Browse files

update MultiJson to 1.3

MultiJson 1.3 changes encode / decode to be load / dump ( intridea/multi_json@e90fd6c ). Lets sort that out :)
  • Loading branch information...
karlfreeman committed Apr 19, 2012
1 parent 19bb6a4 commit 2ffd03cfa95e80eef836f077e7bc16e8cbbcc0e2
Showing with 23 additions and 23 deletions.
  1. +1 −1 jsonify.gemspec
  2. +5 −5 lib/jsonify/builder.rb
  3. +1 −1 lib/jsonify/json_value.rb
  4. +14 −14 spec/builder_spec.rb
  5. +2 −2 spec/generate_spec.rb
View
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_runtime_dependency 'multi_json', '~>1.0'
+ s.add_runtime_dependency 'multi_json', '~>1.3'
s.add_development_dependency 'json' unless RUBY_VERSION =~ /^1.9/
s.add_development_dependency 'bundler'
View
@@ -57,16 +57,16 @@ def tag!(sym, args=nil, &block)
end
# Compiles the JSON objects into a string representation.
- # If initialized with +:verify => true+, the compiled result will be verified by attempting to re-parse it using +MultiJson.decode+.
- # If initialized with +:format => :pretty+, the compiled result will be parsed and encoded via +MultiJson.encode(<json>, :pretty => true)+
+ # If initialized with +:verify => true+, the compiled result will be verified by attempting to re-parse it using +MultiJson.load+.
+ # If initialized with +:format => :pretty+, the compiled result will be parsed and encoded via +MultiJson.dump(<json>, :pretty => true)+
# This method can be called without any side effects. You can call +compile!+ at any time, and multiple times if desired.
#
# @raise [TypeError] only if +:verify+ is set to true
# @raise [JSON::ParseError] only if +:verify+ is set to true
def compile!
result = (@stack[0] || {}).encode_as_json
- MultiJson.decode(result) if @verify
- result = MultiJson.encode(MultiJson.decode(result), :pretty => true) if @pretty
+ MultiJson.load(result) if @verify
+ result = MultiJson.dump(MultiJson.load(result), :pretty => true) if @pretty
result
end
@@ -187,7 +187,7 @@ def method_missing(sym, args=nil, &block)
# @param [String] json_string a full JSON string (e.g. from a rendered partial)
def ingest!(json_string)
return if json_string.empty?
- res = Jsonify::Generate.value(MultiJson.decode(json_string))
+ res = Jsonify::Generate.value(MultiJson.load(json_string))
current = @stack[@level]
if current.nil?
@stack[@level] = res
@@ -1,6 +1,6 @@
class Object
def encode_as_json
- MultiJson.encode self
+ MultiJson.dump self
end
end
View
@@ -108,7 +108,7 @@ def encode_as_json
end
it 'should support the store! message' do
json.store!( "foo", "bar" ).store!( 'no', "whar" )
- MultiJson.decode(json.compile!).should == MultiJson.decode('{"foo":"bar","no":"whar"}')
+ MultiJson.load(json.compile!).should == MultiJson.load('{"foo":"bar","no":"whar"}')
end
end
end
@@ -137,12 +137,12 @@ def encode_as_json
json.foo :bar
json.go :far
expected = '{"foo":"bar","go":"far"}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'should handle arrays' do
json[1] = [2, 3]
json[4] = 5
- MultiJson.decode(json.compile!).should == MultiJson.decode('{"1":[2,3],"4":5}')
+ MultiJson.load(json.compile!).should == MultiJson.load('{"1":[2,3],"4":5}')
end
end
@@ -155,7 +155,7 @@ def encode_as_json
end
end
expected = '{"foo foo":{"bar bar":{"buzz buzz":"goo goo"}}}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'complex hash' do
@@ -216,7 +216,7 @@ def encode_as_json
end
end
expected = "{\"foo\":{\"bar\":{\"baz\":\"goo\",\"years\":[2011,2012]}}}"
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
@@ -226,7 +226,7 @@ def encode_as_json
it 'should work' do
json.bar [1,2,{:foo => 'goo'}]
expected = "{\"bar\":[1,2,{\"foo\":\"goo\"}]}"
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
@@ -259,7 +259,7 @@ def encode_as_json
end
end
expected = "{\"result\":{\"person\":{\"fname\":\"George\",\"lname\":\"Burdell\"},\"links\":[{\"href\":\"example.com\",\"rel\":\"self\"},{\"href\":\"foo.com\",\"rel\":\"parent\"}]}}"
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
@@ -269,20 +269,20 @@ def encode_as_json
context 'into' do
it 'nothing -- should replace it' do
json.ingest! json_string
- MultiJson.decode(json.compile!).should == MultiJson.decode(json_string)
+ MultiJson.load(json.compile!).should == MultiJson.load(json_string)
end
it 'json object -- should merge' do
json["my boy"] = "Monday"
json["my girl"] = "Sunday"
json.ingest! json_string
expected = '{"my boy":"Monday","my girl":"Friday","my daughter":"Wednesday"}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'json array -- should add' do
json << 1 << 2
json.ingest! json_string
expected = '[1,2,{"my girl":"Friday","my daughter":"Wednesday"}]'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
end
@@ -291,7 +291,7 @@ def encode_as_json
context 'into' do
it 'nothing -- should replace it' do
json.ingest! json_string
- MultiJson.decode(json.compile!).should == MultiJson.decode(json_string)
+ MultiJson.load(json.compile!).should == MultiJson.load(json_string)
end
it 'json object -- should raise error' do
json["my boy"] = "Monday"
@@ -302,7 +302,7 @@ def encode_as_json
json << 1 << 2
json.ingest! json_string
expected = '[1,2,[1,2,3]]'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
end
@@ -323,14 +323,14 @@ def encode_as_json
end
expected = '{"results":[{"id":1,"children":[{"id":"a"},{"id":"b"}]},{"id":2,"children":[{"id":"c"},{"id":"d"}]}]}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
it 'simple append' do
json.letters('a'..'c') do |letter|
json << letter.upcase
end
expected = '{"letters":["A","B","C"]}'
- MultiJson.decode(json.compile!).should == MultiJson.decode(expected)
+ MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
end
View
@@ -13,7 +13,7 @@
json = Jsonify::Generate
result = json.value links
expected = '{"links":[{"rel":"foo","href":"goo"},{"rel":"bar","href":"baz"}]}'
- MultiJson.decode(result.encode_as_json).should == MultiJson.decode(expected)
+ MultiJson.load(result.encode_as_json).should == MultiJson.load(expected)
end
describe 'complex example' do
@@ -29,7 +29,7 @@
}
)
expected = "{\"links\":[{\"rel\":\"foo\",\"href\":\"goo\"},{\"rel\":\"bar\",\"href\":\"baz\"}]}"
- MultiJson.decode(json.encode_as_json).should == MultiJson.decode(expected)
+ MultiJson.load(json.encode_as_json).should == MultiJson.load(expected)
end
end
end

0 comments on commit 2ffd03c

Please sign in to comment.