mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Merge pull request #138 from johnotander/spec_generator
Add generators for policy specs / tests with Rspec, MiniTest and Test::Unit
This commit is contained in:
commit
068b5f5d7a
6 changed files with 72 additions and 0 deletions
|
@ -6,6 +6,8 @@ module Pundit
|
||||||
def create_policy
|
def create_policy
|
||||||
template 'policy.rb', File.join('app/policies', class_path, "#{file_name}_policy.rb")
|
template 'policy.rb', File.join('app/policies', class_path, "#{file_name}_policy.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hook_for :test_framework
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
11
lib/generators/rspec/policy_generator.rb
Normal file
11
lib/generators/rspec/policy_generator.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module Rspec
|
||||||
|
module Generators
|
||||||
|
class PolicyGenerator < ::Rails::Generators::NamedBase
|
||||||
|
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
||||||
|
|
||||||
|
def create_policy_spec
|
||||||
|
template 'policy_spec.rb', File.join('spec/policies', class_path, "#{file_name}_policy_spec.rb")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
28
lib/generators/rspec/templates/policy_spec.rb
Normal file
28
lib/generators/rspec/templates/policy_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe <%= class_name %>Policy do
|
||||||
|
|
||||||
|
let(:user) { User.new }
|
||||||
|
|
||||||
|
subject { <%= class_name %>Policy }
|
||||||
|
|
||||||
|
permissions ".scope" do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :create? do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :show? do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :update? do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
|
||||||
|
permissions :destroy? do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
end
|
11
lib/generators/test_unit/policy_generator.rb
Normal file
11
lib/generators/test_unit/policy_generator.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module TestUnit
|
||||||
|
module Generators
|
||||||
|
class PolicyGenerator < ::Rails::Generators::NamedBase
|
||||||
|
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
||||||
|
|
||||||
|
def create_policy_test
|
||||||
|
template 'policy_test.rb', File.join('test/policies', class_path, "#{file_name}_policy_test.rb")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
19
lib/generators/test_unit/templates/policy_test.rb
Normal file
19
lib/generators/test_unit/templates/policy_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class <%= class_name %>PolicyTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
|
def test_scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_create
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_update
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_destroy
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,6 +3,7 @@ require "pundit/policy_finder"
|
||||||
require "active_support/concern"
|
require "active_support/concern"
|
||||||
require "active_support/core_ext/string/inflections"
|
require "active_support/core_ext/string/inflections"
|
||||||
require "active_support/core_ext/object/blank"
|
require "active_support/core_ext/object/blank"
|
||||||
|
require "active_support/dependencies/autoload"
|
||||||
|
|
||||||
module Pundit
|
module Pundit
|
||||||
class NotAuthorizedError < StandardError
|
class NotAuthorizedError < StandardError
|
||||||
|
|
Loading…
Reference in a new issue