Commit 5f6f16b3868957b393aa86d52b3f08f8ee96e04d

Authored by Daniel Alves
Committed by Diego Camarinha
1 parent 1d36a3de

Implemented acceptance tests for compound metric configuration

Missing unit tests

Signed off by: Diego Araújo <diegoamc90@gmail.com>
app/controllers/kalibro_ranges_controller.rb
... ... @@ -23,7 +23,7 @@ class KalibroRangesController &lt; ApplicationController
23 23 def destroy
24 24 @kalibro_range.destroy
25 25 respond_to do |format|
26   - format_metric_configuration_path(format, "Range was successfully edited.")
  26 + format_metric_configuration_path(format, "Range was successfully destroyed.")
27 27 format.json { head :no_content }
28 28 end
29 29 end
... ...
features/kalibro_range/deletion.feature
... ... @@ -4,7 +4,7 @@ Feature: Kalibro Range Deletion
4 4 The system should have an interface to it
5 5  
6 6 @kalibro_configuration_restart
7   - Scenario: Should delete a kalibro range that I own
  7 + Scenario: Should delete a kalibro range I own which belongs to a metric configuration
8 8 Given I am a regular user
9 9 And I am signed in
10 10 And I own a sample configuration
... ... @@ -18,6 +18,20 @@ Feature: Kalibro Range Deletion
18 18 And I should see "There are no Ranges yet!"
19 19  
20 20 @kalibro_configuration_restart
  21 + Scenario: Should delete a kalibro range I own which belongs to a compound metric configuration
  22 + Given I am a regular user
  23 + And I am signed in
  24 + And I own a sample configuration
  25 + And I have a sample reading group
  26 + And I have a sample compound metric configuration within the given mezuro configuration
  27 + And I have a sample reading within the sample reading group labeled "My Reading"
  28 + And I have a sample range within the sample compound metric configuration
  29 + And I am at the sample compound metric configuration page
  30 + When I click the Destroy link
  31 + Then I should be at compound metric configuration sample page
  32 + And I should see "There are no Ranges yet!"
  33 +
  34 + @kalibro_configuration_restart
21 35 Scenario: Should not see the destroy kalibro range link in the kalibro range that I do not own
22 36 Given I am a regular user
23 37 And I am signed in
... ...
features/kalibro_range/edit.feature
... ... @@ -4,7 +4,7 @@ Feature: Kalibro Range Edit
4 4 I should be able to edit my kalibro ranges
5 5  
6 6 @kalibro_configuration_restart
7   - Scenario: editing a kalibro range successfully
  7 + Scenario: successfully editing a kalibro range which belongs to a metric configuration
8 8 Given I am a regular user
9 9 And I am signed in
10 10 And I own a sample configuration
... ... @@ -22,6 +22,24 @@ Feature: Kalibro Range Edit
22 22 Then I should see "2.2"
23 23  
24 24 @kalibro_configuration_restart
  25 + Scenario: successfully editing a kalibro range which belongs to a compound metric configuration
  26 + Given I am a regular user
  27 + And I am signed in
  28 + And I own a sample configuration
  29 + And I own a sample reading group
  30 + And I have a sample compound metric configuration within the given mezuro configuration
  31 + And I have a sample reading within the sample reading group labeled "My Reading"
  32 + And I have a sample range within the sample compound metric configuration with beginning "1.1"
  33 + And I am at the Edit Kalibro Range page for the compound metric configuration
  34 + And the select field "Reading" is set as "My Reading"
  35 + And the field "Beginning" should be filled with "1.1"
  36 + And the field "End" should be filled with "5.1"
  37 + And the field "Comments" should be filled with "Comment"
  38 + When I fill the Beginning field with "2.2"
  39 + And I press the Save button
  40 + Then I should see "2.2"
  41 +
  42 + @kalibro_configuration_restart
