Commit 5ae94e434013dccf1f90bfaa43a05b1e36c2ac5c
Committed by
Rafael Manzo
1 parent
810b3e30
Exists in
colab
and in
4 other branches
Destroy feature for reading
Signed-of By: Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
Showing
5 changed files
with
83 additions
and
3 deletions
Show diff stats
app/controllers/readings_controller.rb
| @@ -37,6 +37,16 @@ class ReadingsController < ApplicationController | @@ -37,6 +37,16 @@ class ReadingsController < ApplicationController | ||
| 37 | end | 37 | end |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | + # DELETE /reading_groups/1/readings/1 | ||
| 41 | + # DELETE /reading_groups/1/readings/1 | ||
| 42 | + def destroy | ||
| 43 | + @reading.destroy | ||
| 44 | + respond_to do |format| | ||
| 45 | + format.html { redirect_to reading_group_path(params[:reading_group_id].to_i) } | ||
| 46 | + format.json { head :no_content } | ||
| 47 | + end | ||
| 48 | + end | ||
| 49 | + | ||
| 40 | private | 50 | private |
| 41 | 51 | ||
| 42 | # Never trust parameters from the scary internet, only allow the white list through. | 52 | # Never trust parameters from the scary internet, only allow the white list through. |
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +Feature: Reading Deletion | ||
| 2 | + In order to be able to remove reading | ||
| 3 | + As a regular user | ||
| 4 | + The system should have an interface to it | ||
| 5 | + | ||
| 6 | + @kalibro_restart | ||
| 7 | + Scenario: Should delete a reading that I own | ||
| 8 | + Given I am a regular user | ||
| 9 | + And I am signed in | ||
| 10 | + And I own a sample reading group | ||
| 11 | + And I have a sample reading within the sample reading group | ||
| 12 | + When I visit the Sample Reading Group page | ||
| 13 | + And I click the Destroy link | ||
| 14 | + Then I should see "There are no readings yet!" | ||
| 15 | + | ||
| 16 | + @kalibro_restart | ||
| 17 | + Scenario: Should not see the destroy reading link in the reading groups that I not own | ||
| 18 | + Given I am a regular user | ||
| 19 | + And I am signed in | ||
| 20 | + And I have a sample reading group | ||
| 21 | + And I have a sample reading within the sample reading group | ||
| 22 | + When I visit the Sample Reading Group page | ||
| 23 | + Then I should not see "Destroy" | ||
| 0 | \ No newline at end of file | 24 | \ No newline at end of file |
features/step_definitions/reading_steps.rb
| @@ -14,10 +14,11 @@ Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$ | @@ -14,10 +14,11 @@ Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$ | ||
| 14 | @reading = FactoryGirl.create(:reading, {label: label, group_id: @reading_group.id, id: nil}) | 14 | @reading = FactoryGirl.create(:reading, {label: label, group_id: @reading_group.id, id: nil}) |
| 15 | end | 15 | end |
| 16 | 16 | ||
| 17 | -Given(/^I have a sample reading within the module result labeled "(.*?)"$/) do |label| | ||
| 18 | - @reading = FactoryGirl.create(:reading, {label: label, group_id: @reading_group.id, id: nil}) | 17 | +When(/^I click the "(.*?)" td$/) do |text| |
| 18 | + p page.find('td', text: text).methods | ||
| 19 | end | 19 | end |
| 20 | 20 | ||
| 21 | Then(/^I should be at the New Reading page$/) do | 21 | Then(/^I should be at the New Reading page$/) do |
| 22 | visit new_reading_group_reading_path(@reading_group.id) | 22 | visit new_reading_group_reading_path(@reading_group.id) |
| 23 | end | 23 | end |
| 24 | + |
features/step_definitions/user_steps.rb
| @@ -17,4 +17,8 @@ end | @@ -17,4 +17,8 @@ end | ||
| 17 | 17 | ||
| 18 | Then(/^I should be in the User Projects page$/) do | 18 | Then(/^I should be in the User Projects page$/) do |
| 19 | page.should have_content("#{@user.name} Projects") | 19 | page.should have_content("#{@user.name} Projects") |
| 20 | +end | ||
| 21 | + | ||
| 22 | +When(/^I take a picture of the page$/) do | ||
| 23 | + page.save_screenshot("/tmp/picture.png") | ||
| 20 | end | 24 | end |
| 21 | \ No newline at end of file | 25 | \ No newline at end of file |
spec/controllers/readings_controller_spec.rb
| @@ -125,7 +125,7 @@ describe ReadingsController do | @@ -125,7 +125,7 @@ describe ReadingsController do | ||
| 125 | post :update, reading_group_id: reading_group.id, id: reading.id, reading: reading_params | 125 | post :update, reading_group_id: reading_group.id, id: reading.id, reading: reading_params |
| 126 | end | 126 | end |
| 127 | 127 | ||
| 128 | - it { should redirect_to(reading_group_reading_path(reading_group.id, reading.id)) } | 128 | + it { should redirect_to(reading_group_path(reading_group.id)) } |
| 129 | it { should respond_with(:redirect) } | 129 | it { should respond_with(:redirect) } |
| 130 | end | 130 | end |
| 131 | 131 | ||
| @@ -161,4 +161,46 @@ describe ReadingsController do | @@ -161,4 +161,46 @@ describe ReadingsController do | ||
| 161 | end | 161 | end |
| 162 | end | 162 | end |
| 163 | 163 | ||
| 164 | + describe 'destroy' do | ||
| 165 | + let(:reading) { FactoryGirl.build(:reading) } | ||
| 166 | + | ||
| 167 | + context 'with an User logged in' do | ||
| 168 | + before do | ||
| 169 | + sign_in FactoryGirl.create(:user) | ||
| 170 | + end | ||
| 171 | + | ||
| 172 | + context 'when the user owns the reading group' do | ||
| 173 | + before :each do | ||
| 174 | + subject.expects(:reading_owner?).returns true | ||
| 175 | + reading.expects(:destroy) | ||
| 176 | + Reading.expects(:find).at_least_once.with(reading.id).returns(reading) | ||
| 177 | + | ||
| 178 | + delete :destroy, id: reading.id, reading_group_id: reading.group_id.to_s | ||
| 179 | + end | ||
| 180 | + | ||
| 181 | + it { should redirect_to(reading_group_path(reading.group_id)) } | ||
| 182 | + it { should respond_with(:redirect) } | ||
| 183 | + end | ||
| 184 | + | ||
| 185 | + context "when the user doesn't own the reading group" do | ||
| 186 | + before :each do | ||
| 187 | + Reading.expects(:find).at_least_once.with(reading.id).returns(reading) | ||
| 188 | + | ||
| 189 | + delete :destroy, id: reading.id, reading_group_id: reading.group_id.to_s | ||
| 190 | + end | ||
| 191 | + | ||
| 192 | + it { should redirect_to(reading_group_path(reading.group_id)) } | ||
| 193 | + it { should respond_with(:redirect) } | ||
| 194 | + end | ||
| 195 | + end | ||
| 196 | + | ||
| 197 | + context 'with no User logged in' do | ||
| 198 | + before :each do | ||
| 199 | + delete :destroy, id: reading.id, reading_group_id: reading.group_id.to_s | ||
| 200 | + end | ||
| 201 | + | ||
| 202 | + it { should redirect_to new_user_session_path } | ||
| 203 | + end | ||
| 204 | + end | ||
| 205 | + | ||
| 164 | end | 206 | end |
| 165 | \ No newline at end of file | 207 | \ No newline at end of file |