acl9 2.1.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +4 -11
  4. data/Appraisals +4 -8
  5. data/Gemfile +0 -2
  6. data/Gemfile.lock +89 -102
  7. data/Rakefile +0 -2
  8. data/acl9.gemspec +1 -2
  9. data/gemfiles/{rails_4.0.gemfile → rails_5.0.gemfile} +2 -4
  10. data/gemfiles/{rails_4.1.gemfile → rails_5.1.gemfile} +2 -4
  11. data/lib/acl9/controller_extensions/generators.rb +2 -2
  12. data/lib/acl9/model_extensions.rb +1 -1
  13. data/lib/acl9/version.rb +1 -1
  14. data/lib/generators/acl9/setup/setup_generator.rb +10 -3
  15. data/lib/generators/acl9/setup/templates/create_role_tables.rb +10 -1
  16. data/lib/generators/acl9/setup/templates/role.rb +1 -1
  17. data/test/controllers/acl_action_override_test.rb +4 -4
  18. data/test/controllers/acl_helper_method_test.rb +2 -2
  19. data/test/controllers/acl_ivars_test.rb +2 -2
  20. data/test/controllers/acl_object_hash_test.rb +1 -1
  21. data/test/controllers/acl_query_mixin.rb +1 -1
  22. data/test/controllers/acl_subject_method_test.rb +1 -1
  23. data/test/controllers/arguments_checking_test.rb +4 -4
  24. data/test/dummy/app/controllers/acl_action_override.rb +5 -5
  25. data/test/dummy/app/controllers/acl_boolean_method.rb +6 -6
  26. data/test/dummy/app/controllers/acl_ivars.rb +3 -3
  27. data/test/dummy/app/controllers/empty_controller.rb +1 -1
  28. data/test/dummy/app/models/string_object_role.rb +3 -0
  29. data/test/dummy/app/models/string_user.rb +3 -0
  30. data/test/dummy/app/models/uuid.rb +1 -1
  31. data/test/dummy/config/environments/test.rb +2 -2
  32. data/test/dummy/config/routes.rb +12 -1
  33. data/test/dummy/db/migrate/20141117132218_create_tables.rb +66 -16
  34. data/test/models/roles_test.rb +5 -1
  35. data/test/test_helper.rb +19 -27
  36. metadata +11 -25
  37. data/gemfiles/rails_4.2.gemfile +0 -10
  38. data/test/dummy/config/environments/production.rb +0 -78
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 42197ff7517796cb0d549260db507f532ff38abd
4
- data.tar.gz: 5a1950ee49a8c32612af387eb6cfa0a9ab3ae2ec
2
+ SHA256:
3
+ metadata.gz: 105b1a050bdefc20d0671c4035500f9abd99f8f588b69ed3ceb3357f61ea01e1
4
+ data.tar.gz: 2e5f73791a47de3e9fe4148c81868d6befcda7075163813eb86877c7e21084a5
5
5
  SHA512:
6
- metadata.gz: 90cdebd216f60a35fed030a1fdf924c41f17af17b7994d1dd30671495ab3b1d941196b30873d4340e05b50971e5efb5fd8d16688d3a9e30e0b0c081694cd3741
7
- data.tar.gz: c62f318d3aab6e16966d2143eb8e30f9635dbc7f668ea16c5fb382fb54887b32e873abcd15ccd77637b63ffb01af608b280a1fbad48eb5fbfca7f4465d26f56b
6
+ metadata.gz: 9caadac85342a7885a46581b4a60fc7c83d51b23c50f85e0e2121fa2d15fd4ab0383984f5f7b48076f18dd49409ad40e5292f9d8a2615aced3088f0f004c28b0
7
+ data.tar.gz: edec0e425c0dfaf67f934b9a79ae37e3fad11baeedb605c04ccf0533bc59d1e3c4851f41f2d909cec855310fe69f811f0ff9aec78755ee3fb8a52c61e47a698d
@@ -1 +1 @@
1
- 2.2.3
1
+ 2.5.0
@@ -1,22 +1,15 @@
1
1
  cache: bundler
2
2
  language: ruby
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1.8
6
- - 2.2.3
7
- - 2.3.0
4
+ - 2.4.3
5
+ - 2.5.0
8
6
  - ruby-head
9
7
 
10
8
  gemfile:
11
- - gemfiles/rails_4.0.gemfile
12
- - gemfiles/rails_4.1.gemfile
13
- - gemfiles/rails_4.2.gemfile
9
+ - gemfiles/rails_5.0.gemfile
10
+ - gemfiles/rails_5.1.gemfile
14
11
 
15
12
  matrix:
16
13
  fast_finish: true
17
14
  allow_failures:
18
15
  - rvm: ruby-head
19
-
20
- addons:
21
- code_climate:
22
- repo_token: 6701faf591ff926cd9b3ea7f07c5e72984d2b1e26b33caba26114a6bfe859a11
data/Appraisals CHANGED
@@ -1,11 +1,7 @@
1
- appraise "rails-4.0" do
2
- gem "rails", "~> 4.0.0"
1
+ appraise "rails-5.0" do
2
+ gem 'rails', '~> 5.0.0'
3
3
  end
4
4
 
