diff test/functional/context_menus_controller_test.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 0a574315af3e 622f24f53b42
children
line wrap: on
line diff
--- a/test/functional/context_menus_controller_test.rb	Fri Jun 14 09:07:32 2013 +0100
+++ b/test/functional/context_menus_controller_test.rb	Fri Jun 14 09:28:30 2013 +0100
@@ -1,3 +1,20 @@
+# Redmine - project management software
+# Copyright (C) 2006-2013  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
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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.
+#
+# 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.
+
 require File.expand_path('../../test_helper', __FILE__)
 
 class ContextMenusControllerTest < ActionController::TestCase
@@ -21,34 +38,21 @@
     get :issues, :ids => [1]
     assert_response :success
     assert_template 'context_menu'
-    assert_tag :tag => 'a', :content => 'Edit',
-                            :attributes => { :href => '/issues/1/edit',
-                                             :class => 'icon-edit' }
-    assert_tag :tag => 'a', :content => 'Closed',
-                            :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5',
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Immediate',
-                            :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
-                                             :class => '' }
-    assert_no_tag :tag => 'a', :content => 'Inactive Priority'
+
+    assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
+    assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
+    assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
+
+    # Statuses
+    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
+    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
+    # No inactive priorities
+    assert_select 'a', :text => /Inactive Priority/, :count => 0
     # Versions
-    assert_tag :tag => 'a', :content => '2.0',
-                            :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
-                            :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
-                                             :class => '' }
-
-    assert_tag :tag => 'a', :content => 'Dave Lopper',
-                            :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Copy',
-                            :attributes => { :href => '/projects/ecookbook/issues/1/copy',
-                                             :class => 'icon-copy' }
-    assert_no_tag :tag => 'a', :content => 'Move'
-    assert_tag :tag => 'a', :content => 'Delete',
-                            :attributes => { :href => '/issues?ids%5B%5D=1',
-                                             :class => 'icon-del' }
+    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
+    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
+    # Assignees
+    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
   end
 
   def test_context_menu_one_issue_by_anonymous
@@ -69,25 +73,14 @@
     assert_equal [1, 2], assigns(:issues).map(&:id).sort
 
     ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
-    assert_tag :tag => 'a', :content => 'Edit',
-                            :attributes => { :href => "/issues/bulk_edit?#{ids}",
-                                             :class => 'icon-edit' }
-    assert_tag :tag => 'a', :content => 'Closed',
-                            :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Immediate',
-                            :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Dave Lopper',
-                            :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3",
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Copy',
-                            :attributes => { :href => "/issues/bulk_edit?copy=1&amp;#{ids}",
-                                             :class => 'icon-copy' }
-    assert_no_tag :tag => 'a', :content => 'Move'
-    assert_tag :tag => 'a', :content => 'Delete',
-                            :attributes => { :href => "/issues?#{ids}",
-                                             :class => 'icon-del' }
+
+    assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
+    assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
+    assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
+
+    assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
+    assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
+    assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
   end
 
   def test_context_menu_multiple_issues_of_different_projects
@@ -99,21 +92,13 @@
     assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
 
     ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
-    assert_tag :tag => 'a', :content => 'Edit',
-                            :attributes => { :href => "/issues/bulk_edit?#{ids}",
-                                             :class => 'icon-edit' }
-    assert_tag :tag => 'a', :content => 'Closed',
-                            :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Immediate',
-                            :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'John Smith',
-                            :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2",
-                                             :class => '' }
-    assert_tag :tag => 'a', :content => 'Delete',
-                            :attributes => { :href => "/issues?#{ids}",
-                                             :class => 'icon-del' }
+
+    assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
+    assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
+
+    assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
+    assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
+    assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
   end
 
   def test_context_menu_should_include_list_custom_fields
@@ -122,17 +107,14 @@
     @request.session[:user_id] = 2
     get :issues, :ids => [1]
 
-    assert_tag 'a',
-      :content => 'List',
-      :attributes => {:href => '#'},
-      :sibling => {:tag => 'ul', :children => {:count => 3}}
-
-    assert_tag 'a',
-      :content => 'Foo',
-      :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"}
-    assert_tag 'a',
-      :content => 'none',
-      :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__"}
+    assert_select "li.cf_#{field.id}" do
+      assert_select 'a[href=#]', :text => 'List'
+      assert_select 'ul' do
+        assert_select 'a', 3
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
+      end
+    end
   end
 
   def test_context_menu_should_not_include_null_value_for_required_custom_fields
@@ -141,10 +123,13 @@
     @request.session[:user_id] = 2
     get :issues, :ids => [1, 2]
 
