annotate test/unit/helpers/issues_helper_test.rb @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@0 19
Chris@1115 20 class IssuesHelperTest < ActionView::TestCase
Chris@0 21 include ApplicationHelper
Chris@0 22 include IssuesHelper
Chris@1115 23 include CustomFieldsHelper
Chris@1115 24 include ERB::Util
Chris@0 25
Chris@909 26 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 27 :enumerations, :users, :issue_categories,
Chris@909 28 :projects_trackers,
Chris@909 29 :roles,
Chris@909 30 :member_roles,
Chris@909 31 :members,
Chris@909 32 :enabled_modules,
Chris@1115 33 :workflows,
Chris@1115 34 :custom_fields,
Chris@1115 35 :attachments,
Chris@1115 36 :versions
Chris@0 37
Chris@0 38 def setup
Chris@0 39 super
Chris@0 40 set_language_if_valid('en')
Chris@0 41 User.current = nil
Chris@0 42 end
Chris@0 43
Chris@441 44 def test_issue_heading
Chris@441 45 assert_equal "Bug #1", issue_heading(Issue.find(1))
Chris@441 46 end
Chris@441 47
Chris@441 48 def test_issues_destroy_confirmation_message_with_one_root_issue
Chris@441 49 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
Chris@441 50 end
Chris@441 51
Chris@441 52 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
Chris@441 53 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
Chris@441 54 end
Chris@441 55
Chris@441 56 def test_issues_destroy_confirmation_message_with_one_parent_issue
Chris@441 57 Issue.find(2).update_attribute :parent_issue_id, 1
Chris@441 58 assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
Chris@441 59 issues_destroy_confirmation_message(Issue.find(1))
Chris@441 60 end
Chris@441 61
Chris@441 62 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
Chris@441 63 Issue.find(2).update_attribute :parent_issue_id, 1
Chris@441 64 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
Chris@441 65 end
Chris@441 66
Chris@0 67 context "IssuesHelper#show_detail" do
Chris@0 68 context "with no_html" do
Chris@0 69 should 'show a changing attribute' do
Chris@1115 70 @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
Chris@0 71 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
Chris@0 72 end
Chris@0 73
Chris@0 74 should 'show a new attribute' do
Chris@1115 75 @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
Chris@0 76 assert_equal "% Done set to 100", show_detail(@detail, true)
Chris@0 77 end
Chris@0 78
Chris@0 79 should 'show a deleted attribute' do
Chris@1115 80 @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
Chris@0 81 assert_equal "% Done deleted (50)", show_detail(@detail, true)
Chris@0 82 end
Chris@0 83 end
Chris@0 84
Chris@0 85 context "with html" do
Chris@0 86 should 'show a changing attribute with HTML highlights' do
Chris@1115 87 @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
Chris@1115 88 html = show_detail(@detail, false)
Chris@0 89
Chris@1115 90 assert_include '<strong>% Done</strong>', html
Chris@1115 91 assert_include '<i>40</i>', html
Chris@1115 92 assert_include '<i>100</i>', html
Chris@0 93 end
Chris@0 94
Chris@0 95 should 'show a new attribute with HTML highlights' do
Chris@1115 96 @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
Chris@1115 97 html = show_detail(@detail, false)
Chris@0 98
Chris@1115 99 assert_include '<strong>% Done</strong>', html
Chris@1115 100 assert_include '<i>100</i>', html
Chris@0 101 end
Chris@0 102
Chris@0 103 should 'show a deleted attribute with HTML highlights' do
Chris@1115 104 @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
Chris@1115 105 html = show_detail(@detail, false)
Chris@0 106
Chris@1115 107 assert_include '<strong>% Done</strong>', html
Chris@1115 108 assert_include '<del><i>50</i></del>', html
Chris@0 109 end
Chris@0 110 end
Chris@0 111
Chris@0 112 context "with a start_date attribute" do
Chris@0 113 should "format the current date" do
Chris@1115 114 @detail = JournalDetail.new(
Chris@1115 115 :property => 'attr',
Chris@1115 116 :old_value => '2010-01-01',
Chris@1115 117 :value => '2010-01-31',
Chris@1115 118 :prop_key => 'start_date'
Chris@1115 119 )
Chris@1115 120 with_settings :date_format => '%m/%d/%Y' do
Chris@1115 121 assert_match "01/31/2010", show_detail(@detail, true)
Chris@1115 122 end
Chris@0 123 end
Chris@0 124
Chris@0 125 should "format the old date" do
Chris@1115 126 @detail = JournalDetail.new(
Chris@1115 127 :property => 'attr',
Chris@1115 128 :old_value => '2010-01-01',
Chris@1115 129 :value => '2010-01-31',
Chris@1115 130 :prop_key => 'start_date'
Chris@1115 131 )
Chris@1115 132 with_settings :date_format => '%m/%d/%Y' do
Chris@1115 133 assert_match "01/01/2010", show_detail(@detail, true)
Chris@1115 134 end
Chris@0 135 end
Chris@0 136 end
Chris@0 137
Chris@0 138 context "with a due_date attribute" do
Chris@0 139 should "format the current date" do
Chris@1115 140 @detail = JournalDetail.new(
Chris@1115 141 :property => 'attr',
Chris@1115 142 :old_value => '2010-01-01',
Chris@1115 143 :value => '2010-01-31',
Chris@1115 144 :prop_key => 'due_date'
Chris@1115 145 )
Chris@1115 146 with_settings :date_format => '%m/%d/%Y' do
Chris@1115 147 assert_match "01/31/2010", show_detail(@detail, true)
Chris@1115 148 end
Chris@0 149 end
Chris@0 150
Chris@0 151 should "format the old date" do
Chris@1115 152 @detail = JournalDetail.new(
Chris@1115 153 :property => 'attr',
Chris@1115 154 :old_value => '2010-01-01',
Chris@1115 155 :value => '2010-01-31',
Chris@1115 156 :prop_key => 'due_date'
Chris@1115 157 )
Chris@1115 158 with_settings :date_format => '%m/%d/%Y' do
Chris@1115 159 assert_match "01/01/2010", show_detail(@detail, true)
Chris@1115 160 end
Chris@0 161 end
Chris@0 162 end
Chris@0 163
Chris@1115 164 should "show old and new values with a project attribute" do
Chris@1115 165 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', :old_value => 1, :value => 2)
Chris@1115 166 assert_match 'eCookbook', show_detail(detail, true)
Chris@1115 167 assert_match 'OnlineStore', show_detail(detail, true)
Chris@0 168 end
Chris@0 169
Chris@1115 170 should "show old and new values with a issue status attribute" do
Chris@1115 171 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :old_value => 1, :value => 2)
Chris@1115 172 assert_match 'New', show_detail(detail, true)
Chris@1115 173 assert_match 'Assigned', show_detail(detail, true)
Chris@0 174 end
Chris@0 175
Chris@1115 176 should "show old and new values with a tracker attribute" do
Chris@1115 177 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', :old_value => 1, :value => 2)
Chris@1115 178 assert_match 'Bug', show_detail(detail, true)
Chris@1115 179 assert_match 'Feature request', show_detail(detail, true)
Chris@0 180 end
Chris@0 181
Chris@1115 182 should "show old and new values with a assigned to attribute" do
Chris@1115 183 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', :old_value => 1, :value => 2)
Chris@1115 184 assert_match 'redMine Admin', show_detail(detail, true)
Chris@1115 185 assert_match 'John Smith', show_detail(detail, true)
Chris@0 186 end
Chris@0 187
Chris@1115 188 should "show old and new values with a priority attribute" do
Chris@1115 189 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', :old_value => 4, :value => 5)
Chris@1115 190 assert_match 'Low', show_detail(detail, true)
Chris@1115 191 assert_match 'Normal', show_detail(detail, true)
Chris@0 192 end
Chris@0 193
Chris@1115 194 should "show old and new values with a category attribute" do
Chris@1115 195 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', :old_value => 1, :value => 2)
Chris@1115 196 assert_match 'Printing', show_detail(detail, true)
Chris@1115 197 assert_match 'Recipes', show_detail(detail, true)
Chris@0 198 end
Chris@0 199
Chris@1115 200 should "show old and new values with a fixed version attribute" do
Chris@1115 201 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', :old_value => 1, :value => 2)
Chris@1115 202 assert_match '0.1', show_detail(detail, true)
Chris@1115 203 assert_match '1.0', show_detail(detail, true)
Chris@0 204 end
Chris@0 205
Chris@1115 206 should "show old and new values with a estimated hours attribute" do
Chris@1115 207 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', :old_value => '5', :value => '6.3')
Chris@1115 208 assert_match '5.00', show_detail(detail, true)
Chris@1115 209 assert_match '6.30', show_detail(detail, true)
Chris@0 210 end
Chris@0 211
Chris@1115 212 should "show old and new values with a custom field" do
Chris@1115 213 detail = JournalDetail.new(:property => 'cf', :prop_key => '1', :old_value => 'MySQL', :value => 'PostgreSQL')
Chris@1115 214 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
Chris@1115 215 end
Chris@0 216
Chris@1115 217 should "show added file" do
Chris@1115 218 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', :old_value => nil, :value => 'error281.txt')
Chris@1115 219 assert_match 'error281.txt', show_detail(detail, true)
Chris@1115 220 end
Chris@1115 221
Chris@1115 222 should "show removed file" do
Chris@1115 223 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', :old_value => 'error281.txt', :value => nil)
Chris@1115 224 assert_match 'error281.txt', show_detail(detail, true)
Chris@1115 225 end
Chris@0 226 end
Chris@0 227 end