5
- appraise "rails-4.1" do
6
- gem "rails", "~> 4.1.0"
7
- end
8
-
9
- appraise "rails-4.2" do
10
- gem 'rails', '~> 4.2.0'
5
+ appraise "rails-5.1" do
6
+ gem 'rails', '~> 5.1.0'
11
7
  end
data/Gemfile CHANGED
@@ -4,6 +4,4 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem 'appraisal'
7
- gem 'tapout'
8
- gem 'minitap'
9
7
  gem 'byebug'
@@ -1,128 +1,118 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acl9 (2.1.1)
5
- rails (~> 4.0)
4
+ acl9 (2.1.2)
5
+ rails (>= 4.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionmailer (4.2.5.1)
11
- actionpack (= 4.2.5.1)
12
- actionview (= 4.2.5.1)
13
- activejob (= 4.2.5.1)
10
+ actioncable (5.1.5)
11
+ actionpack (= 5.1.5)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.1.5)
15
+ actionpack (= 5.1.5)
16
+ actionview (= 5.1.5)
17
+ activejob (= 5.1.5)
14
18
  mail (~> 2.5, >= 2.5.4)
15
- rails-dom-testing (~> 1.0, >= 1.0.5)
16
- actionpack (4.2.5.1)
17
- actionview (= 4.2.5.1)
18
- activesupport (= 4.2.5.1)
19
- rack (~> 1.6)
20
- rack-test (~> 0.6.2)
21
- rails-dom-testing (~> 1.0, >= 1.0.5)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.1.5)
21
+ actionview (= 5.1.5)
22
+ activesupport (= 5.1.5)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
22
26
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
- actionview (4.2.5.1)
24
- activesupport (= 4.2.5.1)
27
+ actionview (5.1.5)
28
+ activesupport (= 5.1.5)
25
29
  builder (~> 3.1)
26
- erubis (~> 2.7.0)
27
- rails-dom-testing (~> 1.0, >= 1.0.5)
28
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- activejob (4.2.5.1)
30
- activesupport (= 4.2.5.1)
31
- globalid (>= 0.3.0)
32
- activemodel (4.2.5.1)
33
- activesupport (= 4.2.5.1)
34
- builder (~> 3.1)
35
- activerecord (4.2.5.1)
36
- activemodel (= 4.2.5.1)
37
- activesupport (= 4.2.5.1)
38
- arel (~> 6.0)
39
- activesupport (4.2.5.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.1.5)
34
+ activesupport (= 5.1.5)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.1.5)
37
+ activesupport (= 5.1.5)
38
+ activerecord (5.1.5)
39
+ activemodel (= 5.1.5)
40
+ activesupport (= 5.1.5)
41
+ arel (~> 8.0)
42
+ activesupport (5.1.5)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
40
44
  i18n (~> 0.7)
41
- json (~> 1.7, >= 1.7.7)
42
45
  minitest (~> 5.1)
43
- thread_safe (~> 0.3, >= 0.3.4)
44
46
  tzinfo (~> 1.1)
45
- ansi (1.5.0)
46
- appraisal (2.1.0)
47
+ appraisal (2.2.0)
47
48
  bundler
48
49
  rake
49
50
  thor (>= 0.14.0)
50
- arel (6.0.3)
51
- builder (3.2.2)
52
- byebug (8.2.2)
53
- codeclimate-test-reporter (0.4.8)
54
- simplecov (>= 0.7.1, < 1.0.0)
55
- concurrent-ruby (1.0.1)
56
- docile (1.1.5)
57
- erubis (2.7.0)
58
- globalid (0.3.6)
59
- activesupport (>= 4.1.0)
60
- i18n (0.7.0)
61
- json (1.8.3)
62
- loofah (2.0.3)
51
+ arel (8.0.0)
52
+ builder (3.2.3)
53
+ byebug (10.0.0)
54
+ concurrent-ruby (1.0.5)
55
+ crass (1.0.3)
56
+ erubi (1.7.1)
57
+ globalid (0.4.1)
58
+ activesupport (>= 4.2.0)
59
+ i18n (0.9.5)
60
+ concurrent-ruby (~> 1.0)
61
+ loofah (2.2.0)
62
+ crass (~> 1.0.2)
63
63
  nokogiri (>= 1.5.9)
