diff test/functional/project_enumerations_controller_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents fb9a13467253
children
line wrap: on
line diff
--- a/test/functional/project_enumerations_controller_test.rb	Mon Mar 17 08:57:04 2014 +0000
+++ b/test/functional/project_enumerations_controller_test.rb	Thu Sep 11 12:46:20 2014 +0100
@@ -1,3 +1,20 @@
+# Redmine - project management software
+# Copyright (C) 2006-2014  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 ProjectEnumerationsControllerTest < ActionController::TestCase
@@ -8,7 +25,6 @@
            :member_roles,
            :members,
            :enabled_modules,
-           :workflows,
            :custom_fields, :custom_fields_projects,
            :custom_fields_trackers, :custom_values,
            :time_entries
@@ -75,14 +91,14 @@
 
     project_activity = TimeEntryActivity.new({
                                                :name => 'Project Specific',
-                                               :parent => TimeEntryActivity.find(:first),
+                                               :parent => TimeEntryActivity.first,
                                                :project => Project.find(1),
                                                :active => true
                                              })
     assert project_activity.save
     project_activity_two = TimeEntryActivity.new({
                                                    :name => 'Project Specific Two',
-                                                   :parent => TimeEntryActivity.find(:last),
+                                                   :parent => TimeEntryActivity.last,
                                                    :project => Project.find(1),
                                                    :active => true
                                                  })
@@ -113,7 +129,7 @@
   end
 
   def test_update_when_creating_new_activities_will_convert_existing_data
-    assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
+    assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count
 
     @request.session[:user_id] = 2 # manager
     put :update, :project_id => 1, :enumerations => {
@@ -122,10 +138,13 @@
     assert_response :redirect
 
     # No more TimeEntries using the system activity
-    assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities"
+    assert_equal 0, TimeEntry.where(:activity_id => 9, :project_id => 1).count,
+                 "Time Entries still assigned to system activities"
     # All TimeEntries using project activity
     project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1)
-    assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity"
+    assert_equal 3, TimeEntry.where(:activity_id => project_specific_activity.id,
+                                    :project_id => 1).count
+                 "No Time Entries assigned to the project activity"
   end
 
   def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
@@ -133,37 +152,44 @@
     # aren't setup for mocking.  Just create a record now so the
     # second one is a dupicate
     parent = TimeEntryActivity.find(9)
-    TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true})
-    TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
-
-    assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
-    assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
+    TimeEntryActivity.create!({:name => parent.name, :project_id => 1,
+                               :position => parent.position, :active => true})
+    TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1),
+                       :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'})
+    assert_equal 3, TimeEntry.where(:activity_id => 9, :project_id => 1).count
+    assert_equal 1, TimeEntry.where(:activity_id => 10, :project_id => 1).count
 
     @request.session[:user_id] = 2 # manager
     put :update, :project_id => 1, :enumerations => {
-      "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
-      "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
+      # Design
+      "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"},
+      # Development, Change custom value
+      "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}
     }
     assert_response :redirect
 
     # TimeEntries shouldn't have been reassigned on the failed record
-    assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities"
+    assert_equal 3, TimeEntry.where(:activity_id => 9,
+                                    :project_id => 1).count
+                 "Time Entries are not assigned to system activities"
     # TimeEntries shouldn't have been reassigned on the saved record either
-    assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
+    assert_equal 1, TimeEntry.where(:activity_id => 10,
+                                    :project_id => 1).count
+                 "Time Entries are not assigned to system activities"
   end
 
   def test_destroy
     @request.session[:user_id] = 2 # manager
     project_activity = TimeEntryActivity.new({
                                                :name => 'Project Specific',
-                                               :parent => TimeEntryActivity.find(:first),
+                                               :parent => TimeEntryActivity.first,
                                                :project => Project.find(1),
                                                :active => true
                                              })
     assert project_activity.save
     project_activity_two = TimeEntryActivity.new({
                                                    :name => 'Project Specific Two',
-                                                   :parent => TimeEntryActivity.find(:last),
+                                                   :parent => TimeEntryActivity.last,
                                                    :project => Project.find(1),
                                                    :active => true
                                                  })
@@ -186,16 +212,24 @@
                                                :active => true
                                              })
     assert project_activity.save
-    assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
-    assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
-
+    assert TimeEntry.where(["project_id = ? AND activity_id = ?", 1, 9]).
+             update_all("activity_id = '#{project_activity.id}'")
+    assert_equal 3, TimeEntry.where(:activity_id => project_activity.id,
+                                    :project_id => 1).count
     delete :destroy, :project_id => 1
     assert_response :redirect
     assert_redirected_to '/projects/ecookbook/settings/activities'
 
     assert_nil TimeEntryActivity.find_by_id(project_activity.id)
-    assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity"
-    assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity"
+    assert_equal 0, TimeEntry.where(
+                      :activity_id => project_activity.id,
+                      :project_id => 1
+                    ).count,
+                 "TimeEntries still assigned to project specific activity"
+    assert_equal 3, TimeEntry.where(
+                      :activity_id => 9,
+                      :project_id => 1
+                    ).count,
+                 "TimeEntries still assigned to project specific activity"
   end
-
 end