Commit cec21e7da4df80d436e931ea63a5bd8f39b1fffd

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent 76f431cb

Edit and update for compound metric configurations.

signed-off-by: Fellipe Souto <fllsouto@gmail.com>
app/controllers/compound_metric_configurations_controller.rb
... ... @@ -28,10 +28,6 @@ class CompoundMetricConfigurationsController &lt; 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   -
35 31 private
36 32  
37 33 # Never trust parameters from the scary internet, only allow the white list through.
... ... @@ -43,6 +39,7 @@ class CompoundMetricConfigurationsController &lt; ApplicationController
43 39 def failed_action(format, destiny_action)
44 40 @mezuro_configuration_id = params[:mezuro_configuration_id]
45 41  
  42 + set_metric_configurations
46 43 format.html { render action: destiny_action }
47 44 format.json { render json: @compound_metric_configuration.errors, status: :unprocessable_entity }
48 45 end
... ...
app/controllers/concerns/metric_configurations_concern.rb
... ... @@ -4,16 +4,4 @@ module MetricConfigurationsConcern
4 4 def set_metric_configuration
5 5 @metric_configuration = MetricConfiguration.find(params[:id].to_i)
6 6 end
7   -
8   - def update_metric_configuration
9   - respond_to do |format|
10   - @metric_configuration.configuration_id = params[:mezuro_configuration_id]
11   - if @metric_configuration.update(metric_configuration_params)
12   - format.html { redirect_to(mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') }
13   - format.json { head :no_content }
14   - else
15   - failed_action(format, 'edit')
16   - end
17   - end
18   - end
19 7 end
... ...
app/controllers/metric_configurations_controller.rb
... ... @@ -36,7 +36,15 @@ class MetricConfigurationsController &lt; ApplicationController
36 36 end
37 37  
38 38 def update
39   - update_metric_configuration
  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
40 48 end
41 49  
42 50 def destroy
... ...
app/views/compound_metric_configurations/_form.html.erb
... ... @@ -30,4 +30,4 @@
30 30  
31 31 <br>
32 32 <%= f.submit 'Save', class: 'btn btn-primary' %>
33   -<%= link_to 'Back', mezuro_configuration_path(@metric_configuration.configuration_id), class: 'btn btn-default' %>
  33 +<%= link_to 'Back', mezuro_configuration_path(@compound_metric_configuration.configuration_id), class: 'btn btn-default' %>
... ...
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_url(@compound_metric_configuration.configuration_id, @compound_metric_configuration.id), method: :put) do |f| %>
  9 +<%= form_for(@compound_metric_configuration, :url => mezuro_configuration_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  
... ...
features/compound_metric_configuration/edition.feature
... ... @@ -29,31 +29,32 @@ Feature: Compound Metric Configuration edition
29 29 And I press the Save button
30 30 Then I should see "Another_code"
31 31  
32   - @kalibro_restart @wip
33   - Scenario: trying to edit with an existing code
  32 + @kalibro_restart
  33 + Scenario: trying to edit with blank fields
34 34 Given I am a regular user
35 35 And I am signed in
36 36 And I own a sample configuration
37 37 And I have a sample reading group
38 38 And I have a sample metric configuration within the given mezuro configuration
39 39 And I have a sample compound metric configuration within the given mezuro configuration
40   - And I have another compound metric configuration with code "Another_Code" within the given mezuro configuration
41 40 When I visit the sample compound metric configuration edit page
42   - And I fill the Code field with "Another_Code"
  41 + And I fill the Code field with " "
  42 + And I fill the Weight field with " "
43 43 And I press the Save button
44   - Then I should see "Code There's already"
  44 + Then I should see "Code can't be blank"
  45 + And I should see "Weight can't be blank"
45 46  
46   - @kalibro_restart @wip
47   - Scenario: trying to edit with blank fields
  47 + @kalibro_restart
  48 + Scenario: trying to edit with an existing code
48 49 Given I am a regular user
49 50 And I am signed in
50 51 And I own a sample configuration
51 52 And I have a sample reading group
52 53 And I have a sample metric configuration within the given mezuro configuration
53 54 And I have a sample compound metric configuration within the given mezuro configuration
  55 + And I have another compound metric configuration with code "Another_Code" within the given mezuro configuration
54 56 When I visit the sample compound metric configuration edit page
55   - And I fill the Code field with " "
56   - And I fill the Weight field with " "
  57 + And I fill the Code field with "Another_Code"
57 58 And I press the Save button
58   - Then I should see "Code can't be blank"
59   - And I should see "Weight can't be blank"
  59 + Then I should see "Code There's already"
  60 +
... ...
features/step_definitions/compound_metric_configuration_steps.rb
... ... @@ -7,11 +7,11 @@ Given(/^I see the sample metric configuration code$/) do
7 7 end
8 8  
9 9 Given(/^I have a sample compound metric configuration within the given mezuro configuration$/) do
10   - @compound_metric_configuration = FactoryGirl.create(:compound_metric_configuration, {id: nil, configuration_id: @mezuro_configuration.id})
  10 + @compound_metric_configuration = FactoryGirl.create(:compound_metric_configuration, {id: nil, configuration_id: @mezuro_configuration.id, reading_group_id: @reading_group.id})
11 11 end
12 12  
13 13 Given(/^I have another compound metric configuration with code "(.*?)" within the given mezuro configuration$/) do |code|
14   - FactoryGirl.create(:compound_metric_configuration, {id: nil, configuration_id: @mezuro_configuration.id, code: code})
  14 + @another_compound_metric_configuration = FactoryGirl.create(:compound_metric_configuration, {id: nil, configuration_id: @mezuro_configuration.id, code: code, reading_group_id: @reading_group.id})
15 15 end
16 16  
17 17 When(/^I visit the sample compound metric configuration edit page$/) do
... ...