spec/builder_spec.rb in jsonify-0.4.0 vs spec/builder_spec.rb in jsonify-0.4.1
- old
+ new
@@ -143,11 +143,19 @@
json[1] = [2, 3]
json[4] = 5
MultiJson.load(json.compile!).should == MultiJson.load('{"1":[2,3],"4":5}')
end
end
-
+
+ describe "attributes!" do
+ it "should allow create object with attributes of another object" do
+ object = stub(:id => 1, :name => 'foo')
+ json.attributes!(object, :id, :name)
+ MultiJson.load(json.compile!).should == {'id' => 1, 'name' => 'foo'}
+ end
+ end
+
describe 'using blocks' do
it 'should allow names with spaces using tag!' do
json.tag!("foo foo") do
json.tag!("bar bar") do
@@ -330,8 +338,23 @@
json << letter.upcase
end
expected = '{"letters":["A","B","C"]}'
MultiJson.load(json.compile!).should == MultiJson.load(expected)
end
-
+
+ end
+
+ describe 'array!' do
+ it 'allow creating array from root' do
+ json.array!([1, 2, 3]) do |number|
+ json.id number
+ json.times2 number * 2
+ end
+
+ MultiJson.load(json.compile!).should == [
+ {'id' => 1, 'times2' => 2},
+ {'id' => 2, 'times2' => 4},
+ {'id' => 3, 'times2' => 6},
+ ]
+ end
end
end