From 88e593ee027b1fc1bdfa63b6ab76b0ae51ec6295 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 4 Dec 2010 11:20:20 +0000 Subject: [PATCH] Fixes unhandled case in json builder. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4464 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/views/builders/structure.rb | 4 ++-- test/unit/lib/redmine/views/builders/json_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/redmine/views/builders/structure.rb b/lib/redmine/views/builders/structure.rb index 9b948158..22d86470 100644 --- a/lib/redmine/views/builders/structure.rb +++ b/lib/redmine/views/builders/structure.rb @@ -36,7 +36,7 @@ module Redmine if args.any? if args.first.is_a?(Hash) if @struct.last.is_a?(Array) - @struct.last << args.first + @struct.last << args.first unless block else @struct.last[sym] = args.first end @@ -50,7 +50,7 @@ module Redmine end if block - @struct << {} + @struct << (args.first.is_a?(Hash) ? args.first : {}) block.call(self) ret = @struct.pop if @struct.last.is_a?(Array) diff --git a/test/unit/lib/redmine/views/builders/json_test.rb b/test/unit/lib/redmine/views/builders/json_test.rb index 919fe223..448965b9 100644 --- a/test/unit/lib/redmine/views/builders/json_test.rb +++ b/test/unit/lib/redmine/views/builders/json_test.rb @@ -51,6 +51,17 @@ class Redmine::Views::Builders::JsonTest < HelperTestCase b.book :title => 'Book 2', :author => 'G. Cooper' end end + + assert_json_output({'books' => [{'title' => 'Book 1', 'author' => 'B. Smith'}, {'title' => 'Book 2', 'author' => 'G. Cooper'}]}) do |b| + b.array :books do |b| + b.book :title => 'Book 1' do + b.author 'B. Smith' + end + b.book :title => 'Book 2' do + b.author 'G. Cooper' + end + end + end end def test_array_with_content_tags