cancancan 1.15.0 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -0
- data/.rubocop_todo.yml +48 -0
- data/.travis.yml +8 -2
- data/Appraisals +1 -0
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +1 -1
- data/README.md +58 -41
- data/Rakefile +7 -3
- data/cancancan.gemspec +13 -12
- data/gemfiles/activerecord_4.2.gemfile +1 -0
- data/lib/cancan.rb +2 -2
- data/lib/cancan/ability.rb +26 -24
- data/lib/cancan/controller_additions.rb +33 -23
- data/lib/cancan/controller_resource.rb +83 -56
- data/lib/cancan/exceptions.rb +1 -1
- data/lib/cancan/matchers.rb +2 -2
- data/lib/cancan/model_adapters/abstract_adapter.rb +8 -8
- data/lib/cancan/model_adapters/active_record_4_adapter.rb +48 -35
- data/lib/cancan/model_adapters/active_record_adapter.rb +18 -17
- data/lib/cancan/model_adapters/mongoid_adapter.rb +26 -21
- data/lib/cancan/model_adapters/sequel_adapter.rb +12 -12
- data/lib/cancan/model_additions.rb +0 -1
- data/lib/cancan/rule.rb +23 -17
- data/lib/cancan/version.rb +1 -1
- data/lib/generators/cancan/ability/ability_generator.rb +1 -1
- data/spec/cancan/ability_spec.rb +189 -180
- data/spec/cancan/controller_additions_spec.rb +77 -64
- data/spec/cancan/controller_resource_spec.rb +230 -228
- data/spec/cancan/exceptions_spec.rb +20 -20
- data/spec/cancan/inherited_resource_spec.rb +21 -21
- data/spec/cancan/matchers_spec.rb +12 -12
- data/spec/cancan/model_adapters/active_record_4_adapter_spec.rb +38 -32
- data/spec/cancan/model_adapters/active_record_adapter_spec.rb +155 -145
- data/spec/cancan/model_adapters/default_adapter_spec.rb +2 -2
- data/spec/cancan/model_adapters/mongoid_adapter_spec.rb +87 -88
- data/spec/cancan/model_adapters/sequel_adapter_spec.rb +44 -47
- data/spec/cancan/rule_spec.rb +18 -18
- data/spec/spec_helper.rb +2 -2
- data/spec/support/ability.rb +0 -1
- metadata +60 -19
data/spec/cancan/rule_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct' # for OpenStruct below
|
3
3
|
|
4
4
|
# Most of Rule functionality is tested in Ability specs
|
5
5
|
describe CanCan::Rule do
|
@@ -8,44 +8,44 @@ describe CanCan::Rule do
|
|
8
8
|
@rule = CanCan::Rule.new(true, :read, Integer, @conditions, nil)
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'returns no association joins if none exist' do
|
12
12
|
expect(@rule.associations_hash).to eq({})
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'returns no association for joins if just attributes' do
|
16
16
|
@conditions[:foo] = :bar
|
17
17
|
expect(@rule.associations_hash).to eq({})
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
@conditions[:foo] = {:
|
22
|
-
expect(@rule.associations_hash).to eq(
|
20
|
+
it 'returns single association for joins' do
|
21
|
+
@conditions[:foo] = { bar: 1 }
|
22
|
+
expect(@rule.associations_hash).to eq(foo: {})
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
@conditions[:foo] = {:
|
27
|
-
@conditions[:test] = {1 => 2}
|
28
|
-
expect(@rule.associations_hash).to eq(
|
25
|
+
it 'returns multiple associations for joins' do
|
26
|
+
@conditions[:foo] = { bar: 1 }
|
27
|
+
@conditions[:test] = { 1 => 2 }
|
28
|
+
expect(@rule.associations_hash).to eq(foo: {}, test: {})
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
@conditions[:foo] = {:
|
33
|
-
expect(@rule.associations_hash).to eq(
|
31
|
+
it 'returns nested associations for joins' do
|
32
|
+
@conditions[:foo] = { bar: { 1 => 2 } }
|
33
|
+
expect(@rule.associations_hash).to eq(foo: { bar: {} })
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'returns no association joins if conditions is nil' do
|
37
37
|
rule = CanCan::Rule.new(true, :read, Integer, nil, nil)
|
38
38
|
expect(rule.associations_hash).to eq({})
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
42
|
-
meta_where = OpenStruct.new(:
|
41
|
+
it 'is not mergeable if conditions are not simple hashes' do
|
42
|
+
meta_where = OpenStruct.new(name: 'metawhere', column: 'test')
|
43
43
|
@conditions[meta_where] = :bar
|
44
44
|
|
45
45
|
expect(@rule).to be_unmergeable
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'is not mergeable if conditions is an empty hash' do
|
49
49
|
@conditions = {}
|
50
50
|
expect(@rule).to_not be_unmergeable
|
51
51
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,11 +12,11 @@ if defined?(I18n) && I18n.respond_to?('enforce_available_locales=')
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# Add support to load paths
|
15
|
-
|
15
|
+
$LOAD_PATH.unshift File.expand_path('../support', __FILE__)
|
16
16
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
19
|
-
config.filter_run :
|
19
|
+
config.filter_run focus: true
|
20
20
|
config.run_all_when_everything_filtered = true
|
21
21
|
config.mock_with :rspec
|
22
22
|
config.order = 'random'
|
data/spec/support/ability.rb
CHANGED
metadata
CHANGED
@@ -1,83 +1,100 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancancan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Alessandro Rodi (Renuo AG)
|
7
8
|
- Bryan Rite
|
8
9
|
- Ryan Bates
|
9
10
|
- Richard Wilson
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: bundler
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
18
19
|
requirements:
|
19
|
-
- -
|
20
|
+
- - ~>
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: '1.3'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
26
|
requirements:
|
26
|
-
- -
|
27
|
+
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
28
29
|
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubocop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0.46'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.46'
|
29
44
|
- !ruby/object:Gem::Dependency
|
30
45
|
name: rake
|
31
46
|
requirement: !ruby/object:Gem::Requirement
|
32
47
|
requirements:
|
33
|
-
- -
|
48
|
+
- - ~>
|
34
49
|
- !ruby/object:Gem::Version
|
35
50
|
version: 10.1.1
|
36
51
|
type: :development
|
37
52
|
prerelease: false
|
38
53
|
version_requirements: !ruby/object:Gem::Requirement
|
39
54
|
requirements:
|
40
|
-
- -
|
55
|
+
- - ~>
|
41
56
|
- !ruby/object:Gem::Version
|
42
57
|
version: 10.1.1
|
43
58
|
- !ruby/object:Gem::Dependency
|
44
59
|
name: rspec
|
45
60
|
requirement: !ruby/object:Gem::Requirement
|
46
61
|
requirements:
|
47
|
-
- -
|
62
|
+
- - ~>
|
48
63
|
- !ruby/object:Gem::Version
|
49
64
|
version: 3.2.0
|
50
65
|
type: :development
|
51
66
|
prerelease: false
|
52
67
|
version_requirements: !ruby/object:Gem::Requirement
|
53
68
|
requirements:
|
54
|
-
- -
|
69
|
+
- - ~>
|
55
70
|
- !ruby/object:Gem::Version
|
56
71
|
version: 3.2.0
|
57
72
|
- !ruby/object:Gem::Dependency
|
58
73
|
name: appraisal
|
59
74
|
requirement: !ruby/object:Gem::Requirement
|
60
75
|
requirements:
|
61
|
-
- -
|
76
|
+
- - '>='
|
62
77
|
- !ruby/object:Gem::Version
|
63
78
|
version: 2.0.0
|
64
79
|
type: :development
|
65
80
|
prerelease: false
|
66
81
|
version_requirements: !ruby/object:Gem::Requirement
|
67
82
|
requirements:
|
68
|
-
- -
|
83
|
+
- - '>='
|
69
84
|
- !ruby/object:Gem::Version
|
70
85
|
version: 2.0.0
|
71
|
-
description:
|
72
|
-
|
73
|
-
email:
|
86
|
+
description: Simple authorization solution for Rails. All permissions are stored in
|
87
|
+
a single location.
|
88
|
+
email: alessandro.rodi@renuo.ch
|
74
89
|
executables: []
|
75
90
|
extensions: []
|
76
91
|
extra_rdoc_files: []
|
77
92
|
files:
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
93
|
+
- .gitignore
|
94
|
+
- .rspec
|
95
|
+
- .rubocop.yml
|
96
|
+
- .rubocop_todo.yml
|
97
|
+
- .travis.yml
|
81
98
|
- Appraisals
|
82
99
|
- CHANGELOG.rdoc
|
83
100
|
- CONTRIBUTING.md
|
@@ -142,19 +159,43 @@ require_paths:
|
|
142
159
|
- lib
|
143
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
144
161
|
requirements:
|
145
|
-
- -
|
162
|
+
- - '>='
|
146
163
|
- !ruby/object:Gem::Version
|
147
164
|
version: 2.0.0
|
148
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
166
|
requirements:
|
150
|
-
- -
|
167
|
+
- - '>='
|
151
168
|
- !ruby/object:Gem::Version
|
152
169
|
version: '0'
|
153
170
|
requirements: []
|
154
171
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.0.14
|
156
173
|
signing_key:
|
157
174
|
specification_version: 4
|
158
175
|
summary: Simple authorization solution for Rails.
|
159
176
|
test_files:
|
160
177
|
- Appraisals
|
178
|
+
- gemfiles/activerecord_3.2.gemfile
|
179
|
+
- gemfiles/activerecord_4.0.gemfile
|
180
|
+
- gemfiles/activerecord_4.1.gemfile
|
181
|
+
- gemfiles/activerecord_4.2.gemfile
|
182
|
+
- gemfiles/activerecord_5.0.gemfile
|
183
|
+
- gemfiles/mongoid_2.x.gemfile
|
184
|
+
- gemfiles/sequel_3.x.gemfile
|
185
|
+
- spec/README.rdoc
|
186
|
+
- spec/cancan/ability_spec.rb
|
187
|
+
- spec/cancan/controller_additions_spec.rb
|
188
|
+
- spec/cancan/controller_resource_spec.rb
|
189
|
+
- spec/cancan/exceptions_spec.rb
|
190
|
+
- spec/cancan/inherited_resource_spec.rb
|
191
|
+
- spec/cancan/matchers_spec.rb
|
192
|
+
- spec/cancan/model_adapters/active_record_4_adapter_spec.rb
|
193
|
+
- spec/cancan/model_adapters/active_record_adapter_spec.rb
|
194
|
+
- spec/cancan/model_adapters/default_adapter_spec.rb
|
195
|
+
- spec/cancan/model_adapters/mongoid_adapter_spec.rb
|
196
|
+
- spec/cancan/model_adapters/sequel_adapter_spec.rb
|
197
|
+
- spec/cancan/rule_spec.rb
|
198
|
+
- spec/matchers.rb
|
199
|
+
- spec/spec.opts
|
200
|
+
- spec/spec_helper.rb
|
201
|
+
- spec/support/ability.rb
|