Commit 76f431cb6fb551456d1f440c925af01f629bfc34
Committed by
Rafael Manzo
1 parent
30bc795d
Exists in
colab
and in
4 other branches
Edit for compound metrics.
Missing unit tests and acceptance tests. signed-off-by: Diego Araújo <diegoamc90@gmail.com>
Showing
8 changed files
with
41 additions
and
25 deletions
Show diff stats
app/controllers/compound_metric_configurations_controller.rb
... | ... | @@ -4,8 +4,8 @@ include MetricConfigurationsConcern |
4 | 4 | class CompoundMetricConfigurationsController < ApplicationController |
5 | 5 | before_action :authenticate_user!, except: [:index] |
6 | 6 | before_action :mezuro_configuration_owner?, only: [:new, :create] |
7 | - before_action :metric_configuration_owner?, only: [:edit] | |
8 | - before_action :set_metric_configuration, only: [:edit] | |
7 | + before_action :metric_configuration_owner?, only: [:edit, :update] | |
8 | + before_action :set_metric_configuration, only: [:edit, :update] | |
9 | 9 | before_action :set_metric_configurations, only: [:new, :edit] |
10 | 10 | |
11 | 11 | # GET mezuro_configurations/1/compound_metric_configurations/new |
... | ... | @@ -28,6 +28,10 @@ class CompoundMetricConfigurationsController < ApplicationController |
28 | 28 | @compound_metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i |
29 | 29 | end |
30 | 30 | |
31 | + def update | |
32 | + update_metric_configuration | |
33 | + end | |
34 | + | |
31 | 35 | private |
32 | 36 | |
33 | 37 | # Never trust parameters from the scary internet, only allow the white list through. | ... | ... |
app/controllers/concerns/metric_configurations_concern.rb
... | ... | @@ -4,4 +4,16 @@ module MetricConfigurationsConcern |
4 | 4 | def set_metric_configuration |
5 | 5 | @metric_configuration = MetricConfiguration.find(params[:id].to_i) |
6 | 6 | end |
7 | -end | |
8 | 7 | \ No newline at end of file |
8 | + | |
9 | + def update_metric_configuration | |
10 | + respond_to do |format| | |
11 | + @metric_configuration.configuration_id = params[:mezuro_configuration_id] | |
12 | + if @metric_configuration.update(metric_configuration_params) | |
13 | + format.html { redirect_to(mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') } | |
14 | + format.json { head :no_content } | |
15 | + else | |
16 | + failed_action(format, 'edit') | |
17 | + end | |
18 | + end | |
19 | + end | |
20 | +end | ... | ... |
app/controllers/metric_configurations_controller.rb
... | ... | @@ -36,15 +36,7 @@ class MetricConfigurationsController < ApplicationController |
36 | 36 | end |
37 | 37 | |
38 | 38 | def update |
39 | - respond_to do |format| | |
40 | - @metric_configuration.configuration_id = params[:mezuro_configuration_id] | |
41 | - if @metric_configuration.update(metric_configuration_params) | |
42 | - format.html { redirect_to(mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') } | |
43 | - format.json { head :no_content } | |
44 | - else | |
45 | - failed_action(format, 'edit') | |
46 | - end | |
47 | - end | |
39 | + update_metric_configuration | |
48 | 40 | end |
49 | 41 | |
50 | 42 | def destroy |
... | ... | @@ -58,6 +50,7 @@ class MetricConfigurationsController < ApplicationController |
58 | 50 | private |
59 | 51 | |
60 | 52 | # Never trust parameters from the scary internet, only allow the white list through. |
53 | + # TODO: this should be refactored to the concern metric configuration | |
61 | 54 | def metric_configuration_params |
62 | 55 | params[:metric_configuration] |
63 | 56 | end | ... | ... |
app/views/compound_metric_configurations/_form.html.erb
1 | 1 | <%= render :partial => 'shared/form_errors', :locals => {:object => @compound_metric_configuration} %> |
2 | 2 | |
3 | 3 | <%= f.fields_for :metric do |metric| %> |
4 | - <%= render "metric_options", :f => metric %> | |
4 | + <%= render partial: "metric_options", :locals => {:f => metric, :metric => @compound_metric_configuration.metric} %> | |
5 | 5 | <% end %> |
6 | 6 | |
7 | 7 | <div class="form-group"> |
... | ... | @@ -30,4 +30,4 @@ |
30 | 30 | |
31 | 31 | <br> |
32 | 32 | <%= f.submit 'Save', class: 'btn btn-primary' %> |
33 | -<%= link_to 'Back', mezuro_configuration_choose_metric_path(@compound_metric_configuration.configuration_id), class: 'btn btn-default' %> | |
33 | +<%= link_to 'Back', mezuro_configuration_path(@metric_configuration.configuration_id), class: 'btn btn-default' %> | ... | ... |
app/views/compound_metric_configurations/_metric_options.html.erb
1 | 1 | <div class="form-group"> |
2 | 2 | <%= f.label :name, class: 'control-label' %> |
3 | - <%= f.text_field :name, class: 'form-control' %> | |
3 | + <%= f.text_field :name, class: 'form-control', value: (metric.name unless metric.nil?) %> | |
4 | 4 | </div> |
5 | 5 | |
6 | 6 | <div class="form-group"> |
7 | 7 | <%= f.label :description, class: 'control-label' %> |
8 | - <%= f.text_field :description, class: 'form-control' %> | |
8 | + <%= f.text_field :description, class: 'form-control', value: (metric.description unless metric.nil?) %> | |
9 | 9 | </div> |
10 | 10 | |
11 | 11 | <div class="form-group"> |
12 | 12 | <%= f.label :script, class: 'control-label' %> |
13 | - <%= f.text_area :script, class: 'form-control' %> | |
13 | + <%= f.text_area :script, class: 'form-control', value: (metric.script unless metric.nil?) %> | |
14 | 14 | </div> |
15 | 15 | |
16 | 16 | <div class="form-group"> |
17 | 17 | <%= f.label :scope, 'Scope', class: 'control-label' %> |
18 | - <%= f.select( :scope, scope_options, {class: 'form-control'} ) %> | |
18 | + <%= f.select( :scope, scope_options, {class: 'form-control', selected: (metric.scope unless metric.nil?)} ) %> | |
19 | 19 | </div> |
20 | + | |
21 | +<%= f.hidden_field(:compound, { value: "true"}) %> | ... | ... |
app/views/compound_metric_configurations/edit.html.erb
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | |
7 | 7 | <br> |
8 | 8 | |
9 | -<%= form_for(@compound_metric_configuration, :url => mezuro_configuration_compound_metric_configuration_update_path(@compound_metric_configuration.configuration_id, @compound_metric_configuration.id)) do |f| %> | |
9 | +<%= form_for(@compound_metric_configuration, :url => mezuro_configuration_compound_metric_configuration_update_url(@compound_metric_configuration.configuration_id, @compound_metric_configuration.id), method: :put) do |f| %> | |
10 | 10 | <%= render partial: 'form', locals: {f: f} %> |
11 | 11 | <% end %> |
12 | 12 | |
... | ... | @@ -18,4 +18,4 @@ |
18 | 18 | collapsible: true, |
19 | 19 | }); |
20 | 20 | }); |
21 | -</script> | |
22 | 21 | \ No newline at end of file |
22 | +</script> | ... | ... |
features/compound_metric_configuration/edition.feature
... | ... | @@ -15,7 +15,7 @@ Feature: Compound Metric Configuration edition |
15 | 15 | Then I should not see "Edit" |
16 | 16 | |
17 | 17 | @kalibro_restart |
18 | - Scenario: editing a metric configuration successfully | |
18 | + Scenario: editing a compound metric configuration successfully | |
19 | 19 | Given I am a regular user |
20 | 20 | And I am signed in |
21 | 21 | And I own a sample configuration |
... | ... | @@ -23,10 +23,11 @@ Feature: Compound Metric Configuration edition |
23 | 23 | And I have a sample metric configuration within the given mezuro configuration |
24 | 24 | And I have a sample compound metric configuration within the given mezuro configuration |
25 | 25 | And I am at the Sample Configuration page |
26 | - When I click the Edit link | |
27 | - And I fill the Code field with "Another_Code" | |
26 | + When I click the edit link of the Coumpound Metric | |
27 | + And I fill the Script field with "Another javascript" | |
28 | + And I fill the Code field with "Another_code" | |
28 | 29 | And I press the Save button |
29 | - Then I should see "Another_Code" | |
30 | + Then I should see "Another_code" | |
30 | 31 | |
31 | 32 | @kalibro_restart @wip |
32 | 33 | Scenario: trying to edit with an existing code |
... | ... | @@ -55,4 +56,4 @@ Feature: Compound Metric Configuration edition |
55 | 56 | And I fill the Weight field with " " |
56 | 57 | And I press the Save button |
57 | 58 | Then I should see "Code can't be blank" |
58 | - And I should see "Weight can't be blank" | |
59 | 59 | \ No newline at end of file |
60 | + And I should see "Weight can't be blank" | ... | ... |
features/step_definitions/compound_metric_configuration_steps.rb
... | ... | @@ -17,3 +17,7 @@ end |
17 | 17 | When(/^I visit the sample compound metric configuration edit page$/) do |
18 | 18 | visit edit_mezuro_configuration_compound_metric_configuration_path(@compound_metric_configuration.configuration_id, @compound_metric_configuration.id) |
19 | 19 | end |
20 | + | |
21 | +When(/^I click the edit link of the Coumpound Metric$/) do | |
22 | + page.find('tr', :text => @compound_metric_configuration.metric.name).click_link('Edit') | |
23 | +end | ... | ... |