annotate .svn/pristine/1a/1a021d35a6845d33a0f5158ab203eef12d7b8200.svn-base @ 1517:dffacf8a6908 redmine-2.5

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