@@ -66,6 +66,9 class TimeEntry < ActiveRecord::Base | |||||
66 | # these attributes make time aggregations easier |
|
66 | # these attributes make time aggregations easier | |
67 | def spent_on=(date) |
|
67 | def spent_on=(date) | |
68 | super |
|
68 | super | |
|
69 | if spent_on.is_a?(Time) | |||
|
70 | self.spent_on = spent_on.to_date | |||
|
71 | end | |||
69 | self.tyear = spent_on ? spent_on.year : nil |
|
72 | self.tyear = spent_on ? spent_on.year : nil | |
70 | self.tmonth = spent_on ? spent_on.month : nil |
|
73 | self.tmonth = spent_on ? spent_on.month : nil | |
71 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil |
|
74 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil |
@@ -48,6 +48,36 class TimeEntryTest < ActiveSupport::TestCase | |||||
48 | def test_hours_should_default_to_nil |
|
48 | def test_hours_should_default_to_nil | |
49 | assert_nil TimeEntry.new.hours |
|
49 | assert_nil TimeEntry.new.hours | |
50 | end |
|
50 | end | |
|
51 | ||||
|
52 | def test_spent_on_with_blank | |||
|
53 | c = TimeEntry.new | |||
|
54 | c.spent_on = '' | |||
|
55 | assert_nil c.spent_on | |||
|
56 | end | |||
|
57 | ||||
|
58 | def test_spent_on_with_nil | |||
|
59 | c = TimeEntry.new | |||
|
60 | c.spent_on = nil | |||
|
61 | assert_nil c.spent_on | |||
|
62 | end | |||
|
63 | ||||
|
64 | def test_spent_on_with_string | |||
|
65 | c = TimeEntry.new | |||
|
66 | c.spent_on = "2011-01-14" | |||
|
67 | assert_equal Date.parse("2011-01-14"), c.spent_on | |||
|
68 | end | |||
|
69 | ||||
|
70 | def test_spent_on_with_date | |||
|
71 | c = TimeEntry.new | |||
|
72 | c.spent_on = Date.today | |||
|
73 | assert_equal Date.today, c.spent_on | |||
|
74 | end | |||
|
75 | ||||
|
76 | def test_spent_on_with_time | |||
|
77 | c = TimeEntry.new | |||
|
78 | c.spent_on = Time.now | |||
|
79 | assert_equal Date.today, c.spent_on | |||
|
80 | end | |||
51 |
|
81 | |||
52 | context "#earilest_date_for_project" do |
|
82 | context "#earilest_date_for_project" do | |
53 | setup do |
|
83 | setup do |
General Comments 0
You need to be logged in to leave comments.
Login now