[#4604] Add test for Rate#update_all_time_entries_with_missing_cost
This commit is contained in:
@@ -70,7 +70,7 @@ class Rate < ActiveRecord::Base
|
|||||||
return rate.amount
|
return rate.amount
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_all_time_entires_with_missing_cost
|
def self.update_all_time_entries_with_missing_cost
|
||||||
Lockfile('update_cost_cache', :retries => 0) do
|
Lockfile('update_cost_cache', :retries => 0) do
|
||||||
TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry|
|
TimeEntry.all(:conditions => {:cost => nil}).each do |time_entry|
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ namespace :rate_plugin do
|
|||||||
namespace :cache do
|
namespace :cache do
|
||||||
desc "Update Time Entry cost caches"
|
desc "Update Time Entry cost caches"
|
||||||
task :update_cost_cache => :environment do
|
task :update_cost_cache => :environment do
|
||||||
Rate.update_all_time_entires_with_missing_cost
|
Rate.update_all_time_entries_with_missing_cost
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -269,5 +269,29 @@ class RateTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#update_all_time_entries_with_missing_cost" do
|
||||||
|
setup do
|
||||||
|
@user = User.generate!
|
||||||
|
@project = Project.generate!
|
||||||
|
@date = Date.today.to_s
|
||||||
|
@rate = Rate.generate!(:user => @user, :project => @project, :date_in_effect => @date, :amount => 200.0)
|
||||||
|
@time_entry1 = TimeEntry.generate!({:user => @user, :project => @project, :spent_on => @date, :hours => 10.0, :activity => TimeEntryActivity.generate!})
|
||||||
|
@time_entry2 = TimeEntry.generate!({:user => @user, :project => @project, :spent_on => @date, :hours => 20.0, :activity => TimeEntryActivity.generate!})
|
||||||
|
end
|
||||||
|
|
||||||
|
should "update the caches of all Time Entries" do
|
||||||
|
TimeEntry.update_all('cost = null')
|
||||||
|
|
||||||
|
# Check that cost is NULL in the database, which skips the caching
|
||||||
|
assert_equal "2", ActiveRecord::Base.connection.select_all('select count(*) as count from time_entries where cost IS NULL').first["count"]
|
||||||
|
|
||||||
|
Rate.update_all_time_entries_with_missing_cost
|
||||||
|
|
||||||
|
assert_equal "0", ActiveRecord::Base.connection.select_all('select count(*) as count from time_entries where cost IS NULL').first["count"]
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
should "timestamp a successful run"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user