pundit-matchers 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/pundit/matchers.rb +137 -0
  3. metadata +104 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed26b791044f0423c328344af02c98b63573bf64
4
+ data.tar.gz: c905afbfc3534b2b660c61c20ee0b7bf6a7cd3c7
5
+ SHA512:
6
+ metadata.gz: a3e57f3a9040a9fb25b0bbbc9f85a6bea9d592f4954fd411688c5f4224fd6b51c02285e780a3e9a4741b3dbbd157ff6ef4147c1599114e2a587961a91a942b23
7
+ data.tar.gz: 249083b0a006e5dddcff20503ba349fc22d1ac113f6e8c83a347d738cf724414cd6b3e02bf28d253bf514f0e3f3095e645b7ec27ba844817aabb47bd9b62772b
@@ -0,0 +1,137 @@
1
+ module Pundit
2
+ module Matchers
3
+ RSpec::Matchers.define :permit_action do |action|
4
+ match do |policy|
5
+ policy.public_send("#{action}?")
6
+ end
7
+
8
+ failure_message do |policy|
9
+ "#{policy.class} does not permit #{action} on #{policy.record} for " +
10
+ "#{policy.user.inspect}."
11
+ end
12
+
13
+ failure_message_when_negated do |policy|
14
+ "#{policy.class} does not forbid #{action} on #{policy.record} for " +
15
+ "#{policy.user.inspect}."
16
+ end
17
+ end
18
+
19
+ RSpec::Matchers.define :permit_new_and_create_actions do
20
+ match do |policy|
21
+ policy.new? and policy.create?
22
+ end
23
+
24
+ failure_message do |policy|
25
+ "#{policy.class} does not permit the new or create action on " +
26
+ "#{policy.record} for #{policy.user.inspect}."
27
+ end
28
+
29
+ failure_message_when_negated do |policy|
30
+ "#{policy.class} does not forbid the new or create action on " +
31
+ "#{policy.record} for #{policy.user.inspect}."
32
+ end
33
+ end
34
+
35
+ RSpec::Matchers.define :permit_edit_and_update_actions do
36
+ match do |policy|
37
+ policy.edit? and policy.update?
38
+ end
39
+
40
+ failure_message do |policy|
41
+ "#{policy.class} does not permit the edit or update action on " +
42
+ "#{policy.record} for #{policy.user.inspect}."
43
+ end
44
+
45
+ failure_message_when_negated do |policy|
46
+ "#{policy.class} does not forbid the edit or update action on " +
47
+ "#{policy.record} for #{policy.user.inspect}."
48
+ end
49
+ end
50
+
51
+ RSpec::Matchers.define :permit_mass_assignment_of do |attribute|
52
+ match do |policy|
53
+ policy.permitted_attributes.include? attribute
54
+ end
55
+
56
+ failure_message do |policy|
57
+ "#{policy.class} does not permit the mass assignment of the " +
58
+ "#{attribute} attribute for #{policy.user.inspect}."
59
+ end
60
+
61
+ failure_message_when_negated do |policy|
62
+ "#{policy.class} does not forbid the mass assignment of the " +
63
+ "#{attribute} attribute for #{policy.user.inspect}."
64
+ end
65
+ end
66
+
67
+ RSpec::Matchers.define :forbid_action do |action|
68
+ match do |policy|
69
+ !policy.public_send("#{action}?")
70
+ end
71
+
72
+ failure_message do |policy|
73
+ "#{policy.class} does not forbid #{action} on #{policy.record} for " +
74
+ "#{policy.user.inspect}."
75
+ end
76
+
77
+ failure_message_when_negated do |policy|
78
+ "#{policy.class} does not permit #{action} on #{policy.record} for " +
79
+ "#{policy.user.inspect}."
80
+ end
81
+ end
82
+
83
+ RSpec::Matchers.define :forbid_new_and_create_actions do
84
+ match do |policy|
85
+ !policy.new? and !policy.create?
86
+ end
87
+
88
+ failure_message do |policy|
89
+ "#{policy.class} does not forbid the new or create action on " +
90
+ "#{policy.record} for #{policy.user.inspect}."
91
+ end
92
+
93
+ failure_message_when_negated do |policy|
94
+ "#{policy.class} does not permit the new or create action on " +
95
+ "#{policy.record} for #{policy.user.inspect}."
96
+ end
97
+ end
98
+
99
+ RSpec::Matchers.define :forbid_edit_and_update_actions do
100
+ match do |policy|
101
+ !policy.edit? and !policy.update?
102
+ end
103
+
104
+ failure_message do |policy|
105
+ "#{policy.class} does not forbid the edit or update action on " +
106
+ "#{policy.record} for #{policy.user.inspect}."
107
+ end
108
+
109
+ failure_message_when_negated do |policy|
110
+ "#{policy.class} does not permit the edit or update action on " +
111
+ "#{policy.record} for #{policy.user.inspect}."
112
+ end
113
+ end
114
+
115
+ RSpec::Matchers.define :forbid_mass_assignment_of do |attribute|
116
+ match do |policy|
117
+ policy.permitted_attributes.exclude? attribute
118
+ end
119
+
120
+ failure_message do |policy|
121
+ "#{policy.class} does not forbid the mass assignment of the " +
122
+ "#{attribute} attribute for #{policy.user.inspect}."
123
+ end
124
+
125
+ failure_message_when_negated do |policy|
126
+ "#{policy.class} does not permit the mass assignment of the " +
127
+ "#{attribute} attribute for #{policy.user.inspect}."
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ if defined?(Pundit)
134
+ RSpec.configure do |config|
135
+ config.include Pundit::Matchers
136
+ end
137
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pundit-matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Alley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pundit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec-rails
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.0.0
73
+ description: A set of RSpec matchers for testing Pundit authorisation policies
74
+ email: chris@chrisalley.info
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - lib/pundit/matchers.rb
80
+ homepage: http://rubygems.org/gems/pundit-matchers
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.5.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: RSpec matchers for Pundit policies
104
+ test_files: []