]> source.dussan.org Git - redmine.git/commitdiff
Make sure that dates are stored as YYYY-MM-DD in journal details (#12713).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 4 Jan 2013 15:38:52 +0000 (15:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 4 Jan 2013 15:38:52 +0000 (15:38 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11117 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/journal_detail.rb
test/unit/journal_test.rb

index 2c4b3a0bfedf32be2a6228ce6fd83e935154a930..331fb889b9d425c14549ad527f7908d7d81c91d3 100644 (file)
@@ -27,10 +27,13 @@ class JournalDetail < ActiveRecord::Base
   end
 
   def normalize(v)
-    if v == true
+    case v
+    when true
       "1"
-    elsif v == false
+    when false
       "0"
+    when Date
+      v.strftime("%Y-%m-%d")
     else
       v
     end
index bec497f466ab0c081cc4b9ad88fcc48d948f504f..a331c7e0f1cf99ec87aba3afe7b7ad4c2931f4ca 100644 (file)
@@ -154,4 +154,25 @@ class JournalTest < ActiveSupport::TestCase
     # Admin should see issues on private projects that he does not belong to
     assert journals.detect {|journal| !journal.issue.project.is_public?}
   end
+
+  def test_details_should_normalize_dates
+    j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02'))
+    j.reload
+    assert_equal '2012-11-03', j.old_value
+    assert_equal '2013-01-02', j.value
+  end
+
+  def test_details_should_normalize_true_values
+    j = JournalDetail.create!(:old_value => true, :value => true)
+    j.reload
+    assert_equal '1', j.old_value
+    assert_equal '1', j.value
+  end
+
+  def test_details_should_normalize_false_values
+    j = JournalDetail.create!(:old_value => false, :value => false)
+    j.reload
+    assert_equal '0', j.old_value
+    assert_equal '0', j.value
+  end
 end