sevencan 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -5
- data/lib/seven/rspec.rb +21 -0
- data/lib/seven/version.rb +1 -1
- metadata +4 -4
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cab00c00fec7af86d2509a2b230efaa721bd7692
|
4
|
+
data.tar.gz: 3f7dd30e8767d0e07507faf4da416e027a3a9b7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f76d9618fc8520c5e1e434e305e5688c434a473111275ae7d88c1cc595c1d19659f6198446bf6e01ee33b9a346ea03b13895485ef8e84f5e0d90440912e3d90
|
7
|
+
data.tar.gz: 56fa080533c6d972e6f0a08eb13e3b62d97c71acfd3fac1e64863d737634b85316021175e134bc2f9208fd7e26284532d86352504c5188fd8f4add43bdc2209d
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Seven
|
2
2
|
|
3
|
-
Permission manage center
|
3
|
+
Permission manage center
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -23,9 +23,9 @@ Or install it yourself as:
|
|
23
23
|
New manager
|
24
24
|
|
25
25
|
```
|
26
|
-
manager = Seven.new # save dynamic abilities to memory store
|
27
|
-
manager = Seven.new(store: {redis: Redis.current}) # redis store
|
28
|
-
manager = Seven.new(store: {activerecord: UserAbility}) # db store
|
26
|
+
manager = Seven::Manager.new # save dynamic abilities to memory store
|
27
|
+
manager = Seven::Manager.new(store: {redis: Redis.current}) # redis store
|
28
|
+
manager = Seven::Manager.new(store: {activerecord: UserAbility}) # db store
|
29
29
|
```
|
30
30
|
|
31
31
|
Define system rules
|
@@ -143,6 +143,28 @@ manager.can?(nil, :edit_user) # false
|
|
143
143
|
|
144
144
|
## Rails
|
145
145
|
|
146
|
+
|
147
|
+
### Init manager
|
148
|
+
|
149
|
+
in `config/initializers/seven_abilities.rb`
|
150
|
+
|
151
|
+
```
|
152
|
+
$abilities_manager = Seven::Manager.new
|
153
|
+
Dir[Rails.root.join('app/abilities/**/*.rb')].each {|file| require file }
|
154
|
+
```
|
155
|
+
|
156
|
+
Define rules in `app/abilities/*.rb`
|
157
|
+
|
158
|
+
```
|
159
|
+
class UserAbilities
|
160
|
+
include Seven::Abilities
|
161
|
+
|
162
|
+
$abilities_manager.define_rules(User, self)
|
163
|
+
|
164
|
+
# define rules
|
165
|
+
end"
|
166
|
+
```
|
167
|
+
|
146
168
|
### Require methods
|
147
169
|
|
148
170
|
* `current_user`: return current user
|
@@ -177,7 +199,7 @@ Default actions
|
|
177
199
|
class TopicController < ApplicationController
|
178
200
|
before_action :find_topic
|
179
201
|
|
180
|
-
# if exist @topic, target is @topic, else use Topic
|
202
|
+
# if exist @topic, target is @topic, else use Proc result or Topic
|
181
203
|
seven_ability_check [:@topic, Proc.new { fetch_check_target }, Topic]
|
182
204
|
|
183
205
|
# auto check current_user allow read_topics of Topic
|
@@ -294,6 +316,30 @@ class TopicController < ApplicationController
|
|
294
316
|
end
|
295
317
|
```
|
296
318
|
|
319
|
+
## RSpec Testing
|
320
|
+
|
321
|
+
in `spec/rails_helper.rb` or `spec/spec_helper.rb`
|
322
|
+
|
323
|
+
```
|
324
|
+
require 'seven/rspec'
|
325
|
+
```
|
326
|
+
|
327
|
+
Write abilities testing
|
328
|
+
|
329
|
+
```
|
330
|
+
RSpec.describe UserAbilities do
|
331
|
+
it 'should can read topic' do
|
332
|
+
# expect([current_user, target]).to abilities_eql([:read_topic])
|
333
|
+
expect([user, topic]).to abilities_eql([:read_topic])
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'should can manager topic' do
|
337
|
+
expect([admin_user, topic]).to abilities_eql([:read_topic, :edit_topic, :destroy_topic])
|
338
|
+
end
|
339
|
+
end
|
340
|
+
```
|
341
|
+
|
342
|
+
|
297
343
|
## TODO
|
298
344
|
|
299
345
|
* [x] Rails Helpers
|
data/lib/seven/rspec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# require 'rspec'
|
2
|
+
|
3
|
+
# expect([current_user, target]).to abilities_eql([:a, :b])
|
4
|
+
|
5
|
+
RSpec::Matchers.define :abilities_eql do |expect_abilities|
|
6
|
+
match do |abilities_class_args|
|
7
|
+
abilities_instance = described_class.new(*abilities_class_args)
|
8
|
+
abilities_instance.abilities.uniq.sort == expect_abilities.sort
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |abilities_class_args|
|
12
|
+
args_string = abilities_class_args.map(&:inspect).join(', ')
|
13
|
+
abilities_instance = described_class.new(*abilities_class_args)
|
14
|
+
abilities = abilities_instance.abilities.uniq.sort
|
15
|
+
|
16
|
+
"Expected abilities #{abilities} == #{expect_abilities.sort} But not\n" +
|
17
|
+
"Abilities generator #{described_class}.new(#{args_string}).abilities"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
data/lib/seven/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevencan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jiangzhi.xie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
92
|
- ".ruby-version"
|
93
|
-
- ".travis.yml"
|
94
93
|
- CODE_OF_CONDUCT.md
|
95
94
|
- Gemfile
|
96
95
|
- LICENSE.txt
|
@@ -104,6 +103,7 @@ files:
|
|
104
103
|
- lib/seven/manager.rb
|
105
104
|
- lib/seven/rails.rb
|
106
105
|
- lib/seven/rails/controller_helpers.rb
|
106
|
+
- lib/seven/rspec.rb
|
107
107
|
- lib/seven/version.rb
|
108
108
|
- lib/sevencan.rb
|
109
109
|
- seven.gemspec
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.4.
|
130
|
+
rubygems_version: 2.4.5.2
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: simple permission manager
|
data/.travis.yml
DELETED