issues_helper_test.rb
285 lines
| 12.4 KiB
| text/x-ruby
|
RubyLexer
|
r3438 | # Redmine - project management software | ||
|
r13490 | # Copyright (C) 2006-2015 Jean-Philippe Lang | ||
|
r3438 | # | ||
# This program is free software; you can redistribute it and/or | ||||
# modify it under the terms of the GNU General Public License | ||||
# as published by the Free Software Foundation; either version 2 | ||||
# of the License, or (at your option) any later version. | ||||
|
r5684 | # | ||
|
r3438 | # This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
|
r5684 | # | ||
|
r3438 | # You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
|
r4395 | require File.expand_path('../../../test_helper', __FILE__) | ||
|
r3438 | |||
|
r8157 | class IssuesHelperTest < ActionView::TestCase | ||
|
r11645 | include Redmine::I18n | ||
|
r3438 | include IssuesHelper | ||
|
r9332 | include CustomFieldsHelper | ||
|
r8193 | include ERB::Util | ||
|
r12152 | include Rails.application.routes.url_helpers | ||
|
r3438 | |||
|
r7372 | fixtures :projects, :trackers, :issue_statuses, :issues, | ||
:enumerations, :users, :issue_categories, | ||||
:projects_trackers, | ||||
:roles, | ||||
:member_roles, | ||||
:members, | ||||
:enabled_modules, | ||||
|
r9332 | :custom_fields, | ||
|
r9927 | :attachments, | ||
:versions | ||||
|
r3438 | |||
def setup | ||||
super | ||||
set_language_if_valid('en') | ||||
User.current = nil | ||||
end | ||||
|
r5684 | |||
|
r5327 | def test_issue_heading | ||
assert_equal "Bug #1", issue_heading(Issue.find(1)) | ||||
end | ||||
|
r5684 | |||
|
r5375 | def test_issues_destroy_confirmation_message_with_one_root_issue | ||
|
r11483 | assert_equal l(:text_issues_destroy_confirmation), | ||
issues_destroy_confirmation_message(Issue.find(1)) | ||||
|
r5375 | end | ||
|
r5684 | |||
|
r5375 | def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues | ||
|
r11483 | assert_equal l(:text_issues_destroy_confirmation), | ||
issues_destroy_confirmation_message(Issue.find([1, 2])) | ||||
|
r5375 | end | ||
|
r5684 | |||
|
r5375 | def test_issues_destroy_confirmation_message_with_one_parent_issue | ||
Issue.find(2).update_attribute :parent_issue_id, 1 | ||||
|
r11483 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + | ||
l(:text_issues_destroy_descendants_confirmation, :count => 1), | ||||
issues_destroy_confirmation_message(Issue.find(1)) | ||||
|
r5375 | end | ||
|
r5684 | |||
|
r5375 | def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child | ||
Issue.find(2).update_attribute :parent_issue_id, 1 | ||||
|
r11483 | assert_equal l(:text_issues_destroy_confirmation), | ||
issues_destroy_confirmation_message(Issue.find([1, 2])) | ||||
|
r5375 | end | ||
|
r3438 | |||
|
r13436 | def test_issues_destroy_confirmation_message_with_issues_that_share_descendants | ||
root = Issue.generate! | ||||
child = Issue.generate!(:parent_issue_id => root.id) | ||||
Issue.generate!(:parent_issue_id => child.id) | ||||
assert_equal l(:text_issues_destroy_confirmation) + "\n" + | ||||
l(:text_issues_destroy_descendants_confirmation, :count => 1), | ||||
issues_destroy_confirmation_message([root.reload, child.reload]) | ||||
end | ||||
|
r11484 | test 'show_detail with no_html should show a changing attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | ||
:value => '100', :prop_key => 'done_ratio') | ||||
|
r11089 | assert_equal "% Done changed from 40 to 100", show_detail(detail, true) | ||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail with no_html should show a new attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, | ||
:value => '100', :prop_key => 'done_ratio') | ||||
|
r11089 | assert_equal "% Done set to 100", show_detail(detail, true) | ||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail with no_html should show a deleted attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', | ||
:value => nil, :prop_key => 'done_ratio') | ||||
|
r11089 | assert_equal "% Done deleted (50)", show_detail(detail, true) | ||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail with html should show a changing attribute with HTML highlights' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | ||
:value => '100', :prop_key => 'done_ratio') | ||||
|
r11089 | html = show_detail(detail, false) | ||
assert_include '<strong>% Done</strong>', html | ||||
assert_include '<i>40</i>', html | ||||
assert_include '<i>100</i>', html | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail with html should show a new attribute with HTML highlights' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :old_value => nil, | ||
:value => '100', :prop_key => 'done_ratio') | ||||
|
r11089 | html = show_detail(detail, false) | ||
assert_include '<strong>% Done</strong>', html | ||||
assert_include '<i>100</i>', html | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail with html should show a deleted attribute with HTML highlights' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :old_value => '50', | ||
:value => nil, :prop_key => 'done_ratio') | ||||
|
r11089 | html = show_detail(detail, false) | ||
assert_include '<strong>% Done</strong>', html | ||||
assert_include '<del><i>50</i></del>', html | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail with a start_date attribute should format the dates' do | ||
|
r11089 | detail = JournalDetail.new( | ||
:property => 'attr', | ||||
:old_value => '2010-01-01', | ||||
:value => '2010-01-31', | ||||
:prop_key => 'start_date' | ||||
) | ||||
with_settings :date_format => '%m/%d/%Y' do | ||||
assert_match "01/31/2010", show_detail(detail, true) | ||||
assert_match "01/01/2010", show_detail(detail, true) | ||||
|
r3438 | end | ||
|
r11089 | end | ||
|
r3438 | |||
|
r11484 | test 'show_detail with a due_date attribute should format the dates' do | ||
|
r11089 | detail = JournalDetail.new( | ||
:property => 'attr', | ||||
:old_value => '2010-01-01', | ||||
:value => '2010-01-31', | ||||
:prop_key => 'due_date' | ||||
) | ||||
with_settings :date_format => '%m/%d/%Y' do | ||||
assert_match "01/31/2010", show_detail(detail, true) | ||||
assert_match "01/01/2010", show_detail(detail, true) | ||||
|
r3438 | end | ||
|
r11089 | end | ||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a project attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', | ||
:old_value => 1, :value => 2) | ||||
|
r11089 | assert_match 'eCookbook', show_detail(detail, true) | ||
assert_match 'OnlineStore', show_detail(detail, true) | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a issue status attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', | ||
:old_value => 1, :value => 2) | ||||
|
r11089 | assert_match 'New', show_detail(detail, true) | ||
assert_match 'Assigned', show_detail(detail, true) | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a tracker attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', | ||
:old_value => 1, :value => 2) | ||||
|
r11089 | assert_match 'Bug', show_detail(detail, true) | ||
assert_match 'Feature request', show_detail(detail, true) | ||||
end | ||||
|
r9332 | |||
|
r11484 | test 'show_detail should show old and new values with a assigned to attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', | ||
:old_value => 1, :value => 2) | ||||
|
r11089 | assert_match 'Redmine Admin', show_detail(detail, true) | ||
assert_match 'John Smith', show_detail(detail, true) | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a priority attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', | ||
:old_value => 4, :value => 5) | ||||
|
r11089 | assert_match 'Low', show_detail(detail, true) | ||
assert_match 'Normal', show_detail(detail, true) | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a category attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', | ||
:old_value => 1, :value => 2) | ||||
|
r11089 | assert_match 'Printing', show_detail(detail, true) | ||
assert_match 'Recipes', show_detail(detail, true) | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a fixed version attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', | ||
:old_value => 1, :value => 2) | ||||
|
r11089 | assert_match '0.1', show_detail(detail, true) | ||
assert_match '1.0', show_detail(detail, true) | ||||
end | ||||
|
r3438 | |||
|
r11484 | test 'show_detail should show old and new values with a estimated hours attribute' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', | ||
:old_value => '5', :value => '6.3') | ||||
|
r11089 | assert_match '5.00', show_detail(detail, true) | ||
assert_match '6.30', show_detail(detail, true) | ||||
end | ||||
|
r9332 | |||
|
r11484 | test 'show_detail should show old and new values with a custom field' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'cf', :prop_key => '1', | ||
:old_value => 'MySQL', :value => 'PostgreSQL') | ||||
|
r11089 | assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) | ||
end | ||||
|
r11484 | test 'show_detail should show added file' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', | ||
:old_value => nil, :value => 'error281.txt') | ||||
|
r11089 | assert_match 'error281.txt', show_detail(detail, true) | ||
end | ||||
|
r11484 | test 'show_detail should show removed file' do | ||
|
r11483 | detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', | ||
:old_value => 'error281.txt', :value => nil) | ||||
|
r11089 | assert_match 'error281.txt', show_detail(detail, true) | ||
|
r3438 | end | ||
|
r11655 | |||
|
r11711 | def test_show_detail_relation_added | ||
|
r11655 | detail = JournalDetail.new(:property => 'relation', | ||
|
r12141 | :prop_key => 'precedes', | ||
|
r11655 | :value => 1) | ||
|
r13393 | assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true) | ||
|
r12597 | str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes) | ||
|
r13393 | assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added", | ||
|
r12597 | show_detail(detail, false) | ||
|
r11711 | end | ||
def test_show_detail_relation_added_with_inexistant_issue | ||||
inexistant_issue_number = 9999 | ||||
assert_nil Issue.find_by_id(inexistant_issue_number) | ||||
|
r11655 | detail = JournalDetail.new(:property => 'relation', | ||
|
r12141 | :prop_key => 'precedes', | ||
|
r11711 | :value => inexistant_issue_number) | ||
assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true) | ||||
assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false) | ||||
|
r11655 | end | ||
|
r11709 | def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible | ||
issue = Issue.generate!(:is_private => true) | ||||
detail = JournalDetail.new(:property => 'relation', | ||||
|
r12141 | :prop_key => 'precedes', | ||
|
r11709 | :value => issue.id) | ||
|
r11710 | assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true) | ||
assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false) | ||||
|
r11709 | end | ||
|
r11711 | def test_show_detail_relation_deleted | ||
|
r11655 | detail = JournalDetail.new(:property => 'relation', | ||
|
r12141 | :prop_key => 'precedes', | ||
|
r11655 | :old_value => 1) | ||
|
r13393 | assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true) | ||
|
r12597 | str = link_to("Bug #1", | ||
"/issues/1", | ||||
:class => Issue.find(1).css_classes) | ||||
|
r13393 | assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)", | ||
|
r11655 | show_detail(detail, false) | ||
|
r11711 | end | ||
def test_show_detail_relation_deleted_with_inexistant_issue | ||||
inexistant_issue_number = 9999 | ||||
assert_nil Issue.find_by_id(inexistant_issue_number) | ||||
|
r11655 | detail = JournalDetail.new(:property => 'relation', | ||
|
r12141 | :prop_key => 'precedes', | ||
|
r11711 | :old_value => inexistant_issue_number) | ||
|
r11710 | assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true) | ||
assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false) | ||||
|
r11655 | end | ||
|
r11709 | |||
def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible | ||||
issue = Issue.generate!(:is_private => true) | ||||
detail = JournalDetail.new(:property => 'relation', | ||||
|
r12141 | :prop_key => 'precedes', | ||
|
r11709 | :old_value => issue.id) | ||
|
r11710 | assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true) | ||
assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false) | ||||
|
r11709 | end | ||
|
r3438 | end | ||