/
denies_controller_spec.rb
62 lines (49 loc) · 1.13 KB
/
denies_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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