64
- mail (2.6.3)
65
- mime-types (>= 1.16, < 3)
66
- mime-types (2.99.1)
67
- mini_portile2 (2.0.0)
68
- minitap (0.5.3)
69
- minitest (~> 5.0)
70
- minitest-reporter-api (>= 0.0.2)
71
- tapout (>= 0.3.0)
72
- minitest (5.8.4)
73
- minitest-reporter-api (0.0.5)
74
- minitest (~> 5.0)
75
- nokogiri (1.6.7.2)
76
- mini_portile2 (~> 2.0.0.rc2)
77
- rack (1.6.4)
78
- rack-test (0.6.3)
79
- rack (>= 1.0)
80
- rails (4.2.5.1)
81
- actionmailer (= 4.2.5.1)
82
- actionpack (= 4.2.5.1)
83
- actionview (= 4.2.5.1)
84
- activejob (= 4.2.5.1)
85
- activemodel (= 4.2.5.1)
86
- activerecord (= 4.2.5.1)
87
- activesupport (= 4.2.5.1)
88
- bundler (>= 1.3.0, < 2.0)
89
- railties (= 4.2.5.1)
90
- sprockets-rails
91
- rails-deprecated_sanitizer (1.0.3)
92
- activesupport (>= 4.2.0.alpha)
93
- rails-dom-testing (1.0.7)
94
- activesupport (>= 4.2.0.beta, < 5.0)
95
- nokogiri (~> 1.6.0)
96
- rails-deprecated_sanitizer (>= 1.0.1)
64
+ mail (2.7.0)
65
+ mini_mime (>= 0.1.1)
66
+ method_source (0.9.0)
67
+ mini_mime (1.0.0)
68
+ mini_portile2 (2.3.0)
69
+ minitest (5.11.3)
70
+ nio4r (2.2.0)
71
+ nokogiri (1.8.2)
72
+ mini_portile2 (~> 2.3.0)
73
+ rack (2.0.4)
74
+ rack-test (0.8.3)
75
+ rack (>= 1.0, < 3)
76
+ rails (5.1.5)
77
+ actioncable (= 5.1.5)
78
+ actionmailer (= 5.1.5)
79
+ actionpack (= 5.1.5)
80
+ actionview (= 5.1.5)
81
+ activejob (= 5.1.5)
82
+ activemodel (= 5.1.5)
83
+ activerecord (= 5.1.5)
84
+ activesupport (= 5.1.5)
85
+ bundler (>= 1.3.0)
86
+ railties (= 5.1.5)
87
+ sprockets-rails (>= 2.0.0)
88
+ rails-dom-testing (2.0.3)
89
+ activesupport (>= 4.2.0)
90
+ nokogiri (>= 1.6)
97
91
  rails-html-sanitizer (1.0.3)
98
92
  loofah (~> 2.0)
99
- railties (4.2.5.1)
100
- actionpack (= 4.2.5.1)
101
- activesupport (= 4.2.5.1)
93
+ railties (5.1.5)
94
+ actionpack (= 5.1.5)
95
+ activesupport (= 5.1.5)
96
+ method_source
102
97
  rake (>= 0.8.7)
103
98
  thor (>= 0.18.1, < 2.0)
104
- rake (10.5.0)
105
- simplecov (0.11.2)
106
- docile (~> 1.1.0)
107
- json (~> 1.8)
108
- simplecov-html (~> 0.10.0)
109
- simplecov-html (0.10.0)
110
- sprockets (3.5.2)
99
+ rake (12.3.0)
100
+ sprockets (3.7.1)
111
101
  concurrent-ruby (~> 1.0)
112
102
  rack (> 1, < 3)
113
- sprockets-rails (3.0.3)
103
+ sprockets-rails (3.2.1)
114
104
  actionpack (>= 4.0)
115
105
  activesupport (>= 4.0)
116
106
  sprockets (>= 3.0.0)
117
- sqlite3 (1.3.11)
118
- tapout (0.4.5)
119
- ansi
120
- json
121
- thor (0.19.1)
122
- thread_safe (0.3.5)
123
- tzinfo (1.2.2)
107
+ sqlite3 (1.3.13)
108
+ thor (0.20.0)
109
+ thread_safe (0.3.6)
110
+ tzinfo (1.2.5)
124
111
  thread_safe (~> 0.1)
125
- yard (0.8.7.6)
112
+ websocket-driver (0.6.5)
113
+ websocket-extensions (>= 0.1.0)
114
+ websocket-extensions (0.1.3)
115
+ yard (0.9.12)
126
116
 
127
117
  PLATFORMS
128
118
  ruby
@@ -131,11 +121,8 @@ DEPENDENCIES
131
121
  acl9!
132
122
  appraisal
133
123
  byebug
134
- codeclimate-test-reporter
135
- minitap
136
124
  sqlite3
137
- tapout
138
125
  yard
139
126
 
140
127
  BUNDLED WITH
141
- 1.11.2
128
+ 1.16.1
data/Rakefile CHANGED
@@ -10,8 +10,6 @@ require 'rake/testtask'
10
10
  Rake::TestTask.new(:test) do |test|
11
11
  test.libs << 'lib' << 'test'
12
12
  test.pattern = 'test/**/*_test.rb'
13
- test.verbose = false
14
- test.options = " | tapout runtime"
15
13
  end
16
14
 
17
15
  require 'yard'
@@ -20,9 +20,8 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.rdoc_options = ["--charset=UTF-8"]
22
22
 
23
- s.add_dependency "rails", '~> 4.0'
23
+ s.add_dependency "rails", '~> 5.0'
24
24
 
25
- s.add_development_dependency "codeclimate-test-reporter"
26
25
  s.add_development_dependency "yard"
27
26
  s.add_development_dependency 'sqlite3'
28
27
  end
@@ -3,8 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "tapout"
7
- gem "minitap"
8
- gem "rails", "~> 4.0.0"
6
+ gem "rails", "~> 5.0.0"
9
7
 
10
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -3,8 +3,6 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "tapout"
7
- gem "minitap"
8
- gem "rails", "~> 4.1.0"
6
+ gem "rails", "~> 5.1.0"
9
7
 
10
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -93,7 +93,7 @@ module Acl9
93
93
  def install_on(controller_class, options)
94
94
  super
95
95
 
96
- controller_class.send(:before_filter, options, &self.to_proc)
96
+ controller_class.send(:before_action, options, &self.to_proc)
97
97
  end
98
98
 
99
99
  def to_proc
@@ -124,7 +124,7 @@ module Acl9
124
124
  def install_on(controller_class, options)
