diff options
-rw-r--r-- | .project | 24 | ||||
-rw-r--r-- | app/models/time_entry.rb | 3 | ||||
-rw-r--r-- | test/unit/time_entry_test.rb | 36 |
3 files changed, 63 insertions, 0 deletions
diff --git a/.project b/.project new file mode 100644 index 000000000..67a673a00 --- /dev/null +++ b/.project @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>1.1-stable</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.aptana.ide.core.unifiedBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.aptana.ide.project.nature.web</nature>
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
+ <nature>org.radrails.rails.core.railsnature</nature>
+ </natures>
+</projectDescription>
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index b832277da..ade802868 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -66,6 +66,9 @@ class TimeEntry < ActiveRecord::Base # these attributes make time aggregations easier def spent_on=(date) super + if spent_on.is_a?(Time) + self.spent_on = spent_on.to_date + end self.tyear = spent_on ? spent_on.year : nil self.tmonth = spent_on ? spent_on.month : nil self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil diff --git a/test/unit/time_entry_test.rb b/test/unit/time_entry_test.rb index ef4ad81b2..bd49494c6 100644 --- a/test/unit/time_entry_test.rb +++ b/test/unit/time_entry_test.rb @@ -48,6 +48,42 @@ class TimeEntryTest < ActiveSupport::TestCase def test_hours_should_default_to_nil assert_nil TimeEntry.new.hours end + + def test_spent_on_with_blank + c = TimeEntry.new + c.spent_on = '' + assert_nil c.spent_on + end + + def test_spent_on_with_nil + c = TimeEntry.new + c.spent_on = nil + assert_nil c.spent_on + end + + def test_spent_on_with_string + c = TimeEntry.new + c.spent_on = "2011-01-14" + assert_equal Date.parse("2011-01-14"), c.spent_on + end + + def test_spent_on_with_invalid_string + c = TimeEntry.new + c.spent_on = "foo" + assert_nil c.spent_on + end + + def test_spent_on_with_date + c = TimeEntry.new + c.spent_on = Date.today + assert_equal Date.today, c.spent_on + end + + def test_spent_on_with_time + c = TimeEntry.new + c.spent_on = Time.now + assert_equal Date.today, c.spent_on + end context "#earilest_date_for_project" do setup do |