Skip to content

Commit

Permalink
Make sure that dates are stored as YYYY-MM-DD in journal details (#12…
Browse files Browse the repository at this point in the history
…713).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11117 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed Jan 4, 2013
1 parent 9a66463 commit 9adb0c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/journal_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ def normalize_values
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
Expand Down
21 changes: 21 additions & 0 deletions test/unit/journal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,25 @@ def test_visible_scope_for_admin
# 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

0 comments on commit 9adb0c6

Please sign in to comment.