access_policy_rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +7 -0
  5. data/Guardfile +25 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +71 -0
  8. data/Rakefile +14 -0
  9. data/access_policy_rails.gemspec +48 -0
  10. data/lib/access_policy_rails/change_storage_scope.rb +15 -0
  11. data/lib/access_policy_rails/controller_extensions.rb +69 -0
  12. data/lib/access_policy_rails/policy_wrapper.rb +11 -0
  13. data/lib/access_policy_rails/railtie.rb +11 -0
  14. data/lib/access_policy_rails/request_local_storage.rb +12 -0
  15. data/lib/access_policy_rails/version.rb +3 -0
  16. data/lib/access_policy_rails.rb +13 -0
  17. data/spec/acceptance/dummy/README.rdoc +28 -0
  18. data/spec/acceptance/dummy/Rakefile +6 -0
  19. data/spec/acceptance/dummy/app/assets/images/.keep +0 -0
  20. data/spec/acceptance/dummy/app/assets/javascripts/application.js +13 -0
  21. data/spec/acceptance/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/spec/acceptance/dummy/app/controllers/application_controller.rb +5 -0
  23. data/spec/acceptance/dummy/app/controllers/concerns/.keep +0 -0
  24. data/spec/acceptance/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/acceptance/dummy/app/mailers/.keep +0 -0
  26. data/spec/acceptance/dummy/app/models/.keep +0 -0
  27. data/spec/acceptance/dummy/app/models/concerns/.keep +0 -0
  28. data/spec/acceptance/dummy/app/views/layouts/application.html.erb +14 -0
  29. data/spec/acceptance/dummy/bin/bundle +3 -0
  30. data/spec/acceptance/dummy/bin/rails +4 -0
  31. data/spec/acceptance/dummy/bin/rake +4 -0
  32. data/spec/acceptance/dummy/config/application.rb +28 -0
  33. data/spec/acceptance/dummy/config/boot.rb +5 -0
  34. data/spec/acceptance/dummy/config/environment.rb +5 -0
  35. data/spec/acceptance/dummy/config/environments/development.rb +27 -0
  36. data/spec/acceptance/dummy/config/environments/production.rb +80 -0
  37. data/spec/acceptance/dummy/config/environments/test.rb +36 -0
  38. data/spec/acceptance/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/acceptance/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/spec/acceptance/dummy/config/initializers/inflections.rb +16 -0
  41. data/spec/acceptance/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/acceptance/dummy/config/initializers/secret_token.rb +12 -0
  43. data/spec/acceptance/dummy/config/initializers/session_store.rb +3 -0
  44. data/spec/acceptance/dummy/config/initializers/wrap_parameters.rb +9 -0
  45. data/spec/acceptance/dummy/config/locales/en.yml +23 -0
  46. data/spec/acceptance/dummy/config/routes.rb +56 -0
  47. data/spec/acceptance/dummy/config.ru +4 -0
  48. data/spec/acceptance/dummy/lib/assets/.keep +0 -0
  49. data/spec/acceptance/dummy/log/.keep +0 -0
  50. data/spec/acceptance/dummy/log/test.log +0 -0
  51. data/spec/acceptance/dummy/public/404.html +58 -0
  52. data/spec/acceptance/dummy/public/422.html +58 -0
  53. data/spec/acceptance/dummy/public/500.html +57 -0
  54. data/spec/acceptance/dummy/public/favicon.ico +0 -0
  55. data/spec/acceptance/enables_permission_query_spec.rb +49 -0
  56. data/spec/acceptance/enforce_authorize_outside_of_action_spec.rb +67 -0
  57. data/spec/acceptance/protect_controller_actions_spec.rb +25 -0
  58. data/spec/acceptance/support/dummy_controller.rb +13 -0
  59. data/spec/acceptance/support/dummy_controller_policy.rb +11 -0
  60. data/spec/acceptance/support/feature.rb +30 -0
  61. data/spec/acceptance/use_different_user_for_policy_checks_spec.rb +40 -0
  62. data/spec/acceptance_spec_helper.rb +12 -0
  63. data/spec/spec_helper.rb +42 -0
  64. data/spec/support/base_controller_dummy.rb +26 -0
  65. data/spec/unit/lib/access_policy_rails/controller_extensions_spec.rb +89 -0
  66. data/spec/unit/lib/access_policy_rails/policy_wrapper_spec.rb +20 -0
  67. data/spec/unit/lib/access_policy_rails/request_local_storage_spec.rb +52 -0
  68. data/spec/unit_spec_helper.rb +1 -0
  69. metadata +387 -0
