I want to check this destruction action:
def destroy
@comment = Comment.find(params[:id])
@comment_id = @comment.id
if @comment.delete_permission(current_user.id)
@remove_comment = true
@comment.destroy
else
@remove_comment = false
head :forbidden
end
end
My specification is as follows:
describe "DELETE 'destroy'" do
describe 'via ajx' do
it "should be successful if permission true" do
comment = Comment.stub(:find).with(37).and_return @comment
comment.should_receive(:delete_permission).with(@user.id).and_return true
comment.should_receive(:destroy)
delete 'destroy', :id => 37
end
end
end
I always get:
comment.should_receive....
expected: 1 time
received: 0 times
Why: delete_permission is never called? Do you have any suggestions for testing it?
source
share