diff test/functional/project_enumerations_controller_test.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children fb9a13467253
line wrap: on
line diff
--- a/test/functional/project_enumerations_controller_test.rb	Tue Sep 09 09:28:31 2014 +0100
+++ b/test/functional/project_enumerations_controller_test.rb	Tue Sep 09 09:29:00 2014 +0100
@@ -129,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 => {
@@ -138,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
@@ -149,23 +152,30 @@
     # 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
@@ -202,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