action_policy 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 782d6e62c1723d8aa9b128cf054d90ace4a52a65467db205a079f898a9e068a8
4
- data.tar.gz: e581bec4f5a7aaa782229f85aa34d09d7ed27eb19c870dcc9d3982c3271205d8
3
+ metadata.gz: 272123a33fae55ffd9e6e09b1098862fbbf353a6ed5ff71d090bc5fd01396244
4
+ data.tar.gz: ec53e2634999660b46c95dddc85bcf71055e336fdae5a8ea47023a671bba55ce
5
5
  SHA512:
6
- metadata.gz: 8178fe440e7b7b8f1b60a858e503ad65e37eaa3157dca0f48b772a626704f66763392d60a2f18758d9e903d19e687f292c0b261f5c531d81693ee5e1df38472c
7
- data.tar.gz: 8126f417658773d0deeca4d927881d8a9bf504853d89d58d1d43dd07d6f1328bc355b81bd9f12e7742ce753d20d6c17caf07a0ce2f4fd6df50e2fb0bb70ca034
6
+ metadata.gz: 62353ff2be45386257efcd127a43c7eac61d1cb7fc3cfcbf1acc6d6563e6d0a0a91873a0593b8ff62d51adc70b730e1799eb5a1565e3a1ed3c1f2593d46a05ff
7
+ data.tar.gz: 837e717de9323e7131c535a41fe848aaa9501ad8f10471f082ff1355ae824afa7691b44bb9c8db71cb0b33898ad126963f3518b8cfcc1207e34469a282648d62
@@ -1,5 +1,12 @@
1
1
  ## master
2
2
 
3
+ ## 0.3.4 (2019-11-27)
4
+
5
+ - Fix Rails generators. ([@palkan][])
6
+
7
+ Only invoke install generator if `application_policy.rb` is missing.
8
+ Fix hooking into test frameworks.
9
+
3
10
  ## 0.3.3 (2019-11-27)
4
11
 
5
12
  - Improve pretty print functionality. ([@palkan][])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionPolicy
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
@@ -1,2 +1,2 @@
1
1
  Description:
2
- Generates an application policy for your application.
2
+ Generates a base policy class (ApplicationPolicy) for your application.
@@ -1,2 +1,18 @@
1
+ # Base class for application policies
1
2
  class ApplicationPolicy < ActionPolicy::Base
3
+ # Configure additional authorization contexts here
4
+ # (`user` is added by default).
5
+ #
6
+ # authorize :account, optional: true
7
+ #
8
+ # Read more about authoriztion context: https://actionpolicy.evilmartians.io/#/authorization_context
9
+
10
+ private
11
+
12
+ # Define shared methods useful for most policies.
13
+ # For example:
14
+ #
15
+ # def owner?
16
+ # record.user_id == user.id
17
+ # end
2
18
  end
@@ -7,7 +7,10 @@ module ActionPolicy
7
7
  class PolicyGenerator < ::Rails::Generators::NamedBase
8
8
  source_root File.expand_path("templates", __dir__)
9
9
 
10
- invoke "action_policy:install"
10
+ def run_install_if_needed
11
+ return if ::Rails.root.join("app/policies/application_policy.rb").exist?
12
+ generate "action_policy:install"
13
+ end
11
14
 
12
15
  def create_policy
13
16
  template "policy.rb", File.join("app/policies", class_path, "#{file_name}_policy.rb")
@@ -1,6 +1,8 @@
1
- require '<%= File.exists?("spec/rails_helper.rb") ? "rails_helper" : "spec_helper" %>'
1
+ require "<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>"
2
2
 
3
3
  RSpec.describe <%= class_name %>Policy, type: :policy do
4
+ # See https://actionpolicy.evilmartians.io/#/testing?id=rspec-dsl
5
+ #
4
6
  # let(:user) { build_stubbed :user }
5
7
  # let(:record) { build_stubbed :post, draft: false }
6
8
  # let(:context) { {user: user} }
@@ -1,5 +1,6 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
+ # See https://actionpolicy.evilmartians.io/#/testing?id=testing-policies
3
4
  class <%= class_name %>PolicyTest < ActiveSupport::TestCase
4
5
  def test_index
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
@@ -273,10 +273,10 @@ files:
273
273
  - lib/generators/action_policy/policy/USAGE
274
274
  - lib/generators/action_policy/policy/policy_generator.rb
275
275
  - lib/generators/action_policy/policy/templates/policy.rb
276
- - lib/generators/action_policy/rspec/policy_generator.rb
277
- - lib/generators/action_policy/rspec/templates/policy_spec.rb
278
- - lib/generators/action_policy/test_unit/policy_generator.rb
279
- - lib/generators/action_policy/test_unit/templates/policy_test.rb
276
+ - lib/generators/rspec/policy_generator.rb
277
+ - lib/generators/rspec/templates/policy_spec.rb
278
+ - lib/generators/test_unit/policy_generator.rb
279
+ - lib/generators/test_unit/templates/policy_test.rb
280
280
  homepage: https://github.com/palkan/action_policy
281
281
  licenses:
282
282
  - MIT