annotate test/unit/helpers/issues_helper_test.rb @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 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@1464 21 include Redmine::I18n
Chris@0 22 include IssuesHelper
Chris@1115 23 include CustomFieldsHelper
Chris@1115 24 include ERB::Util
Chris@1517 25 include Rails.application.routes.url_helpers
Chris@0 26
Chris@909 27 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 28 :enumerations, :users, :issue_categories,
Chris@909 29 :projects_trackers,
Chris@909 30 :roles,
Chris@909 31 :member_roles,
Chris@909 32 :members,
Chris@909 33 :enabled_modules,
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@1464 49 assert_equal l(:text_issues_destroy_confirmation),
Chris@1464 50 issues_destroy_confirmation_message(Issue.find(1))
Chris@441 51 end
Chris@441 52
Chris@441 53 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
Chris@1464 54 assert_equal l(:text_issues_destroy_confirmation),
Chris@1464 55 issues_destroy_confirmation_message(Issue.find([1, 2]))
Chris@441 56 end
Chris@441 57
Chris@441 58 def test_issues_destroy_confirmation_message_with_one_parent_issue
Chris@441 59 Issue.find(2).update_attribute :parent_issue_id, 1
Chris@1464 60 assert_equal l(:text_issues_destroy_confirmation) + "\n" +
Chris@1464 61 l(:text_issues_destroy_descendants_confirmation, :count => 1),
Chris@1464 62 issues_destroy_confirmation_message(Issue.find(1))
Chris@441 63 end
Chris@441 64
Chris@441 65 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
Chris@441 66 Issue.find(2).update_attribute :parent_issue_id, 1
Chris@1464 67 assert_equal l(:text_issues_destroy_confirmation),
Chris@1464 68 issues_destroy_confirmation_message(Issue.find([1, 2]))
Chris@441 69 end
Chris@441 70
Chris@1464 71 test 'show_detail with no_html should show a changing attribute' do
Chris@1464 72 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
Chris@1464 73 :value => '100', :prop_key => 'done_ratio')
Chris@1464 74 assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
Chris@1464 75 end
Chris@0 76
Chris@1464 77 test 'show_detail with no_html should show a new attribute' do
Chris@1464 78 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
Chris@1464 79 :value => '100', :prop_key => 'done_ratio')
Chris@1464 80 assert_equal "% Done set to 100", show_detail(detail, true)
Chris@1464 81 end
Chris@0 82
Chris@1464 83 test 'show_detail with no_html should show a deleted attribute' do
Chris@1464 84 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
Chris@1464 85 :value => nil, :prop_key => 'done_ratio')
Chris@1464 86 assert_equal "% Done deleted (50)", show_detail(detail, true)
Chris@1464 87 end
Chris@0 88
Chris@1464 89 test 'show_detail with html should show a changing attribute with HTML highlights' do
Chris@1464 90 detail = JournalDetail.new(:property => 'attr', :old_value => '40',
Chris@1464 91 :value => '100', :prop_key => 'done_ratio')
Chris@1464 92 html = show_detail(detail, false)
Chris@1464 93 assert_include '<strong>% Done</strong>', html
Chris@1464 94 assert_include '<i>40</i>', html
Chris@1464 95 assert_include '<i>100</i>', html
Chris@1464 96 end
Chris@0 97
Chris@1464 98 test 'show_detail with html should show a new attribute with HTML highlights' do
Chris@1464 99 detail = JournalDetail.new(:property => 'attr', :old_value => nil,
Chris@1464 100 :value => '100', :prop_key => 'done_ratio')
Chris@1464 101 html = show_detail(detail, false)
Chris@1464 102 assert_include '<strong>% Done</strong>', html
Chris@1464 103 assert_include '<i>100</i>', html
Chris@1464 104 end
Chris@0 105
Chris@1464 106 test 'show_detail with html should show a deleted attribute with HTML highlights' do
Chris@1464 107 detail = JournalDetail.new(:property => 'attr', :old_value => '50',
Chris@1464 108 :value => nil, :prop_key => 'done_ratio')
Chris@1464 109 html = show_detail(detail, false)
Chris@1464 110 assert_include '<strong>% Done</strong>', html
Chris@1464 111 assert_include '<del><i>50</i></del>', html
Chris@1464 112 end
Chris@0 113
Chris@1464 114 test 'show_detail with a start_date attribute should format the dates' do
Chris@1464 115 detail = JournalDetail.new(
Chris@1464 116 :property => 'attr',
Chris@1464 117 :old_value => '2010-01-01',
Chris@1464 118 :value => '2010-01-31',
Chris@1464 119 :prop_key => 'start_date'
Chris@1464 120 )
Chris@1464 121 with_settings :date_format => '%m/%d/%Y' do
Chris@1464 122 assert_match "01/31/2010", show_detail(detail, true)
Chris@1464 123 assert_match "01/01/2010", show_detail(detail, true)
Chris@1115 124 end
Chris@0 125 end
Chris@1464 126
Chris@1464 127 test 'show_detail with a due_date attribute should format the dates' do
Chris@1464 128 detail = JournalDetail.new(
Chris@1464 129 :property => 'attr',
Chris@1464 130 :old_value => '2010-01-01',
Chris@1464 131 :value => '2010-01-31',
Chris@1464 132 :prop_key => 'due_date'
Chris@1464 133 )
Chris@1464 134 with_settings :date_format => '%m/%d/%Y' do
Chris@1464 135 assert_match "01/31/2010", show_detail(detail, true)
Chris@1464 136 assert_match "01/01/2010", show_detail(detail, true)
Chris@1464 137 end
Chris@1464 138 end
Chris@1464 139
Chris@1464 140 test 'show_detail should show old and new values with a project attribute' do
Chris@1464 141 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
Chris@1464 142 :old_value => 1, :value => 2)
Chris@1464 143 assert_match 'eCookbook', show_detail(detail, true)
Chris@1464 144 assert_match 'OnlineStore', show_detail(detail, true)
Chris@1464 145 end
Chris@1464 146
Chris@1464 147 test 'show_detail should show old and new values with a issue status attribute' do
Chris@1464 148 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
Chris@1464 149 :old_value => 1, :value => 2)
Chris@1464 150 assert_match 'New', show_detail(detail, true)
Chris@1464 151 assert_match 'Assigned', show_detail(detail, true)
Chris@1464 152 end
Chris@1464 153
Chris@1464 154 test 'show_detail should show old and new values with a tracker attribute' do
Chris@1464 155 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
Chris@1464 156 :old_value => 1, :value => 2)
Chris@1464 157 assert_match 'Bug', show_detail(detail, true)
Chris@1464 158 assert_match 'Feature request', show_detail(detail, true)
Chris@1464 159 end
Chris@1464 160
Chris@1464 161 test 'show_detail should show old and new values with a assigned to attribute' do
Chris@1464 162 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
Chris@1464 163 :old_value => 1, :value => 2)
Chris@1464 164 assert_match 'Redmine Admin', show_detail(detail, true)
Chris@1464 165 assert_match 'John Smith', show_detail(detail, true)
Chris@1464 166 end
Chris@1464 167
Chris@1464 168 test 'show_detail should show old and new values with a priority attribute' do
Chris@1464 169 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
Chris@1464 170 :old_value => 4, :value => 5)
Chris@1464 171 assert_match 'Low', show_detail(detail, true)
Chris@1464 172 assert_match 'Normal', show_detail(detail, true)
Chris@1464 173 end
Chris@1464 174
Chris@1464 175 test 'show_detail should show old and new values with a category attribute' do
Chris@1464 176 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
Chris@1464 177 :old_value => 1, :value => 2)
Chris@1464 178 assert_match 'Printing', show_detail(detail, true)
Chris@1464 179 assert_match 'Recipes', show_detail(detail, true)
Chris@1464 180 end
Chris@1464 181
Chris@1464 182 test 'show_detail should show old and new values with a fixed version attribute' do
Chris@1464 183 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
Chris@1464 184 :old_value => 1, :value => 2)
Chris@1464 185 assert_match '0.1', show_detail(detail, true)
Chris@1464 186 assert_match '1.0', show_detail(detail, true)
Chris@1464 187 end
Chris@1464 188
Chris@1464 189 test 'show_detail should show old and new values with a estimated hours attribute' do
Chris@1464 190 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
Chris@1464 191 :old_value => '5', :value => '6.3')
Chris@1464 192 assert_match '5.00', show_detail(detail, true)
Chris@1464 193 assert_match '6.30', show_detail(detail, true)
Chris@1464 194 end
Chris@1464 195
Chris@1464 196 test 'show_detail should show old and new values with a custom field' do
Chris@1464 197 detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
Chris@1464 198 :old_value => 'MySQL', :value => 'PostgreSQL')
Chris@1464 199 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
Chris@1464 200 end
Chris@1464 201
Chris@1464 202 test 'show_detail should show added file' do
Chris@1464 203 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
Chris@1464 204 :old_value => nil, :value => 'error281.txt')
Chris@1464 205 assert_match 'error281.txt', show_detail(detail, true)
Chris@1464 206 end
Chris@1464 207
Chris@1464 208 test 'show_detail should show removed file' do
Chris@1464 209 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
Chris@1464 210 :old_value => 'error281.txt', :value => nil)
Chris@1464 211 assert_match 'error281.txt', show_detail(detail, true)
Chris@1464 212 end
Chris@1464 213
Chris@1464 214 def test_show_detail_relation_added
Chris@1464 215 detail = JournalDetail.new(:property => 'relation',
Chris@1517 216 :prop_key => 'precedes',
Chris@1464 217 :value => 1)
Chris@1464 218 assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true)
Chris@1517 219 str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes)
Chris@1517 220 assert_equal "<strong>Precedes</strong> <i>#{str}: #{ESCAPED_UCANT} print recipes</i> added",
Chris@1517 221 show_detail(detail, false)
Chris@1464 222 end
Chris@1464 223
Chris@1464 224 def test_show_detail_relation_added_with_inexistant_issue
Chris@1464 225 inexistant_issue_number = 9999
Chris@1464 226 assert_nil Issue.find_by_id(inexistant_issue_number)
Chris@1464 227 detail = JournalDetail.new(:property => 'relation',
Chris@1517 228 :prop_key => 'precedes',
Chris@1464 229 :value => inexistant_issue_number)
Chris@1464 230 assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
Chris@1464 231 assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
Chris@1464 232 end
Chris@1464 233
Chris@1464 234 def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
Chris@1464 235 issue = Issue.generate!(:is_private => true)
Chris@1464 236 detail = JournalDetail.new(:property => 'relation',
Chris@1517 237 :prop_key => 'precedes',
Chris@1464 238 :value => issue.id)
Chris@1464 239
Chris@1464 240 assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
Chris@1464 241 assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
Chris@1464 242 end
Chris@1464 243
Chris@1464 244 def test_show_detail_relation_deleted
Chris@1464 245 detail = JournalDetail.new(:property => 'relation',
Chris@1517 246 :prop_key => 'precedes',
Chris@1464 247 :old_value => 1)
Chris@1464 248 assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true)
Chris@1517 249 str = link_to("Bug #1",
Chris@1517 250 "/issues/1",
Chris@1517 251 :class => Issue.find(1).css_classes)
Chris@1517 252 assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: #{ESCAPED_UCANT} print recipes</i>)",
Chris@1464 253 show_detail(detail, false)
Chris@1464 254 end
Chris@1464 255
Chris@1464 256 def test_show_detail_relation_deleted_with_inexistant_issue
Chris@1464 257 inexistant_issue_number = 9999
Chris@1464 258 assert_nil Issue.find_by_id(inexistant_issue_number)
Chris@1464 259 detail = JournalDetail.new(:property => 'relation',
Chris@1517 260 :prop_key => 'precedes',
Chris@1464 261 :old_value => inexistant_issue_number)
Chris@1464 262 assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
Chris@1464 263 assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
Chris@1464 264 end
Chris@1464 265
Chris@1464 266 def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
Chris@1464 267 issue = Issue.generate!(:is_private => true)
Chris@1464 268 detail = JournalDetail.new(:property => 'relation',
Chris@1517 269 :prop_key => 'precedes',
Chris@1464 270 :old_value => issue.id)
Chris@1464 271
Chris@1464 272 assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
Chris@1464 273 assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
Chris@1464 274 end
Chris@0 275 end