Commit 5659d0a3ea53297fe3ee0c030f204aa833dd7fde

Authored by Rafael Manzo
1 parent 8be8048a

Fixes KalibroRange creation and edition through kalibro_client conversions

Signed off by: Heitor Reis <marcheing@gmail.com>
app/helpers/kalibro_ranges_helper.rb
@@ -2,4 +2,12 @@ module KalibroRangesHelper @@ -2,4 +2,12 @@ module KalibroRangesHelper
2 def readings_options(readings) 2 def readings_options(readings)
3 readings.map { |reading| [reading.label, reading.id] } 3 readings.map { |reading| [reading.label, reading.id] }
4 end 4 end
  5 +
  6 + # FIXME: this is a workaround while kalibro_client does not handle Infinity text instead of INF
  7 + # see: https://github.com/mezuro/kalibro_client/issues/73
  8 + def format_boundary(value)
  9 + return "INF" if value == Float::INFINITY
  10 + return "-INF" if value == -Float::INFINITY
  11 + value
  12 + end
5 end 13 end
app/views/metric_configurations/_ranges.html.erb
@@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@
5 <span style="color: #<%= kalibro_range.color %>"><%= kalibro_range.label %></span> 5 <span style="color: #<%= kalibro_range.color %>"><%= kalibro_range.label %></span>
6 </div> 6 </div>
7 </td> 7 </td>
8 - <td><%= kalibro_range.beginning %></td>  
9 - <td><%= kalibro_range.end %></td> 8 + <td><%= format_boundary(kalibro_range.beginning) %></td>
  9 + <td><%= format_boundary(kalibro_range.end) %></td>
10 <td> 10 <td>
11 <% if kalibro_configuration_owner? @metric_configuration.kalibro_configuration_id %> 11 <% if kalibro_configuration_owner? @metric_configuration.kalibro_configuration_id %>
12 <%= link_to t('edit'), edit_kalibro_configuration_metric_configuration_kalibro_range_path( 12 <%= link_to t('edit'), edit_kalibro_configuration_metric_configuration_kalibro_range_path(
spec/helpers/kalibro_ranges_helper_spec.rb
@@ -7,5 +7,31 @@ describe KalibroRangesHelper, :type =&gt; :helper do @@ -7,5 +7,31 @@ describe KalibroRangesHelper, :type =&gt; :helper do
7 expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]] 7 expect(helper.readings_options([reading])).to eq [[reading.label, reading.id]]
8 end 8 end
9 end 9 end
  10 +
  11 + describe 'format_boundary' do
  12 + context 'with a finite value' do
  13 + let(:value) { 10 }
  14 +
  15 + it 'is expected to return the value itself' do
  16 + expect(helper.format_boundary(value)).to eq(value)
  17 + end
  18 + end
  19 +
  20 + context 'with positive infinity value' do
  21 + let(:value) { Float::INFINITY }
  22 +
  23 + it 'is expected to return the string "INF"' do
  24 + expect(helper.format_boundary(value)).to eq("INF")
  25 + end
  26 + end
  27 +
  28 + context 'with negative infinity value' do
  29 + let(:value) { -Float::INFINITY }
  30 +
  31 + it 'is expected to return the string "-INF"' do
  32 + expect(helper.format_boundary(value)).to eq("-INF")
  33 + end
  34 + end
  35 + end
10 end 36 end
11 37