Skip to content

Commit c784666

Browse files
committed
appraisal install and removing policy tests
1 parent 902a31a commit c784666

6 files changed

Lines changed: 8 additions & 66 deletions

File tree

app/controllers/rails_admin/main_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class MainController < RailsAdmin::ApplicationController
33
include ActionView::Helpers::TextHelper
44
include RailsAdmin::MainHelper
55
include RailsAdmin::ApplicationHelper
6-
include Pundit
76

87
layout :get_layout
98

gemfiles/rails_4.0.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ group :test do
5757
gem "rubocop", "~> 0.31.0"
5858
gem "simplecov", ">= 0.9", :require => false
5959
gem "timecop", ">= 0.5"
60+
gem "pundit"
6061

6162
platforms :ruby_21, :ruby_22 do
6263
gem "refile", "~> 0.5", :require => "refile/rails"

gemfiles/rails_4.1.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ group :test do
5555
gem "rubocop", "~> 0.31.0"
5656
gem "simplecov", ">= 0.9", :require => false
5757
gem "timecop", ">= 0.5"
58+
gem "pundit"
5859

5960
platforms :ruby_21, :ruby_22 do
6061
gem "refile", "~> 0.5", :require => "refile/rails"

gemfiles/rails_4.2.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ group :test do
5656
gem "rubocop", "~> 0.31.0"
5757
gem "simplecov", ">= 0.9", :require => false
5858
gem "timecop", ">= 0.5"
59+
gem "pundit"
5960

6061
platforms :ruby_21, :ruby_22 do
6162
gem "refile", "~> 0.5", :require => "refile/rails"

lib/generators/rails_admin/templates/initializer.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ RailsAdmin.config do |config|
1111
## == Cancan ==
1212
# config.authorize_with :cancan
1313

14+
## == Pundit ==
15+
# config.authorize_with :pundit
16+
1417
## == PaperTrail ==
1518
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
1619

spec/integration/authorization/pundit_spec.rb

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'spec_helper'
2+
include Pundit
23

34
class 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
8461
end
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

12865
describe '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

Comments
 (0)