diff test/unit/helpers/issues_helper_test.rb @ 1338:25603efa57b5

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:14 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
line wrap: on
line diff
--- a/test/unit/helpers/issues_helper_test.rb	Wed Jan 23 13:11:25 2013 +0000
+++ b/test/unit/helpers/issues_helper_test.rb	Thu Jun 20 13:14:14 2013 +0100
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -17,11 +17,12 @@
 
 require File.expand_path('../../../test_helper', __FILE__)
 
-class IssuesHelperTest < HelperTestCase
+class IssuesHelperTest < ActionView::TestCase
   include ApplicationHelper
   include IssuesHelper
+  include CustomFieldsHelper
+  include ERB::Util
 
-  include ActionController::Assertions::SelectorAssertions
   fixtures :projects, :trackers, :issue_statuses, :issues,
            :enumerations, :users, :issue_categories,
            :projects_trackers,
@@ -29,26 +30,15 @@
            :member_roles,
            :members,
            :enabled_modules,
-           :workflows
-
-  # Used by assert_select
-  def html_document
-    HTML::Document.new(@response.body)
-  end
+           :workflows,
+           :custom_fields,
+           :attachments,
+           :versions
 
   def setup
     super
     set_language_if_valid('en')
     User.current = nil
-    @response = ActionController::TestResponse.new
-  end
-
-  def controller
-    @controller ||= IssuesController.new
-  end
-
-  def request
-    @request ||= ActionController::TestRequest.new
   end
 
   def test_issue_heading
@@ -77,113 +67,161 @@
   context "IssuesHelper#show_detail" do
     context "with no_html" do
       should 'show a changing attribute' do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
+        @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
         assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
       end
 
       should 'show a new attribute' do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
+        @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
         assert_equal "% Done set to 100", show_detail(@detail, true)
       end
 
       should 'show a deleted attribute' do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
+        @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
         assert_equal "% Done deleted (50)", show_detail(@detail, true)
       end
     end
 
     context "with html" do
       should 'show a changing attribute with HTML highlights' do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
-        @response.body = show_detail(@detail, false)
+        @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
+        html = show_detail(@detail, false)
 
-        assert_select 'strong', :text => '% Done'
-        assert_select 'i', :text => '40'
-        assert_select 'i', :text => '100'
+        assert_include '<strong>% Done</strong>', html
+        assert_include '<i>40</i>', html
+        assert_include '<i>100</i>', html
       end
 
       should 'show a new attribute with HTML highlights' do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
-        @response.body = show_detail(@detail, false)
+        @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
+        html = show_detail(@detail, false)
 
-        assert_select 'strong', :text => '% Done'
-        assert_select 'i', :text => '100'
+        assert_include '<strong>% Done</strong>', html
+        assert_include '<i>100</i>', html
       end
 
       should 'show a deleted attribute with HTML highlights' do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
-        @response.body = show_detail(@detail, false)
+        @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
+        html = show_detail(@detail, false)
 
-        assert_select 'strong', :text => '% Done'
-        assert_select 'strike' do
-          assert_select 'i', :text => '50'
-        end
+        assert_include '<strong>% Done</strong>', html
+        assert_include '<del><i>50</i></del>', html
       end
     end
 
     context "with a start_date attribute" do
       should "format the current date" do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
-        assert_match "01/31/2010", show_detail(@detail, true)
+        @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)
+        end
       end
 
       should "format the old date" do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
-        assert_match "01/01/2010", show_detail(@detail, true)
+        @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/01/2010", show_detail(@detail, true)
+        end
       end
     end
 
     context "with a due_date attribute" do
       should "format the current date" do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
-        assert_match "01/31/2010", show_detail(@detail, true)
+        @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)
+        end
       end
 
       should "format the old date" do
-        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
-        assert_match "01/01/2010", show_detail(@detail, true)
+        @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/01/2010", show_detail(@detail, true)
+        end
       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.new(: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.new(: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.new(: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.new(: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.new(: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
 
-    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 category attribute" do
+      detail = JournalDetail.new(: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 fixed version attribute" do
-      should_show_the_old_and_new_values_for('fixed_version_id', Version)
+    should "show old and new values with a fixed version attribute" do
+      detail = JournalDetail.new(: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 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 estimated hours attribute" do
+      detail = JournalDetail.new(: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
 
-    should "test custom fields"
-    should "test attachments"
+    should "show old and new values with a custom field" do
+      detail = JournalDetail.new(:property => 'cf', :prop_key => '1', :old_value => 'MySQL', :value => 'PostgreSQL')
+      assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
+    end
 
+    should "show added file" do
+      detail = JournalDetail.new(: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.new(:property => 'attachment', :prop_key => '1', :old_value => 'error281.txt', :value => nil)
+      assert_match 'error281.txt', show_detail(detail, true)
+    end
   end
-
 end