3 Commits

Author SHA1 Message Date
Eric Davis
25c3bf5898 Release v0.2.1 2011-04-28 11:17:06 -07:00
Eric Davis
4c3e6b6b6d [#5734] Fix the cost caching case where Time Entry attributes changed
A cost value wasn't getting recaclulated by TimeEntry#cost when the
attributes were changing. It only was recalculated when .cost changed.
2011-04-06 09:27:20 -07:00
Eric Davis
b20ebe587b Tweak ObjectDaddy so it's loaded into Rate when testing 2011-04-06 09:18:54 -07:00
6 changed files with 39 additions and 8 deletions

View File

@@ -1 +1 @@
0.2.0
0.2.1

View File

@@ -151,6 +151,9 @@ class Rate < ActiveRecord::Base
end
if Rails.env.test?
require 'object_daddy'
include ObjectDaddy
public
generator_for :date_in_effect => Date.today
end

View File

@@ -26,7 +26,7 @@ Redmine::Plugin.register :redmine_rate do
url 'https://projects.littlestreamsoftware.com/projects/redmine-rate'
author_url 'http://www.littlestreamsoftware.com'
description "The Rate plugin provides an API that can be used to find the rate for a Member of a Project at a specific date. It also stores historical rate data so calculations will remain correct in the future."
version '0.2.0'
version '0.2.1'
requires_redmine :version_or_higher => '1.0.0'

View File

@@ -9,7 +9,7 @@ module RateTimeEntryPatch
unloadable # Send unloadable so it will not be unloaded in development
belongs_to :rate
before_save :cost
before_save :recalculate_cost
end
@@ -32,7 +32,9 @@ module RateTimeEntryPatch
# Returns the current cost of the TimeEntry based on it's rate and hours
#
# Is a read-through cache method
def cost
def cost(options={})
store_to_db = options[:store] || false
unless read_attribute(:cost)
if self.rate.nil?
amount = Rate.amount_for(self.user, self.project, self.spent_on.to_s)
@@ -43,8 +45,13 @@ module RateTimeEntryPatch
if amount.nil?
write_attribute(:cost, 0.0)
else
# Write the cost to the database for caching
update_attribute(:cost, amount.to_f * hours.to_f)
if store_to_db
# Write the cost to the database for caching
update_attribute(:cost, amount.to_f * hours.to_f)
else
# Cache to object only
write_attribute(:cost, amount.to_f * hours.to_f)
end
end
end
@@ -59,6 +66,12 @@ module RateTimeEntryPatch
clear_cost_cache
update_attribute(:cost, cost)
end
def recalculate_cost
clear_cost_cache
cost(:store => false)
true # for callback
end
end
end

View File

@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{redmine_rate}
s.version = "0.2.0"
s.version = "0.2.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Eric Davis"]
s.date = %q{2011-03-03}
s.date = %q{2011-04-28}
s.description = %q{The Rate plugin stores billing rates for Users. It also provides an API that can be used to find the rate for a Member of a Project at a specific date.}
s.email = %q{edavis@littlestreamsoftware.com}
s.extra_rdoc_files = [

View File

@@ -71,6 +71,21 @@ class RateTimeEntryPatchTest < ActiveSupport::TestCase
assert_equal 2000.0, @time_entry.read_attribute(:cost)
end
should "clear and recalculate the cache when the attribute is already set but stale" do
# Set the cost
assert @time_entry.save
assert_equal 2000.0, @time_entry.read_attribute(:cost)
@time_entry.reload
@time_entry.hours = 20
assert @time_entry.save
assert_equal 4000.0, @time_entry.read_attribute(:cost)
assert_equal 4000.0, @time_entry.reload.cost
end
end