Add specs for destroy

openid
Micha Wrobel 13 years ago
parent e7567848d3
commit 4f47f0a7fc

@ -20,7 +20,12 @@ class CommentsController < ApplicationController
#TODO Add Authorization
def destroy
respond_with Comment.destroy(params[:id])
comment = Comment.find(params[:id])
if comment.user == current_user
respond_with comment.delete
else
raise Unauthorized
end
end
private

@ -2,19 +2,17 @@ require 'spec_helper'
describe CommentsController do
let(:user) { mock_model(User) }
let(:user) { Factory(:user) }
let(:asciicast) { mock_model(Asciicast) }
it "should ensure user is authenticated" do
end
before do
Asciicast.stub(:find).and_return(asciicast)
login_as(user)
end
describe "#create" do
before do
Asciicast.stub(:find).and_return(asciicast)
end
context "given valid data" do
def dispatch
@ -60,6 +58,9 @@ describe CommentsController do
end
describe "#index" do
before do
Asciicast.stub(:find).and_return(asciicast)
end
it "return comments" do
asciicast.should_receive(:comments).and_return([])
@ -68,4 +69,37 @@ describe CommentsController do
end
describe "#destroy" do
let(:comment) { mock_model(Comment).as_null_object }
before do
Comment.stub(:find).with("1").and_return(comment)
end
context "when user is creator of comment" do
before do
comment.stub(:user).and_return(user)
end
it "calls delete on comment" do
comment.should_receive(:delete)
delete :destroy, :id => 1
end
end
context "when user is not creator of comment" do
let(:other_user) { Factory(:user) }
before do
comment.stub(:user).and_return(other_user)
end
it "raise Unauthorized exception" do
expect {
delete :destroy, :id => 1
}.to raise_error
end
end
end
end

Loading…
Cancel
Save