fixes spec

This commit is contained in:
rgarcia
2016-03-29 17:36:31 +02:00
parent 6f723a871f
commit d5453f1733
5 changed files with 12 additions and 9 deletions

View File

@@ -29,7 +29,7 @@ class SpendingProposalsController < ApplicationController
end
def destroy
spending_proposal = current_user.spending_proposals.find(params[:id])
spending_proposal = SpendingProposal.find(params[:id])
spending_proposal.destroy
redirect_to user_path(current_user, filter: 'spending_proposals'), notice: t('flash.actions.destroy.spending_proposal')
end

View File

@@ -132,10 +132,12 @@ feature 'Spending proposals' do
context "Destroy" do
scenario "User can destroy owned spending proposals" do
scenario "Admin can destroy owned spending proposals" do
admin = create(:administrator)
user = create(:user, :level_two)
spending_proposal = create(:spending_proposal, author: user)
login_as(user)
login_as(admin.user)
visit user_path(user)
within("#spending_proposal_#{spending_proposal.id}") do

View File

@@ -240,19 +240,19 @@ feature 'Users' do
expect(page).to have_content('Build a school')
end
scenario 'delete button is shown if logged in user is author' do
scenario 'delete button is not shown if logged in user is author' do
login_as(@author)
visit user_path(@author)
within("#spending_proposal_#{@spending_proposal.id}") do
expect(page).to have_content('Delete')
expect(page).to_not have_content('Delete')
end
end
scenario 'delete button is not shown if logged in user is admin' do
scenario 'delete button is shown if logged in user is admin' do
login_as(create(:administrator).user)
visit user_path(@author)
within("#spending_proposal_#{@spending_proposal.id}") do
expect(page).to_not have_content('Delete')
expect(page).to have_content('Delete')
end
end

View File

@@ -55,4 +55,5 @@ describe "Abilities::Administrator" do
it { should be_able_to(:read, SpendingProposal) }
it { should be_able_to(:update, SpendingProposal) }
it { should be_able_to(:valuate, SpendingProposal) }
it { should be_able_to(:destroy, SpendingProposal) }
end

View File

@@ -92,7 +92,7 @@ describe "Abilities::Common" do
it { should be_able_to(:create, SpendingProposal) }
it { should_not be_able_to(:destroy, create(:spending_proposal)) }
it { should be_able_to(:destroy, own_spending_proposal) }
it { should_not be_able_to(:destroy, own_spending_proposal) }
end
describe "when level 3 verified" do
@@ -104,6 +104,6 @@ describe "Abilities::Common" do
it { should be_able_to(:create, SpendingProposal) }
it { should_not be_able_to(:destroy, create(:spending_proposal)) }
it { should be_able_to(:destroy, own_spending_proposal) }
it { should_not be_able_to(:destroy, own_spending_proposal) }
end
end