Skip to content

Commit

Permalink
Extract view logic to a view helper
Browse files Browse the repository at this point in the history
  • Loading branch information
njonsson committed Jul 4, 2009
1 parent 246cec3 commit 4546e6e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/helpers/measurements_helper.rb
Expand Up @@ -2,4 +2,14 @@

# Provides view helpers to MeasurementsController views.
module MeasurementsHelper

def date_time_column_header
header = ''
if @measurements.any? { |m| m.approximate_time? }
header << content_tag(:span, '(≈ Approximate) ', :class => 'approximate')
end
header << 'Date/Time'
header
end

end
5 changes: 1 addition & 4 deletions app/views/measurements/_measurements.html.haml
Expand Up @@ -4,10 +4,7 @@
%thead
%tr
%th{'align' => 'right', 'valign' => 'bottom'}<
- if @measurements.any? { |m| m.approximate_time? }
%span.approximate<
(≈ Approximate)
Date/Time
= date_time_column_header

%th{'align' => 'right', 'valign' => 'bottom'}<
Adjusted Date
Expand Down
26 changes: 25 additions & 1 deletion test/unit/helpers/measurements_helper_test.rb
@@ -1,4 +1,28 @@
require 'test_helper'

class MeasurementsHelperTest < ActionView::TestCase
module MeasurementsHelperTest

class DateTimeColumnHeader < ActionView::TestCase

include MeasurementsHelper

test 'should return expected text when @measurements is empty' do
@measurements = []
assert_equal 'Date/Time', date_time_column_header
end

test 'should return expected text when @measurements contains no approximate times' do
@measurements = [stub(:approximate_time? => false)]
assert_equal 'Date/Time', date_time_column_header
end

test 'should return expected text when @measurements contains both an approximate time and an exact time' do
@measurements = [stub(:approximate_time? => true),
stub(:approximate_time? => false)]
assert_equal '<span class="approximate">(≈ Approximate) </span>Date/Time',
date_time_column_header
end

end

end

0 comments on commit 4546e6e

Please sign in to comment.