Skip to content

Commit

Permalink
More test fixes, more helper cleanup.
Browse files Browse the repository at this point in the history
Bridge method to get breadcrumbs from controller to helper in header.
  • Loading branch information
Doug Rand committed Feb 13, 2012
1 parent e98578c commit 93bdd8c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ GEM
i18n (0.6.0)
journey (1.0.1)
jquery-rails (2.0.0)
railties (< 5.0, >= 3.2.0.beta)
railties (>= 3.2.0.beta, < 5.0)
thor (~> 0.14)
json (1.6.5)
launchy (2.0.5)
Expand Down Expand Up @@ -199,7 +199,7 @@ GEM
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1)
tilt (~> 1.1, != 1.3.0)
systemu (2.4.2)
term-ansicolor (1.0.7)
therubyracer (0.9.9)
Expand Down
14 changes: 6 additions & 8 deletions app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def section_enumerator record, section, earliest
end
end

# Return the sex character from the "gender" field
def sex record
record.gender
end
Expand All @@ -49,11 +50,7 @@ def latest_matching_vital record, name
end
end
if match
value = match.value
rval = value['scalar']
rval = rval.to_s
rval += " " + value['units'] if value['units']
rval
show_value match.value
else
""
end
Expand Down Expand Up @@ -84,12 +81,13 @@ def most_recent_vital_date record
end

# Takes the value portion of a record and formats it
def lab_result_value value
def show_value value
return "" unless value
scalar = value['scalar']
units = value['units']
scalar = scalar.to_s
return "" unless scalar
return "<span class='lab_value'>" + scalar + "</span>".html_safe unless units
return "<span class='lab_value'>" + scalar + "(" + units + ")</span>".html_safe unless units
return ("<span class='lab_value'>" + scalar + "</span>").html_safe unless units
return ("<span class='lab_value'>" + scalar + "&nbps;(" + units + ")</span>").html_safe
end
end
5 changes: 5 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<%
def breadcrumbs
controller.breadcrumbs
end
%>
<div id="page_header">
<% unless current_user.nil? || current_user.username.nil? %>
<a href="#">Logout</a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<% end %>
<h2>Lab Results</h2>
<% section_enumerator(@record, :results, earliest) do |x| %>
<%= labeled_field(x['description'] + lab_result_value(x['value']), date(x['time'])) %>
<%= labeled_field(x['description'] + show_value(x['value']), date(x['time'])) %>
<% end %>
</div>

Expand Down
12 changes: 11 additions & 1 deletion test/unit/helpers/record_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ class RecordHelperTest < ActionView::TestCase
vs3 = FactoryGirl.create(:lab_result)
rec.vital_signs.concat([ vs1, vs2, vs3 ])
v = latest_matching_vital rec, 'ldl'
assert_equal "127 mg/dL", v
assert_equal "<span class='lab_value'>127&nbps;(mg/dL)</span>", v
end

test "sex method" do
rec = FactoryGirl.create(:record)
assert_equal "M", sex(rec)
end

test "format a value" do
r = FactoryGirl.create(:lab_result)
assert_equal "<span class='lab_value'>127&nbps;(mg/dL)</span>", show_value(r.value)
end
end

0 comments on commit 93bdd8c

Please sign in to comment.