Commit 43a656396000b003d5779914dc7098b85d3cc265
Committed by
Daniel
1 parent
07fca75c
Exists in
colab
and in
4 other branches
Add helper to return the metric creation path
To decide betwen the different routes for tree metrics or hotspot metrics. Signed off by: Rafael Reggiani Manzo <rr.manzo@gmail.com>
Showing
2 changed files
with
28 additions
and
0 deletions
Show diff stats
app/helpers/metric_configurations_helper.rb
| ... | ... | @@ -17,4 +17,12 @@ module MetricConfigurationsHelper |
| 17 | 17 | # find_by_name throws an exception instead of returning nil, unlike ActiveRecord's API |
| 18 | 18 | KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name(metric_collector_name).supported_metrics |
| 19 | 19 | end |
| 20 | + | |
| 21 | + def choose_metric_path(metric, kalibro_configuration_id) | |
| 22 | + if metric.type == 'HotspotMetricSnapshot' | |
| 23 | + kalibro_configuration_hotspot_metric_configurations_path(kalibro_configuration_id: kalibro_configuration_id) | |
| 24 | + else | |
| 25 | + kalibro_configuration_new_metric_configuration_path(kalibro_configuration_id: kalibro_configuration_id) | |
| 26 | + end | |
| 27 | + end | |
| 20 | 28 | end | ... | ... |
spec/helpers/metric_configurations_helper_spec.rb
| ... | ... | @@ -43,4 +43,24 @@ describe MetricConfigurationsHelper, :type => :helper do |
| 43 | 43 | expect(helper.supported_metrics_of(metric_collector_details.name)).to eq(metric_collector_details.supported_metrics) |
| 44 | 44 | end |
| 45 | 45 | end |
| 46 | + | |
| 47 | + describe 'choose_metric_path' do | |
| 48 | + let(:kalibro_configuration_id) { 1 } | |
| 49 | + | |
| 50 | + context 'with a tree metric' do | |
| 51 | + let(:metric) { FactoryGirl.build(:loc) } | |
| 52 | + | |
| 53 | + it 'is expected to generate the path for MetricConfigurationsController' do | |
| 54 | + expect(helper.choose_metric_path(metric, kalibro_configuration_id)).to eq(helper.kalibro_configuration_new_metric_configuration_path(kalibro_configuration_id: kalibro_configuration_id)) | |
| 55 | + end | |
| 56 | + end | |
| 57 | + | |
| 58 | + context 'with a hotspot metric' do | |
| 59 | + let(:metric) { FactoryGirl.build(:hotspot_metric) } | |
| 60 | + | |
| 61 | + it 'is expected to generate the path for HotspotMetricConfigurationsController' do | |
| 62 | + expect(helper.choose_metric_path(metric, kalibro_configuration_id)).to eq(helper.kalibro_configuration_hotspot_metric_configurations_path(kalibro_configuration_id: kalibro_configuration_id)) | |
| 63 | + end | |
| 64 | + end | |
| 65 | + end | |
| 46 | 66 | end | ... | ... |