From 4598c64ebd6d07b0e0f24e4bedf667d7c4fd3d57 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 22 Apr 2012 08:24:39 +0000 Subject: [PATCH] Additional tests for IssuesHelper#show_detail. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9466 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/test_helper.rb | 31 ----------- test/unit/helpers/issues_helper_test.rb | 73 +++++++++++++++++-------- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 2b80c851e..1ddb77c21 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -210,37 +210,6 @@ class ActiveSupport::TestCase end end - def self.should_show_the_old_and_new_values_for(prop_key, model, &block) - context "" do - setup do - if block_given? - instance_eval &block - else - @old_value = model.generate! - @new_value = model.generate! - end - end - - should "use the new value's name" do - @detail = JournalDetail.generate!(:property => 'attr', - :old_value => @old_value.id, - :value => @new_value.id, - :prop_key => prop_key) - - assert_match @new_value.name, show_detail(@detail, true) - end - - should "use the old value's name" do - @detail = JournalDetail.generate!(:property => 'attr', - :old_value => @old_value.id, - :value => @new_value.id, - :prop_key => prop_key) - - assert_match @old_value.name, show_detail(@detail, true) - end - end - end - # Test that a request allows the three types of API authentication # # * HTTP Basic with username and password diff --git a/test/unit/helpers/issues_helper_test.rb b/test/unit/helpers/issues_helper_test.rb index ac0dc85d1..e227b40f9 100644 --- a/test/unit/helpers/issues_helper_test.rb +++ b/test/unit/helpers/issues_helper_test.rb @@ -20,6 +20,7 @@ require File.expand_path('../../../test_helper', __FILE__) class IssuesHelperTest < ActionView::TestCase include ApplicationHelper include IssuesHelper + include CustomFieldsHelper include ERB::Util fixtures :projects, :trackers, :issue_statuses, :issues, @@ -29,7 +30,9 @@ class IssuesHelperTest < ActionView::TestCase :member_roles, :members, :enabled_modules, - :workflows + :workflows, + :custom_fields, + :attachments def setup super @@ -129,43 +132,67 @@ class IssuesHelperTest < ActionView::TestCase end end - context "with a project attribute" do - should_show_the_old_and_new_values_for('project_id', Project) + should "show old and new values with a project attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'project_id', :old_value => 1, :value => 2) + assert_match 'eCookbook', show_detail(detail, true) + assert_match 'OnlineStore', show_detail(detail, true) end - context "with a issue status attribute" do - should_show_the_old_and_new_values_for('status_id', IssueStatus) + should "show old and new values with a issue status attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'status_id', :old_value => 1, :value => 2) + assert_match 'New', show_detail(detail, true) + assert_match 'Assigned', show_detail(detail, true) end - context "with a tracker attribute" do - should_show_the_old_and_new_values_for('tracker_id', Tracker) + should "show old and new values with a tracker attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'tracker_id', :old_value => 1, :value => 2) + assert_match 'Bug', show_detail(detail, true) + assert_match 'Feature request', show_detail(detail, true) end - context "with a assigned to attribute" do - should_show_the_old_and_new_values_for('assigned_to_id', User) + should "show old and new values with a assigned to attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'assigned_to_id', :old_value => 1, :value => 2) + assert_match 'redMine Admin', show_detail(detail, true) + assert_match 'John Smith', show_detail(detail, true) end - context "with a priority attribute" do - should_show_the_old_and_new_values_for('priority_id', IssuePriority) do - @old_value = IssuePriority.generate!(:type => 'IssuePriority') - @new_value = IssuePriority.generate!(:type => 'IssuePriority') - end + should "show old and new values with a priority attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'priority_id', :old_value => 4, :value => 5) + assert_match 'Low', show_detail(detail, true) + assert_match 'Normal', show_detail(detail, true) + end + + should "show old and new values with a category attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'category_id', :old_value => 1, :value => 2) + assert_match 'Printing', show_detail(detail, true) + assert_match 'Recipes', show_detail(detail, true) end - context "with a category attribute" do - should_show_the_old_and_new_values_for('category_id', IssueCategory) + should "show old and new values with a fixed version attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'fixed_version_id', :old_value => 1, :value => 2) + assert_match '0.1', show_detail(detail, true) + assert_match '1.0', show_detail(detail, true) end - context "with a fixed version attribute" do - should_show_the_old_and_new_values_for('fixed_version_id', Version) + should "show old and new values with a estimated hours attribute" do + detail = JournalDetail.generate!(:property => 'attr', :prop_key => 'estimated_hours', :old_value => '5', :value => '6.3') + assert_match '5.00', show_detail(detail, true) + assert_match '6.30', show_detail(detail, true) end - context "with a estimated hours attribute" do - should "format the time into two decimal places" - should "format the old time into two decimal places" + should "show old and new values with a custom field" do + detail = JournalDetail.generate!(:property => 'cf', :prop_key => '1', :old_value => 'MySQL', :value => 'PostgreSQL') + assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) end - should "test custom fields" - should "test attachments" + should "show added file" do + detail = JournalDetail.generate!(:property => 'attachment', :prop_key => '1', :old_value => nil, :value => 'error281.txt') + assert_match 'error281.txt', show_detail(detail, true) + end + + should "show removed file" do + detail = JournalDetail.generate!(:property => 'attachment', :prop_key => '1', :old_value => 'error281.txt', :value => nil) + assert_match 'error281.txt', show_detail(detail, true) + end end end -- 2.39.5