-    assert_tag 'a',
-      :content => 'List',
-      :attributes => {:href => '#'},
-      :sibling => {:tag => 'ul', :children => {:count => 2}}
+    assert_select "li.cf_#{field.id}" do
+      assert_select 'a[href=#]', :text => 'List'
+      assert_select 'ul' do
+        assert_select 'a', 2
+        assert_select 'a', :text => 'none', :count => 0
+      end
+    end
   end
 
   def test_context_menu_on_single_issue_should_select_current_custom_field_value
@@ -156,13 +141,13 @@
     @request.session[:user_id] = 2
     get :issues, :ids => [1]
 
-    assert_tag 'a',
-      :content => 'List',
-      :attributes => {:href => '#'},
-      :sibling => {:tag => 'ul', :children => {:count => 3}}
-    assert_tag 'a',
-      :content => 'Bar',
-      :attributes => {:class => /icon-checked/}
+    assert_select "li.cf_#{field.id}" do
+      assert_select 'a[href=#]', :text => 'List'
+      assert_select 'ul' do
+        assert_select 'a', 3
+        assert_select 'a.icon-checked', :text => 'Bar'
+      end
+    end
   end
 
   def test_context_menu_should_include_bool_custom_fields
@@ -171,14 +156,15 @@
     @request.session[:user_id] = 2
     get :issues, :ids => [1]
 
-    assert_tag 'a',
-      :content => 'Bool',
-      :attributes => {:href => '#'},
-      :sibling => {:tag => 'ul', :children => {:count => 3}}
-
-    assert_tag 'a',
-      :content => 'Yes',
-      :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"}
+    assert_select "li.cf_#{field.id}" do
+      assert_select 'a[href=#]', :text => 'Bool'
+      assert_select 'ul' do
+        assert_select 'a', 3
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
+      end
+    end
   end
 
   def test_context_menu_should_include_user_custom_fields
@@ -187,14 +173,14 @@
     @request.session[:user_id] = 2
     get :issues, :ids => [1]
 
-    assert_tag 'a',
-      :content => 'User',
-      :attributes => {:href => '#'},
-      :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}}
-
-    assert_tag 'a',
-      :content => 'John Smith',
-      :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"}
+    assert_select "li.cf_#{field.id}" do
+      assert_select 'a[href=#]', :text => 'User'
+      assert_select 'ul' do
+        assert_select 'a', Project.find(1).members.count + 1
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
+      end
+    end
   end
 
   def test_context_menu_should_include_version_custom_fields
@@ -202,14 +188,14 @@
     @request.session[:user_id] = 2
     get :issues, :ids => [1]
 
-    assert_tag 'a',
-      :content => 'Version',
-      :attributes => {:href => '#'},
-      :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}}
-
-    assert_tag 'a',
-      :content => '2.0',
-      :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"}
+    assert_select "li.cf_#{field.id}" do
+      assert_select 'a[href=#]', :text => 'Version'
+      assert_select 'ul' do
+        assert_select 'a', Project.find(1).shared_versions.count + 1
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
+        assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
+      end
+    end
   end
 
   def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
@@ -218,9 +204,7 @@
     assert_response :success
     assert_template 'context_menu'
 
-    assert_tag :tag => 'a', :content => / me /,
-                            :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2',
-                                             :class => '' }
+    assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
   end
 
   def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
@@ -232,7 +216,7 @@
     assert_template 'context_menu'
 
     assert_include version, assigns(:versions)
-    assert_tag :tag => 'a', :content => 'eCookbook - Shared'
+    assert_select 'a', :text => 'eCookbook - Shared'
   end
 
   def test_context_menu_issue_visibility
@@ -241,16 +225,21 @@
     assert_template 'context_menu'
     assert_equal [1], assigns(:issues).collect(&:id)
   end
-  
+
+  def test_should_respond_with_404_without_ids
+    get :issues
+    assert_response 404
+  end
+
   def test_time_entries_context_menu
     @request.session[:user_id] = 2
     get :time_entries, :ids => [1, 2]
     assert_response :success
     assert_template 'time_entries'
-    assert_tag 'a', :content => 'Edit'
-    assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
+
+    assert_select 'a:not(.disabled)', :text => 'Edit'
   end
-  
+
   def test_time_entries_context_menu_without_edit_permission
     @request.session[:user_id] = 2
     Role.find_by_name('Manager').remove_permission! :edit_time_entries
@@ -258,6 +247,6 @@
     get :time_entries, :ids => [1, 2]
     assert_response :success
     assert_template 'time_entries'
-    assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
+    assert_select 'a.disabled', :text => 'Edit'
   end
 end