[#4604] Add basic caching for TimeEntry#cost

This commit is contained in:
Eric Davis
2010-10-06 12:12:45 -07:00
parent cec35ad3af
commit dbfc6c5335
3 changed files with 66 additions and 8 deletions
+37 -1
View File
@@ -5,7 +5,7 @@ class RateTimeEntryPatchTest < ActiveSupport::TestCase
@user = User.generate!
@project = Project.generate!
@date = Date.today.to_s
@time_entry = TimeEntry.new({:user => @user, :project => @project, :spent_on => @date, :hours => 10.0})
@time_entry = TimeEntry.new({:user => @user, :project => @project, :spent_on => @date, :hours => 10.0, :activity => TimeEntryActivity.generate!})
end
should 'should return 0.0 if there are no rates for the user' do
@@ -26,4 +26,40 @@ class RateTimeEntryPatchTest < ActiveSupport::TestCase
end
context "#cost" do
setup do
@time_entry.save!
Rate.generate!(:user => @user, :project => @project, :date_in_effect => @date, :amount => 200.0)
end
context "without a cache" do
should "return the calculated cost" do
@time_entry.update_attribute(:cost, nil)
assert_equal 2000.0, @time_entry.cost
end
should "cache the cost to the field" do
@time_entry.update_attribute(:cost, nil)
@time_entry.cost
assert_equal 2000.0, @time_entry.read_attribute(:cost)
assert_equal 2000.0, @time_entry.reload.read_attribute(:cost)
end
end
context "with a cache" do
setup do
@time_entry.cache_cost
end
should "return the cached cost" do
assert_equal 2000.0, @time_entry.read_attribute(:cost)
assert_equal 2000.0, @time_entry.cost
end
end
end
end