Commit 3d56744a525c13b3b28030d89ffdfe8ea986416b

Authored by Rafael Manzo
Committed by Daniel
1 parent 25cbbb33

Add action_path parameter to choose_metric

This will enable different actions for TreeMetricConfigurations and
Hotspot ones.

Signed off by: Diego Araújo <diegoamc90@gmail.com>
app/assets/javascripts/metric_collector.js.coffee
1 class @MetricCollector 1 class @MetricCollector
2 2
3 # Static Method 3 # Static Method
4 - @choose_metric: (metric_code, metric_collector_name) -> 4 + @choose_metric: (metric_code, metric_collector_name, action_path) ->
5 $("#metric_code").val(metric_code) 5 $("#metric_code").val(metric_code)
6 $("#metric_collector_name").val(metric_collector_name) 6 $("#metric_collector_name").val(metric_collector_name)
  7 + $("form").attr('action', action_path)
7 $("form").submit() 8 $("form").submit()
spec/javascripts/metric_collector_spec.js.coffee
@@ -16,15 +16,18 @@ describe &quot;MetricCollector&quot;, -&gt; @@ -16,15 +16,18 @@ describe &quot;MetricCollector&quot;, -&gt;
16 16
17 @form = sinon.stub() 17 @form = sinon.stub()
18 @form.submit = sinon.stub() 18 @form.submit = sinon.stub()
  19 + @action_path = '/en/kalibro_configurations/1/metric_configurations/new'
  20 + @form.attr = sinon.stub().withArgs('action', @action_path)
19 21
20 $.withArgs("#metric_code").returns(@metric_code_field) 22 $.withArgs("#metric_code").returns(@metric_code_field)
21 $.withArgs("#metric_collector_name").returns(@metric_collector_name_field) 23 $.withArgs("#metric_collector_name").returns(@metric_collector_name_field)
22 $.withArgs("form").returns(@form) 24 $.withArgs("form").returns(@form)
23 25
24 it 'is expected to fill in the form and submit', -> 26 it 'is expected to fill in the form and submit', ->
25 - MetricCollector.choose_metric(@metric_code, @metric_collector_name) 27 + MetricCollector.choose_metric(@metric_code, @metric_collector_name, @action_path)
26 28
27 sinon.assert.calledOnce(@metric_code_field.val, @metric_code) 29 sinon.assert.calledOnce(@metric_code_field.val, @metric_code)
28 sinon.assert.calledOnce(@metric_collector_name_field.val, @metric_collector_name) 30 sinon.assert.calledOnce(@metric_collector_name_field.val, @metric_collector_name)
29 sinon.assert.calledOnce(@form.submit) 31 sinon.assert.calledOnce(@form.submit)
  32 + sinon.assert.calledOnce(@form.attr, 'action', @action_path)
30 33