125
125
  super
126
126
  _add_method(controller_class)
127
- controller_class.send(:before_filter, @method_name, options)
127
+ controller_class.send(:before_action, @method_name, options)
128
128
  end
129
129
 
130
130
  protected
@@ -129,7 +129,7 @@ module Acl9
129
129
  :class_name => subject,
130
130
  :join_table => join_table
131
131
 
132
- belongs_to :authorizable, :polymorphic => true
132
+ belongs_to :authorizable, polymorphic: true, optional: true
133
133
  end
134
134
  end
135
135
  end
@@ -1,3 +1,3 @@
1
1
  module Acl9
2
- VERSION = "2.1.2"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -10,9 +10,8 @@ module Acl9
10
10
  argument :arg_role, type: :string, default: 'role', banner: "role"
11
11
  argument :arg_objects, type: :array, default: [], banner: "objects..."
12
12
 
13
- def create_migration
14
- next_migration_number = self.class.next_migration_number( File.expand_path( '../db/migrate', __FILE__))
15
- template "create_role_tables.rb", "db/migrate/#{next_migration_number}_create_#{role_name}_tables.rb"
13
+ def create_migration_file
14
+ migration_template "create_role_tables.rb", File.join(db_migrate_path, "create_#{role_name}_tables.rb")
16
15
  end
17
16
 
18
17
  def create_models
@@ -56,6 +55,14 @@ module Acl9
56
55
  role_name.classify
57
56
  end
58
57
 
58
+ def model_base_name
59
+ r5? ? ApplicationRecord : ActiveRecord::Base
60
+ end
61
+
62
+ def r5?
63
+ Rails.gem_version >= Gem::Version.new(5)
64
+ end
65
+
59
66
  def habtm_table
60
67
  Acl9.config.default_join_table_name || [ subject_name, role_name ].map(&:pluralize).sort.join('_')
61
68
  end
@@ -1,22 +1,31 @@
1
- class Create<%= role_class_name %>Tables < ActiveRecord::Migration
1
+ class Create<%= role_class_name %>Tables < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
2
  def change
3
3
  create_table :<%= role_table_name %> do |t|
4
4
  t.string :name, null: false
5
+ <% if r5? %>
6
+ t.references :authorizable, polymorphic: true
7
+ <% else %>
5
8
  t.string :authorizable_type, null: true
6
9
  t.integer :authorizable_id, null: true
10
+ <% end %>
7
11
  t.boolean :system, default: false, null: false
8
12
  t.timestamps null: false
9
13
  end
10
14
 
11
15
  add_index :<%= role_table_name %>, :name
16
+
17
+ <% unless r5? %>
12
18
  add_index :<%= role_table_name %>, [:authorizable_type, :authorizable_id]
19
+ <% end -%>
13
20
 
14
21
  create_table :<%= habtm_table %>, id: false do |t|
15
22
  t.references :<%= subject_name %>, null: false
16
23
  t.references :<%= role_name %>, null: false
17
24
  end
18
25
 
26
+ <% unless r5? %>
19
27
  add_index :<%= habtm_table %>, :<%= subject_name %>_id
20
28
  add_index :<%= habtm_table %>, :<%= role_name %>_id
29
+ <% end %>
21
30
  end
22
31
  end
@@ -1,3 +1,3 @@
1
- class <%= role_class_name %> < ActiveRecord::Base
1
+ class <%= role_class_name %> < <%= model_base_name %>
2
2
  <%= role_helper %>
3
3
  end
@@ -2,23 +2,23 @@ require 'test_helper'
2
2
 
3
3
  class ACLActionOverrideTest < ActionController::TestCase
4
4
  test "anon can index" do
5
- assert get :check_allow, :_action => :index
5
+ assert get :check_allow, params: { _action: :index }
6
6
  assert_response :ok
7
7
  end
8
8
 
9
9
  test "anon can't show" do
10
- assert get :check_allow, :_action => :show
10
+ assert get :check_allow, params: { _action: :show }
11
11
  assert_response :unauthorized
12
12
  end
13
13
 
14
14
  test "normal user can't edit" do
15
- assert get :check_allow_with_foo, :_action => :edit, :user_id => User.create.id
15
+ assert get :check_allow_with_foo, params: { _action: :edit, user_id: User.create.id }
16
16
  assert_response :unauthorized
17
17
  end
18
18
 
19
19
  test "foo owner can edit" do
20
20
  assert ( user = User.create ).has_role! :owner, Foo.first_or_create
21
- assert get :check_allow_with_foo, :_action => :edit, :user_id => user.id
21
+ assert get :check_allow_with_foo, params: { _action: :edit, user_id: user.id }
22
22
  assert_response :ok
23
23
  end
24
24
  end
@@ -8,14 +8,14 @@ class ACLHelperMethodTest < ActionController::TestCase
8
8
  test "foo owner allowed" do
9
9
  assert @user.has_role! :owner, Foo.first_or_create
10
10
 
11
- assert get :allow, :user_id => @user.id
11
+ assert get :allow, params: { user_id: @user.id }
12
12
  assert_select 'div', 'OK'
13
13
  end
14
14
 
15
15
  test "another user denied" do
16
16
  assert @user.has_role! :owner
17
17
 
