diff --git a/lib/generators/pundit/policy/policy_generator.rb b/lib/generators/pundit/policy/policy_generator.rb index 4b61320..474dbb6 100644 --- a/lib/generators/pundit/policy/policy_generator.rb +++ b/lib/generators/pundit/policy/policy_generator.rb @@ -6,6 +6,8 @@ module Pundit def create_policy template 'policy.rb', File.join('app/policies', class_path, "#{file_name}_policy.rb") end + + hook_for :test_framework end end end diff --git a/lib/generators/rspec/policy_generator.rb b/lib/generators/rspec/policy_generator.rb new file mode 100644 index 0000000..4a91a5f --- /dev/null +++ b/lib/generators/rspec/policy_generator.rb @@ -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 diff --git a/lib/generators/rspec/templates/policy_spec.rb b/lib/generators/rspec/templates/policy_spec.rb new file mode 100644 index 0000000..80abde8 --- /dev/null +++ b/lib/generators/rspec/templates/policy_spec.rb @@ -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 diff --git a/lib/generators/test_unit/policy_generator.rb b/lib/generators/test_unit/policy_generator.rb new file mode 100644 index 0000000..5baf50c --- /dev/null +++ b/lib/generators/test_unit/policy_generator.rb @@ -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 diff --git a/lib/generators/test_unit/templates/policy_test.rb b/lib/generators/test_unit/templates/policy_test.rb new file mode 100644 index 0000000..281737d --- /dev/null +++ b/lib/generators/test_unit/templates/policy_test.rb @@ -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 diff --git a/lib/pundit.rb b/lib/pundit.rb index baabef2..04a2a77 100644 --- a/lib/pundit.rb +++ b/lib/pundit.rb @@ -3,6 +3,7 @@ require "pundit/policy_finder" require "active_support/concern" require "active_support/core_ext/string/inflections" require "active_support/core_ext/object/blank" +require "active_support/dependencies/autoload" module Pundit class NotAuthorizedError < StandardError