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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dd155001e1b7b4bad6352d9aaec53b7ae78680f
4
- data.tar.gz: 81bc37e3680dd46b262e86f9eecc484893f91e6c
3
+ metadata.gz: 6e531e56210489d4c915cd1aadb8190e6d83808c
4
+ data.tar.gz: 1c861891a3e79b3f7adb93673a45b4e25713a7fe
5
5
  SHA512:
6
- metadata.gz: 78dbf072b3af692b64c1556fe19e8eac2392cd781881f397eecb75d57e7fd09d552970daa96c66705aef2278cdf64ebc42ed4cf47092b8c3f12b3ead0b1681cf
7
- data.tar.gz: 134e186dbfd51d0ebf485f485d6b7f53e0ae7d447eb25aa4c86c21856d33e6d28e20725666b05af15c796f798e5c9838ba97d4db8724a9e1fbfe3b17589abe02
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,4 @@
1
+ module <%= options[:namespace].camelize %>
2
+ class <%= options[:name].camelize %> < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module <%= options[:namespace].camelize %>
2
+ class <%= options[:namespace].camelize %>Controller < ApplicationController
3
+ end
4
+ end
@@ -1,5 +1,4 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe <%= options[:name].camelize %> do
4
-
5
4
  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
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+
3
+ module <%= options[:namespace] %>
4
+ describe <%= options[:name].camelize %> do
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Myrails
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
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
- template 'rspec/model.rb', "spec/models/#{options[:name]}_spec.rb"
19
- template 'rails/model.rb', "app/models/#{options[:name]}.rb"
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
- template 'rails/controller.rb', "app/controllers/#{options[:name].pluralize}_controller.rb"
26
- template 'rspec/controller.rb', "spec/controllers/#{options[:name].pluralize}_controller_spec.rb"
27
- run "mkdir -p app/views/#{options[:name].pluralize}"
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.2
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