Skip to content

Commit

Permalink
appraisal install and removing policy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasi committed Sep 15, 2015
1 parent 902a31a commit c784666
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 66 deletions.
1 change: 0 additions & 1 deletion app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class MainController < RailsAdmin::ApplicationController
include ActionView::Helpers::TextHelper
include RailsAdmin::MainHelper
include RailsAdmin::ApplicationHelper
include Pundit

layout :get_layout

Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_4.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ group :test do
gem "rubocop", "~> 0.31.0"
gem "simplecov", ">= 0.9", :require => false
gem "timecop", ">= 0.5"
gem "pundit"

platforms :ruby_21, :ruby_22 do
gem "refile", "~> 0.5", :require => "refile/rails"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ group :test do
gem "rubocop", "~> 0.31.0"
gem "simplecov", ">= 0.9", :require => false
gem "timecop", ">= 0.5"
gem "pundit"

platforms :ruby_21, :ruby_22 do
gem "refile", "~> 0.5", :require => "refile/rails"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ group :test do
gem "rubocop", "~> 0.31.0"
gem "simplecov", ">= 0.9", :require => false
gem "timecop", ">= 0.5"
gem "pundit"

platforms :ruby_21, :ruby_22 do
gem "refile", "~> 0.5", :require => "refile/rails"
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/rails_admin/templates/initializer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ RailsAdmin.config do |config|
## == Cancan ==
# config.authorize_with :cancan

## == Pundit ==
# config.authorize_with :pundit

## == PaperTrail ==
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0

Expand Down
67 changes: 2 additions & 65 deletions spec/integration/authorization/pundit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
include Pundit

class ApplicationPolicy
attr_reader :user, :record
Expand All @@ -8,30 +9,6 @@ def initialize(user, record)
@record = record
end

def new?
user.roles.include? :admin
end

def show?
true
end

def update?
user.roles.include? :admin
end

def create?
user.roles.include? :admin
end

def edit?
user.roles.include? :admin
end

def destroy?
user.roles.include? :admin
end

def rails_admin?(action)
case action
when :dashboard
Expand Down Expand Up @@ -83,47 +60,7 @@ def rails_admin?(action)
end
end

describe PlayerPolicy do
before do
RailsAdmin.config do |c|
c.authorize_with(:pundit)
c.authenticate_with { warden.authenticate! scope: :user }
c.current_user_method(&:current_user)
end
@user = FactoryGirl.create :user
@player_model = RailsAdmin::AbstractModel.new(Player)
login_as @user
end

subject { PlayerPolicy.new(user, player) }

let(:player) { @player_model }

describe 'for a user with no roles' do
let(:user) { @user }

it { should permit(:show) }
it { should_not permit(:create) }
it { should_not permit(:new) }
it { should_not permit(:update) }
it { should_not permit(:edit) }
it { should_not permit(:destroy) }
end

describe 'for an admin' do
before do
@user.update_attributes(roles: [:admin, :read_player])
end

let(:user) { @user }
it { should permit(:show) }
it { should permit(:create) }
it { should permit(:new) }
it { should permit(:update) }
it { should permit(:edit) }
it { should permit(:destroy) }
end
end

describe 'RailsAdmin Pundit Authorization', type: :request do
subject { page }
Expand Down Expand Up @@ -195,7 +132,7 @@ def rails_admin?(action)
fill_in 'player[name]', with: 'Jackie Robinson'
fill_in 'player[number]', with: '42'
fill_in 'player[position]', with: 'Second baseman'
click_button 'Save' # first(:button, "Save").click
click_button 'Save'
is_expected.not_to have_content('Edit')

@player = RailsAdmin::AbstractModel.new('Player').first
Expand Down

0 comments on commit c784666

Please sign in to comment.