openid
Marcin Kulik 13 years ago
parent 98d5285a23
commit 80df89ec84

@ -24,7 +24,7 @@ class Api::CommentsController < ApplicationController
if comment.user == current_user
respond_with comment.delete
else
raise Forbiden
raise Forbidden
end
end

@ -5,10 +5,10 @@ class ApplicationController < ActionController::Base
rescue_from(ActiveRecord::RecordNotFound) { render 'exceptions/not_found' }
class Unauthorized < Exception; end
class Forbiden < Exception; end
class Forbidden < Exception; end
rescue_from Unauthorized, :with => :unauthorized
rescue_from Forbiden, :with => :forbiden
rescue_from Forbidden, :with => :forbidden
helper_method :current_user
@ -32,11 +32,11 @@ class ApplicationController < ActionController::Base
raise Unauthorized unless current_user
end
def forbiden
def forbidden
if request.xhr?
render :json => "Forbiden", :status => 403
render :json => "Forbidden", :status => 403
else
redirect_to root_path, :alert => "This action is forbiden"
redirect_to root_path, :alert => "This action is forbidden"
end
end

@ -7,7 +7,7 @@ class FakeController < ApplicationController
end
def bar
raise Forbiden
raise Forbidden
end
end
@ -42,7 +42,7 @@ describe FakeController do
end
end
context "when action raise forbiden" do
context "when action raise forbidden" do
context "when xhr" do
before{ request.stub(:xhr?).and_return(true) }
@ -58,7 +58,7 @@ describe FakeController do
it "redirects to root_path" do
get :bar
flash[:alert].should == "This action is forbiden"
flash[:alert].should == "This action is forbidden"
should redirect_to(root_path)
end

Loading…
Cancel
Save