From 61763a24f283751ba478326734c82f0b0f9ac93d Mon Sep 17 00:00:00 2001 From: Diego Araújo Date: Fri, 22 Jan 2016 14:34:25 -0200 Subject: [PATCH] Extract kalibro configurations metric type check to a helper --- app/helpers/metric_configurations_helper.rb | 4 ++++ app/views/kalibro_configurations/_metric_configurations.html.erb | 2 +- spec/helpers/metric_configurations_helper_spec.rb | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/helpers/metric_configurations_helper.rb b/app/helpers/metric_configurations_helper.rb index 69cfceb..6775364 100644 --- a/app/helpers/metric_configurations_helper.rb +++ b/app/helpers/metric_configurations_helper.rb @@ -25,4 +25,8 @@ module MetricConfigurationsHelper kalibro_configuration_new_metric_configuration_path(kalibro_configuration_id: kalibro_configuration_id) end end + + def hotspot_metric_configuration?(metric_configuration) + metric_configuration.metric.type == 'HotspotMetricSnapshot' + end end diff --git a/app/views/kalibro_configurations/_metric_configurations.html.erb b/app/views/kalibro_configurations/_metric_configurations.html.erb index a06c613..3a51561 100644 --- a/app/views/kalibro_configurations/_metric_configurations.html.erb +++ b/app/views/kalibro_configurations/_metric_configurations.html.erb @@ -8,7 +8,7 @@ <%= link_to_show_page(metric_configuration, @kalibro_configuration.id) %> <% if kalibro_configuration_owner? @kalibro_configuration.id %> - <% if metric_configuration.metric.type != "HotspotMetricSnapshot" %> + <% unless hotspot_metric_configuration?(metric_configuration) %> <%= link_to_edit_form(metric_configuration, @kalibro_configuration.id) %> diff --git a/spec/helpers/metric_configurations_helper_spec.rb b/spec/helpers/metric_configurations_helper_spec.rb index 3462ac6..2d16a25 100644 --- a/spec/helpers/metric_configurations_helper_spec.rb +++ b/spec/helpers/metric_configurations_helper_spec.rb @@ -63,4 +63,20 @@ describe MetricConfigurationsHelper, :type => :helper do end end end + + describe 'hotspot_metric_configuration?' do + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } + let(:hotspot_type) { 'HotspotMetricSnapshot' } + let(:other_type) { 'NativeMetricSnapshot' } + + it 'is expected to return true for a HotspotMetricSnapshot' do + metric_configuration.metric.expects(:type).returns(hotspot_type) + expect(helper.hotspot_metric_configuration?(metric_configuration)).to eq true + end + + it 'is expected to return false for every other type of metric' do + metric_configuration.metric.expects(:type).returns(other_type) + expect(helper.hotspot_metric_configuration?(metric_configuration)).to eq false + end + end end -- libgit2 0.21.2