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