You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
class FakeController < ApplicationController
|
|
|
|
|
|
|
|
def foo
|
|
|
|
raise Unauthorized
|
|
|
|
end
|
|
|
|
|
|
|
|
def bar
|
|
|
|
raise Forbidden
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe FakeController do
|
|
|
|
|
|
|
|
describe "#ensure_authenticated!" do
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "action raise unauthorized" do
|
|
|
|
|
|
|
|
context "when xhr" do
|
|
|
|
before{ request.stub(:xhr?).and_return(true) }
|
|
|
|
|
|
|
|
it "response with 401" do
|
|
|
|
get :foo
|
|
|
|
|
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when typical request" do
|
|
|
|
|
|
|
|
it "redirects to login_path" do
|
|
|
|
get :foo
|
|
|
|
|
|
|
|
flash[:notice].should == "Please login"
|
|
|
|
should redirect_to(login_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when action raise forbidden" do
|
|
|
|
context "when xhr" do
|
|
|
|
before{ request.stub(:xhr?).and_return(true) }
|
|
|
|
|
|
|
|
it "response with 401" do
|
|
|
|
get :bar
|
|
|
|
|
|
|
|
response.status.should == 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when typical request" do
|
|
|
|
|
|
|
|
it "redirects to root_path" do
|
|
|
|
get :bar
|
|
|
|
|
|
|
|
flash[:alert].should == "This action is forbidden"
|
|
|
|
should redirect_to(root_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|