Permalink
Browse files

added after_destroy_path

  • Loading branch information...
1 parent af97d3c commit 009cd211110413e36e6b6fb56d6240bf95aa5f64 @Draiken committed Jul 19, 2012
@@ -40,7 +40,7 @@ def destroy
respond_to do |format|
format.js
- format.html { redirect_to( @comment.commentable ) }
+ format.html { redirect_to( opinio_after_destroy_path(@comment) ) }
end
end
@@ -27,9 +27,12 @@ def can_destroy_opinio?(opinio)
end
def opinio_after_create_path(resource)
- puts self.class.name
resource.is_a?(Opinio.model_name.constantize) ? resource.commentable : resource
end
+
+ def opinio_after_destroy_path(comment)
+ comment.commentable
+ end
end
end
end
@@ -82,13 +82,15 @@
end
describe "GET reply" do
- it "should return javascript" do
- get :reply,
- :id => create_valid_comment.id,
- :format => :js
-
- response.headers["Content-Type"].should =~ /text\/javascript/
- response.should be_success
+ context "with a javascript request" do
+ it "should return javascript" do
+ get :reply,
+ :id => create_valid_comment.id,
+ :format => :js
+
+ response.headers["Content-Type"].should =~ /text\/javascript/
+ response.should be_success
+ end
end
end
@@ -100,24 +102,44 @@
end
end
- it "should remove the comment" do
- comment = create_valid_comment
- delete :destroy,
- :id => comment.id
+ context "with an HTML request" do
+ it "should remove the comment" do
+ comment = create_valid_comment
+ delete :destroy,
+ :id => comment.id
- response.should redirect_to( post_path(comment.commentable) )
- flash[:error].should_not be_present
+ response.should redirect_to( post_path(comment.commentable) )
+ flash[:error].should_not be_present
+ end
end
- it "should remove the comment with javascript" do
- comment = create_valid_comment
- delete :destroy,
- :id => comment.id,
- :format => :js
+ context "with a javascript request" do
+ it "should remove the comment" do
+ comment = create_valid_comment
+ delete :destroy,
+ :id => comment.id,
+ :format => :js
+
+ response.should be_success
+ response.headers["Content-Type"].should =~ /text\/javascript/
+ flash[:error].should_not be_present
+ end
+ end
- response.should be_success
- response.headers["Content-Type"].should =~ /text\/javascript/
- flash[:error].should_not be_present
+ context "with a different opinio_after_destroy_path" do
+
+ before do
+ subject.stub(:opinio_after_destroy_path).and_return(root_path)
+ end
+
+ it "should redirect to the set path" do
+ comment = create_valid_comment
+
+ delete :destroy,
+ :id => comment.id
+
+ response.should redirect_to( root_path )
+ end
end
end

0 comments on commit 009cd21

Please sign in to comment.