18
- assert get :allow, :user_id => @user.id
18
+ assert get :allow, params: { user_id: @user.id }
19
19
  assert_select 'div', 'OK'
20
20
  end
21
21
 
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class ACLIvarsTest < ActionController::TestCase
4
4
  test "owner of foo destroys" do
5
5
  assert ( user = User.create ).has_role! :owner, Bar
6
- assert delete :destroy, :id => 1, :user_id => user.id
6
+ assert delete :destroy, params: { id: 1, user_id: user.id }
7
7
  assert_response :ok
8
8
  end
9
9
 
10
10
  test "bartender at Foo destroys" do
11
11
  assert ( user = User.create ).has_role! :bartender, Foo
12
- assert delete :destroy, :id => 1, :user_id => user.id
12
+ assert delete :destroy, params: { id: 1, user_id: user.id }
13
13
  assert_response :ok
14
14
  end
15
15
  end
@@ -7,7 +7,7 @@ class ACLObjectsHashTest < ActionController::TestCase
7
7
  end
8
8
 
9
9
  test "objects hash preferred to @ivar" do
10
- assert get :allow, :user_id => @user.id
10
+ assert get :allow, params: { user_id: @user.id }
11
11
  assert_response :ok
12
12
  end
13
13
 
@@ -44,7 +44,7 @@ module ACLQueryMixin
44
44
 
45
45
  test "should return true for foo owner" do
46
46
  assert @controller.current_user = @owneroffoo
47
- assert @controller.acl? :fooize, :foo => Foo.first
47
+ assert @controller.acl? :fooize, foo: Foo.first
48
48
  end
49
49
  end
50
50
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class ACLSubjectMethodTest < ActionController::TestCase
4
4
  test "allow the only user to index" do
5
5
  assert ( user = User.create ).has_role! :the_only_one
6
- assert get :index, :user_id => user.id
6
+ assert get :index, params: { user_id: user.id }
7
7
  assert_response :ok
8
8
  end
9
9
 
@@ -25,18 +25,18 @@ class ArgumentsCheckingTest < ActionController::TestCase
25
25
  end
26
26
  end
27
27
 
28
- test "raise ArgumentError with :helper => true and no method name" do
28
+ test "raise ArgumentError with helper: true and no method name" do
29
29
  assert_raise ArgumentError do
30
30
  class FailureController < ApplicationController
31
- access_control :helper => true do end
31
+ access_control helper: true do end
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
- test "raise ArgumentError with :helper => :method and a method name" do
36
+ test "raise ArgumentError with helper: :method and a method name" do
37
37
  assert_raise ArgumentError do
38
38
  class FailureController < ApplicationController
39
- access_control :meth, :helper => :another_meth do end
39
+ access_control :meth, helper: :another_meth do end
40
40
  end
41
41
  end
42
42
  end
@@ -1,8 +1,8 @@
1
1
  class ACLActionOverride < ApplicationController
2
- access_control :allowed?, :filter => false do
3
- allow all, :to => :index
4
- deny all, :to => :show
5
- allow :owner, :of => :foo, :to => :edit
2
+ access_control :allowed?, filter: false do
3
+ allow all, to: :index
4
+ deny all, to: :show
5
+ allow :owner, of: :foo, to: :edit
6
6
  end
7
7
 
8
8
  def check_allow
@@ -10,6 +10,6 @@ class ACLActionOverride < ApplicationController
10
10
  end
11
11
 
12
12
  def check_allow_with_foo
13
- head allowed?(params[:_action], :foo => Foo.first) ? :ok : :unauthorized
13
+ head allowed?(params[:_action], foo: Foo.first) ? :ok : :unauthorized
14
14
  end
15
15
  end
@@ -1,12 +1,12 @@
1
1
  class ACLBooleanMethod < EmptyController
2
- access_control :acl, :filter => false do
3
- allow all, :to => [:index, :show], :if => :true_meth
4
- allow :admin, :unless => :false_meth
5
- allow all, :if => :false_meth
6
- allow all, :unless => :true_meth
2
+ access_control :acl, filter: false do
3
+ allow all, to: [:index, :show], if: :true_meth
4
+ allow :admin, unless: :false_meth
5
+ allow all, if: :false_meth
6
+ allow all, unless: :true_meth
7
7
  end
8
8
 
9
- before_filter :check_acl
9
+ before_action :check_acl
10
10
 
11
11
  def check_acl
12
12
  if self.acl
@@ -1,11 +1,11 @@
1
1
  class ACLIvars < EmptyController
2
2
 
3
- before_filter :set_ivars
3
+ before_action :set_ivars
4
4
 
5
5
  access_control do
6
6
  action :destroy do
7
- allow :owner, :of => :foo
8
- allow :bartender, :at => Foo
7
+ allow :owner, of: :foo
8
+ allow :bartender, at: Foo
9
9
  end
10
10
  end
11
11
 
@@ -1,5 +1,5 @@
1
1
  class EmptyController < ApplicationController
2
2
  %i[index show new edit create update destroy].each do |action|
3
- define_method(action) { render :text => 'OK' }
3
+ define_method(action) { render plain: 'OK' }
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ class StringObjectRole < ActiveRecord::Base
2
+ acts_as_authorization_role subject_class_name: "StringUser"
3
+ end
@@ -0,0 +1,3 @@
1
+ class StringUser < ActiveRecord::Base
2
+ acts_as_authorization_subject role_class_name: "StringObjectRole"
3
+ end
@@ -1,4 +1,4 @@
1
1
  class Uuid < ActiveRecord::Base
