Sha256: f64ab1b5b074abad12fe66e4f597411494038200e1e5c527938868e25adda733

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

class DeniesController < ActionController::Base
  include Clearance::Controller

  before_filter :authorize, :only => :show

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

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

  protected

  def authorize
    deny_access 'Access denied.'
  end
end

describe DeniesController do
  before do
    Rails.application.routes.draw do
      resource :deny, :only => [:new, :show]
      get '/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

5 entries across 5 versions & 1 rubygems

Version Path
clearance-1.0.1 spec/controllers/denies_controller_spec.rb
clearance-1.0.0 spec/controllers/denies_controller_spec.rb
clearance-1.0.0.rc8 spec/controllers/denies_controller_spec.rb
clearance-1.0.0.rc7 spec/controllers/denies_controller_spec.rb
clearance-1.0.0.rc6 spec/controllers/denies_controller_spec.rb