asciinema.org/spec/controllers/application_controller_spec.rb

70 lines
1.1 KiB
Ruby
Raw Normal View History

require 'spec_helper'
class FakeController < ApplicationController
def foo
raise Unauthorized
end
def bar
2012-03-06 20:27:17 +00:00
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
2012-03-06 20:27:17 +00:00
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
2012-03-06 20:27:17 +00:00
flash[:alert].should == "This action is forbidden"
should redirect_to(root_path)
end
end
end
end