Commit 25de4137bbdbb74d5cc7ae0b15322b25206be9b2
1 parent
24d5f118
Exists in
colab
and in
4 other branches
Redirect for Configuration ownership now forwards for the show view
Signed off by: Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
Showing
6 changed files
with
216 additions
and
216 deletions
Show diff stats
app/controllers/concerns/ownership_authentication.rb
| @@ -76,7 +76,7 @@ module OwnershipAuthentication | @@ -76,7 +76,7 @@ module OwnershipAuthentication | ||
| 76 | def check_mezuro_configuration_ownership(id) | 76 | def check_mezuro_configuration_ownership(id) |
| 77 | if current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(id).nil? | 77 | if current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(id).nil? |
| 78 | respond_to do |format| | 78 | respond_to do |format| |
| 79 | - format.html { redirect_to mezuro_configurations_url, notice: "You're not allowed to do this operation" } | 79 | + format.html { redirect_to mezuro_configurations_url(id), notice: "You're not allowed to do this operation" } |
| 80 | format.json { head :no_content } | 80 | format.json { head :no_content } |
| 81 | end | 81 | end |
| 82 | end | 82 | end |
spec/controllers/compound_metric_configurations_controller_spec.rb
| @@ -25,7 +25,7 @@ describe CompoundMetricConfigurationsController do | @@ -25,7 +25,7 @@ describe CompoundMetricConfigurationsController do | ||
| 25 | get :new, mezuro_configuration_id: mezuro_configuration.id | 25 | get :new, mezuro_configuration_id: mezuro_configuration.id |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | - it { should redirect_to(mezuro_configurations_url) } | 28 | + it { should redirect_to(mezuro_configurations_url(mezuro_configuration.id)) } |
| 29 | it { should respond_with(:redirect) } | 29 | it { should respond_with(:redirect) } |
| 30 | end | 30 | end |
| 31 | end | 31 | end |
| @@ -105,7 +105,7 @@ describe CompoundMetricConfigurationsController do | @@ -105,7 +105,7 @@ describe CompoundMetricConfigurationsController do | ||
| 105 | get :edit, id: compound_metric_configuration.id, mezuro_configuration_id: compound_metric_configuration.configuration_id.to_s | 105 | get :edit, id: compound_metric_configuration.id, mezuro_configuration_id: compound_metric_configuration.configuration_id.to_s |
| 106 | end | 106 | end |
| 107 | 107 | ||
| 108 | - it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page | 108 | + it { should redirect_to(mezuro_configurations_path(mezuro_configuration.id)) } |
| 109 | it { should respond_with(:redirect) } | 109 | it { should respond_with(:redirect) } |
| 110 | it { should set_the_flash[:notice].to("You're not allowed to do this operation") } | 110 | it { should set_the_flash[:notice].to("You're not allowed to do this operation") } |
| 111 | end | 111 | end |
spec/controllers/metric_configurations_controller_spec.rb
| @@ -42,7 +42,7 @@ describe MetricConfigurationsController do | @@ -42,7 +42,7 @@ describe MetricConfigurationsController do | ||
| 42 | post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name | 42 | post :new, mezuro_configuration_id: mezuro_configuration.id, metric_name: "Lines of Code", base_tool_name: base_tool.name |
| 43 | end | 43 | end |
| 44 | 44 | ||
| 45 | - it { should redirect_to(mezuro_configurations_url) } | 45 | + it { should redirect_to(mezuro_configurations_url(mezuro_configuration.id)) } |
| 46 | it { should respond_with(:redirect) } | 46 | it { should respond_with(:redirect) } |
| 47 | end | 47 | end |
| 48 | end | 48 | end |
| @@ -124,7 +124,7 @@ describe MetricConfigurationsController do | @@ -124,7 +124,7 @@ describe MetricConfigurationsController do | ||
| 124 | get :edit, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s | 124 | get :edit, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s |
| 125 | end | 125 | end |
| 126 | 126 | ||
| 127 | - it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page | 127 | + it { should redirect_to(mezuro_configurations_path(metric_configuration.configuration_id)) } |
| 128 | it { should respond_with(:redirect) } | 128 | it { should respond_with(:redirect) } |
| 129 | it { should set_the_flash[:notice].to("You're not allowed to do this operation") } | 129 | it { should set_the_flash[:notice].to("You're not allowed to do this operation") } |
| 130 | end | 130 | end |
| @@ -182,7 +182,7 @@ describe MetricConfigurationsController do | @@ -182,7 +182,7 @@ describe MetricConfigurationsController do | ||
| 182 | post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params | 182 | post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: metric_configuration.id, metric_configuration: metric_configuration_params |
| 183 | end | 183 | end |
| 184 | 184 | ||
| 185 | - it { should redirect_to mezuro_configurations_path } | 185 | + it { should redirect_to mezuro_configurations_path(metric_configuration.configuration_id) } |
| 186 | end | 186 | end |
| 187 | end | 187 | end |
| 188 | end | 188 | end |
| @@ -214,7 +214,7 @@ describe MetricConfigurationsController do | @@ -214,7 +214,7 @@ describe MetricConfigurationsController do | ||
| 214 | delete :destroy, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s | 214 | delete :destroy, id: metric_configuration.id, mezuro_configuration_id: metric_configuration.configuration_id.to_s |
| 215 | end | 215 | end |
| 216 | 216 | ||
| 217 | - it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page | 217 | + it { should redirect_to(mezuro_configurations_path(metric_configuration.configuration_id)) } |
| 218 | it { should respond_with(:redirect) } | 218 | it { should respond_with(:redirect) } |
| 219 | end | 219 | end |
| 220 | end | 220 | end |
spec/controllers/mezuro_configurations_controller_spec.rb
| @@ -115,7 +115,7 @@ describe MezuroConfigurationsController do | @@ -115,7 +115,7 @@ describe MezuroConfigurationsController do | ||
| 115 | delete :destroy, :id => @subject.id | 115 | delete :destroy, :id => @subject.id |
| 116 | end | 116 | end |
| 117 | 117 | ||
| 118 | - it { should redirect_to(mezuro_configurations_path) } | 118 | + it { should redirect_to(mezuro_configurations_path(@subject.id)) } |
| 119 | end | 119 | end |
| 120 | end | 120 | end |
| 121 | 121 | ||
| @@ -177,7 +177,7 @@ describe MezuroConfigurationsController do | @@ -177,7 +177,7 @@ describe MezuroConfigurationsController do | ||
| 177 | get :edit, :id => @subject.id | 177 | get :edit, :id => @subject.id |
| 178 | end | 178 | end |
| 179 | 179 | ||
| 180 | - it { should redirect_to(mezuro_configurations_path) } | 180 | + it { should redirect_to(mezuro_configurations_path(@subject.id)) } |
| 181 | it { should set_the_flash[:notice].to("You're not allowed to do this operation") } | 181 | it { should set_the_flash[:notice].to("You're not allowed to do this operation") } |
| 182 | end | 182 | end |
| 183 | end | 183 | end |
| @@ -255,7 +255,7 @@ describe MezuroConfigurationsController do | @@ -255,7 +255,7 @@ describe MezuroConfigurationsController do | ||
| 255 | post :update, :id => @subject.id, :mezuro_configuration => @subject_params | 255 | post :update, :id => @subject.id, :mezuro_configuration => @subject_params |
| 256 | end | 256 | end |
| 257 | 257 | ||
| 258 | - it { should redirect_to mezuro_configurations_path } | 258 | + it { should redirect_to mezuro_configurations_path(@subject.id) } |
| 259 | end | 259 | end |
| 260 | end | 260 | end |
| 261 | 261 |
| @@ -0,0 +1,206 @@ | @@ -0,0 +1,206 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe MezuroRangesController do | ||
| 4 | + let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1) } | ||
| 5 | + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 6 | + | ||
| 7 | + describe 'new' do | ||
| 8 | + let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } | ||
| 9 | + | ||
| 10 | + before :each do | ||
| 11 | + sign_in FactoryGirl.create(:user) | ||
| 12 | + end | ||
| 13 | + | ||
| 14 | + context 'when the current user owns the metric configuration' do | ||
| 15 | + before :each do | ||
| 16 | + subject.expects(:metric_configuration_owner?).returns true | ||
| 17 | + MetricConfiguration.expects(:find).with(mezuro_range.metric_configuration_id).returns(metric_configuration) | ||
| 18 | + Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([]) | ||
| 19 | + get :new, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: mezuro_range.metric_configuration_id | ||
| 20 | + end | ||
| 21 | + | ||
| 22 | + it { should respond_with(:success) } | ||
| 23 | + it { should render_template(:new) } | ||
| 24 | + end | ||
| 25 | + | ||
| 26 | + context "when the current user doesn't owns the metric configuration" do | ||
| 27 | + before :each do | ||
| 28 | + get :new, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: mezuro_range.metric_configuration_id | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + it { should redirect_to(mezuro_configurations_path(mezuro_configuration.id)) } | ||
| 32 | + it { should respond_with(:redirect) } | ||
| 33 | + end | ||
| 34 | + end | ||
| 35 | + | ||
| 36 | + describe 'create' do | ||
| 37 | + let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers | ||
| 38 | + let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } | ||
| 39 | + | ||
| 40 | + before do | ||
| 41 | + sign_in FactoryGirl.create(:user) | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | + context 'when the current user owns the mezuro range' do | ||
| 45 | + before :each do | ||
| 46 | + subject.expects(:metric_configuration_owner?).returns true | ||
| 47 | + end | ||
| 48 | + | ||
| 49 | + context 'with valid fields' do | ||
| 50 | + before :each do | ||
| 51 | + MezuroRange.any_instance.expects(:save).returns(true) | ||
| 52 | + | ||
| 53 | + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 54 | + end | ||
| 55 | + | ||
| 56 | + it { should respond_with(:redirect) } | ||
| 57 | + end | ||
| 58 | + | ||
| 59 | + context 'with invalid fields' do | ||
| 60 | + before :each do | ||
| 61 | + MezuroRange.any_instance.expects(:save).returns(false) | ||
| 62 | + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | ||
| 63 | + Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([]) | ||
| 64 | + | ||
| 65 | + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 66 | + end | ||
| 67 | + | ||
| 68 | + it { should render_template(:new) } | ||
| 69 | + end | ||
| 70 | + end | ||
| 71 | + end | ||
| 72 | + | ||
| 73 | + describe 'destroy' do | ||
| 74 | + context 'with an User logged in' do | ||
| 75 | + before do | ||
| 76 | + sign_in FactoryGirl.create(:user) | ||
| 77 | + end | ||
| 78 | + | ||
| 79 | + context 'when the user owns the metric configuration' do | ||
| 80 | + before :each do | ||
| 81 | + subject.expects(:metric_configuration_owner?).returns true | ||
| 82 | + mezuro_range.expects(:destroy) | ||
| 83 | + MezuroRange.expects(:find).at_least_once.with(mezuro_range.id).returns(mezuro_range) | ||
| 84 | + | ||
| 85 | + delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
| 86 | + end | ||
| 87 | + | ||
| 88 | + it { should redirect_to(mezuro_configuration_metric_configuration_path(metric_configuration.configuration_id, metric_configuration.id)) } | ||
| 89 | + it { should respond_with(:redirect) } | ||
| 90 | + end | ||
| 91 | + | ||
| 92 | + context "when the user doesn't own the metric configuration" do | ||
| 93 | + before :each do | ||
| 94 | + delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
| 95 | + end | ||
| 96 | + | ||
| 97 | + it { should redirect_to(mezuro_configurations_path(metric_configuration.configuration_id)) } | ||
| 98 | + it { should respond_with(:redirect) } | ||
| 99 | + end | ||
| 100 | + end | ||
| 101 | + | ||
| 102 | + context 'with no User logged in' do | ||
| 103 | + before :each do | ||
| 104 | + delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
| 105 | + end | ||
| 106 | + | ||
| 107 | + it { should redirect_to new_user_session_path } | ||
| 108 | + end | ||
| 109 | + end | ||
| 110 | + | ||
| 111 | + describe 'edit' do | ||
| 112 | + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 113 | + let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } | ||
| 114 | + let(:reading) { FactoryGirl.build(:reading, group_id: metric_configuration.reading_group_id) } | ||
| 115 | + | ||
| 116 | + context 'with an User logged in' do | ||
| 117 | + before do | ||
| 118 | + sign_in FactoryGirl.create(:user) | ||
| 119 | + end | ||
| 120 | + | ||
| 121 | + context 'when the user owns the mezuro range' do | ||
| 122 | + before :each do | ||
| 123 | + subject.expects(:metric_configuration_owner?).returns true | ||
| 124 | + MezuroRange.expects(:find).with(mezuro_range.id).returns(mezuro_range) | ||
| 125 | + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | ||
| 126 | + Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([reading]) | ||
| 127 | + get :edit, id: mezuro_range.id, mezuro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | ||
| 128 | + end | ||
| 129 | + | ||
| 130 | + it { should render_template(:edit) } | ||
| 131 | + end | ||
| 132 | + | ||
| 133 | + context 'when the user does not own the mezuro range' do | ||
| 134 | + let!(:reading_group) { FactoryGirl.build(:reading_group, id: metric_configuration.reading_group_id) } | ||
| 135 | + | ||
| 136 | + before do | ||
| 137 | + get :edit, id: mezuro_range.id, mezuro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | ||
| 138 | + end | ||
| 139 | + | ||
| 140 | + it { should redirect_to(mezuro_configurations_url(metric_configuration.configuration_id)) } | ||
| 141 | + it { should respond_with(:redirect) } | ||
| 142 | + it { should set_the_flash[:notice].to("You're not allowed to do this operation") } | ||
| 143 | + end | ||
| 144 | + end | ||
| 145 | + | ||
| 146 | + context 'with no user logged in' do | ||
| 147 | + before :each do | ||
| 148 | + get :edit, id: mezuro_range.id, mezuro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | ||
| 149 | + end | ||
| 150 | + | ||
| 151 | + it { should redirect_to new_user_session_path } | ||
| 152 | + end | ||
| 153 | + end | ||
| 154 | + | ||
| 155 | + describe 'update' do | ||
| 156 | + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 157 | + let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } | ||
| 158 | + let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers | ||
| 159 | + let(:reading) { FactoryGirl.build(:reading, group_id: metric_configuration.reading_group_id) } | ||
| 160 | + | ||
| 161 | + context 'when the user is logged in' do | ||
| 162 | + before do | ||
| 163 | + sign_in FactoryGirl.create(:user) | ||
| 164 | + end | ||
| 165 | + | ||
| 166 | + context 'when user owns the mezuro range' do | ||
| 167 | + before :each do | ||
| 168 | + subject.expects(:metric_configuration_owner?).returns true | ||
| 169 | + end | ||
| 170 | + | ||
| 171 | + context 'with valid fields' do | ||
| 172 | + before :each do | ||
| 173 | + MezuroRange.expects(:find).with(mezuro_range.id).returns(mezuro_range) | ||
| 174 | + MezuroRange.any_instance.expects(:update).with(mezuro_range_params).returns(true) | ||
| 175 | + | ||
| 176 | + post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 177 | + end | ||
| 178 | + | ||
| 179 | + it { should redirect_to(mezuro_configuration_metric_configuration_path(metric_configuration.configuration_id, metric_configuration.id)) } | ||
| 180 | + it { should respond_with(:redirect) } | ||
| 181 | + end | ||
| 182 | + | ||
| 183 | + context 'with an invalid field' do | ||
| 184 | + before :each do | ||
| 185 | + MezuroRange.expects(:find).with(mezuro_range.id).returns(mezuro_range) | ||
| 186 | + MezuroRange.any_instance.expects(:update).with(mezuro_range_params).returns(false) | ||
| 187 | + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | ||
| 188 | + Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([reading]) | ||
| 189 | + | ||
| 190 | + post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 191 | + end | ||
| 192 | + | ||
| 193 | + it { should render_template(:edit) } | ||
| 194 | + end | ||
| 195 | + end | ||
| 196 | + | ||
| 197 | + context 'when the user does not own the mezuro range' do | ||
| 198 | + before :each do | ||
| 199 | + post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 200 | + end | ||
| 201 | + | ||
| 202 | + it { should redirect_to mezuro_configurations_path(metric_configuration.configuration_id) } | ||
| 203 | + end | ||
| 204 | + end | ||
| 205 | + end | ||
| 206 | +end |
spec/controllers/mezuro_ranges_spec.rb
| @@ -1,206 +0,0 @@ | @@ -1,206 +0,0 @@ | ||
| 1 | -require 'spec_helper' | ||
| 2 | - | ||
| 3 | -describe MezuroRangesController do | ||
| 4 | - let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1) } | ||
| 5 | - let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 6 | - | ||
| 7 | - describe 'new' do | ||
| 8 | - let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } | ||
| 9 | - | ||
| 10 | - before :each do | ||
| 11 | - sign_in FactoryGirl.create(:user) | ||
| 12 | - end | ||
| 13 | - | ||
| 14 | - context 'when the current user owns the metric configuration' do | ||
| 15 | - before :each do | ||
| 16 | - subject.expects(:metric_configuration_owner?).returns true | ||
| 17 | - MetricConfiguration.expects(:find).with(mezuro_range.metric_configuration_id).returns(metric_configuration) | ||
| 18 | - Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([]) | ||
| 19 | - get :new, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: mezuro_range.metric_configuration_id | ||
| 20 | - end | ||
| 21 | - | ||
| 22 | - it { should respond_with(:success) } | ||
| 23 | - it { should render_template(:new) } | ||
| 24 | - end | ||
| 25 | - | ||
| 26 | - context "when the current user doesn't owns the metric configuration" do | ||
| 27 | - before :each do | ||
| 28 | - get :new, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: mezuro_range.metric_configuration_id | ||
| 29 | - end | ||
| 30 | - | ||
| 31 | - it { should redirect_to(mezuro_configurations_path) } | ||
| 32 | - it { should respond_with(:redirect) } | ||
| 33 | - end | ||
| 34 | - end | ||
| 35 | - | ||
| 36 | - describe 'create' do | ||
| 37 | - let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers | ||
| 38 | - let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } | ||
| 39 | - | ||
| 40 | - before do | ||
| 41 | - sign_in FactoryGirl.create(:user) | ||
| 42 | - end | ||
| 43 | - | ||
| 44 | - context 'when the current user owns the mezuro range' do | ||
| 45 | - before :each do | ||
| 46 | - subject.expects(:metric_configuration_owner?).returns true | ||
| 47 | - end | ||
| 48 | - | ||
| 49 | - context 'with valid fields' do | ||
| 50 | - before :each do | ||
| 51 | - MezuroRange.any_instance.expects(:save).returns(true) | ||
| 52 | - | ||
| 53 | - post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 54 | - end | ||
| 55 | - | ||
| 56 | - it { should respond_with(:redirect) } | ||
| 57 | - end | ||
| 58 | - | ||
| 59 | - context 'with invalid fields' do | ||
| 60 | - before :each do | ||
| 61 | - MezuroRange.any_instance.expects(:save).returns(false) | ||
| 62 | - MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | ||
| 63 | - Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([]) | ||
| 64 | - | ||
| 65 | - post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 66 | - end | ||
| 67 | - | ||
| 68 | - it { should render_template(:new) } | ||
| 69 | - end | ||
| 70 | - end | ||
| 71 | - end | ||
| 72 | - | ||
| 73 | - describe 'destroy' do | ||
| 74 | - context 'with an User logged in' do | ||
| 75 | - before do | ||
| 76 | - sign_in FactoryGirl.create(:user) | ||
| 77 | - end | ||
| 78 | - | ||
| 79 | - context 'when the user owns the metric configuration' do | ||
| 80 | - before :each do | ||
| 81 | - subject.expects(:metric_configuration_owner?).returns true | ||
| 82 | - mezuro_range.expects(:destroy) | ||
| 83 | - MezuroRange.expects(:find).at_least_once.with(mezuro_range.id).returns(mezuro_range) | ||
| 84 | - | ||
| 85 | - delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
| 86 | - end | ||
| 87 | - | ||
| 88 | - it { should redirect_to(mezuro_configuration_metric_configuration_path(metric_configuration.configuration_id, metric_configuration.id)) } | ||
| 89 | - it { should respond_with(:redirect) } | ||
| 90 | - end | ||
| 91 | - | ||
| 92 | - context "when the user doesn't own the metric configuration" do | ||
| 93 | - before :each do | ||
| 94 | - delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
| 95 | - end | ||
| 96 | - | ||
| 97 | - it { should redirect_to(mezuro_configurations_path) } #FIXME : It should redirect to configuration show page | ||
| 98 | - it { should respond_with(:redirect) } | ||
| 99 | - end | ||
| 100 | - end | ||
| 101 | - | ||
| 102 | - context 'with no User logged in' do | ||
| 103 | - before :each do | ||
| 104 | - delete :destroy, id: mezuro_range.id.to_s, metric_configuration_id: metric_configuration.id.to_s, mezuro_configuration_id: metric_configuration.configuration_id.to_s | ||
| 105 | - end | ||
| 106 | - | ||
| 107 | - it { should redirect_to new_user_session_path } | ||
| 108 | - end | ||
| 109 | - end | ||
| 110 | - | ||
| 111 | - describe 'edit' do | ||
| 112 | - let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 113 | - let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } | ||
| 114 | - let(:reading) { FactoryGirl.build(:reading, group_id: metric_configuration.reading_group_id) } | ||
| 115 | - | ||
| 116 | - context 'with an User logged in' do | ||
| 117 | - before do | ||
| 118 | - sign_in FactoryGirl.create(:user) | ||
| 119 | - end | ||
| 120 | - | ||
| 121 | - context 'when the user owns the mezuro range' do | ||
| 122 | - before :each do | ||
| 123 | - subject.expects(:metric_configuration_owner?).returns true | ||
| 124 | - MezuroRange.expects(:find).with(mezuro_range.id).returns(mezuro_range) | ||
| 125 | - MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | ||
| 126 | - Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([reading]) | ||
| 127 | - get :edit, id: mezuro_range.id, mezuro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | ||
| 128 | - end | ||
| 129 | - | ||
| 130 | - it { should render_template(:edit) } | ||
| 131 | - end | ||
| 132 | - | ||
| 133 | - context 'when the user does not own the mezuro range' do | ||
| 134 | - let!(:reading_group) { FactoryGirl.build(:reading_group, id: metric_configuration.reading_group_id) } | ||
| 135 | - | ||
| 136 | - before do | ||
| 137 | - get :edit, id: mezuro_range.id, mezuro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | ||
| 138 | - end | ||
| 139 | - | ||
| 140 | - it { should redirect_to(mezuro_configurations_url) } | ||
| 141 | - it { should respond_with(:redirect) } | ||
| 142 | - it { should set_the_flash[:notice].to("You're not allowed to do this operation") } | ||
| 143 | - end | ||
| 144 | - end | ||
| 145 | - | ||
| 146 | - context 'with no user logged in' do | ||
| 147 | - before :each do | ||
| 148 | - get :edit, id: mezuro_range.id, mezuro_configuration_id: metric_configuration.configuration_id, metric_configuration_id: metric_configuration.id | ||
| 149 | - end | ||
| 150 | - | ||
| 151 | - it { should redirect_to new_user_session_path } | ||
| 152 | - end | ||
| 153 | - end | ||
| 154 | - | ||
| 155 | - describe 'update' do | ||
| 156 | - let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | ||
| 157 | - let(:mezuro_range) { FactoryGirl.build(:mezuro_range, id: 1, metric_configuration_id: metric_configuration.id) } | ||
| 158 | - let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers | ||
| 159 | - let(:reading) { FactoryGirl.build(:reading, group_id: metric_configuration.reading_group_id) } | ||
| 160 | - | ||
| 161 | - context 'when the user is logged in' do | ||
| 162 | - before do | ||
| 163 | - sign_in FactoryGirl.create(:user) | ||
| 164 | - end | ||
| 165 | - | ||
| 166 | - context 'when user owns the mezuro range' do | ||
| 167 | - before :each do | ||
| 168 | - subject.expects(:metric_configuration_owner?).returns true | ||
| 169 | - end | ||
| 170 | - | ||
| 171 | - context 'with valid fields' do | ||
| 172 | - before :each do | ||
| 173 | - MezuroRange.expects(:find).with(mezuro_range.id).returns(mezuro_range) | ||
| 174 | - MezuroRange.any_instance.expects(:update).with(mezuro_range_params).returns(true) | ||
| 175 | - | ||
| 176 | - post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 177 | - end | ||
| 178 | - | ||
| 179 | - it { should redirect_to(mezuro_configuration_metric_configuration_path(metric_configuration.configuration_id, metric_configuration.id)) } | ||
| 180 | - it { should respond_with(:redirect) } | ||
| 181 | - end | ||
| 182 | - | ||
| 183 | - context 'with an invalid field' do | ||
| 184 | - before :each do | ||
| 185 | - MezuroRange.expects(:find).with(mezuro_range.id).returns(mezuro_range) | ||
| 186 | - MezuroRange.any_instance.expects(:update).with(mezuro_range_params).returns(false) | ||
| 187 | - MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | ||
| 188 | - Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([reading]) | ||
| 189 | - | ||
| 190 | - post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 191 | - end | ||
| 192 | - | ||
| 193 | - it { should render_template(:edit) } | ||
| 194 | - end | ||
| 195 | - end | ||
| 196 | - | ||
| 197 | - context 'when the user does not own the mezuro range' do | ||
| 198 | - before :each do | ||
| 199 | - post :update, mezuro_configuration_id: metric_configuration.configuration_id, id: mezuro_range.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params | ||
| 200 | - end | ||
| 201 | - | ||
| 202 | - it { should redirect_to mezuro_configurations_path } | ||
| 203 | - end | ||
| 204 | - end | ||
| 205 | - end | ||
| 206 | -end |