perm 0.0.1 → 0.0.2

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: 080272d1ed540e83d52c7648bf23896347c590e2
4
- data.tar.gz: 2f8ec937d059ef5d5631531d97769ff5e9efd37d
3
+ metadata.gz: d5374535f076e9f2f48a6d5f83e2a601afda7f79
4
+ data.tar.gz: 283b6018f0690aa50362e37d763dac8e25c7877b
5
5
  SHA512:
6
- metadata.gz: 2a270c390c4c6b6fbce1cabedcfc1a63274b8cac495129c0682bca75357be7877e81f99e4b7821daf647617d7ad1ec5f58df6885ccb1c7cd09811fb1a69b7e72
7
- data.tar.gz: a18dcb8f283bb94a41f30c7cd5561f9f2f51184a1d0f9eb3b4b84651bc41297fe5b99e5c7a65af533d43f9390e0b97a13be8977f6903dfdcf8ae35cce0871f1b
6
+ metadata.gz: 45345d4954fe9cd46cbf84ecb0b5fcb38787780248465a4f1a390673fdde4af7def2c6c20fc9c5de0b32f7ad6fd09cea6bf83d8c10836f1160c0112b04d4d3d1
7
+ data.tar.gz: f9c7cf0b73028c0c7dbec87e0b5e55eab69bb08a9b568e5335d5423785a8bbd5d159d5699be0211ec8f0280dffc93c5f0891e695c5eb7f7a10228446660c9737
data/lib/perm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Perm
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,117 @@
1
+ require "simplecov"
2
+ require 'coveralls'
3
+
4
+ SimpleCov.start
5
+ SimpleCov.command_name "mt"
6
+ Coveralls.wear!
7
+
8
+ require_relative "../lib/perm"
9
+
10
+ module Perm
11
+ class AuthorizerTest < MicroTest::Test
12
+ class User
13
+ include Roleup::HasRoles
14
+ attr_reader :posts
15
+
16
+ def initialize
17
+ @posts = []
18
+ end
19
+ end
20
+
21
+ class Post
22
+ attr_accessor :user, :title, :published
23
+ end
24
+
25
+ class PostAuthorizer < Perm::Authorizer
26
+ def can_read?(post)
27
+ return true if user.has_one_role?(:admin, :editor)
28
+ return true if user == post.user
29
+ post.published
30
+ end
31
+
32
+ def can_update?(post)
33
+ return true if user.has_one_role?(:admin, :editor)
34
+ user == post.user
35
+ end
36
+
37
+ def can_delete?(post)
38
+ return true if user.has_role?(:admin)
39
+ user == post.user
40
+ end
41
+ end
42
+
43
+ before do
44
+ mary = User.new
45
+ mary.roles = [:admin]
46
+ @mary = PostAuthorizer.new(mary)
47
+
48
+ john = User.new
49
+ john.roles = [:editor, :writer]
50
+ @john = PostAuthorizer.new(john)
51
+
52
+ beth = User.new
53
+ beth.roles = [:writer]
54
+ @beth = PostAuthorizer.new(beth)
55
+
56
+ @drew = PostAuthorizer.new(User.new)
57
+
58
+ @post = Post.new
59
+ @post.title = "Authorization made easy"
60
+ @post.user = beth
61
+ end
62
+
63
+ test "mary can read" do
64
+ assert @mary.can_read?(@post)
65
+ end
66
+
67
+ test "mary can update" do
68
+ assert @mary.can_update?(@post)
69
+ end
70
+
71
+ test "mary can delete" do
72
+ assert @mary.can_delete?(@post)
73
+ end
74
+
75
+ test "john can read" do
76
+ assert @john.can_read?(@post)
77
+ end
78
+
79
+ test "john can update" do
80
+ assert @john.can_update?(@post)
81
+ end
82
+
83
+ test "john cannot delete" do
84
+ assert !@john.can_delete?(@post)
85
+ end
86
+
87
+ test "beth can read" do
88
+ assert @beth.can_read?(@post)
89
+ end
90
+
91
+ test "beth can update" do
92
+ assert @beth.can_update?(@post)
93
+ end
94
+
95
+ test "beth can delete" do
96
+ assert @beth.can_delete?(@post)
97
+ end
98
+
99
+ test "drew cannot read" do
100
+ assert !@drew.can_read?(@post)
101
+ end
102
+
103
+ test "drew cannot update" do
104
+ assert !@drew.can_update?(@post)
105
+ end
106
+
107
+ test "drew cannot delete" do
108
+ assert !@drew.can_delete?(@post)
109
+ end
110
+
111
+ test "drew can read after published" do
112
+ @post.published = true
113
+ assert @drew.can_read?(@post)
114
+ end
115
+
116
+ end
117
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -90,6 +90,7 @@ files:
90
90
  - lib/perm.rb
91
91
  - lib/perm/authorizer.rb
92
92
  - lib/perm/version.rb
93
+ - test/authorizer_test.rb
93
94
  homepage: https://github.com/hopsoft/perm
94
95
  licenses:
95
96
  - MIT
@@ -114,4 +115,5 @@ rubygems_version: 2.2.2
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: Simple permission management
117
- test_files: []
118
+ test_files:
119
+ - test/authorizer_test.rb