Commit 76490fcd authored by Holger Just's avatar Holger Just

Merge remote-tracking branch 'finnlabs/pulls/539/cleanup-issue_helper-show_detail'

parents e2d16e13 008a29dc
......@@ -129,82 +129,6 @@ module IssuesHelper
out
end
def show_detail(detail, no_html=false)
case detail.property
when 'attr'
field = detail.prop_key.to_s.gsub(/\_id$/, "")
label = l(("field_" + field).to_sym)
case
when ['due_date', 'start_date'].include?(detail.prop_key)
value = format_date(detail.value.to_date) if detail.value
old_value = format_date(detail.old_value.to_date) if detail.old_value
when ['project_id', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key)
value = find_name_by_reflection(field, detail.value)
old_value = find_name_by_reflection(field, detail.old_value)
when detail.prop_key == 'estimated_hours'
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
when detail.prop_key == 'parent_id'
label = l(:field_parent_issue)
value = "##{detail.value}" unless detail.value.blank?
old_value = "##{detail.old_value}" unless detail.old_value.blank?
end
when 'cf'
custom_field = CustomField.find_by_id(detail.prop_key)
if custom_field
label = custom_field.name
value = format_value(detail.value, custom_field.field_format) if detail.value
old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
end
when 'attachment'
label = l(:label_attachment)
end
call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
label ||= detail.prop_key
value ||= detail.value
old_value ||= detail.old_value
unless no_html
label = content_tag('strong', label)
old_value = content_tag("i", h(old_value)) if detail.old_value
old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
value = link_to_attachment(a)
else
value = content_tag("i", h(value)) if value
end
end
if detail.property == 'attr' && detail.prop_key == 'description'
s = l(:text_journal_changed_no_detail, :label => label)
unless no_html
diff_link = link_to 'diff',
{:controller => 'journals', :action => 'diff', :id => detail.journal_id, :detail_id => detail.id},
:title => l(:label_view_diff)
s << " (#{ diff_link })"
end
s
elsif !detail.value.blank?
case detail.property
when 'attr', 'cf'
if !detail.old_value.blank?
l(:text_journal_changed, :label => label, :old => old_value, :new => value)
else
l(:text_journal_set_to, :label => label, :value => value)
end
when 'attachment'
l(:text_journal_added, :label => label, :value => value)
end
else
l(:text_journal_deleted, :label => label, :old => old_value)
end
end
# Find the name of an associated record stored in the field attribute
def find_name_by_reflection(field, id)
association = Issue.reflect_on_association(field.to_sym)
......
......@@ -39,33 +39,30 @@ class IssuesHelperTest < HelperTestCase
@request ||= ActionController::TestRequest.new
end
# This is probably needed in this test only anymore
def show_detail(journal, detail, html = true)
journal.render_detail(detail, html)
end
# TODO: Move test code to Journal class
context "IssuesHelper#show_detail" do
context "with no_html" do
should 'show a changing attribute' do
@journal = IssueJournal.generate!(:changes => {"done_ratio" => [40, 100]}, :journaled => Issue.last)
assert_equal "% Done changed from 40 to 100", show_detail(@journal, @journal.details.to_a.first, true)
assert_equal "% Done changed from 40 to 100", @journal.render_detail(@journal.details.to_a.first, true)
end
should 'show a new attribute' do
@journal = IssueJournal.generate!(:changes => {"done_ratio" => [nil, 100]}, :journaled => Issue.last)
assert_equal "% Done set to 100", show_detail(@journal, @journal.details.to_a.first, true)
assert_equal "% Done set to 100", @journal.render_detail(@journal.details.to_a.first, true)
end
should 'show a deleted attribute' do
@journal = IssueJournal.generate!(:changes => {"done_ratio" => [50, nil]}, :journaled => Issue.last)
assert_equal "% Done deleted (50)", show_detail(@journal, @journal.details.to_a.first, true)
assert_equal "% Done deleted (50)", @journal.render_detail(@journal.details.to_a.first, true)
end
end
context "with html" do
should 'show a changing attribute with HTML highlights' do
@journal = IssueJournal.generate!(:changes => {"done_ratio" => [40, 100]}, :journaled => Issue.last)
@response.body = show_detail(@journal, @journal.details.to_a.first, false)
@response.body = @journal.render_detail(@journal.details.to_a.first, false)
assert_select 'strong', :text => '% Done'
assert_select 'i', :text => '40'
......@@ -74,7 +71,7 @@ class IssuesHelperTest < HelperTestCase
should 'show a new attribute with HTML highlights' do
@journal = IssueJournal.generate!(:changes => {"done_ratio" => [nil, 100]}, :journaled => Issue.last)
@response.body = show_detail(@journal, @journal.details.to_a.first, false)
@response.body = @journal.render_detail(@journal.details.to_a.first, false)
assert_select 'strong', :text => '% Done'
assert_select 'i', :text => '100'
......@@ -82,7 +79,7 @@ class IssuesHelperTest < HelperTestCase
should 'show a deleted attribute with HTML highlights' do
@journal = IssueJournal.generate!(:changes => {"done_ratio" => [50, nil]}, :journaled => Issue.last)
@response.body = show_detail(@journal, @journal.details.to_a.first, false)
@response.body = @journal.render_detail(@journal.details.to_a.first, false)
assert_select 'strong', :text => '% Done'
assert_select 'strike' do
......@@ -94,24 +91,24 @@ class IssuesHelperTest < HelperTestCase
context "with a start_date attribute" do
should "format the current date" do
@journal = IssueJournal.generate!(:changes => {"start_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/31/2010", show_detail(@journal, @journal.details.to_a.first, true)
assert_match "01/31/2010", @journal.render_detail(@journal.details.to_a.first, true)
end
should "format the old date" do
@journal = IssueJournal.generate!(:changes => {"start_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/01/2010", show_detail(@journal, @journal.details.to_a.first, true)
assert_match "01/01/2010", @journal.render_detail(@journal.details.to_a.first, true)
end
end
context "with a due_date attribute" do
should "format the current date" do
@journal = IssueJournal.generate!(:changes => {"due_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/31/2010", show_detail(@journal, @journal.details.to_a.first, true)
assert_match "01/31/2010", @journal.render_detail(@journal.details.to_a.first, true)
end
should "format the old date" do
@journal = IssueJournal.generate!(:changes => {"due_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/01/2010", show_detail(@journal, @journal.details.to_a.first, true)
assert_match "01/01/2010", @journal.render_detail(@journal.details.to_a.first, true)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment