redmine_rate 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/models/rate.rb +3 -0
- data/init.rb +1 -1
- data/lib/rate_time_entry_patch.rb +17 -4
- data/test/unit/lib/rate_time_entry_patch_test.rb +15 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/app/models/rate.rb
CHANGED
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.
|
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 :
|
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
|
-
|
47
|
-
|
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
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-
|
18
|
+
date: 2011-04-28 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|