Skip to content

Commit

Permalink
Pull out this one to a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 16, 2016
1 parent f7bb47e commit c09a3fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ def insulin_for_time
end
'humalog'
end

def class_for_table_cell metric, field
"#{metric.class.name.underscore.gsub('_', '-')}-#{field}"
end
end
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</td>
<% count = 0 %>
<% class_name(value).fields.each do |field| %>
<td class='<%= "#{value.class.name.underscore.gsub('_', '-')}-#{field}" %>'>
<td class='<%= class_for_table_cell value, field %>'>
<% if value.class.units[:applies_to] == field.to_sym %>
<span class='value' data-toggle='tooltip' data-placement='top' title='<%= value.send(field) %> <%= value.class.units[:full] %>'>
<%= value.send(field) %> <%= value.class.units[:short] %>
Expand Down
25 changes: 16 additions & 9 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@

describe '#insulin_for_time' do
it 'defaults to humalog' do
Timecop.freeze 2016, 02, 16, 12, 00
expect(helper.insulin_for_time).to eq 'humalog'
Timecop.return
Timecop.freeze 2016, 02, 16, 12, 00 do
expect(helper.insulin_for_time).to eq 'humalog'
end
end

it 'knows lantus is for bedtime' do
Timecop.freeze 2016, 02, 16, 22, 00
Timecop.freeze 2016, 02, 16, 22, 00 do
expect(helper.insulin_for_time).to eq 'lantus'
Timecop.return
end
end

it 'thinks bedtime lasts until 06:00' do
Timecop.freeze 2016, 02, 16, 06, 00
expect(helper.insulin_for_time).to eq 'lantus'
Timecop.return
Timecop.freeze 2016, 02, 16, 06, 00 do
expect(helper.insulin_for_time).to eq 'lantus'
end
end
end

describe '#class_for_table_cell' do
let(:metric) { build :medication_event }
it 'generates the correct class' do
expect(helper.class_for_table_cell metric, 'insulin').to eq 'medication-event-insulin'
end
end
end

0 comments on commit c09a3fa

Please sign in to comment.