acl9 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: d257d3fbf2e9facce72082825fae4bf4ab77245c
4
- data.tar.gz: bb2d0e3c004d4c426f55893adf342abaa28f822c
3
+ metadata.gz: f5811b1b61ac97d9081b9786e8dc361c93ff7b35
4
+ data.tar.gz: f1df54b8e0902d8b6d45928f2d6e2a2303bafae1
5
5
  SHA512:
6
- metadata.gz: 67dbfd73321644d1a4758100ca477233f4c07eee3f0e3c0effc02be909c166d62f2a763e8b68e12d04e9c1d64b9bbe93b1d588960a45a3fad0e5667395ac72c3
7
- data.tar.gz: 165cf932d81dd5fbf2d37499f6a43429a118285d0fd3e91db72f253ec603279cf35f92764a944f2816f88265258e2db86d459db7e0ed1137e32d7845a54ae92a
6
+ metadata.gz: 275e6d8c27b7c520b52f943621f61f4507f88b55b2a75650583c6f1a572c8396d933fecb3e3eb7fdbfb32d8f9db22c3ddec06d084e752c66b776d9d8dd5595f9
7
+ data.tar.gz: 78de89953adc12b839df2791eae3d07d896d197f5df92ff8986dc4813a6484a3cd56ab5c00d58247ee1672afdd8e67e0b9ee0fccbf44685338fc379e7212649d
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml CHANGED
@@ -2,12 +2,13 @@ cache: bundler
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.0.0
5
- - 2.1.2
5
+ - 2.1.5
6
6
  - ruby-head
7
7
 
8
8
  gemfile:
9
9
  - gemfiles/rails_4.0.gemfile
10
10
  - gemfiles/rails_4.1.gemfile
11
+ - gemfiles/rails_4.2.rc1.gemfile
11
12
 
12
13
  matrix:
13
14
  fast_finish: true
data/Appraisals CHANGED
@@ -6,3 +6,7 @@ appraise "rails-4.1" do
6
6
  gem "rails", "~> 4.1.0"
7
7
  end
8
8
 
9
+ appraise "rails-4.2" do
10
+ gem 'rails', '~> 4.2.0.rc3'
11
+ end
12
+
data/CONTRIBUTING.md CHANGED
@@ -26,6 +26,10 @@ and submit a pull request.
26
26
 
27
27
  ### Setup
28
28
 
29
+ We have a `.ruby-version` file, so if you use a ruby manager that
30
+ understands that then you might need to install that version of ruby, but you
31
+ should know how to do that yourself.
32
+
29
33
  You should be able to just fork the repo and run `bundle && rake` to see the
30
34
  tests running.