25 43 Scenario: editing a kalibro range with blank fields
26 44 Given I am a regular user
27 45 And I am signed in
... ...
features/step_definitions/compound_metric_configuration_steps.rb
... ... @@ -26,6 +26,12 @@ When(/^I click the show link of &quot;(.*?)&quot;$/) do |name|
26 26 page.find('tr', :text => name).click_link('Show')
27 27 end
28 28  
  29 +When(/^I am at the sample compound metric configuration page$/) do
  30 + visit kalibro_configuration_compound_metric_configuration_path(@compound_metric_configuration.kalibro_configuration_id, @compound_metric_configuration.id)
  31 + expect(page).to have_content(@compound_metric_configuration.metric.name)
  32 + expect(page).to have_content("Ranges")
  33 +end
  34 +
29 35 Then(/^I should be at compound metric configuration sample page$/) do
30 36 expect(page).to have_content(@compound_metric_configuration.metric.name)
31 37 expect(page).to have_content("Ranges")
... ...
features/step_definitions/kalibro_range_steps.rb
... ... @@ -3,10 +3,19 @@ Given(/^I have a sample range within the sample metric configuration with beginn
3 3 reading_id: @reading.id})
4 4 end
5 5  
  6 +Given(/^I have a sample range within the sample compound metric configuration with beginning "(.*?)"$/) do |beginning|
  7 + @kalibro_range = FactoryGirl.create(:kalibro_range, {beginning: beginning, metric_configuration_id: @compound_metric_configuration.id,
  8 + reading_id: @reading.id})
  9 +end
  10 +
6 11 Given(/^I am at the Edit Kalibro Range page$/) do
7 12 visit edit_kalibro_configuration_metric_configuration_kalibro_range_path(@metric_configuration.kalibro_configuration_id, @metric_configuration.id, @kalibro_range.id)
8 13 end
9 14  
  15 +Given(/^I am at the Edit Kalibro Range page for the compound metric configuration$/) do
  16 + visit edit_kalibro_configuration_metric_configuration_kalibro_range_path(@compound_metric_configuration.kalibro_configuration_id, @compound_metric_configuration.id, @kalibro_range.id)
  17 +end
  18 +
10 19 Given(/^the select field "(.*?)" is set as "(.*?)"$/) do |field, text|
11 20 select text, from: field
12 21 end
... ...
spec/controllers/kalibro_ranges_controller_spec.rb
... ... @@ -49,8 +49,9 @@ describe KalibroRangesController, :type =&gt; :controller do
49 49 context 'with valid fields' do
50 50 before :each do
51 51 KalibroRange.any_instance.expects(:save).returns(true)
  52 + MetricConfiguration.expects(:find).with(kalibro_range.metric_configuration_id).returns(metric_configuration)
52 53  
53   - post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: metric_configuration.id, kalibro_range: kalibro_range_params
  54 + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: kalibro_range.metric_configuration_id, kalibro_range: kalibro_range_params
54 55 end
55 56  
56 57 it { is_expected.to respond_with(:redirect) }
... ... @@ -81,6 +82,7 @@ describe KalibroRangesController, :type =&gt; :controller do
81 82 subject.expects(:metric_configuration_owner?).returns true
82 83 kalibro_range.expects(:destroy)
83 84 subject.expects(:find_resource).with(KalibroRange, kalibro_range.id).returns(kalibro_range)
  85 + MetricConfiguration.expects(:find).with(kalibro_range.metric_configuration_id).returns(metric_configuration)
84 86  
85 87 delete :destroy, id: kalibro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s
86 88 end
... ... @@ -172,6 +174,7 @@ describe KalibroRangesController, :type =&gt; :controller do
172 174 before :each do
173 175 subject.expects(:find_resource).with(KalibroRange, kalibro_range.id).returns(kalibro_range)
174 176 KalibroRange.any_instance.expects(:update).with(kalibro_range_params).returns(true)
  177 + MetricConfiguration.expects(:find).with(kalibro_range.metric_configuration_id).returns(metric_configuration)
175 178  
176 179 post :update, kalibro_configuration_id: metric_configuration.kalibro_configuration_id, id: kalibro_range.id, metric_configuration_id: metric_configuration.id, kalibro_range: kalibro_range_params
177 180 end
... ...