annotate .svn/pristine/7d/7d347f5736383447d929cfa493b44727c73c536a.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../../../../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class Redmine::Views::Builders::XmlTest < ActiveSupport::TestCase
Chris@1295 21
Chris@1295 22 def test_hash
Chris@1295 23 assert_xml_output('<person><name>Ryan</name><age>32</age></person>') do |b|
Chris@1295 24 b.person do
Chris@1295 25 b.name 'Ryan'
Chris@1295 26 b.age 32
Chris@1295 27 end
Chris@1295 28 end
Chris@1295 29 end
Chris@1295 30
Chris@1295 31 def test_array
Chris@1295 32 assert_xml_output('<books type="array"><book title="Book 1"/><book title="Book 2"/></books>') do |b|
Chris@1295 33 b.array :books do |b|
Chris@1295 34 b.book :title => 'Book 1'
Chris@1295 35 b.book :title => 'Book 2'
Chris@1295 36 end
Chris@1295 37 end
Chris@1295 38 end
Chris@1295 39
Chris@1295 40 def test_array_with_content_tags
Chris@1295 41 assert_xml_output('<books type="array"><book author="B. Smith">Book 1</book><book author="G. Cooper">Book 2</book></books>') do |b|
Chris@1295 42 b.array :books do |b|
Chris@1295 43 b.book 'Book 1', :author => 'B. Smith'
Chris@1295 44 b.book 'Book 2', :author => 'G. Cooper'
Chris@1295 45 end
Chris@1295 46 end
Chris@1295 47 end
Chris@1295 48
Chris@1295 49 def test_nested_arrays
Chris@1295 50 assert_xml_output('<books type="array"><book><authors type="array"><author>B. Smith</author><author>G. Cooper</author></authors></book></books>') do |b|
Chris@1295 51 b.array :books do |books|
Chris@1295 52 books.book do |book|
Chris@1295 53 book.array :authors do |authors|
Chris@1295 54 authors.author 'B. Smith'
Chris@1295 55 authors.author 'G. Cooper'
Chris@1295 56 end
Chris@1295 57 end
Chris@1295 58 end
Chris@1295 59 end
Chris@1295 60 end
Chris@1295 61
Chris@1295 62 def assert_xml_output(expected, &block)
Chris@1295 63 builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.new, ActionDispatch::TestResponse.new)
Chris@1295 64 block.call(builder)
Chris@1295 65 assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output)
Chris@1295 66 end
Chris@1295 67 end