redmine_rate 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -151,6 +151,9 @@ class Rate < ActiveRecord::Base
151
151
  end
152
152
 
153
153
  if Rails.env.test?
154
+ require 'object_daddy'
155
+ include ObjectDaddy
156
+
154
157
  public
155
158
  generator_for :date_in_effect => Date.today
156
159
  end
data/init.rb CHANGED
@@ -26,7 +26,7 @@ Redmine::Plugin.register :redmine_rate do
26
26
  url 'https://projects.littlestreamsoftware.com/projects/redmine-rate'
27
27
  author_url 'http://www.littlestreamsoftware.com'
28
28
  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."
29
- version '0.2.0'
29
+ version '0.2.1'
30
30
 
31
31
  requires_redmine :version_or_higher => '1.0.0'
32
32
 
@@ -9,7 +9,7 @@ module RateTimeEntryPatch
9
9
  unloadable # Send unloadable so it will not be unloaded in development
10
10
  belongs_to :rate
11
11
 
12
- before_save :cost
12
+ before_save :recalculate_cost
13
13
 
14
14
  end
15
15
 
@@ -32,7 +32,9 @@ module RateTimeEntryPatch
32
32
  # Returns the current cost of the TimeEntry based on it's rate and hours
33
33
  #
34
34
  # Is a read-through cache method
35
- def cost
35
+ def cost(options={})
36
+ store_to_db = options[:store] || false
37
+
36
38
  unless read_attribute(:cost)
37
39
  if self.rate.nil?
38
40
  amount = Rate.amount_for(self.user, self.project, self.spent_on.to_s)
@@ -43,8 +45,13 @@ module RateTimeEntryPatch
43
45
  if amount.nil?
44
46
  write_attribute(:cost, 0.0)
45
47
  else
46
- # Write the cost to the database for caching
47
- update_attribute(:cost, amount.to_f * hours.to_f)
48
+ if store_to_db
49
+ # Write the cost to the database for caching
50
+ update_attribute(:cost, amount.to_f * hours.to_f)
51
+ else
52
+ # Cache to object only
53
+ write_attribute(:cost, amount.to_f * hours.to_f)
54
+ end
48
55
  end
49
56
  end
50
57
 
@@ -59,6 +66,12 @@ module RateTimeEntryPatch
59
66
  clear_cost_cache
60
67
  update_attribute(:cost, cost)
61
68
  end
69
+
70
+ def recalculate_cost
71
+ clear_cost_cache
72
+ cost(:store => false)
73
+ true # for callback
74
+ end
62
75
 
63
76
  end
64
77
  end
@@ -71,6 +71,21 @@ class RateTimeEntryPatchTest < ActiveSupport::TestCase
71
71
 
72
72
  assert_equal 2000.0, @time_entry.read_attribute(:cost)
73
73
  end
74
+
75
+ should "clear and recalculate the cache when the attribute is already set but stale" do
76
+ # Set the cost
77
+ assert @time_entry.save
78
+ assert_equal 2000.0, @time_entry.read_attribute(:cost)
79
+
80
+ @time_entry.reload
81
+ @time_entry.hours = 20
82
+ assert @time_entry.save
83
+
84
+ assert_equal 4000.0, @time_entry.read_attribute(:cost)
85
+ assert_equal 4000.0, @time_entry.reload.cost
86
+ end
87
+
88
+
74
89
  end
75
90
 
76
91
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_rate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Davis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-03 00:00:00 -08:00
18
+ date: 2011-04-28 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21