shoulda-matchers-pundit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +20 -20
- data/README.md +17 -1
- data/lib/shoulda/matchers/pundit.rb +56 -8
- data/lib/shoulda/matchers/pundit/version.rb +1 -1
- data/shoulda-matchers-pundit.gemspec +6 -3
- data/spec/minitest_matchers_spec.rb +39 -14
- metadata +61 -14
- data/lib/shoulda-matchers-pundit.rb +0 -7
data/Gemfile
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
group :development do
|
4
|
+
# group :development do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
# gem 'foreman', '~> 0.62.0'
|
7
|
+
# gem 'guard', '~> 1.6.2'
|
8
|
+
# gem 'guard-minitest', '~> 0.5.0'
|
9
|
+
# gem 'pry'
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
# gem 'rspec-web', github: 'dcunited001/rspec-web'
|
12
|
+
# gem 'minitest-reporters-ws', "~> 0.0.2"
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# if RbConfig::CONFIG['target_os'] =~ /linux/i
|
15
|
+
# gem 'rb-inotify', require: false
|
16
|
+
# gem 'ruby_gntp'
|
17
|
+
# end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
# if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
20
|
+
# gem 'rb-fsevent', require: false
|
21
|
+
# gem 'growl'
|
22
|
+
# end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
|
25
|
+
# gem 'wdm', require: false, platforms: [:mswin, :mingw]
|
26
|
+
# gem 'rb-notifu', platforms: [:mswin, :mingw]
|
27
|
+
# end
|
28
28
|
|
29
|
-
end
|
29
|
+
# end
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
# Shoulda::Matchers::Pundit
|
4
4
|
|
5
|
+
### Issues:
|
6
|
+
|
7
|
+
TODO: fix bundler dependancy problem!!
|
8
|
+
TODO: fix failure message for wont (doesn't output failing actions)
|
9
|
+
|
5
10
|
TODO: update readme: description, installation, usage
|
6
11
|
TODO: Configure Travis
|
7
12
|
TODO: Configure Appraisal?
|
@@ -38,4 +43,15 @@ TODO: Write usage instructions here
|
|
38
43
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
44
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
45
|
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
-
5. Create new Pull
|
46
|
+
5. Create new Pull
|
47
|
+
|
48
|
+
## Changelog
|
49
|
+
|
50
|
+
#### 0.0.2
|
51
|
+
|
52
|
+
* Added ForbidMatcher. May add ForbiddenToMatcher later on.
|
53
|
+
* Match multiple actions with a single permit/forbid statement
|
54
|
+
|
55
|
+
#### 0.0.1
|
56
|
+
|
57
|
+
* Added PermitMatcher & PermittedToMatcher.
|
@@ -4,8 +4,12 @@ module Shoulda
|
|
4
4
|
module Matchers
|
5
5
|
module Pundit
|
6
6
|
|
7
|
-
def permit(
|
8
|
-
PermitMatcher.new(
|
7
|
+
def permit(*actions)
|
8
|
+
PermitMatcher.new(*actions)
|
9
|
+
end
|
10
|
+
|
11
|
+
def forbid(*actions)
|
12
|
+
ForbidMatcher.new(*actions)
|
9
13
|
end
|
10
14
|
|
11
15
|
def be_permitted_to(action)
|
@@ -13,27 +17,32 @@ module Shoulda
|
|
13
17
|
end
|
14
18
|
|
15
19
|
class PermitMatcher
|
16
|
-
attr_reader :
|
20
|
+
attr_reader :actions, :policy
|
21
|
+
attr_reader :failed_actions
|
17
22
|
|
18
|
-
def initialize(
|
19
|
-
@
|
23
|
+
def initialize(*actions)
|
24
|
+
@actions = actions
|
25
|
+
@failed_actions = []
|
20
26
|
end
|
21
27
|
|
22
28
|
def matches?(policy)
|
23
29
|
@policy = policy
|
24
|
-
|
30
|
+
|
31
|
+
actions.inject(true) do |pass, action|
|
32
|
+
match?(action) && pass
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
def failure_message_for_should
|
28
37
|
<<-message
|
29
|
-
#{policy.class} does not
|
38
|
+
#{policy.class} does not #{failure_keyword_permit} #{failed_actions.join('/')} on #{policy.record}
|
30
39
|
for #{policy.user.inspect}.
|
31
40
|
message
|
32
41
|
end
|
33
42
|
|
34
43
|
def failure_message_for_should_not
|
35
44
|
<<-message
|
36
|
-
#{policy.class} does not
|
45
|
+
#{policy.class} does not #{failure_keyword_forbid} #{failed_actions.join('/')} on #{policy.record}
|
37
46
|
for #{policy.user.inspect}.
|
38
47
|
message
|
39
48
|
end
|
@@ -41,6 +50,45 @@ module Shoulda
|
|
41
50
|
def description
|
42
51
|
"permits #{@action}"
|
43
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def match?(action)
|
57
|
+
p = permits? action
|
58
|
+
append_failed(action) unless p
|
59
|
+
p
|
60
|
+
end
|
61
|
+
|
62
|
+
def permits?(action)
|
63
|
+
policy.public_send("#{action}?")
|
64
|
+
end
|
65
|
+
|
66
|
+
def append_failed(action)
|
67
|
+
@failed_actions << action
|
68
|
+
end
|
69
|
+
|
70
|
+
def failure_keyword_permit; 'permit'; end
|
71
|
+
def failure_keyword_forbid; 'forbid'; end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class ForbidMatcher < PermitMatcher
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def match?(action)
|
80
|
+
f = forbids? action
|
81
|
+
append_failed(action) unless f
|
82
|
+
f
|
83
|
+
end
|
84
|
+
|
85
|
+
def forbids?(action)
|
86
|
+
!permits? action
|
87
|
+
end
|
88
|
+
|
89
|
+
def failure_keyword_permit; 'forbid'; end
|
90
|
+
def failure_keyword_forbid; 'permit'; end
|
91
|
+
|
44
92
|
end
|
45
93
|
|
46
94
|
class PermittedToMatcher
|
@@ -19,10 +19,13 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "shoulda-matchers", "
|
22
|
+
spec.add_dependency "shoulda-matchers", "~> 1.4.0"
|
23
23
|
spec.add_dependency "pundit", "~> 0.2.0"
|
24
24
|
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake", "~> 0.9"
|
27
|
+
spec.add_development_dependency "minitest-matchers", "~> 1.2"
|
28
|
+
spec.add_development_dependency "minitest-reporters-ws", "~> 0.0.2"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
27
30
|
|
28
31
|
end
|
@@ -10,11 +10,8 @@ describe Shoulda::Matchers::Pundit::PermitMatcher do
|
|
10
10
|
describe 'Guest' do
|
11
11
|
let(:user) { nil }
|
12
12
|
|
13
|
-
wont { permit
|
14
|
-
must { permit
|
15
|
-
wont { permit(:update) }
|
16
|
-
wont { permit(:destroy) }
|
17
|
-
|
13
|
+
wont { permit :create, :update, :destroy }
|
14
|
+
must { permit :show }
|
18
15
|
end
|
19
16
|
|
20
17
|
describe 'Any User' do
|
@@ -22,22 +19,50 @@ describe Shoulda::Matchers::Pundit::PermitMatcher do
|
|
22
19
|
let(:another_user) { User.new(1) }
|
23
20
|
let(:article) { Article.new(another_user) }
|
24
21
|
|
25
|
-
must { permit
|
26
|
-
|
27
|
-
wont { permit(:update) }
|
28
|
-
wont { permit(:destroy) }
|
29
|
-
|
22
|
+
must { permit :create, :show }
|
23
|
+
wont { permit :update, :destroy }
|
30
24
|
end
|
31
25
|
|
32
26
|
describe 'Article Creater' do
|
33
27
|
let(:user) { User.new(1) }
|
34
28
|
|
35
|
-
must { permit
|
36
|
-
must {
|
37
|
-
|
38
|
-
|
29
|
+
must { permit :create, :show, :update }
|
30
|
+
must { forbid :destroy }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Shoulda::Matchers::Pundit::ForbidMatcher do
|
37
|
+
|
38
|
+
describe ArticlePolicy do
|
39
|
+
|
40
|
+
subject { ArticlePolicy.new(user, article) }
|
41
|
+
let(:article) { Article.new(user) }
|
42
|
+
|
43
|
+
describe 'Guest' do
|
44
|
+
let(:user) { nil }
|
45
|
+
|
46
|
+
wont { forbid :show }
|
47
|
+
must { forbid :create, :update, :destroy }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'Any User' do
|
51
|
+
let(:user) { User.new(0) }
|
52
|
+
let(:another_user) { User.new(1) }
|
53
|
+
let(:article) { Article.new(another_user) }
|
54
|
+
|
55
|
+
wont { forbid :create, :show }
|
56
|
+
must { forbid :update, :destroy }
|
57
|
+
end
|
39
58
|
|
59
|
+
describe 'Article Creater' do
|
60
|
+
let(:user) { User.new(1) }
|
61
|
+
|
62
|
+
wont { forbid :create, :show, :update }
|
63
|
+
must { forbid :destroy }
|
40
64
|
end
|
65
|
+
|
41
66
|
end
|
42
67
|
end
|
43
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-matchers-pundit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,17 +16,17 @@ dependencies:
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.4.
|
21
|
+
version: 1.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.4.
|
29
|
+
version: 1.4.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: pundit
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,38 +43,86 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rake
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
49
65
|
none: false
|
50
66
|
requirements:
|
51
|
-
- -
|
67
|
+
- - ~>
|
52
68
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.9
|
69
|
+
version: '0.9'
|
54
70
|
type: :development
|
55
71
|
prerelease: false
|
56
72
|
version_requirements: !ruby/object:Gem::Requirement
|
57
73
|
none: false
|
58
74
|
requirements:
|
59
|
-
- -
|
75
|
+
- - ~>
|
60
76
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.9
|
77
|
+
version: '0.9'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: minitest-matchers
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
65
81
|
none: false
|
66
82
|
requirements:
|
67
|
-
- -
|
83
|
+
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.2
|
85
|
+
version: '1.2'
|
70
86
|
type: :development
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
73
89
|
none: false
|
74
90
|
requirements:
|
75
|
-
- -
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.2'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: minitest-reporters-ws
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.0.2
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.0.2
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: pry
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
76
124
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
125
|
+
version: '0.9'
|
78
126
|
description: Shoulda Matchers for Pundit & Setup for RSpec/Minitest
|
79
127
|
email:
|
80
128
|
- dconner.pro@gmail.com
|
@@ -90,7 +138,6 @@ files:
|
|
90
138
|
- Procfile.example
|
91
139
|
- README.md
|
92
140
|
- Rakefile
|
93
|
-
- lib/shoulda-matchers-pundit.rb
|
94
141
|
- lib/shoulda/matchers/pundit.rb
|
95
142
|
- lib/shoulda/matchers/pundit/minitest.rb
|
96
143
|
- lib/shoulda/matchers/pundit/version.rb
|