11require 'spec_helper'
2+ include Pundit
23
34class ApplicationPolicy
45 attr_reader :user , :record
@@ -8,30 +9,6 @@ def initialize(user, record)
89 @record = record
910 end
1011
11- def new?
12- user . roles . include? :admin
13- end
14-
15- def show?
16- true
17- end
18-
19- def update?
20- user . roles . include? :admin
21- end
22-
23- def create?
24- user . roles . include? :admin
25- end
26-
27- def edit?
28- user . roles . include? :admin
29- end
30-
31- def destroy?
32- user . roles . include? :admin
33- end
34-
3512 def rails_admin? ( action )
3613 case action
3714 when :dashboard
@@ -83,47 +60,7 @@ def rails_admin?(action)
8360 end
8461end
8562
86- describe PlayerPolicy do
87- before do
88- RailsAdmin . config do |c |
89- c . authorize_with ( :pundit )
90- c . authenticate_with { warden . authenticate! scope : :user }
91- c . current_user_method ( &:current_user )
92- end
93- @user = FactoryGirl . create :user
94- @player_model = RailsAdmin ::AbstractModel . new ( Player )
95- login_as @user
96- end
97-
98- subject { PlayerPolicy . new ( user , player ) }
99-
100- let ( :player ) { @player_model }
101-
102- describe 'for a user with no roles' do
103- let ( :user ) { @user }
10463
105- it { should permit ( :show ) }
106- it { should_not permit ( :create ) }
107- it { should_not permit ( :new ) }
108- it { should_not permit ( :update ) }
109- it { should_not permit ( :edit ) }
110- it { should_not permit ( :destroy ) }
111- end
112-
113- describe 'for an admin' do
114- before do
115- @user . update_attributes ( roles : [ :admin , :read_player ] )
116- end
117-
118- let ( :user ) { @user }
119- it { should permit ( :show ) }
120- it { should permit ( :create ) }
121- it { should permit ( :new ) }
122- it { should permit ( :update ) }
123- it { should permit ( :edit ) }
124- it { should permit ( :destroy ) }
125- end
126- end
12764
12865describe 'RailsAdmin Pundit Authorization' , type : :request do
12966 subject { page }
@@ -195,7 +132,7 @@ def rails_admin?(action)
195132 fill_in 'player[name]' , with : 'Jackie Robinson'
196133 fill_in 'player[number]' , with : '42'
197134 fill_in 'player[position]' , with : 'Second baseman'
198- click_button 'Save' # first(:button, "Save").click
135+ click_button 'Save'
199136 is_expected . not_to have_content ( 'Edit' )
200137
201138 @player = RailsAdmin ::AbstractModel . new ( 'Player' ) . first
0 commit comments