myrails 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/myrails/templates/initializers/application_vars.rb +2 -0
- data/lib/myrails/templates/mailer/sendgrid.rb +8 -8
- data/lib/myrails/templates/rails/application.yml +19 -0
- data/lib/myrails/templates/rails/controller.rb +6 -6
- data/lib/myrails/templates/rails/namespace_controller.rb +1 -13
- data/lib/myrails/templates/rails/namespace_model.rb +3 -2
- data/lib/myrails/templates/rails/pundit.rb +7 -7
- data/lib/myrails/templates/rspec/factory.rb +1 -1
- data/lib/myrails/templates/rspec/pundit.rb +3 -3
- data/lib/myrails/version.rb +1 -1
- data/lib/myrails.rb +29 -32
- metadata +5 -7
- data/lib/myrails/templates/rails/parent_namespace_controller.rb +0 -4
- data/lib/myrails/templates/rspec/namespace_controller.rb +0 -100
- data/lib/myrails/templates/rspec/namespace_model.rb +0 -6
- data/lib/myrails/templates/rspec/pundit_matchers.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ed7e61ea2b40e5a344c676140da8f60af448c8e
|
4
|
+
data.tar.gz: d41681dca063a5c9b72fe9642754ce560725c440
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5438539fcbd03f0d222086028234936d46c5e0be42d86a7f61a7688c9f91470794f569fc0a4d48d1d2ada1c4ef85f4484eac99000137055918b942a8b08b0e62
|
7
|
+
data.tar.gz: 3185b829a2982195df217b380496851e2c15bd1d98bea77827fe807e395c60b17ba8202821e2893623de23ef7dc320842ecf3716139295332ef4e504cc59c8ee
|
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
config.action_mailer.delivery_method = :smtp
|
2
|
+
config.action_mailer.smtp_settings = { address: 'smtp.sendgrid.net',
|
3
|
+
port: 587,
|
4
|
+
domain: 'yourdomain.com',
|
5
|
+
user_name: 'someuser',
|
6
|
+
password: 'somepassword',
|
7
|
+
authentication: 'plain',
|
8
|
+
enable_starttls_auto: true }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# use: ENV['email']
|
2
|
+
# Add code to place file in config/initializers
|
3
|
+
# Load application ENV vars and merge with existing ENV vars. Loaded here so can use values in initializers.
|
4
|
+
# ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
|
5
|
+
defaults: &defaults
|
6
|
+
email: dev@example.com
|
7
|
+
secret: mypassword
|
8
|
+
|
9
|
+
development:
|
10
|
+
<<: *defaults
|
11
|
+
|
12
|
+
test:
|
13
|
+
<<: *defaults
|
14
|
+
email: test@example.com
|
15
|
+
|
16
|
+
production:
|
17
|
+
<<: *defaults
|
18
|
+
email: info@example.com
|
19
|
+
secret: mypassword
|
@@ -1,12 +1,12 @@
|
|
1
|
-
class <%= options[:name].pluralize.camelize %>Controller <
|
2
|
-
# before_action :<%= options[:name].singularize %>, only: []
|
1
|
+
class <%= options[:name].pluralize.camelize %>Controller < <% if options[:name].include?("/")%><%= options[:name].split("/").first.camelize %>::<%= options[:name].split("/").first.camelize %><% else %>Application<% end %>Controller
|
2
|
+
# before_action :<%= options[:name].split("/").last.singularize %>, only: []
|
3
3
|
private
|
4
4
|
|
5
|
-
def <%= options[:name].singularize %>
|
6
|
-
@<%= options[:name].singularize %> = <%= options[:name].camelize.singularize %>.find(params[:id])
|
5
|
+
def <%= options[:name].split("/").last.singularize %>
|
6
|
+
@<%= options[:name].split("/").last.singularize %> = <%= options[:name].camelize.singularize %>.find(params[:id])
|
7
7
|
end
|
8
8
|
|
9
|
-
def <%= options[:name].singularize %>_params
|
10
|
-
params.require(:<%= options[:name].singularize %>).permit()
|
9
|
+
def <%= options[:name].split("/").last.singularize %>_params
|
10
|
+
params.require(:<%= options[:name].split("/").last.singularize %>).permit()
|
11
11
|
end
|
12
12
|
end
|
@@ -1,14 +1,2 @@
|
|
1
|
-
|
2
|
-
class <%= options[:name].pluralize.camelize %>Controller < <%= options[:namespace].camelize %>::<%= options[:namespace].camelize %>Controller
|
3
|
-
# before_action :<%= options[:name].singularize %>, only: []
|
4
|
-
private
|
5
|
-
|
6
|
-
def <%= options[:name].singularize.downcase %>
|
7
|
-
@<%= options[:name].singularize %> = <%= options[:name].camelize.singularize %>.find(params[:id])
|
8
|
-
end
|
9
|
-
|
10
|
-
def <%= options[:name].singularize.downcase %>_params
|
11
|
-
params.require(:<%= options[:name.downcase].singularize %>).permit()
|
12
|
-
end
|
13
|
-
end
|
1
|
+
class <%= options[:name].split("/").first.camelize %>::<%= options[:name].split("/").first.camelize %>Controller < ApplicationController
|
14
2
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
# @author Lovell McIlwain
|
2
2
|
#
|
3
|
-
# Authorization for
|
3
|
+
# Authorization for <%= options[:name] %> objects
|
4
4
|
class <%= options[:name].camelize %>Policy < ApplicationPolicy
|
5
|
-
# Allow all users to access new
|
5
|
+
# Allow all users to access new <%= options[:name] %>
|
6
6
|
def new?
|
7
7
|
true
|
8
8
|
end
|
9
9
|
|
10
|
-
# Allows owner
|
10
|
+
# Allows owner to edit <%= options[:name].camelize %>
|
11
11
|
def edit?
|
12
12
|
user == record.user
|
13
13
|
end
|
14
14
|
|
15
|
-
# Allows all users to create
|
15
|
+
# Allows all users to create <%= options[:name].camelize %>
|
16
16
|
alias_method :create?, :new?
|
17
17
|
|
18
|
-
# Allows all users to view
|
18
|
+
# Allows all users to view <%= options[:name].camelize %>
|
19
19
|
alias_method :show?, :new?
|
20
20
|
|
21
|
-
# Allows owner
|
21
|
+
# Allows owner to update an <%= options[:name].camelize %>
|
22
22
|
alias_method :update?, :edit?
|
23
23
|
|
24
|
-
# Allows owner
|
24
|
+
# Allows owner to remove an <%= options[:name].camelize %>
|
25
25
|
alias_method :destroy?, :edit?
|
26
26
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Use with Pundit Matches: https://github.com/chrisalley/pundit-matchers
|
2
2
|
require 'rails_helper'
|
3
3
|
describe <%= options[:name].camelize %>Policy do
|
4
|
-
subject { <%= options[:name].camelize %>Policy.new(user, <%= options[:name] %>) }
|
4
|
+
subject { <%= options[:name].camelize %>Policy.new(user, <%= options[:name].split("/").last %>) }
|
5
5
|
|
6
|
-
let(:<%= options[:name] %>) { create :<%= options[:name] %> }
|
6
|
+
let(:<%= options[:name].split("/").last %>) { create :<%= options[:name].gsub("/", "_") %> }
|
7
7
|
|
8
8
|
context 'for a visitor' do
|
9
9
|
it {is_expected.to permit_action(:new)}
|
@@ -16,7 +16,7 @@ describe <%= options[:name].camelize %>Policy do
|
|
16
16
|
|
17
17
|
context "for an admin" do
|
18
18
|
|
19
|
-
let(:user) { <%= options[:name] %>.user }
|
19
|
+
let(:user) { <%= options[:name].split("/").last %>.user }
|
20
20
|
|
21
21
|
it {is_expected.to permit_action(:new)}
|
22
22
|
it {is_expected.to permit_action(:create)}
|
data/lib/myrails/version.rb
CHANGED
data/lib/myrails.rb
CHANGED
@@ -9,55 +9,46 @@ module Myrails
|
|
9
9
|
TEMPLATES = source_root
|
10
10
|
ENVIRONMENTS = %w(development test production)
|
11
11
|
|
12
|
-
desc 'model',
|
12
|
+
desc 'model', "Generates a rails model with the given name along with its related spec file and namespace prefix for table creation. Use '/' to create a namespaced model"
|
13
13
|
option :name, required: true
|
14
|
-
option :namespace
|
15
14
|
def model
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
template 'rails/model.rb', "app/models/#{options[:name]}.rb"
|
21
|
-
template 'rspec/model.rb', "spec/models/#{options[:name]}_spec.rb"
|
22
|
-
end
|
15
|
+
template 'rails/model.rb', "app/models/#{options[:name].downcase}.rb"
|
16
|
+
template 'rails/namespace_model.rb', "app/models/#{options[:name].split("/").first.singularize.downcase}.rb" if options[:name].include?("/")
|
17
|
+
template 'rspec/model.rb', "spec/models/#{options[:name].downcase}_spec.rb"
|
23
18
|
end
|
24
19
|
|
25
|
-
desc 'controller',
|
20
|
+
desc 'controller', "Generates a rails controller with the given name along with related spec file. Use '/' to create a namespaced controller"
|
26
21
|
option :name, required: true
|
27
|
-
option :namespace
|
28
22
|
def controller
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
template '
|
33
|
-
run "mkdir -p app/views/#{options[:namespace]}/#{options[:name].pluralize}"
|
34
|
-
else
|
35
|
-
template 'rails/controller.rb', "app/controllers/#{options[:name].pluralize}_controller.rb"
|
36
|
-
template 'rspec/controller.rb', "spec/controllers/#{options[:name].pluralize}_controller_spec.rb"
|
37
|
-
run "mkdir -p app/views/#{options[:name].pluralize}"
|
23
|
+
template 'rails/controller.rb', "app/controllers/#{options[:name].downcase.pluralize}_controller.rb"
|
24
|
+
if options[:name].include?("/")
|
25
|
+
parent, child = options[:name].split("/")
|
26
|
+
template 'rails/namespace_controller.rb', "app/controllers/#{parent}/#{parent.downcase}_controller.rb"
|
38
27
|
end
|
28
|
+
template 'rspec/controller.rb', "spec/controllers/#{options[:name].downcase.pluralize}_controller_spec.rb"
|
29
|
+
run "mkdir -p app/views/#{options[:name].downcase.pluralize}"
|
39
30
|
end
|
40
31
|
|
41
|
-
desc 'policy',
|
32
|
+
desc 'policy', "Generates a pundit policy with the given name and a related spec file. Use '/' to create a namespaced policy"
|
42
33
|
option :name, required: true
|
43
34
|
def policy
|
44
|
-
template 'rails/pundit.rb', "app/policies/#{options[:name]}_policy.rb"
|
45
|
-
template 'rspec/pundit.rb', "spec/policies/#{options[:name]}_policy_spec.rb"
|
35
|
+
template 'rails/pundit.rb', "app/policies/#{options[:name].downcase}_policy.rb"
|
36
|
+
template 'rspec/pundit.rb', "spec/policies/#{options[:name].downcase}_policy_spec.rb"
|
46
37
|
end
|
47
38
|
|
48
|
-
desc 'presenter',
|
39
|
+
desc 'presenter', "Generates a presenter class with the given name and a related spec file. Use '/' to create a namespaced presenter"
|
49
40
|
option :name, required: true
|
50
41
|
def presenters
|
51
42
|
copy_file 'presenters/base.rb', 'app/presenters/base_presenter.rb'
|
52
|
-
template 'presenters/presenter.rb', "app/presenters/#{options[:name]}_presenter.rb"
|
43
|
+
template 'presenters/presenter.rb', "app/presenters/#{options[:name].downcase}_presenter.rb"
|
53
44
|
copy_file 'presenters/presenter_config.rb', 'spec/support/configs/presenter.rb'
|
54
|
-
template 'presenters/presenter_spec.rb', "spec/presenters/#{options[:name]}_presenter_spec.rb"
|
45
|
+
template 'presenters/presenter_spec.rb', "spec/presenters/#{options[:name].downcase}_presenter_spec.rb"
|
55
46
|
end
|
56
47
|
|
57
|
-
desc 'factory',
|
48
|
+
desc 'factory', "Generates a factory_girl factory in the spec/factories directory. Use '/' to create a namespaced factory"
|
58
49
|
option :name, required: true
|
59
50
|
def factory
|
60
|
-
template 'rspec/factory.rb', "spec/factories/#{options[:name]}.rb"
|
51
|
+
template 'rspec/factory.rb', "spec/factories/#{options[:name].downcase}.rb"
|
61
52
|
end
|
62
53
|
|
63
54
|
desc 'install_application_helper', 'Replace current application helper with one that has commonly used code'
|
@@ -98,15 +89,15 @@ gem 'rspec-rails', group: :test
|
|
98
89
|
copy_file 'rspec/files.rb', 'spec/support/configs/files.rb'
|
99
90
|
end
|
100
91
|
|
101
|
-
desc '
|
92
|
+
desc 'sendgrid', 'Generate sendgrid initializer and mail interceptor'
|
102
93
|
option :email, required: true
|
103
|
-
def
|
94
|
+
def sendgrid
|
104
95
|
copy_file 'mailer/sendgrid.rb', 'config/initializers/sendgrid.rb'
|
105
96
|
template 'mailer/dev_mail_interceptor.rb', 'app/mailers/dev_mail_interceptor.rb'
|
106
97
|
ENVIRONMENTS.each do |environment|
|
107
98
|
unless environment == 'production'
|
108
|
-
inject_into_file "config/environments/#{environment}.rb", after: "
|
109
|
-
|
99
|
+
inject_into_file "config/environments/#{environment}.rb", after: "Rails.application.configure do\n" do <<-CODE
|
100
|
+
ActionMailer::Base.register_interceptor(DevMailInterceptor)
|
110
101
|
CODE
|
111
102
|
end
|
112
103
|
end
|
@@ -518,6 +509,12 @@ require 'database_cleaner'
|
|
518
509
|
install_footnotes
|
519
510
|
git_init
|
520
511
|
end
|
512
|
+
|
513
|
+
desc 'use_global_varables', 'creates and loads config/application.yml'
|
514
|
+
def use_global_variables
|
515
|
+
copy_file 'initializers/application_vars.rb', 'config/initializers/application_vars.rb'
|
516
|
+
copy_file 'rails/application.yml', 'config/application.yml'
|
517
|
+
end
|
521
518
|
end
|
522
519
|
end
|
523
520
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/myrails/templates/engines/rakefile
|
123
123
|
- lib/myrails/templates/heroku/Procfile
|
124
124
|
- lib/myrails/templates/heroku/puma.rb
|
125
|
+
- lib/myrails/templates/initializers/application_vars.rb
|
125
126
|
- lib/myrails/templates/layout/_error_messages.html.haml
|
126
127
|
- lib/myrails/templates/layout/_footer.html.haml
|
127
128
|
- lib/myrails/templates/layout/_info_messages.html.haml
|
@@ -142,12 +143,12 @@ files:
|
|
142
143
|
- lib/myrails/templates/presenters/presenter.rb
|
143
144
|
- lib/myrails/templates/presenters/presenter_config.rb
|
144
145
|
- lib/myrails/templates/presenters/presenter_spec.rb
|
146
|
+
- lib/myrails/templates/rails/application.yml
|
145
147
|
- lib/myrails/templates/rails/application_helper.rb
|
146
148
|
- lib/myrails/templates/rails/controller.rb
|
147
149
|
- lib/myrails/templates/rails/model.rb
|
148
150
|
- lib/myrails/templates/rails/namespace_controller.rb
|
149
151
|
- lib/myrails/templates/rails/namespace_model.rb
|
150
|
-
- lib/myrails/templates/rails/parent_namespace_controller.rb
|
151
152
|
- lib/myrails/templates/rails/pundit.rb
|
152
153
|
- lib/myrails/templates/rspec/controller.rb
|
153
154
|
- lib/myrails/templates/rspec/database_cleaner.rb
|
@@ -158,10 +159,7 @@ files:
|
|
158
159
|
- lib/myrails/templates/rspec/javascript.rb
|
159
160
|
- lib/myrails/templates/rspec/mailer.rb
|
160
161
|
- lib/myrails/templates/rspec/model.rb
|
161
|
-
- lib/myrails/templates/rspec/namespace_controller.rb
|
162
|
-
- lib/myrails/templates/rspec/namespace_model.rb
|
163
162
|
- lib/myrails/templates/rspec/pundit.rb
|
164
|
-
- lib/myrails/templates/rspec/pundit_matchers.rb
|
165
163
|
- lib/myrails/templates/rspec/request.rb
|
166
164
|
- lib/myrails/templates/rspec/request_shared_example.rb
|
167
165
|
- lib/myrails/templates/rspec/router.rb
|
@@ -196,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
194
|
version: '0'
|
197
195
|
requirements: []
|
198
196
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.
|
197
|
+
rubygems_version: 2.6.10
|
200
198
|
signing_key:
|
201
199
|
specification_version: 4
|
202
200
|
summary: A thor backed generator for generating rails related files based on my style
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module <%= options[:namespace].camelize %>
|
4
|
-
# Does this controller require authentication?
|
5
|
-
describe <%= options[:name].pluralize.camelize %>Controller do
|
6
|
-
# let(:user) {create :user}
|
7
|
-
let(:<%= options[:name].pluralize %>) {[]}
|
8
|
-
let(:<%= options[:name].singularize %>) {create :<%= options[:name].singularize %>}
|
9
|
-
|
10
|
-
# before {sign_in user}
|
11
|
-
|
12
|
-
describe 'GET index' do
|
13
|
-
before do
|
14
|
-
3.times {<%= options[:name].pluralize %> << create(:<%= options[:name].singularize %>)}
|
15
|
-
get :index
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'sets @<%= options[:name].pluralize %>' do
|
19
|
-
expect(assigns[:<%= options[:name].pluralize %>]).to eq <%= options[:name].pluralize %>
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'GET show' do
|
24
|
-
before {get :show, params: {id: <%= options[:name].singularize %>.id}}
|
25
|
-
|
26
|
-
it 'sets @<%= options[:name].singularize %>' do
|
27
|
-
expect(assigns[:<%= options[:name].singularize %>]).to eq <%= options[:name].singularize %>
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'GET new' do
|
32
|
-
before {get :new}
|
33
|
-
|
34
|
-
it 'sets @<%= options[:name].singularize %>' do
|
35
|
-
expect(assigns[:<%= options[:name].singularize %>]).to be_a_new <%= options[:name].singularize.camelize %>
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'POST create' do
|
40
|
-
context 'successful create' do
|
41
|
-
before {post :create, params: {<%= options[:name].singularize %>: attributes_for(:<%= options[:name].singularize %>)}}
|
42
|
-
|
43
|
-
subject(:<%= options[:name].first %>){assigns[:<%= options[:name].singularize %>]}
|
44
|
-
|
45
|
-
it 'redirects to :show'
|
46
|
-
it 'sets @<%= options[:name].singularize %>'
|
47
|
-
it 'sets flash[:success]'
|
48
|
-
it 'tags the current_user as creator'
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'unsuccessful create' do
|
52
|
-
before {post :create, params: {<%= options[:name].singularize %>: attributes_for(:<%= options[:name].singularize %>, attr: nil)}}
|
53
|
-
|
54
|
-
it 'renders :new template'
|
55
|
-
it 'sets @<%= options[:name].singularize %>'
|
56
|
-
it 'sets flash[:error]'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe 'GET edit' do
|
61
|
-
before {get :edit, params: {id: <%= options[:name].singularize %>.id}}
|
62
|
-
|
63
|
-
it 'sets @<%= options[:name].singularize %>' do
|
64
|
-
expect(assigns[:<%= options[:name].singularize %>]).to eq <%= options[:name].singularize %>
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'PUT/PATCH update' do
|
69
|
-
context 'successful update' do
|
70
|
-
before {put :update, params: {id: <%= options[:name].singularize %>.id, <%= options[:name].singularize %>: attributes_for(:<%= options[:name].singularize %>)}}
|
71
|
-
|
72
|
-
subject(:<%= options[:name].first %>) {assigns[:<%= options[:name].singularize %>]}
|
73
|
-
|
74
|
-
it 'redirects to :show'
|
75
|
-
it 'sets @<%= options[:name].singularize %>'
|
76
|
-
it 'sets flash[:success]'
|
77
|
-
it 'tags current_user as updater'
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'unsuccessful update' do
|
81
|
-
before {put :update, params: {id: <%= options[:name].singularize %>.id, <%= options[:name].singularize %>: attributes_for(:<%= options[:name].singularize %>, attr: nil)}}
|
82
|
-
|
83
|
-
it 'renders :edit template'
|
84
|
-
it 'sets @<%= options[:name].singularize %>'
|
85
|
-
it 'sets flash[:error]'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'DELETE destroy' do
|
90
|
-
before {delete :destroy, params: {id: <%= options[:name].singularize %>.id}}
|
91
|
-
|
92
|
-
it 'redirects to :index' do
|
93
|
-
expect(response).to redirect_to <%= options[:name].pluralize %>_path
|
94
|
-
end
|
95
|
-
it 'sets @<%= options[:name].singularize %>'
|
96
|
-
it 'deletes @<%= options[:name].singularize %>'
|
97
|
-
it 'sets flash[success]'
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :permitted_to do |action|
|
2
|
-
match do |policy|
|
3
|
-
policy.public_send("#{action}?")
|
4
|
-
end
|
5
|
-
|
6
|
-
failure_message do |policy|
|
7
|
-
"#{policy.class} does not permit #{action} on #{policy.record} for #{policy.user.inspect}."
|
8
|
-
end
|
9
|
-
|
10
|
-
failure_message_when_negated do |policy|
|
11
|
-
"#{policy.class} does not forbid #{action} on #{policy.record} for #{policy.user.inspect}."
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def pundit_error
|
16
|
-
Pundit::NotAuthorizedError
|
17
|
-
end
|
18
|
-
|
19
|
-
=begin
|
20
|
-
|
21
|
-
example: spec/policies/projects_policy_spec.rb
|
22
|
-
|
23
|
-
require 'rails_helper'
|
24
|
-
|
25
|
-
describe ProjectPolicy do
|
26
|
-
subject { ProjectPolicy.new(user, project) }
|
27
|
-
let(:project) { Fabricate :project }
|
28
|
-
|
29
|
-
|
30
|
-
context 'for a visitor' do
|
31
|
-
it { should_not permitted_to(:create) }
|
32
|
-
it { should_not permitted_to(:new) }
|
33
|
-
it { should_not permitted_to(:update) }
|
34
|
-
it { should_not permitted_to(:edit) }
|
35
|
-
end
|
36
|
-
|
37
|
-
context "for an admin" do
|
38
|
-
let(:user) { Fabricate(:user, admin: true) }
|
39
|
-
|
40
|
-
it { should permitted_to(:create) }
|
41
|
-
it { should permitted_to(:new) }
|
42
|
-
it { should permitted_to(:update) }
|
43
|
-
it { should permitted_to(:edit) }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
=end
|