2
2
  self.primary_key = "uuid"
3
- acts_as_authorization_object
3
+ acts_as_authorization_object role_class_name: "StringObjectRole", subject_class_name: "StringUser"
4
4
  end
@@ -13,8 +13,8 @@ Dummy::Application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
16
+ config.public_file_server.enabled = true
17
+ config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
18
18
 
19
19
  # Show full error reports and disable caching.
20
20
  config.consider_all_requests_local = true
@@ -1,3 +1,14 @@
1
1
  Dummy::Application.routes.draw do
2
- get ':controller(/:action(/:id))'
2
+ resources :acl_action_override do
3
+ collection do
4
+ get :check_allow_with_foo
5
+ get :check_allow
6
+ end
7
+ end
8
+
9
+ resources :acl_boolean_method, :acl_block, :acl_ivars, :acl_method, :acl_method2, :acl_subject_method, :acl_arguments
10
+
11
+ get :acl_helper_method, to: "acl_helper_method#allow"
12
+ get :acl_objects_hash, to: "acl_objects_hash#allow"
13
+
3
14
  end
@@ -1,22 +1,37 @@
1
- class CreateTables < ActiveRecord::Migration
1
+ class CreateTables < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
2
+ def self.r5?
3
+ Rails.gem_version >= Gem::Version.new(5)
4
+ end
5
+ def r5?
6
+ self.class.r5?
7
+ end
8
+
2
9
  def change
3
10
  create_table :roles do |t|
4
11
  t.string :name, :limit => 40
5
12
  t.boolean :system
6
- t.string :authorizable_type, :limit => 40
7
- t.integer :authorizable_id
13
+ if r5?
14
+ t.references :authorizable, polymorphic: true
15
+ else
16
+ t.string :authorizable_type, :limit => 40
17
+ t.integer :authorizable_id
18
+ end
8
19
  t.timestamps null: false
9
20
  end
10
21
 
11
- add_index :roles, [:authorizable_type, :authorizable_id]
22
+ unless r5?
23
+ add_index :roles, [:authorizable_type, :authorizable_id]
24
+ end
12
25
 
13
26
  create_table :roles_users, id: false do |t|
14
27
  t.references :user
15
28
  t.references :role
16
29
  end
17
30
 
18
- add_index :roles_users, :user_id
19
- add_index :roles_users, :role_id
31
+ unless r5?
32
+ add_index :roles_users, :user_id
33
+ add_index :roles_users, :role_id
34
+ end
20
35
 
21
36
  create_table :users do |t|
22
37
  t.string :name
@@ -39,6 +54,25 @@ class CreateTables < ActiveRecord::Migration
39
54
  t.timestamps null: false
40
55
  end
41
56
 
57
+ create_table :string_object_roles do |t|
58
+ t.string :name
59
+ t.boolean :system
60
+ t.string :authorizable_type
61
+ t.string :authorizable_id
62
+ t.timestamps null: false
63
+ end
64
+
65
+ create_table :string_object_roles_string_users, id: false do |t|
66
+ t.references :string_user, index: { name: "susor" }
67
+ t.references :string_object_role, index: { name: "sorsu" }
68
+ end
69
+
70
+ create_table :string_users do |t|
71
+ t.string :name
72
+ t.timestamps null: false
73
+ end
74
+
75
+
42
76
  create_table :accounts do |t|
43
77
  t.string :name
44
78
  t.timestamps null: false
@@ -47,20 +81,28 @@ class CreateTables < ActiveRecord::Migration
47
81
  create_table :accesses do |t|
48
82
  t.string :name
49
83
  t.boolean :system
50
- t.string :authorizable_type, :limit => 40
51
- t.integer :authorizable_id
84
+ if r5?
85
+ t.references :authorizable, polymorphic: true
86
+ else
87
+ t.string :authorizable_type, :limit => 40
88
+ t.integer :authorizable_id
89
+ end
52
90
  t.timestamps null: false
53
91
  end
54
92
 
55
- add_index :accesses, [:authorizable_type, :authorizable_id]
93
+ unless r5?
94
+ add_index :accesses, [:authorizable_type, :authorizable_id]
95
+ end
56
96
 
57
97
  create_table :accesses_accounts, id: false do |t|
58
98
  t.references :account
59
99
  t.references :access
60
100
  end
61
101
 
62
- add_index :accesses_accounts, :access_id
63
- add_index :accesses_accounts, :account_id
102
+ unless r5?
103
+ add_index :accesses_accounts, :access_id
104
+ add_index :accesses_accounts, :account_id
105
+ end
64
106
 
65
107
  create_table :foo_bars do |t|
66
108
  t.string :name
@@ -71,20 +113,28 @@ class CreateTables < ActiveRecord::Migration
71
113
  create_table :other_roles do |t|
72
114
  t.string :name, :limit => 40
73
115
  t.boolean :system
74
- t.string :authorizable_type, :limit => 40
75
- t.integer :authorizable_id
116
+ if r5?
117
+ t.references :authorizable, polymorphic: true
118
+ else
119
+ t.string :authorizable_type, :limit => 40
120
+ t.integer :authorizable_id
121
+ end
76
122
  t.timestamps null: false
77
123
  end