@@ -0,0 +1,36 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ config.serve_static_assets = true
17
+ config.static_cache_control = "public, max-age=3600"
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Print deprecation notices to the stderr.
35
+ config.active_support.deprecation = :stderr
36
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ Dummy::Application.config.secret_key_base = '16ce008690d50afa9e7eabb77bb6ee1ea25c92a18998c91f1f2248fe249750113fb37b055d4665f77c2a62a354dfb4eb3b2273c8feb46bdf7c5ec5164f011d05'
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
@@ -0,0 +1,9 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,56 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+ # See how all your routes lay out with "rake routes".
4
+
5
+ # You can have the root of your site routed with "root"
6
+ # root 'welcome#index'
7
+
8
+ # Example of regular route:
9
+ # get 'products/:id' => 'catalog#view'
10
+
11
+ # Example of named route that can be invoked with purchase_url(id: product.id)
12
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
+
14
+ # Example resource route (maps HTTP verbs to controller actions automatically):
15
+ # resources :products
16
+
17
+ # Example resource route with options:
18
+ # resources :products do
19
+ # member do
20
+ # get 'short'
21
+ # post 'toggle'
22
+ # end
23
+ #
24
+ # collection do
25
+ # get 'sold'
26
+ # end
27
+ # end
28
+
29
+ # Example resource route with sub-resources:
30
+ # resources :products do
31
+ # resources :comments, :sales
32
+ # resource :seller
33
+ # end
34
+
35
+ # Example resource route with more complex sub-resources:
36
+ # resources :products do
37
+ # resources :comments
38
+ # resources :sales do
39
+ # get 'recent', on: :collection
40
+ # end
41
+ # end
42
+
43
+ # Example resource route with concerns:
44
+ # concern :toggleable do
45
+ # post 'toggle'
46
+ # end
47
+ # resources :posts, concerns: :toggleable
48
+ # resources :photos, concerns: :toggleable
49
+
50
+ # Example resource route within a namespace:
51
+ # namespace :admin do
52
+ # # Directs /admin/products/* to Admin::ProductsController
53
+ # # (app/controllers/admin/products_controller.rb)
54
+ # resources :products
55
+ # end
56
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
File without changes
File without changes
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,49 @@
1
+ require 'acceptance_spec_helper'
2
+
3
+ feature 'Enables permission query', %q{
4
+ In order to execute command depended on permissions
5
+ as a developer
6
+ I want to be able to query permissions
7
+ } do
8
+
9
+ given(:a_controller){
10
+ Class.new(ProtectControllerActionsSpec::DummyController) do
11
+
12
+ end.new.tap {|c|
13
+ c.current_user = a_user
14
+ }
15
+ }
16
+
17
+ given(:a_user){
18
+ double('user', create_allowed?: false, show_allowed?: true)
19
+ }
20
+
21
+ given(:service_object){
22
+ Class.new() do
23
+ include AccessPolicy
24
+
25
+ def self.policy_class
26
+ Struct.new(:current_user, :service_object) do
27
+ def create?
28
+ !!(current_user && current_user.create_allowed?)
29
+ end
30
+
31
+ def show?
32
+ !!(current_user && current_user.show_allowed?)
33
+ end
34
+ end
35
+ end
36
+
37
+ end.new
38
+ }
39
+
40
+ scenario 'action is allowed' do
41
+ expect(a_controller.policy_for(service_object).allow?(:show)).to be_truthy
42
+ end
43
+
44
+ scenario 'action is forbidden' do
45
+ expect(a_controller.policy_for(service_object).allow?(:create)).to be_falsy
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,67 @@
1
+ require 'acceptance_spec_helper'
2
+
3
+ feature 'Enforce authorize outside of a controller action', %q{
4
+ In order to enforce authorization in service objects
5
+ as a developer
6
+ I want to be able to mark actions as authorization needed but not self authorized
7
+ } do
8
+
9
+ given(:a_controller_with_guarded_actions){
10
+ Class.new(ProtectControllerActionsSpec::DummyController) do
11
+ attr_accessor :service_object
12
+
13
+ def self.policy_class
14
+ ProtectControllerActionsSpec::DummyControllerPolicy
15
+ end
16
+
17
+ guarded_action :update, authorize_action: false do
18
+ service_object.call
19
+ end
20
+
21
+ guarded_action :post, authorize_action: false do
22
+ service_object.post
23
+ end
24
+
25
+ end.new.tap {|c|
26
+ c.current_user = a_user
27
+ c.service_object = service_object
28
+ }
29
+ }
30
+
31
+ given(:a_user){
32
+ double('user', create_allowed?: false, show_allowed?: false)
33
+ }
34
+
35
+ given(:service_object){
36
+ Class.new() do
37
+ include AccessPolicy
38
+
39
+ def self.policy_class
40
+ Struct.new(:current_user, :service_object) do
41
+ def call?
42
+ true
43
+ end
44
+ end
45
+ end
46
+
47
+ policy_guarded_method "call" do
48
+
49
+ end
50
+
51
+ def post
52
+
53
+ end
54
+
55
+ end.new
56
+ }
57
+
58
+ scenario 'action is authorized in service object' do
59
+ expect{a_controller_with_guarded_actions.update}.not_to raise_error
60
+ end
61
+
62
+ scenario 'action is not authorized in service object' do
63
+ expect{a_controller_with_guarded_actions.post}.to raise_error AccessPolicy::AuthorizeNotCalledError
64
+ end
65
+
66
+
67
+ end
@@ -0,0 +1,25 @@
1
+ require 'acceptance_spec_helper'
2
+
3
+ feature 'Protect controller actions', %q{
4
+ In order to secure my rails application
5
+ as a developer
6
+ I want to protect some actions
7
+ } do
8
+
9
+ given(:a_controller_with_guarded_actions){
10
+ ProtectControllerActionsSpec::DummyController.new.tap {|c| c.current_user = a_user}
11
+ }
12
+
13
+ given(:a_user){
14
+ double('user', create_allowed?: false, show_allowed?: true)
15
+ }
16
+
17
+ scenario "access protected actions without permission" do
18
+ expect{a_controller_with_guarded_actions.create}.to raise_error AccessPolicy::NotAuthorizedError
19
+ end
20
+
21
+ scenario "access protected actions with permission" do
22
+ expect{a_controller_with_guarded_actions.show}.not_to raise_error
23
+ end
24
+
25
+ end
@@ -0,0 +1,13 @@
1
+ module ProtectControllerActionsSpec
2
+ class DummyController < ActionController::Base
3
+ attr_accessor :current_user
4
+
5
+ guarded_action :create do
6
+
7
+ end
8
+
9
+ guarded_action :show do
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module ProtectControllerActionsSpec
2
+ DummyControllerPolicy = Struct.new(:current_user, :controller) do
3
+ def create?
4
+ current_user && current_user.create_allowed?
5
+ end
6
+
7
+ def show?
8
+ current_user && current_user.show_allowed?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # taken from https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/features.rb
3
+ #
4
+ module Capybara
5
+ module Features
6
+ def self.included(base)
7
+ base.instance_eval do
8
+ alias :background :before
9
+ alias :scenario :it
10
+ alias :xscenario :xit
11
+ alias :given :let
12
+ alias :given! :let!
13
+ alias :feature :describe
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ def self.feature(*args, &block)
21
+ options = if args.last.is_a?(Hash) then args.pop else {} end
22
+ options[:capybara_feature] = true
23
+ options[:type] = :feature
24
+ options[:caller] ||= caller
25
+ args.push(options)
26
+
27
+ describe(*args, &block)
28
+ end
29
+
30
+ RSpec.configuration.include Capybara::Features, :capybara_feature => true
@@ -0,0 +1,40 @@
1
+ require 'acceptance_spec_helper'
2
+
3
+ feature 'Use different user for policy checks', %q{
4
+ In order to use another user then the current user
5
+ as a developer
6
+ I want to be able to override policy_check_user
7
+ } do
8
+
9
+ given(:a_controller_with_guarded_actions){
10
+ Class.new(ProtectControllerActionsSpec::DummyController) do
11
+ attr_accessor :other_user
12
+
13
+ def self.policy_class
14
+ ProtectControllerActionsSpec::DummyControllerPolicy
15
+ end
16
+
17
+ protected
18
+ def policy_check_user
19
+ other_user
20
+ end
21
+ end.new.tap {|c|
22
+ c.current_user = a_user
23
+ c.other_user = a_user_with_permissions
24
+ }
25
+ }
26
+
27
+ given(:a_user){
28
+ double('user', create_allowed?: false, show_allowed?: false)
29
+ }
30
+
31
+ given(:a_user_with_permissions){
32
+ double('a_user_with_permissions', create_allowed?: true, show_allowed?: true)
33
+ }
34
+
35
+ scenario 'policy check user is overridden' do
36
+ expect{a_controller_with_guarded_actions.create}.not_to raise_error
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ # Configure Rails Environment
4
+ ENV["RAILS_ENV"] = "test"
5
+ require File.join(File.expand_path(__dir__ ),"acceptance/dummy/config/environment.rb")
6
+
7
+ #require "action_controller/railtie"
8
+ #require "action_mailer/railtie"
9
+
10
+ require 'rspec/rails'
11
+
12
+ Dir[File.join(File.expand_path(__dir__), "acceptance/support/**/*.rb")].each { |f| require f }
@@ -0,0 +1,42 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:development)
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear! unless ENV["SIMPLE_COVERAGE"]
6
+
7
+ begin
8
+ if ENV["SIMPLE_COVERAGE"]
9
+ require 'simplecov'
10
+ SimpleCov.start do
11
+ add_group "Lib", "lib"
12
+
13
+ add_filter "/spec/"
14
+ end
15
+ end
16
+ rescue LoadError
17
+ warn "=" * 80
18
+ warn 'simplecov not installed. No coverage report'
19
+ warn "=" * 80
20
+ end
21
+
22
+ require 'access_policy_rails'
23
+
24
+ Dir[File.join(File.expand_path(__dir__ ), "support/**/*.rb")].each { |f| require f }
25
+
26
+ # This file was generated by the `rspec --init` command. Conventionally, all
27
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
28
+ # Require this file using `require "spec_helper"` to ensure that it is only
29
+ # loaded once.
30
+ #
31
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
32
+ RSpec.configure do |config|
33
+ config.treat_symbols_as_metadata_keys_with_true_values = true
34
+ config.run_all_when_everything_filtered = true
35
+ config.filter_run :focus
36
+
37
+ # Run specs in random order to surface order dependencies. If you find an
38
+ # order dependency and want to debug it, you can fix the order by providing
39
+ # the seed, which is printed after each run.
40
+ # --seed 1234
41
+ config.order = 'random'
42
+ end