myrails 1.0.2 → 1.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/rails/controller.rb +1 -1
- data/lib/myrails/templates/rails/namespace_controller.rb +14 -0
- data/lib/myrails/templates/rails/namespace_model.rb +4 -0
- data/lib/myrails/templates/rails/parent_namespace_controller.rb +4 -0
- data/lib/myrails/templates/rspec/model.rb +0 -1
- data/lib/myrails/templates/rspec/namespace_controller.rb +100 -0
- data/lib/myrails/templates/rspec/namespace_model.rb +6 -0
- data/lib/myrails/version.rb +1 -1
- data/lib/myrails.rb +19 -5
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e531e56210489d4c915cd1aadb8190e6d83808c
|
4
|
+
data.tar.gz: 1c861891a3e79b3f7adb93673a45b4e25713a7fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7dd1cfd092e687b215501755a88b04ea5f0543fc2d72d8912c5d4abc56abf81330ec92edec8d59ab98c87db100b7e61b6f514b679410ee8544202f4ef603bd6
|
7
|
+
data.tar.gz: 91a4132b81202550c89eb735c6cdec7322200ee1509684a997cf89bb7b3cedb9fb7d6aa00183c337ac63527d90f3c0bbb1ca1bc6cf981c995f510022ca515a86
|
@@ -3,7 +3,7 @@ class <%= options[:name].pluralize.camelize %>Controller < ApplicationController
|
|
3
3
|
private
|
4
4
|
|
5
5
|
def <%= options[:name].singularize %>
|
6
|
-
@<%= options[:name].singularize %> = <%= options[:name].capitalize%>.find(params[:id])
|
6
|
+
@<%= options[:name].singularize %> = <%= options[:name].capitalize%>.find(params[:id]) %>
|
7
7
|
end
|
8
8
|
|
9
9
|
def <%= options[:name].singularize %>_params
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module <%= options[:namespace].camelize %>
|
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].capitalize%>.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
|
14
|
+
end
|
@@ -0,0 +1,100 @@
|
|
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
|
data/lib/myrails/version.rb
CHANGED
data/lib/myrails.rb
CHANGED
@@ -14,17 +14,31 @@ module Myrails
|
|
14
14
|
|
15
15
|
desc 'model --name=model-name', 'Generates and empty rails model with the given name and its related spec file'
|
16
16
|
option :name, required: true
|
17
|
+
option :namespace
|
17
18
|
def model
|
18
|
-
|
19
|
-
|
19
|
+
if options[:namespace]
|
20
|
+
template 'rails/namespace_model.rb', "app/models/#{options[:namespace]}/#{options[:name]}.rb"
|
21
|
+
template 'rspec/namespace_model.rb', "spec/models/#{options[:namespace]}/#{options[:name]}_spec.rb"
|
22
|
+
else
|
23
|
+
template 'rails/model.rb', "app/models/#{options[:name]}.rb"
|
24
|
+
template 'rspec/model.rb', "spec/models/#{options[:name]}_spec.rb"
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
desc 'controller --name=controller-name', 'Generate a rails controller with the given name along with boiler plate code and related spec filet'
|
23
29
|
option :name, required: true
|
30
|
+
option :namespace
|
24
31
|
def controller
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
if options[:namespace]
|
33
|
+
template 'rails/namespace_controller.rb', "app/controllers/#{options[:namespace]}/#{options[:name].pluralize}_controller.rb"
|
34
|
+
template 'rails/parent_namespace_controller.rb', "app/controllers/#{options[:namespace]}/#{options[:namespace]}_controller.rb"
|
35
|
+
template 'rspec/namespace_controller.rb', "spec/controllers/#{options[:namespace]}/#{options[:name].pluralize}_controller_spec.rb"
|
36
|
+
run "mkdir -p app/views/#{options[:namespace]}/#{options[:name].pluralize}"
|
37
|
+
else
|
38
|
+
template 'rails/controller.rb', "app/controllers/#{options[:name].pluralize}_controller.rb"
|
39
|
+
template 'rspec/controller.rb', "spec/controllers/#{options[:name].pluralize}_controller_spec.rb"
|
40
|
+
run "mkdir -p app/views/#{options[:name].pluralize}"
|
41
|
+
end
|
28
42
|
end
|
29
43
|
|
30
44
|
desc 'policy --name=policy-name', 'Generate a pundit policy with the given name and a related spec file'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vell
|
@@ -143,6 +143,9 @@ files:
|
|
143
143
|
- lib/myrails/templates/rails/application_helper.rb
|
144
144
|
- lib/myrails/templates/rails/controller.rb
|
145
145
|
- lib/myrails/templates/rails/model.rb
|
146
|
+
- lib/myrails/templates/rails/namespace_controller.rb
|
147
|
+
- lib/myrails/templates/rails/namespace_model.rb
|
148
|
+
- lib/myrails/templates/rails/parent_namespace_controller.rb
|
146
149
|
- lib/myrails/templates/rails/pundit.rb
|
147
150
|
- lib/myrails/templates/rspec/controller.rb
|
148
151
|
- lib/myrails/templates/rspec/database_cleaner.rb
|
@@ -153,6 +156,8 @@ files:
|
|
153
156
|
- lib/myrails/templates/rspec/javascript.rb
|
154
157
|
- lib/myrails/templates/rspec/mailer.rb
|
155
158
|
- lib/myrails/templates/rspec/model.rb
|
159
|
+
- lib/myrails/templates/rspec/namespace_controller.rb
|
160
|
+
- lib/myrails/templates/rspec/namespace_model.rb
|
156
161
|
- lib/myrails/templates/rspec/pundit.rb
|
157
162
|
- lib/myrails/templates/rspec/pundit_matchers.rb
|
158
163
|
- lib/myrails/templates/rspec/router.rb
|