78
124
 
79
- add_index :other_roles, [:authorizable_type, :authorizable_id]
125
+ unless r5?
126
+ add_index :other_roles, [:authorizable_type, :authorizable_id]
127
+ end
80
128
 
81
129
  create_table :other_roles_users, id: false do |t|
82
130
  t.references :user
83
131
  t.references :role
84
132
  end
85
133
 
86
- add_index :other_roles_users, :user_id
87
- add_index :other_roles_users, :role_id
134
+ unless r5?
135
+ add_index :other_roles_users, :user_id
136
+ add_index :other_roles_users, :role_id
137
+ end
88
138
 
89
139
  create_table :other_users do |t|
90
140
  t.string :name
@@ -243,12 +243,16 @@ class RolesTest < ActiveSupport::TestCase
243
243
  end
244
244
 
245
245
  test "should be able to get users that have a role on a authorized object with text primary key" do
246
+
247
+ assert @user = StringUser.create
248
+ assert @user2 = StringUser.create
249
+
246
250
  assert uuid = Uuid.create( id: "C41642EE-2780-0001-189F-17F3101B26E0" )
247
251
 
248
252
  assert @user.has_role! :owner, uuid
249
253
  assert @user2.has_role! :owner, uuid
250
254
 
251
- assert_equal 2, uuid.users.count
255
+ assert_equal 2, uuid.string_users.count
252
256
  end
253
257
 
254
258
  test "should accept :symbols as role names" do
@@ -1,16 +1,6 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
1
  ENV["RAILS_ENV"] = "test"
5
2
 
6
3
  require 'minitest/autorun'
7
- require 'minitap'
8
-
9
- if defined? Minitap
10
- Minitest.reporter = Minitap::TapY
11
- else
12
- MiniTest::Unit.runner = MiniTest::TapY.new
13
- end
14
4
 
15
5
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
16
6
  require "rails/test_help"
@@ -20,27 +10,29 @@ Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
20
10
  ActiveRecord::Migration.verbose = false
21
11
  ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
22
12
 
13
+ $VERBOSE = nil
14
+
23
15
  class ActionController::TestCase
24
16
  class << self
25
- def test_allowed method, action, params=nil, cookies=nil
26
- test "allowed #{action} #{method}" do
17
+ def test_allowed method, action, params={}
18
+ test "allowed #{method} #{action}" do
27
19
  if block_given?
28
20
  yield user = User.create
29
- ( params ||= {} ).merge! :user_id => user.id
21
+ params.merge! user_id: user.id
30
22
  end
31
- assert send( method, action, params, cookies )
23
+ assert send( method, action, params: params )
32
24
  assert_response :ok
33
25
  end
34
26
  end
35
27
 
36
- def test_denied method, action, params=nil, cookies=nil
37
- test "denied #{action} #{method}" do
28
+ def test_denied method, action, params={}
29
+ test "denied #{method} #{action}" do
38
30
  assert_raises Acl9::AccessDenied do
39
31
  if block_given?
40
32
  yield user = User.create
41
- ( params ||= {} ).merge! :user_id => user.id
33
+ params.merge! user_id: user.id
42
34
  end
43
- assert send( method, action, params, cookies )
35
+ assert send( method, action, params: params )
44
36
  end
45
37
  end
46
38
  end
@@ -57,21 +49,21 @@ module BaseTests
57
49
  def self.included(klass)
58
50
  klass.class_eval do
59
51
  test_allowed :get, :index
60
- test_allowed :get, :show, :id => 1
52
+ test_allowed :get, :show, id: 1
61
53
  test_denied :get, :new
62
- test_denied :get, :edit, :id => 1
54
+ test_denied :get, :edit, id: 1
63
55
  test_denied :post, :create
64
- test_denied :put, :update, :id => 1
65
- test_denied :patch, :update, :id => 1
66
- test_denied :delete, :destroy, :id => 1
56
+ test_denied :put, :update, id: 1
57
+ test_denied :patch, :update, id: 1
58
+ test_denied :delete, :destroy, id: 1
67
59
 
68
60
  admin = -> (user) { user.has_role! :admin }
69
61
  test_allowed :get, :new, &admin
70
- test_allowed :get, :edit, :id => 1, &admin
62
+ test_allowed :get, :edit, id: 1, &admin
71
63
  test_allowed :post, :create, &admin
72
- test_allowed :put, :update, :id => 1, &admin
73
- test_allowed :patch, :update, :id => 1, &admin
74
- test_allowed :delete, :destroy, :id => 1, &admin
64
+ test_allowed :put, :update, id: 1, &admin
65
+ test_allowed :patch, :update, id: 1, &admin
66
+ test_allowed :delete, :destroy, id: 1, &admin
75
67
  end
76
68
  end
77
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acl9
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oleg dashevskii
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-07 00:00:00.000000000 Z
12
+ date: 2018-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -17,28 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '4.0'
20
+ version: '5.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '4.0'
28
- - !ruby/object:Gem::Dependency
29
- name: codeclimate-test-reporter
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
27
+ version: '5.0'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: yard
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -106,9 +92,8 @@ files:
106
92
  - bin/yard
107
93
  - bin/yardoc
108
94
  - bin/yri
