|
|
@ -2,19 +2,17 @@ require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
|
|
describe CommentsController do
|
|
|
|
describe CommentsController do
|
|
|
|
|
|
|
|
|
|
|
|
let(:user) { mock_model(User) }
|
|
|
|
let(:user) { Factory(:user) }
|
|
|
|
let(:asciicast) { mock_model(Asciicast) }
|
|
|
|
let(:asciicast) { mock_model(Asciicast) }
|
|
|
|
|
|
|
|
|
|
|
|
it "should ensure user is authenticated" do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
before do
|
|
|
|
Asciicast.stub(:find).and_return(asciicast)
|
|
|
|
|
|
|
|
login_as(user)
|
|
|
|
login_as(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
describe "#create" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
|
|
|
Asciicast.stub(:find).and_return(asciicast)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context "given valid data" do
|
|
|
|
context "given valid data" do
|
|
|
|
def dispatch
|
|
|
|
def dispatch
|
|
|
@ -60,6 +58,9 @@ describe CommentsController do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
describe "#index" do
|
|
|
|
describe "#index" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
|
|
|
Asciicast.stub(:find).and_return(asciicast)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it "return comments" do
|
|
|
|
it "return comments" do
|
|
|
|
asciicast.should_receive(:comments).and_return([])
|
|
|
|
asciicast.should_receive(:comments).and_return([])
|
|
|
@ -68,4 +69,37 @@ describe CommentsController do
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|