Commit 61763a24f283751ba478326734c82f0b0f9ac93d

Authored by Diego Camarinha
Committed by Heitor
1 parent ccaa17a7

Extract kalibro configurations metric type check to a helper

Signed-off-by: Heitor Reis <marcheing@gmail.com>
app/helpers/metric_configurations_helper.rb
... ... @@ -25,4 +25,8 @@ module MetricConfigurationsHelper
25 25 kalibro_configuration_new_metric_configuration_path(kalibro_configuration_id: kalibro_configuration_id)
26 26 end
27 27 end
  28 +
  29 + def hotspot_metric_configuration?(metric_configuration)
  30 + metric_configuration.metric.type == 'HotspotMetricSnapshot'
  31 + end
28 32 end
... ...
app/views/kalibro_configurations/_metric_configurations.html.erb
... ... @@ -8,7 +8,7 @@
8 8 <%= link_to_show_page(metric_configuration, @kalibro_configuration.id) %>
9 9 </td>
10 10 <% if kalibro_configuration_owner? @kalibro_configuration.id %>
11   - <% if metric_configuration.metric.type != "HotspotMetricSnapshot" %>
  11 + <% unless hotspot_metric_configuration?(metric_configuration) %>
12 12 <td>
13 13 <%= link_to_edit_form(metric_configuration, @kalibro_configuration.id) %>
14 14 </td>
... ...
spec/helpers/metric_configurations_helper_spec.rb
... ... @@ -63,4 +63,20 @@ describe MetricConfigurationsHelper, :type =&gt; :helper do
63 63 end
64 64 end
65 65 end
  66 +
  67 + describe 'hotspot_metric_configuration?' do
  68 + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
  69 + let(:hotspot_type) { 'HotspotMetricSnapshot' }
  70 + let(:other_type) { 'NativeMetricSnapshot' }
  71 +
  72 + it 'is expected to return true for a HotspotMetricSnapshot' do
  73 + metric_configuration.metric.expects(:type).returns(hotspot_type)
  74 + expect(helper.hotspot_metric_configuration?(metric_configuration)).to eq true
  75 + end
  76 +
  77 + it 'is expected to return false for every other type of metric' do
  78 + metric_configuration.metric.expects(:type).returns(other_type)
  79 + expect(helper.hotspot_metric_configuration?(metric_configuration)).to eq false
  80 + end
  81 + end
66 82 end
... ...