Sha256: 7fe0bff06bf2ffe55ee96196b73a54ae9b075e2b1835a21958fe8ecc2ff871b2

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

class DeniesController < ActionController::Base
  include Clearance::Authentication
  before_filter :authorize, :only => :show

  def new
    render :text => "New page"
  end

  def show
    render :text => "Show page"
  end

  protected

  def authorize
    deny_access(:flash => "Access denied.")
  end
end

describe DeniesController do
  before do
    Rails.application.routes.draw do
      resource :deny, :only => [:new, :show]
      match 'sign_in'  => 'clearance/sessions#new', :as => 'sign_in'
    end
  end

  after do
    Rails.application.reload_routes!
  end

  context "signed in user" do
    before { sign_in }

    it "allows access to new" do
      get :new
      subject.should_not deny_access
    end

    it "denies access to show" do
      get :show
      subject.should deny_access(:redirect => '/')
    end
  end

  context "visitor" do
    it "allows access to new" do
      get :new
      subject.should_not deny_access
    end

    it "denies access to show" do
      get :show
      subject.should deny_access
      subject.should deny_access(:redirect => sign_in_url, :flash => "Access denied.")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clearance-0.13.0 spec/controllers/denies_controller_spec.rb
clearance-0.12.0 spec/controllers/denies_controller_spec.rb