109
- - gemfiles/rails_4.0.gemfile
110
- - gemfiles/rails_4.1.gemfile
111
- - gemfiles/rails_4.2.gemfile
95
+ - gemfiles/rails_5.0.gemfile
96
+ - gemfiles/rails_5.1.gemfile
112
97
  - lib/acl9.rb
113
98
  - lib/acl9/controller_extensions.rb
114
99
  - lib/acl9/controller_extensions/dsl_base.rb
@@ -178,6 +163,8 @@ files:
178
163
  - test/dummy/app/models/other/role.rb
179
164
  - test/dummy/app/models/other/user.rb
180
165
  - test/dummy/app/models/role.rb
166
+ - test/dummy/app/models/string_object_role.rb
167
+ - test/dummy/app/models/string_user.rb
181
168
  - test/dummy/app/models/user.rb
182
169
  - test/dummy/app/models/uuid.rb
183
170
  - test/dummy/config.ru
@@ -186,7 +173,6 @@ files:
186
173
  - test/dummy/config/database.yml
187
174
  - test/dummy/config/environment.rb
188
175
  - test/dummy/config/environments/development.rb
189
- - test/dummy/config/environments/production.rb
190
176
  - test/dummy/config/environments/test.rb
191
177
  - test/dummy/config/initializers/assets.rb
192
178
  - test/dummy/config/initializers/backtrace_silencers.rb
@@ -229,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
215
  version: '0'
230
216
  requirements: []
231
217
  rubyforge_project:
232
- rubygems_version: 2.4.5.1
218
+ rubygems_version: 2.7.3
233
219
  signing_key:
234
220
  specification_version: 4
235
221
  summary: Role-based authorization system for Rails with a concise DSL for securing
@@ -290,6 +276,8 @@ test_files:
290
276
  - test/dummy/app/models/other/role.rb
291
277
  - test/dummy/app/models/other/user.rb
292
278
  - test/dummy/app/models/role.rb
279
+ - test/dummy/app/models/string_object_role.rb
280
+ - test/dummy/app/models/string_user.rb
293
281
  - test/dummy/app/models/user.rb
294
282
  - test/dummy/app/models/uuid.rb
295
283
  - test/dummy/config.ru
@@ -298,7 +286,6 @@ test_files:
298
286
  - test/dummy/config/database.yml
299
287
  - test/dummy/config/environment.rb
300
288
  - test/dummy/config/environments/development.rb
301
- - test/dummy/config/environments/production.rb
302
289
  - test/dummy/config/environments/test.rb
303
290
  - test/dummy/config/initializers/assets.rb
304
291
  - test/dummy/config/initializers/backtrace_silencers.rb
@@ -320,4 +307,3 @@ test_files:
320
307
  - test/models/users_roles_and_subjects_with_namespaced_class_names_test.rb
321
308
  - test/test_helper.rb
322
309
  - test/version_test.rb
323
- has_rdoc:
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "tapout"
7
- gem "minitap"
8
- gem "rails", "~> 4.2.0"
9
-
10
- gemspec :path => "../"
@@ -1,78 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb.
3
-
4
- # Code is not reloaded between requests.
5
- config.cache_classes = true
6
-
7
- # Eager load code on boot. This eager loads most of Rails and
8
- # your application in memory, allowing both threaded web servers
9
- # and those relying on copy on write to perform better.
10
- # Rake tasks automatically ignore this option for performance.
11
- config.eager_load = true
12
-
13
- # Full error reports are disabled and caching is turned on.
14
- config.consider_all_requests_local = false
15
- config.action_controller.perform_caching = true
16
-
17
- # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
- # Add `rack-cache` to your Gemfile before enabling this.
19
- # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
- # config.action_dispatch.rack_cache = true
21
-
22
- # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_files = false
24
-
25
- # Compress JavaScripts and CSS.
26
- config.assets.js_compressor = :uglifier
27
- # config.assets.css_compressor = :sass
28
-
29
- # Do not fallback to assets pipeline if a precompiled asset is missed.
30
- config.assets.compile = false
31
-
32
- # Generate digests for assets URLs.
33
- config.assets.digest = true
34
-
35
- # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
36
-
37
- # Specifies the header that your server uses for sending files.
38
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
39
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
40
-
41
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
42
- # config.force_ssl = true
43
-
44
- # Set to :debug to see everything in the log.
45
- config.log_level = :info
46
-
47
- # Prepend all log lines with the following tags.
48
- # config.log_tags = [ :subdomain, :uuid ]
49
-
50
- # Use a different logger for distributed setups.
51
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
52
-
53
- # Use a different cache store in production.
54
- # config.cache_store = :mem_cache_store
55
-
56
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
57
- # config.action_controller.asset_host = "http://assets.example.com"
58
-
59
- # Ignore bad email addresses and do not raise email delivery errors.
60
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
61
- # config.action_mailer.raise_delivery_errors = false
62
-
63
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
64
- # the I18n.default_locale when a translation cannot be found).
65
- config.i18n.fallbacks = true
66
-
67
- # Send deprecation notices to registered listeners.
68
- config.active_support.deprecation = :notify
69
-
70
- # Disable automatic flushing of the log to improve performance.
71
- # config.autoflush_log = false
72
-
73
- # Use default logging formatter so that PID and timestamp are not suppressed.
74
- config.log_formatter = ::Logger::Formatter.new
75
-
76
- # Do not dump schema after migrations.
77
- config.active_record.dump_schema_after_migration = false
78
- end