31
35
 
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem 'appraisal'
7
+ gem 'tapout'
8
+ gem 'minitap'
data/Gemfile.lock CHANGED
@@ -1,38 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acl9 (1.0.0)
4
+ acl9 (1.1.0)
5
5
  rails (~> 4.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionmailer (4.1.7)
11
- actionpack (= 4.1.7)
12
- actionview (= 4.1.7)
10
+ actionmailer (4.1.8)
11
+ actionpack (= 4.1.8)
12
+ actionview (= 4.1.8)
13
13
  mail (~> 2.5, >= 2.5.4)
14
- actionpack (4.1.7)
15
- actionview (= 4.1.7)
16
- activesupport (= 4.1.7)
14
+ actionpack (4.1.8)
15
+ actionview (= 4.1.8)
16
+ activesupport (= 4.1.8)
17
17
  rack (~> 1.5.2)
18
18
  rack-test (~> 0.6.2)
19
- actionview (4.1.7)
20
- activesupport (= 4.1.7)
19
+ actionview (4.1.8)
20
+ activesupport (= 4.1.8)
21
21
  builder (~> 3.1)
22
22
  erubis (~> 2.7.0)
23
- activemodel (4.1.7)
24
- activesupport (= 4.1.7)
23
+ activemodel (4.1.8)
24
+ activesupport (= 4.1.8)
25
25
  builder (~> 3.1)
26
- activerecord (4.1.7)
27
- activemodel (= 4.1.7)
28
- activesupport (= 4.1.7)
26
+ activerecord (4.1.8)
27
+ activemodel (= 4.1.8)
28
+ activesupport (= 4.1.8)
29
29
  arel (~> 5.0.0)
30
- activesupport (4.1.7)
30
+ activesupport (4.1.8)
31
31
  i18n (~> 0.6, >= 0.6.9)
32
32
  json (~> 1.7, >= 1.7.7)
33
33
  minitest (~> 5.1)
34
34
  thread_safe (~> 0.1)
35
35
  tzinfo (~> 1.1)
36
+ ansi (1.4.3)
36
37
  appraisal (1.0.2)
37
38
  bundler
38
39
  rake
@@ -49,24 +50,30 @@ GEM
49
50
  mail (2.6.3)
50
51
  mime-types (>= 1.16, < 3)
51
52
  mime-types (2.4.3)
53
+ minitap (0.5.3)
54
+ minitest (~> 5.0)
55
+ minitest-reporter-api (>= 0.0.2)
56
+ tapout (>= 0.3.0)
52
57
  minitest (5.4.3)
58
+ minitest-reporter-api (0.0.5)
59
+ minitest (~> 5.0)
53
60
  multi_json (1.10.1)
54
61
  rack (1.5.2)
55
62
  rack-test (0.6.2)
56
63
  rack (>= 1.0)
57
- rails (4.1.7)
58
- actionmailer (= 4.1.7)
59
- actionpack (= 4.1.7)
60
- actionview (= 4.1.7)
61
- activemodel (= 4.1.7)
62
- activerecord (= 4.1.7)
63
- activesupport (= 4.1.7)
64
+ rails (4.1.8)
65
+ actionmailer (= 4.1.8)
66
+ actionpack (= 4.1.8)
67
+ actionview (= 4.1.8)
68
+ activemodel (= 4.1.8)
69
+ activerecord (= 4.1.8)
70
+ activesupport (= 4.1.8)
64
71
  bundler (>= 1.3.0, < 2.0)
65
- railties (= 4.1.7)
72
+ railties (= 4.1.8)
66
73
  sprockets-rails (~> 2.0)
67
- railties (4.1.7)
68
- actionpack (= 4.1.7)
69
- activesupport (= 4.1.7)
74
+ railties (4.1.8)
75
+ actionpack (= 4.1.8)
76
+ activesupport (= 4.1.8)
70
77
  rake (>= 0.8.7)
71
78
  thor (>= 0.18.1, < 2.0)
72
79
  rake (10.3.2)
@@ -80,11 +87,14 @@ GEM
80
87
  multi_json (~> 1.0)
81
88
  rack (~> 1.0)
82
89
  tilt (~> 1.1, != 1.3.0)
83
- sprockets-rails (2.2.0)
90
+ sprockets-rails (2.2.2)
84
91
  actionpack (>= 3.0)
85
92
  activesupport (>= 3.0)
86
93
  sprockets (>= 2.8, < 4.0)
87
94
  sqlite3 (1.3.10)
95
+ tapout (0.4.5)
96
+ ansi
97
+ json
88
98
  thor (0.19.1)
89
99
  thread_safe (0.3.4)
90
100
  tilt (1.4.1)
@@ -99,5 +109,7 @@ DEPENDENCIES
99
109
  acl9!
100
110
  appraisal
101
111
  codeclimate-test-reporter
112
+ minitap
102
113
  sqlite3
114
+ tapout
103
115
  yard
data/README.md CHANGED
@@ -19,6 +19,8 @@ Acl9 is [Semantically Versioned](http://semver.org/), so just add this to your
19
19
  gem 'acl9', '~> 1.0'
20
20
  ```
21
21
 
22
+ You will need Ruby 2.x
23
+
22
24
  We dropped support for Rails < 4 in the 1.x releases, so if you're still using
23
25
  Rails 2.x or 3.x then you'll want this:
24
26
 
@@ -38,7 +40,7 @@ obvious for any developer looking at the controller:
38
40
  ```ruby
39
41
  class Admin::SchoolsController < ApplicationController
40
42
  access_control do
41
- allow :support, School
43
+ allow :support, :of => School
42
44
  allow :admins, :managers, :teachers, :of => :school
43
45
  deny :teachers, :to => :destroy
44
46
 
@@ -97,6 +99,73 @@ user.has_no_role! :support, School
97
99
  You can see more about all this stuff in the wiki under [Role
98
100
  Subsystem](//github.com/be9/acl9/wiki/Role-Subsystem)
99
101
 
102
+ ## Configuration
103
+
104
+ There are five configurable settings. These all have sensible defaults which can
105
+ be easily overridden by merging into the `Acl9::config` hash. You can also
106
+ override each of the `:default_*` settings (dropping the "default_" prefix) in
107
+ your models/controllers - see below for more detail:
108
+
109
+ ### :default_role_class_name
110
+
111
+ Set to `'Role'` and can be overridden in your "user" model, [see the wiki for more](//github.com/be9/acl9/wiki/Role-Subsystem#custom-class-names).
112
+
113
+ ### :default_association_name
114
+
115
+ Set to `:role_objects` and can be overridden in
116
+ your "user" model, [see the wiki for more](//github.com/be9/acl9/wiki/Role-Subsystem#subject-model).
117
+ We chose a name for this association that was unlikely to conflict with
118
+ existing models but a lot of people override this to be just `:roles`
119
+
120
+ ### :default_subject_class_name
121
+
122
+ Set to `'User'` and can be overridden in your
123
+ "role" model, [see the wiki for more](//github.com/be9/acl9/wiki/Role-Subsystem#custom-class-names).
124
+
125
+ ### :default_subject_method
126
+
127
+ Set to `:current_user` and can be overridden in
128
+ your controllers, [see the wiki for more](//github.com/be9/acl9/wiki/Access-Control-Subsystem#subject_method).
129
+
130
+ ### :protect_global_roles
131
+
132
+ Set to `true` (see "Upgrade Notes" below if you're upgrading) and can only be
133
+ changed by merging into `Acl9::config`. This setting changes how global roles
134
+ (ie. roles with no object) are treated.
135
+
136
+ Say we set a role like so:
137
+
138
+ ```ruby
139
+ user.has_role! :admin, school
140
+ ```
141
+
142
+ When `:protect_global_roles` is `true` (as is the default) then `user.has_role?
143
+ :admin` is `false`. Ie. changing the role on a specific instance doesn't impact
144
+ the global role (hence the name).
145
+
146
+ When `:protect_global_roles` is `false` then `user.has_role? :admin` is `true`.
147
+ Ie. setting a role on a specific instance makes that person a global one of
148
+ those roles.
149
+
150
+ Basically these are just two different ways of working with roles, if you're
151
+ protecting your global roles then you can use them as sort of a superuser
152
+ version of a given role. So you can have an admin of a school **and** a global
153
+ admin with different privileges.
154
+
155
+ If you don't protect your global roles then you can use them as a catch-all for
156
+ any specific roles, so then the admins of schools, classrooms and students can
157
+ all be granted a privilege by allowing the global `:admin` role.
158
+
159
+ ### Example
160
+
161
+ ```ruby
162
+ # config/initializers/acl9.rb
163
+ Acl9::config.merge! :default_association_name => :roles
164
+
165
+ # or...
166
+ Acl9::config[:default_association_name] = :roles
167
+ ```
168
+
100
169
  ## Upgrade Notes
101
170
 
102
171
  Please, PLEASE, **PLEASE** note. If you're upgrading from the `0.x` series of acl9
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ Rake::TestTask.new(:test) do |test|
11
11
  test.libs << 'lib' << 'test'
12
12
  test.pattern = 'test/**/*_test.rb'
13
13
  test.verbose = false
14
+ test.options = " | tapout runtime"
14
15
  end
15
16
 
16
17
  require 'yard'
data/bin/appraisal ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'appraisal' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('appraisal', 'appraisal')
data/bin/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('bundler', 'bundler')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'cc-tddium-post-worker' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('codeclimate-test-reporter', 'cc-tddium-post-worker')
data/bin/erubis ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'erubis' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('erubis', 'erubis')
data/bin/rackup ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rackup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rack', 'rackup')
data/bin/rails ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rails' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('railties', 'rails')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/sprockets ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'sprockets' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('sprockets', 'sprockets')
data/bin/tapout ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'tapout' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('tapout', 'tapout')
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('thor', 'thor')
data/bin/tilt ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'tilt' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('tilt', 'tilt')
data/bin/yard ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'yard' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('yard', 'yard')
data/bin/yardoc ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'yardoc' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('yard', 'yardoc')
data/bin/yri ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'yri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('yard', 'yri')
@@ -3,6 +3,8 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
+ gem "tapout"
7
+ gem "minitap"
6
8
  gem "rails", "~> 4.0.0"
7
9
 
8
10
  gemspec :path => "../"
@@ -3,6 +3,8 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
+ gem "tapout"
7
+ gem "minitap"
6
8
  gem "rails", "~> 4.1.0"
7
9
 
8
10
  gemspec :path => "../"
@@ -0,0 +1,10 @@
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.rc3"
9
+
10
+ gemspec :path => "../"
@@ -164,10 +164,12 @@ module Acl9
164
164
 
165
165
  def delete_role(role)
166
166
  if role
167
- self._role_objects.delete role
168
- if role.send(self._auth_subject_class_name.demodulize.tableize).empty?
169
- role.destroy unless role.respond_to?(:system?) && role.system?
167
+ if ret = self._role_objects.delete(role)
168
+ if role.send(self._auth_subject_class_name.demodulize.tableize).empty?
169
+ ret &&= role.destroy unless role.respond_to?(:system?) && role.system?
170
+ end
170
171
  end
172
+ ret
171
173
  end
172
174
  end
173
175
 
@@ -24,7 +24,7 @@ module Acl9
24
24
  # end
25
25
  #
26
26
  # user = User.new
27
- # user.roles #=> returns Role objects, associated with the user
27
+ # user.role_objects #=> returns Role objects, associated with the user
28
28
  # user.has_role!(...)
29
29
  # user.has_no_role!(...)
30
30
  #
@@ -39,6 +39,8 @@ module Acl9
39
39
 
40
40
  has_and_belongs_to_many assoc.to_sym, :class_name => role, :join_table => join_table
41
41
 
42
+ before_destroy :has_no_roles!
43
+
42
44
  cattr_accessor :_auth_role_class_name, :_auth_subject_class_name,
43
45
  :_auth_role_assoc_name
44
46
 
data/lib/acl9/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Acl9
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -163,5 +163,37 @@ module ControllerExtensions
163
163
  permit_some member, %w(index show)
164
164
  permit_some nil, %w(index show)
165
165
  end
166
+
167
+ test "multiple allows in an action" do
168
+ assert ( special = User.create ).has_role! :special
169
+ assert ( viewer = User.create ).has_role! :viewer
170
+
171
+ @tester.acl_block! do
172
+ action :show do
173
+ allow all
174
+ allow :viewer
175
+ end
176
+ end
177
+
178
+ assert set_all_actions
179
+ permit_some special, %w(show)
180
+ permit_some viewer, %w(show)
181
+ end
182
+
183
+ test "multiple allows with logged_in" do
184
+ assert ( normal = User.create )
185
+ assert ( viewer = User.create ).has_role! :viewer
186
+
187
+ @tester.acl_block! do
188
+ action :index do
189
+ allow logged_in
190
+ allow :viewer
191
+ end
192
+ end
193
+
194
+ assert set_all_actions
195
+ permit_some normal, %w(index)
196
+ permit_some viewer, %w(index)
197
+ end
166
198
  end
167
199
  end
@@ -4,9 +4,9 @@ module ACLQueryMixin
4
4
  def self.included base
5
5
  base.class_eval do
6
6
  setup do
7
- ( @editor = User.create ).has_role! :editor
8
- ( @viewer = User.create ).has_role! :viewer
9
- ( @owneroffoo = User.create ).has_role! :owner, Foo.first_or_create
7
+ assert ( @editor = User.create ).has_role! :editor
8
+ assert ( @viewer = User.create ).has_role! :viewer
9
+ assert ( @owneroffoo = User.create ).has_role! :owner, Foo.first_or_create
10
10
  end
11
11
 
12
12
  %i[edit update destroy].each do |meth|
@@ -5,7 +5,7 @@ class CreateTables < ActiveRecord::Migration
5
5
  t.boolean :system
6
6
  t.string :authorizable_type, :limit => 40
7
7
  t.integer :authorizable_id
8
- t.timestamps
8
+ t.timestamps null: false
9
9
  end
10
10
 
11
11
  add_index :roles, [:authorizable_type, :authorizable_id]
@@ -13,7 +13,6 @@ class CreateTables < ActiveRecord::Migration
13
13
  create_table :roles_users, id: false do |t|
14
14
  t.references :user
15
15
  t.references :role
16
- t.timestamps
17
16
  end
18
17
 
19
18
  add_index :roles_users, :user_id
@@ -21,28 +20,28 @@ class CreateTables < ActiveRecord::Migration
21
20
 
22
21
  create_table :users do |t|
23
22
  t.string :name
24
- t.timestamps
23
+ t.timestamps null: false
25
24
  end
26
25
 
27
26
  create_table :foos do |t|
28
27
  t.string :name
29
- t.timestamps
28
+ t.timestamps null: false
30
29
  end
31
30
 
32
31
  create_table :bars do |t|
33
32
  t.string :name
34
- t.timestamps
33
+ t.timestamps null: false
35
34
  end
36
35
 
37
36
  create_table :uuids, id: false do |t|
38
37
  t.string :uuid, primary_key: true
39
38
  t.string :name
40
- t.timestamps
39
+ t.timestamps null: false
41
40
  end
42
41
 
43
42
  create_table :accounts do |t|
44
43
  t.string :name
45
- t.timestamps
44
+ t.timestamps null: false
46
45
  end
47
46
 
48
47
  create_table :accesses do |t|
@@ -50,7 +49,7 @@ class CreateTables < ActiveRecord::Migration
50
49
  t.boolean :system
51
50
  t.string :authorizable_type, :limit => 40
52
51
  t.integer :authorizable_id
53
- t.timestamps
52
+ t.timestamps null: false
54
53
  end
55
54
 
56
55
  add_index :accesses, [:authorizable_type, :authorizable_id]
@@ -58,7 +57,6 @@ class CreateTables < ActiveRecord::Migration
58
57
  create_table :accesses_accounts, id: false do |t|
59
58
  t.references :account
60
59
  t.references :access
61
- t.timestamps
62
60
  end
63
61
 
64
62
  add_index :accesses_accounts, :access_id
@@ -66,7 +64,7 @@ class CreateTables < ActiveRecord::Migration
66
64
 
67
65
  create_table :foo_bars do |t|
68
66
  t.string :name
69
- t.timestamps
67
+ t.timestamps null: false
70
68
  end
71
69
 
72
70
 
@@ -75,7 +73,7 @@ class CreateTables < ActiveRecord::Migration
75
73
  t.boolean :system
76
74
  t.string :authorizable_type, :limit => 40
77
75
  t.integer :authorizable_id
78
- t.timestamps
76
+ t.timestamps null: false
79
77
  end
80
78
 
81
79
  add_index :other_roles, [:authorizable_type, :authorizable_id]
@@ -83,7 +81,6 @@ class CreateTables < ActiveRecord::Migration
83
81
  create_table :other_roles_users, id: false do |t|
84
82
  t.references :user
85
83
  t.references :role
86
- t.timestamps
87
84
  end
88
85
 
89
86
  add_index :other_roles_users, :user_id
@@ -91,12 +88,12 @@ class CreateTables < ActiveRecord::Migration
91
88
 
92
89
  create_table :other_users do |t|
93
90
  t.string :name
94
- t.timestamps
91
+ t.timestamps null: false
95
92
  end
96
93
 
97
94
  create_table :other_foos do |t|
98
95
  t.string :name
99
- t.timestamps
96
+ t.timestamps null: false
100
97
  end
101
98
  end
102
99
  end
@@ -190,16 +190,23 @@ class RolesTest < ActiveSupport::TestCase
190
190
  assert_equal 0, @user.role_objects.count
191
191
  end
192
192
 
193
+ test "role setters true even with multiple roles" do
194
+ assert @user.has_role! :owner, @bar
195
+ assert @user2.has_role! :owner, @bar
196
+
197
+ assert @user.has_no_role! :owner, @bar
198
+ end
199
+
193
200
  test "should delete unused roles from table" do
194
201
  assert @user.has_role! :owner, @bar
195
202
  assert @user2.has_role! :owner, @bar
196
203
 
197
204
  assert_equal 1, Role.count
198
205
 
199
- @bar.accepts_no_role! :owner, @user2
206
+ assert @bar.accepts_no_role! :owner, @user2
200
207
  assert_equal 1, Role.count
201
208
 
202
- @bar.accepts_no_role! :owner, @user
209
+ assert @bar.accepts_no_role! :owner, @user
203
210
 
204
211
  assert_equal 0, Role.count
205
212
  end
@@ -236,6 +243,34 @@ class RolesTest < ActiveSupport::TestCase
236
243
  assert @user.has_role?(:manager, @foo)
237
244
  end
238
245
 
246
+ test "remove access for destroyed object" do
247
+ assert_empty @user.role_objects
248
+ assert @user.has_role! :admin, @foo
249
+ refute_empty @user.role_objects
250
+ assert @user.has_role? :admin, @foo
251
+
252
+ assert @foo.destroy
253
+ refute @foo.accepts_role? :admin, @user
254
+
255
+ assert @user.reload
256
+ assert_empty @user.role_objects
257
+ refute @user.has_role? :admin, @foo
258
+ end
259
+
260
+ test "remove access for destroyed subject" do
261
+ assert_empty @foo.accepted_roles
262
+ assert @foo.accepts_role! :admin, @user
263
+ refute_empty @foo.accepted_roles
264
+ assert @foo.accepts_role? :admin, @user
265
+
266
+ assert @user.destroy
267
+ refute @user.has_role? :admin, @foo
268
+
269
+ assert @foo.reload
270
+ assert_empty @foo.accepted_roles
271
+ refute @foo.accepts_role? :admin, @user
272
+ end
273
+
239
274
  private
240
275
 
241
276
  def set_some_roles
@@ -7,10 +7,16 @@ class SystemRolesTest < ActiveSupport::TestCase
7
7
  assert_equal 1, Role.count
8
8
 
9
9
  assert user = User.create
10
- assert user.has_role! :admin
11
- assert_equal 1, Role.count
10
+ assert_difference -> { Role.count }, 0 do
11
+ assert user.has_role! :admin
12
+ end
12
13
 
13
- refute user.has_no_role! :admin
14
- assert_equal 1, Role.count
14
+ assert user.has_role? :admin
15
+
16
+ assert_difference -> { Role.count }, 0 do
17
+ assert user.has_no_role! :admin
18
+ end
19
+
20
+ refute user.has_role? :admin
15
21
  end
16
22
  end
data/test/test_helper.rb CHANGED
@@ -4,12 +4,20 @@ CodeClimate::TestReporter.start
4
4
  ENV["RAILS_ENV"] = "test"
5
5
 
6
6
  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
7
14
 
8
15
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
9
16
  require "rails/test_help"
10
17
 
11
18
  Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
12
19
 
20
+ ActiveRecord::Migration.verbose = false
13
21
  ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
14
22
 
15
23
  class ActionController::TestCase
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: 1.0.0
4
+ version: 1.1.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: 2014-11-23 00:00:00.000000000 Z
12
+ date: 2014-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -79,6 +79,7 @@ extensions: []
79
79
  extra_rdoc_files: []
80
80
  files:
81
81
  - ".gitignore"
82
+ - ".ruby-version"
82
83
  - ".travis.yml"
83
84
  - Appraisals
84
85
  - CHANGELOG.textile
@@ -91,8 +92,23 @@ files:
91
92
  - Rakefile
92
93
  - TODO
93
94
  - acl9.gemspec
95
+ - bin/appraisal
96
+ - bin/bundler
97
+ - bin/cc-tddium-post-worker
98
+ - bin/erubis
99
+ - bin/rackup
100
+ - bin/rails
101
+ - bin/rake
102
+ - bin/sprockets
103
+ - bin/tapout
104
+ - bin/thor
105
+ - bin/tilt
106
+ - bin/yard
107
+ - bin/yardoc
108
+ - bin/yri
94
109
  - gemfiles/rails_4.0.gemfile
95
110
  - gemfiles/rails_4.1.gemfile
111
+ - gemfiles/rails_4.2.gemfile
96
112
  - lib/acl9.rb
97
113
  - lib/acl9/controller_extensions.rb
98
114
  - lib/acl9/controller_extensions/dsl_base.rb