Commit 237cd272838d772bcffc231e1f0a14fa00024f21
Exists in
colab
and in
4 other branches
Merge pull request #179 from mezuro/fixing_ranges_redirection
Changing the redirection path after create, edit or delete on a range
Showing
7 changed files
with
148 additions
and
16 deletions
Show diff stats
app/controllers/kalibro_ranges_controller.rb
... | ... | @@ -23,8 +23,7 @@ class KalibroRangesController < ApplicationController |
23 | 23 | def destroy |
24 | 24 | @kalibro_range.destroy |
25 | 25 | respond_to do |format| |
26 | - format.html { redirect_to kalibro_configuration_metric_configuration_path( | |
27 | - @kalibro_configuration_id, @metric_configuration_id) } | |
26 | + format_metric_configuration_path(format, "Range was successfully destroyed.") | |
28 | 27 | format.json { head :no_content } |
29 | 28 | end |
30 | 29 | end |
... | ... | @@ -37,8 +36,7 @@ class KalibroRangesController < ApplicationController |
37 | 36 | respond_to do |format| |
38 | 37 | @kalibro_range.metric_configuration_id = @metric_configuration_id |
39 | 38 | if @kalibro_range.update(kalibro_range_params) |
40 | - format.html { redirect_to kalibro_configuration_metric_configuration_path( | |
41 | - @kalibro_configuration_id, @metric_configuration_id), notice: 'Range was successfully edited.' } | |
39 | + format_metric_configuration_path(format, 'Range was successfully edited.') | |
42 | 40 | format.json { head :no_content } |
43 | 41 | else |
44 | 42 | failed_action(format, 'edit') |
... | ... | @@ -55,13 +53,23 @@ class KalibroRangesController < ApplicationController |
55 | 53 | |
56 | 54 | def create_and_redir(format) |
57 | 55 | if @kalibro_range.save |
58 | - format.html { redirect_to kalibro_configuration_metric_configuration_path( | |
59 | - @kalibro_configuration_id, @metric_configuration_id), notice: 'Range was successfully created.' } | |
56 | + format_metric_configuration_path(format, 'Range was successfully created.') | |
60 | 57 | else |
61 | 58 | failed_action(format, 'new') |
62 | 59 | end |
63 | 60 | end |
64 | 61 | |
62 | + def format_metric_configuration_path(format, notice) | |
63 | + @metric_configuration = MetricConfiguration.find @kalibro_range.metric_configuration_id | |
64 | + if(@metric_configuration.metric.is_a? KalibroClient::Entities::Miscellaneous::CompoundMetric) | |
65 | + format.html { redirect_to kalibro_configuration_compound_metric_configuration_path( | |
66 | + @kalibro_configuration_id, @metric_configuration_id), notice: notice } | |
67 | + else | |
68 | + format.html { redirect_to kalibro_configuration_metric_configuration_path( | |
69 | + @kalibro_configuration_id, @metric_configuration_id), notice: notice } | |
70 | + end | |
71 | + end | |
72 | + | |
65 | 73 | def failed_action(format, destiny_action) |
66 | 74 | before_form |
67 | 75 | format.html { render action: destiny_action } | ... | ... |
features/kalibro_range/create.feature
... | ... | @@ -186,3 +186,23 @@ Feature: Create Kalibro Range |
186 | 186 | Then I should be at metric configuration sample page |
187 | 187 | And I should see "666" |
188 | 188 | And I should see "INF" |
189 | + | |
190 | + @kalibro_configuration_restart @javascript | |
191 | + Scenario: Should create a kalibro range and redirect to the compound metric configuration page | |
192 | + Given I am a regular user | |
193 | + And I am signed in | |
194 | + And I own a sample configuration | |
195 | + And I own a sample reading group | |
196 | + And I have a sample metric configuration within the given mezuro configuration | |
197 | + And I have a sample compound metric configuration within the given mezuro configuration | |
198 | + And I have a sample reading within the sample reading group labeled "My Reading" | |
199 | + And I am at the New Range page for the compound metric configuration | |
200 | + And I click the -∞ link | |
201 | + And I click the ∞ link | |
202 | + And I fill the Comments field with "My Comment" | |
203 | + And I set the select field "Reading" as "My Reading" | |
204 | + When I press the Save button | |
205 | + Then I should be at compound metric configuration sample page | |
206 | + And I should see "-INF" | |
207 | + And I should see "INF" | |
208 | + | ... | ... |
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 "(.*?)"$/) 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 |
... | ... | @@ -25,6 +34,11 @@ When(/^I am at the New Range page$/) do |
25 | 34 | visit kalibro_configuration_metric_configuration_new_kalibro_range_path(@metric_configuration.kalibro_configuration_id, @metric_configuration.id) |
26 | 35 | end |
27 | 36 | |
37 | +Given(/^I am at the New Range page for the compound metric configuration$/) do | |
38 | + visit kalibro_configuration_metric_configuration_new_kalibro_range_path(@compound_metric_configuration.kalibro_configuration_id, @compound_metric_configuration.id) | |
39 | +end | |
40 | + | |
41 | + | |
28 | 42 | Then(/^I should be at the New Range page$/) do |
29 | 43 | expect(page).to have_content("New Range") |
30 | 44 | expect(page).to have_content("Beginning") | ... | ... |
spec/controllers/kalibro_ranges_controller_spec.rb
1 | 1 | require 'rails_helper' |
2 | 2 | |
3 | 3 | describe KalibroRangesController, :type => :controller do |
4 | - let(:kalibro_range) { FactoryGirl.build(:kalibro_range_with_id) } | |
5 | 4 | let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } |
5 | + let(:kalibro_range) { FactoryGirl.build(:kalibro_range_with_id, metric_configuration_id: metric_configuration.id) } | |
6 | 6 | |
7 | 7 | describe 'new' do |
8 | 8 | let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) } |
... | ... | @@ -46,13 +46,30 @@ describe KalibroRangesController, :type => :controller do |
46 | 46 | subject.expects(:metric_configuration_owner?).returns true |
47 | 47 | end |
48 | 48 | |
49 | - context 'with valid fields' do | |
49 | + context 'with valid fields and a native metric configuration' 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 | |
57 | + it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(metric_configuration.kalibro_configuration_id, metric_configuration.id)) } | |
58 | + it { is_expected.to respond_with(:redirect) } | |
59 | + end | |
60 | + | |
61 | + context 'with valid fields and a compound metric configuration' do | |
62 | + let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration_with_id) } | |
63 | + let(:new_kalibro_range) { FactoryGirl.build(:kalibro_range, metric_configuration_id: compound_metric_configuration.id) } | |
64 | + | |
65 | + before :each do | |
66 | + KalibroRange.any_instance.expects(:save).returns(true) | |
67 | + MetricConfiguration.expects(:find).with(new_kalibro_range.metric_configuration_id).returns(compound_metric_configuration) | |
68 | + | |
69 | + post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration_id: new_kalibro_range.metric_configuration_id, kalibro_range: new_kalibro_range.to_hash | |
70 | + end | |
71 | + | |
72 | + it { is_expected.to redirect_to(kalibro_configuration_compound_metric_configuration_path(compound_metric_configuration.kalibro_configuration_id, compound_metric_configuration.id)) } | |
56 | 73 | it { is_expected.to respond_with(:redirect) } |
57 | 74 | end |
58 | 75 | |
... | ... | @@ -81,27 +98,45 @@ describe KalibroRangesController, :type => :controller do |
81 | 98 | subject.expects(:metric_configuration_owner?).returns true |
82 | 99 | kalibro_range.expects(:destroy) |
83 | 100 | subject.expects(:find_resource).with(KalibroRange, kalibro_range.id).returns(kalibro_range) |
101 | + MetricConfiguration.expects(:find).with(kalibro_range.metric_configuration_id).returns(metric_configuration) | |
84 | 102 | |
85 | - 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 | |
103 | + delete :destroy, id: kalibro_range.id, metric_configuration_id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id | |
86 | 104 | end |
87 | 105 | |
88 | 106 | it { is_expected.to redirect_to(kalibro_configuration_metric_configuration_path(metric_configuration.kalibro_configuration_id, metric_configuration.id)) } |
89 | 107 | it { is_expected.to respond_with(:redirect) } |
90 | 108 | end |
91 | 109 | |
110 | + context 'when the user owns the compound metric configuration' do | |
111 | + let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration_with_id) } | |
112 | + let(:new_kalibro_range) { FactoryGirl.build(:kalibro_range_with_id, metric_configuration_id: compound_metric_configuration.id) } | |
113 | + | |
114 | + before :each do | |
115 | + subject.expects(:metric_configuration_owner?).returns true | |
116 | + new_kalibro_range.expects(:destroy) | |
117 | + subject.expects(:find_resource).with(KalibroRange, new_kalibro_range.id).returns(new_kalibro_range) | |
118 | + MetricConfiguration.expects(:find).with(new_kalibro_range.metric_configuration_id).returns(compound_metric_configuration) | |
119 | + | |
120 | + delete :destroy, id: new_kalibro_range.id, metric_configuration_id: compound_metric_configuration.id, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id | |
121 | + end | |
122 | + | |
123 | + it { is_expected.to redirect_to(kalibro_configuration_compound_metric_configuration_path(compound_metric_configuration.kalibro_configuration_id, compound_metric_configuration.id)) } | |
124 | + it { is_expected.to respond_with(:redirect) } | |
125 | + end | |
126 | + | |
92 | 127 | context "when the user doesn't own the metric configuration" do |
93 | 128 | before :each do |
94 | - 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 | |
129 | + delete :destroy, id: kalibro_range.id, metric_configuration_id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id | |
95 | 130 | end |
96 | 131 | |
97 | - it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.kalibro_configuration_id)) } | |
98 | - it { is_expected.to respond_with(:redirect) } | |
132 | + it { is_expected.to redirect_to(kalibro_configurations_path(metric_configuration.kalibro_configuration_id)) } | |
133 | + it { is_expected.to respond_with(:redirect) } | |
99 | 134 | end |
100 | 135 | end |
101 | 136 | |
102 | 137 | context 'with no User logged in' do |
103 | 138 | before :each do |
104 | - 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 | |
139 | + delete :destroy, id: kalibro_range.id, metric_configuration_id: metric_configuration.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id | |
105 | 140 | end |
106 | 141 | |
107 | 142 | it { is_expected.to redirect_to new_user_session_path } |
... | ... | @@ -172,6 +207,7 @@ describe KalibroRangesController, :type => :controller do |
172 | 207 | before :each do |
173 | 208 | subject.expects(:find_resource).with(KalibroRange, kalibro_range.id).returns(kalibro_range) |
174 | 209 | KalibroRange.any_instance.expects(:update).with(kalibro_range_params).returns(true) |
210 | + MetricConfiguration.expects(:find).with(kalibro_range.metric_configuration_id).returns(metric_configuration) | |
175 | 211 | |
176 | 212 | 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 | 213 | end |
... | ... | @@ -180,6 +216,22 @@ describe KalibroRangesController, :type => :controller do |
180 | 216 | it { is_expected.to respond_with(:redirect) } |
181 | 217 | end |
182 | 218 | |
219 | + context 'with valid fields and a compound metric configuration' do | |
220 | + let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration_with_id) } | |
221 | + let(:new_kalibro_range) { FactoryGirl.build(:kalibro_range_with_id, metric_configuration_id: compound_metric_configuration.id) } | |
222 | + | |
223 | + before :each do | |
224 | + subject.expects(:find_resource).with(KalibroRange, new_kalibro_range.id).returns(new_kalibro_range) | |
225 | + KalibroRange.any_instance.expects(:update).with(new_kalibro_range.to_hash).returns(true) | |
226 | + MetricConfiguration.expects(:find).with(new_kalibro_range.metric_configuration_id).returns(compound_metric_configuration) | |
227 | + | |
228 | + post :update, kalibro_configuration_id: compound_metric_configuration.kalibro_configuration_id, id: new_kalibro_range.id, metric_configuration_id: compound_metric_configuration.id, kalibro_range: new_kalibro_range.to_hash | |
229 | + end | |
230 | + | |
231 | + it { is_expected.to redirect_to(kalibro_configuration_compound_metric_configuration_path(compound_metric_configuration.kalibro_configuration_id, compound_metric_configuration.id)) } | |
232 | + it { is_expected.to respond_with(:redirect) } | |
233 | + end | |
234 | + | |
183 | 235 | context 'with an invalid field' do |
184 | 236 | before :each do |
185 | 237 | subject.expects(:find_resource).with(KalibroRange, kalibro_range.id).returns(kalibro_range) | ... | ... |