Chris@0: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@441: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@441: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../../test_helper', __FILE__) Chris@0: Chris@0: class IssuesHelperTest < HelperTestCase Chris@0: include ApplicationHelper Chris@0: include IssuesHelper Chris@0: Chris@0: include ActionController::Assertions::SelectorAssertions Chris@909: fixtures :projects, :trackers, :issue_statuses, :issues, Chris@909: :enumerations, :users, :issue_categories, Chris@909: :projects_trackers, Chris@909: :roles, Chris@909: :member_roles, Chris@909: :members, Chris@909: :enabled_modules, Chris@909: :workflows Chris@0: Chris@0: # Used by assert_select Chris@0: def html_document Chris@0: HTML::Document.new(@response.body) Chris@0: end Chris@0: Chris@0: def setup Chris@0: super Chris@0: set_language_if_valid('en') Chris@0: User.current = nil Chris@0: @response = ActionController::TestResponse.new Chris@0: end Chris@0: Chris@0: def controller Chris@0: @controller ||= IssuesController.new Chris@0: end Chris@0: Chris@0: def request Chris@0: @request ||= ActionController::TestRequest.new Chris@0: end Chris@0: Chris@441: def test_issue_heading Chris@441: assert_equal "Bug #1", issue_heading(Issue.find(1)) Chris@441: end Chris@441: Chris@441: def test_issues_destroy_confirmation_message_with_one_root_issue Chris@441: assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1)) Chris@441: end Chris@441: Chris@441: def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues Chris@441: assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2])) Chris@441: end Chris@441: Chris@441: def test_issues_destroy_confirmation_message_with_one_parent_issue Chris@441: Issue.find(2).update_attribute :parent_issue_id, 1 Chris@441: assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1), Chris@441: issues_destroy_confirmation_message(Issue.find(1)) Chris@441: end Chris@441: Chris@441: def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child Chris@441: Issue.find(2).update_attribute :parent_issue_id, 1 Chris@441: assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2])) Chris@441: end Chris@441: Chris@0: context "IssuesHelper#show_detail" do Chris@0: context "with no_html" do Chris@0: should 'show a changing attribute' do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') Chris@0: assert_equal "% Done changed from 40 to 100", show_detail(@detail, true) Chris@0: end Chris@0: Chris@0: should 'show a new attribute' do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') Chris@0: assert_equal "% Done set to 100", show_detail(@detail, true) Chris@0: end Chris@0: Chris@0: should 'show a deleted attribute' do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') Chris@0: assert_equal "% Done deleted (50)", show_detail(@detail, true) Chris@0: end Chris@0: end Chris@0: Chris@0: context "with html" do Chris@0: should 'show a changing attribute with HTML highlights' do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') Chris@0: @response.body = show_detail(@detail, false) Chris@0: Chris@0: assert_select 'strong', :text => '% Done' Chris@0: assert_select 'i', :text => '40' Chris@0: assert_select 'i', :text => '100' Chris@0: end Chris@0: Chris@0: should 'show a new attribute with HTML highlights' do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') Chris@0: @response.body = show_detail(@detail, false) Chris@0: Chris@0: assert_select 'strong', :text => '% Done' Chris@0: assert_select 'i', :text => '100' Chris@0: end Chris@0: Chris@0: should 'show a deleted attribute with HTML highlights' do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') Chris@0: @response.body = show_detail(@detail, false) Chris@0: Chris@0: assert_select 'strong', :text => '% Done' Chris@0: assert_select 'strike' do Chris@0: assert_select 'i', :text => '50' Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: context "with a start_date attribute" do Chris@0: should "format the current date" do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date') Chris@0: assert_match "01/31/2010", show_detail(@detail, true) Chris@0: end Chris@0: Chris@0: should "format the old date" do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date') Chris@0: assert_match "01/01/2010", show_detail(@detail, true) Chris@0: end Chris@0: end Chris@0: Chris@0: context "with a due_date attribute" do Chris@0: should "format the current date" do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date') Chris@0: assert_match "01/31/2010", show_detail(@detail, true) Chris@0: end Chris@0: Chris@0: should "format the old date" do Chris@0: @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date') Chris@0: assert_match "01/01/2010", show_detail(@detail, true) Chris@0: end Chris@0: end Chris@0: Chris@0: context "with a project attribute" do Chris@0: should_show_the_old_and_new_values_for('project_id', Project) Chris@0: end Chris@0: Chris@0: context "with a issue status attribute" do Chris@0: should_show_the_old_and_new_values_for('status_id', IssueStatus) Chris@0: end Chris@0: Chris@0: context "with a tracker attribute" do Chris@0: should_show_the_old_and_new_values_for('tracker_id', Tracker) Chris@0: end Chris@0: Chris@0: context "with a assigned to attribute" do Chris@0: should_show_the_old_and_new_values_for('assigned_to_id', User) Chris@0: end Chris@0: Chris@0: context "with a priority attribute" do Chris@0: should_show_the_old_and_new_values_for('priority_id', IssuePriority) do Chris@0: @old_value = IssuePriority.generate!(:type => 'IssuePriority') Chris@0: @new_value = IssuePriority.generate!(:type => 'IssuePriority') Chris@0: end Chris@0: end Chris@0: Chris@0: context "with a category attribute" do Chris@0: should_show_the_old_and_new_values_for('category_id', IssueCategory) Chris@0: end Chris@0: Chris@0: context "with a fixed version attribute" do Chris@0: should_show_the_old_and_new_values_for('fixed_version_id', Version) Chris@0: end Chris@0: Chris@0: context "with a estimated hours attribute" do Chris@0: should "format the time into two decimal places" Chris@0: should "format the old time into two decimal places" Chris@0: end Chris@0: Chris@0: should "test custom fields" Chris@0: should "test attachments" Chris@0: Chris@0: end Chris@0: Chris@0: end