templaty 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/LICENSE +21 -0
- data/README.md +67 -0
- data/lib/generators/templaty/crud_generator.rb +179 -0
- data/lib/generators/templaty/migrations/add_column_generator.rb +102 -0
- data/lib/generators/templaty/templates/crud/app/assets/stylesheets/namespace/views/table/form.scss.erb +21 -0
- data/lib/generators/templaty/templates/crud/app/assets/stylesheets/namespace/views/table/index.scss.erb +3 -0
- data/lib/generators/templaty/templates/crud/app/assets/templates/namespace/table.gridy.hbs.erb +33 -0
- data/lib/generators/templaty/templates/crud/app/controllers/system/table_controller.rb.erb +71 -0
- data/lib/generators/templaty/templates/crud/app/javascripts/form.js.erb +24 -0
- data/lib/generators/templaty/templates/crud/app/javascripts/index.js.erb +48 -0
- data/lib/generators/templaty/templates/crud/app/models/model.rb.erb +41 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/_form.html.erb.erb +32 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/_submenu.html.erb.erb +5 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/_title.html.erb.erb +1 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/edit.html.erb.erb +14 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/gridy.json.jbuilder.erb +23 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/index.html.erb.erb +8 -0
- data/lib/generators/templaty/templates/crud/app/views/namespace/table/new.html.erb.erb +5 -0
- data/lib/generators/templaty/templates/crud/app/views/shared/icons/_model.html.erb.erb +1 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/model.yml.erb +14 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/namespace/table/create.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/namespace/table/destroy.yml.erb +6 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/namespace/table/edit.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/namespace/table/index.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/namespace/table/show.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/en/namespace/table/update.yml.erb +6 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/model.yml.erb +15 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/namespace/table/create.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/namespace/table/destroy.yml.erb +6 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/namespace/table/edit.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/namespace/table/index.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/namespace/table/show.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/pt-BR/namespace/table/update.yml.erb +7 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/model.yml.erb +14 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/namespace/table/create.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/namespace/table/destroy.yml.erb +6 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/namespace/table/edit.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/namespace/table/index.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/namespace/table/show.yml.erb +5 -0
- data/lib/generators/templaty/templates/crud/config/locales/ru/namespace/table/update.yml.erb +6 -0
- data/lib/generators/templaty/templates/crud/db/seeds/pd/model.rb.erb +8 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/create_spec.rb.erb +60 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/destroy_spec.rb.erb +120 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/edit_spec.rb.erb +43 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/gridy/json_spec.rb.erb +52 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/gridy/unlogged_spec.rb.erb +12 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/index_spec.rb.erb +24 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/new_spec.rb.erb +24 -0
- data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/update_spec.rb.erb +82 -0
- data/lib/generators/templaty/templates/crud/spec/features/namespace/model/create_spec.rb.erb +35 -0
- data/lib/generators/templaty/templates/crud/spec/features/namespace/model/destroy_spec.rb.erb +27 -0
- data/lib/generators/templaty/templates/crud/spec/features/namespace/model/gridy/initial_spec.rb.erb +53 -0
- data/lib/generators/templaty/templates/crud/spec/features/namespace/model/gridy/search_spec.rb.erb +46 -0
- data/lib/generators/templaty/templates/crud/spec/features/namespace/model/gridy/sort_spec.rb.erb +47 -0
- data/lib/generators/templaty/templates/crud/spec/features/namespace/model/update_spec.rb.erb +34 -0
- data/lib/generators/templaty/templates/crud/spec/models/model/list_spec.rb.erb +16 -0
- data/lib/generators/templaty/templates/db/migrate/add_column.rb.erb +7 -0
- data/lib/generators/templaty/templates/db/migrate/backfill.rb.erb +13 -0
- data/lib/generators/templaty/templates/db/migrate/not_null.rb.erb +7 -0
- data/lib/generators/templaty/templates/db/migrate/set_default.rb.erb +12 -0
- data/lib/generators/templaty/templates/db/migrate/validate_not_null.rb.erb +12 -0
- data/lib/templaty/helper.rb +131 -0
- data/lib/templaty/version.rb +5 -0
- data/lib/templaty.rb +5 -0
- metadata +208 -0
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render 'shared/ice_menu_title', href: <%= options[:namespace] %>_<%= options[:table] %>_path, image: :<%= options[:table].singularize %>, label: '<%= options[:table] %>.title' %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<h2 class="system-title">Editar <%= options[:name_one].capitalize %></h2>
|
2
|
+
|
3
|
+
<%%= form_for [:<%= options[:namespace] %>, @<%= options[:table].singularize %>], html: { class: nil, <%= options[:multipart] ? "enctype: 'multipart/form-data', " : nil %>id: nil } do |f| %>
|
4
|
+
<%%= render 'form', f: f %>
|
5
|
+
<%% end %>
|
6
|
+
|
7
|
+
<div class="clearfix form-field">
|
8
|
+
<%%= button_to(t('helpers.submit.<%= options[:table].singularize %>.destroy'), [:<%= options[:namespace] %>, @<%= options[:table].singularize %>],
|
9
|
+
class: 'form-destroy__button',
|
10
|
+
data: { confirm: t('<%= options[:table].singularize %>.destroy.confirm', name: @<%= options[:table].singularize %>.name), disable_with: t(:wait) },
|
11
|
+
form_class: 'form-destroy',
|
12
|
+
method: :delete
|
13
|
+
) %>
|
14
|
+
</div>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%- fields = Templaty::Helper.fields(options) -%>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
json.list do
|
5
|
+
json.array! @items do |<%= options[:table].singularize %>|
|
6
|
+
json.edit_path edit_<%= options[:namespace] %>_<%= options[:table].singularize %>_path(<%= options[:table].singularize %>)
|
7
|
+
json.more_image image_path('icons/ellipsis.svg')
|
8
|
+
<%- if options[:show_route] -%>
|
9
|
+
json.show_path <%= options[:table].singularize %>_path(<%= options[:table].singularize %>)
|
10
|
+
<%- end -%>
|
11
|
+
<%- fields.sort.each do |field| -%>
|
12
|
+
<%- if field.start_with?('percentage') -%>
|
13
|
+
json.<%= field.sub('_cents', '') %> Helper.percentage(<%= options[:table].singularize %>.<%= field %>)
|
14
|
+
<%- elsif field.end_with?('_cents') -%>
|
15
|
+
json.<%= field.sub('_cents', '') %> Helper.money(<%= options[:table].singularize %>.<%= field %>, type: :cents)
|
16
|
+
<%- else -%>
|
17
|
+
json.<%= field %> <%= options[:table].singularize %>.<%= field %>
|
18
|
+
<%- end -%>
|
19
|
+
<%- end -%>
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
json.total @total
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%%= render 'submenu' %>
|
2
|
+
<%%= render 'title' %>
|
3
|
+
|
4
|
+
<%%= link_to t('.new'), new_<%= options[:namespace] %>_<%= options[:table].singularize %>_path, class: 'button--strong button-new' %>
|
5
|
+
|
6
|
+
<%%= render 'shared/<%= options[:namespace] %>/gridy' %>
|
7
|
+
|
8
|
+
<input data-param name="gridy.url" type="hidden" value="<%%= gridy_<%= options[:namespace] %>_<%= options[:table] %>_path %>">
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<h2 class="system-title">Cadastrar <%= options[:name_one].capitalize %></h2>
|
2
|
+
|
3
|
+
<%%= form_for [:<%= options[:namespace] %>, @<%= options[:table].singularize %>], html: { class: nil, <%= options[:multipart] ? "enctype: 'multipart/form-data', " : nil %>id: nil } do |f| %>
|
4
|
+
<%%= render 'form', f: f %>
|
5
|
+
<%% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 236.108 236.108" style="enable-background:new 0 0 236.108 236.108" xml:space="preserve"><path d="M7.5 69.21a7.5 7.5 0 0 0-7.5 7.5v58.54a7.5 7.5 0 0 0 15 0V76.71a7.5 7.5 0 0 0-7.5-7.5zM166.428 25.459h-31.204a7.5 7.5 0 0 0-7.5 7.5v6.775L27.289 69.517a7.5 7.5 0 0 0-5.368 7.19v58.512c-.002.375.034.753.09 1.132a7.002 7.002 0 0 0 .253 1.137l21.261 67.9a7.503 7.503 0 0 0 7.155 5.261c.741 0 1.495-.111 2.24-.344l30.961-9.681a7.5 7.5 0 0 0 4.919-9.398l-10.536-33.669 49.459 14.67v6.774a7.5 7.5 0 0 0 7.5 7.5h31.204a7.5 7.5 0 0 0 7.5-7.5V32.959a7.499 7.499 0 0 0-7.499-7.5zM72.245 188.546l-16.646 5.205-14.814-47.311 20.154 5.977 11.306 36.129zm-3.167-49.359-.064-.019-32.092-9.519V82.306l90.803-26.926v101.202l-58.647-17.395zm89.85 32.315h-16.204V40.46h16.204v131.042zM224.962 147.969 192.51 131.74a7.5 7.5 0 0 0-6.709 13.417l32.452 16.229a7.5 7.5 0 0 0 10.063-3.354 7.502 7.502 0 0 0-3.354-10.063zM189.161 81.012a7.458 7.458 0 0 0 3.348-.794l32.453-16.227a7.5 7.5 0 0 0 3.354-10.062 7.5 7.5 0 0 0-10.062-3.354l-32.453 16.227a7.5 7.5 0 0 0-3.354 10.062 7.499 7.499 0 0 0 6.714 4.148zM228.608 98.48H201.51a7.5 7.5 0 0 0 0 15h27.098a7.5 7.5 0 0 0 0-15z"/></svg>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%- fields = Templaty::Helper.fields(options) -%>
|
2
|
+
en:
|
3
|
+
activerecord:
|
4
|
+
attributes:
|
5
|
+
<%= options[:table].singularize %>:
|
6
|
+
<%- fields.sort.each do |field| -%>
|
7
|
+
<%= field %>: <%= field.split('_').map(&:capitalize).join(' ') %>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<%= options[:table].singularize %>:
|
11
|
+
destroy:
|
12
|
+
confirm: "Deseja mesmo excluir o item %{name}?"
|
13
|
+
|
14
|
+
other: <%= options[:name_one].capitalize %>s
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%- fields = Templaty::Helper.fields(options) -%>
|
2
|
+
<%- data_i18n = Templaty::Helper.data_i18n(options) -%>
|
3
|
+
pt-BR:
|
4
|
+
activerecord:
|
5
|
+
attributes:
|
6
|
+
<%= options[:table].singularize %>:
|
7
|
+
<%- fields.sort.each do |field| -%>
|
8
|
+
<%= field %>: <%= data_i18n[field] %>
|
9
|
+
<%- end -%>
|
10
|
+
|
11
|
+
<%= options[:table].singularize %>:
|
12
|
+
destroy:
|
13
|
+
confirm: "Deseja mesmo excluir o item %{name}?"
|
14
|
+
|
15
|
+
other: <%= options[:name_one].capitalize %>s
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%- fields = Templaty::Helper.fields(options).sort -%>
|
2
|
+
ru:
|
3
|
+
activerecord:
|
4
|
+
attributes:
|
5
|
+
<%= options[:table].singularize %>:
|
6
|
+
<%- fields.sort.each do |field| -%>
|
7
|
+
<%= field %>: <%= field %>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<%= options[:table].singularize %>:
|
11
|
+
destroy:
|
12
|
+
confirm: "Вы действительно хотите удалить элемент %{name}?"
|
13
|
+
|
14
|
+
other: Кампании
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%- fields = Templaty::Helper.fields(options) -%>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
puts "[seed] #{File.basename(__FILE__)}"
|
5
|
+
|
6
|
+
@<%= options[:table] %> = {
|
7
|
+
one: create_<%= options[:table].singularize %>(<%= fields.sort.map { |field| "#{field}: #{field}" }.join(', ') %>),
|
8
|
+
}
|
data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/create_spec.rb.erb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
<%- data = Templaty::Helper.data_for(options) -%>
|
2
|
+
<%- fields = Templaty::Helper.fields(options) -%>
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'support/factory_bot'
|
6
|
+
require 'support/shared/logged'
|
7
|
+
|
8
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#create' do
|
9
|
+
context 'when unlogged' do
|
10
|
+
it 'redirects' do
|
11
|
+
post :create
|
12
|
+
|
13
|
+
expect(response.status).to be 302
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when logged' do
|
18
|
+
include_context 'when_logged', permissions: [['<%= options[:namespace] %>/<%= options[:table] %>', :create]], with_plan: true
|
19
|
+
|
20
|
+
let!(:parameters) { { <%= Templaty::Helper.data_as_hash_string(data, value_attribute: :raw) %> } }
|
21
|
+
|
22
|
+
context 'when fail' do
|
23
|
+
before { parameters[:<%= Templaty::Helper.fields_presence(options).first %>] = nil }
|
24
|
+
|
25
|
+
it 're-renders' do
|
26
|
+
post :create, params: { <%= options[:table].singularize %>: parameters }
|
27
|
+
|
28
|
+
expect(response).to render_template :new
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'does not destroy the record' do
|
32
|
+
expect { post :create, params: { <%= options[:table].singularize %>: parameters } }.not_to change(<%= options[:table].classify%>, :count)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when success' do
|
37
|
+
it 'redirects' do
|
38
|
+
post :create, params: { <%= options[:table].singularize %>: parameters }
|
39
|
+
|
40
|
+
expect(response).to redirect_to <%= options[:namespace] %>_<%= options[:table] %>_url
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'flashes' do
|
44
|
+
post :create, params: { <%= options[:table].singularize %>: parameters }
|
45
|
+
|
46
|
+
expect(flash[:info]).to eq '<%= options[:name_one].capitalize %> <%= Templaty::Helper.i18n_created(options) %> com sucesso.'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'creates the record' do
|
50
|
+
post :create, params: { <%= options[:table].singularize %>: parameters }
|
51
|
+
|
52
|
+
<%= options[:table].singularize %> = <%= options[:table].classify%>.last
|
53
|
+
|
54
|
+
<%- fields.sort.each do |field| -%>
|
55
|
+
expect(<%= options[:table].singularize %>.<%= field %>).to <%= Templaty::Helper.rspec_matcher(data[field][:raw]) %>
|
56
|
+
<%- end -%>
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/destroy_spec.rb.erb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
<%- model_name = options[:table].singularize -%>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'support/factory_bot'
|
5
|
+
require 'support/shared/logged'
|
6
|
+
require '<%= options[:namespace] %>/<%= options[:table] %>_controller'
|
7
|
+
|
8
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#destroy' do
|
9
|
+
context 'when unlogged' do
|
10
|
+
it 'redirects' do
|
11
|
+
delete :destroy, params: { id: 0 }
|
12
|
+
|
13
|
+
expect(response.status).to be 302
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when logged' do
|
18
|
+
include_context 'when_logged', permissions: [['<%= options[:namespace] %>/<%= options[:table] %>', :destroy]], with_plan: true
|
19
|
+
|
20
|
+
let!(:<%= model_name %>) { create(:<%= model_name %>, unit: current_unit) }
|
21
|
+
|
22
|
+
context 'when fail' do
|
23
|
+
before { allow_any_instance_of(<%= options[:table].classify%>).to receive(:destroy).and_return(false) }
|
24
|
+
|
25
|
+
it 'assigns record' do
|
26
|
+
delete :destroy, params: { id: <%= model_name %> }
|
27
|
+
|
28
|
+
expect(assigns(:<%= model_name %>)).to eq(<%= model_name %>)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 're-renders' do
|
32
|
+
delete :destroy, params: { id: <%= model_name %> }
|
33
|
+
|
34
|
+
expect(response).to render_template(:edit)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'does not destroy the record' do
|
38
|
+
expect { delete :destroy, params: { id: <%= model_name %> } }.not_to change(<%= options[:table].classify%>, :count)
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with no xxx' do
|
42
|
+
it 'builds one new xxx' do
|
43
|
+
delete :destroy, params: { id: <%= model_name %> }
|
44
|
+
|
45
|
+
xxxs = assigns(:xxxs)
|
46
|
+
|
47
|
+
expect(xxxs).to be_a Branch
|
48
|
+
expect(xxxs).to be_new_record
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with xxx' do
|
53
|
+
let!(:xxx_1) { create(:xxx, <%= model_name %>: <%= model_name %>, aaa: 'aaa-1') }
|
54
|
+
let!(:xxx_2) { create(:xxx, <%= model_name %>: <%= model_name %>, aaa: 'aaa-2') }
|
55
|
+
|
56
|
+
it 'keeps the data sent' do
|
57
|
+
delete :destroy, params: { id: <%= model_name %> }
|
58
|
+
|
59
|
+
xxxs = assigns(:xxxs)
|
60
|
+
|
61
|
+
expect(xxxs.size).to be(2)
|
62
|
+
|
63
|
+
xxx = xxxs[0]
|
64
|
+
|
65
|
+
expect(xxx.aaa).to eq('aaa-1')
|
66
|
+
|
67
|
+
xxx = xxxs[1]
|
68
|
+
|
69
|
+
expect(xxx.aaa).to eq('aaa-2')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when <%= model_name %> is from other unit' do
|
75
|
+
let!(:<%= model_name %>_other_unit) { create :<%= model_name %> }
|
76
|
+
|
77
|
+
it 'redirects' do
|
78
|
+
delete :destroy, params: { id: <%= model_name %>_other_unit.id }
|
79
|
+
|
80
|
+
expect(response).to redirect_to(<%= options[:namespace] %>_<%= options[:table] %>_url)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'flashes' do
|
84
|
+
delete :destroy, params: { id: <%= model_name %>_other_unit.id }
|
85
|
+
|
86
|
+
expect(flash[:info]).to eq('<%= options[:name_one].capitalize %> inexistente.')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'does not destroy' do
|
90
|
+
delete :destroy, params: { id: <%= model_name %>_other_unit.id }
|
91
|
+
|
92
|
+
expect(<%= model_name %>_other_unit.reload).not_to be(nil)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when success' do
|
97
|
+
it 'assigns record' do
|
98
|
+
delete :destroy, params: { id: <%= model_name %> }
|
99
|
+
|
100
|
+
expect(assigns(:<%= model_name %>)).to eq(<%= model_name %>)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'destroys the record' do
|
104
|
+
expect { delete :destroy, params: { id: <%= model_name %> } }.to change(<%= options[:table].classify%>, :count).by(-1)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'redirects' do
|
108
|
+
delete :destroy, params: { id: <%= model_name %> }
|
109
|
+
|
110
|
+
expect(response).to redirect_to(<%= options[:namespace] %>_<%= options[:table] %>_url)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'flashes' do
|
114
|
+
delete :destroy, params: { id: <%= model_name %> }
|
115
|
+
|
116
|
+
expect(flash[:info]).to eq('<%= options[:name_one].capitalize %> <%= Templaty::Helper.i18n_removed(options) %> com sucesso.')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'support/factory_bot'
|
4
|
+
require 'support/shared/logged'
|
5
|
+
require '<%= options[:namespace] %>/<%= options[:table] %>_controller'
|
6
|
+
|
7
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#edit' do
|
8
|
+
context 'when unlogged' do
|
9
|
+
it 'redirects' do
|
10
|
+
get :edit, params: { id: 0 }
|
11
|
+
|
12
|
+
expect(response.status).to be 302
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when logged' do
|
17
|
+
include_context 'when_logged', permissions: [['<%= options[:namespace] %>/<%= options[:table] %>', :edit]], with_plan: true
|
18
|
+
|
19
|
+
let!(:<%= options[:table].singularize %>) { create(:<%= options[:table].singularize %>, unit: current_unit) }
|
20
|
+
|
21
|
+
it 'assigns the record' do
|
22
|
+
get :edit, params: { id: <%= options[:table].singularize %> }
|
23
|
+
|
24
|
+
expect(assigns(:<%= options[:table].singularize %>)).to eq(<%= options[:table].singularize %>)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when <%= options[:table].singularize %> is from other unit' do
|
28
|
+
let!(:<%= options[:table].singularize %>) { create :<%= options[:table].singularize %> }
|
29
|
+
|
30
|
+
it 'redirects' do
|
31
|
+
get :edit, params: { id: <%= options[:table].singularize %> }
|
32
|
+
|
33
|
+
expect(response).to redirect_to(<%= options[:namespace] %>_<%= options[:table] %>_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'flashes' do
|
37
|
+
get :edit, params: { id: <%= options[:table].singularize %> }
|
38
|
+
|
39
|
+
expect(flash[:info]).to eq('<%= options[:name_one].capitalize %> inexistente.')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/gridy/json_spec.rb.erb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
<%- data = Templaty::Helper.data_for(options) -%>
|
2
|
+
<%- fields = Templaty::Helper.fields(options) -%>
|
3
|
+
<%- data_as_hash_string_raw = Templaty::Helper.data_as_hash_string(data, value_attribute: :raw) -%>
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
require 'support/factory_bot'
|
7
|
+
require 'support/shared/logged'
|
8
|
+
|
9
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#gridy' do
|
10
|
+
include_context 'when_logged', permissions: [['<%= options[:namespace] %>/<%= options[:table] %>', :gridy]], with_plan: true
|
11
|
+
|
12
|
+
render_views
|
13
|
+
|
14
|
+
let!(:<%= options[:table].singularize %>) { create(:<%= options[:table].singularize %>, <%= data_as_hash_string_raw %>, unit: current_unit) }
|
15
|
+
|
16
|
+
# ignored: other unit
|
17
|
+
before { create(:<%= options[:table].singularize %>, <%= Templaty::Helper.data_as_hash_string(data, value_attribute: :raw) %>) }
|
18
|
+
|
19
|
+
it 'serializes' do
|
20
|
+
get :gridy, xhr: true
|
21
|
+
|
22
|
+
result = json_for(response)
|
23
|
+
|
24
|
+
expect(contain_icon?(result[:list], :more_image, '/assets/icons/ellipsis.svg')).to be(true)
|
25
|
+
|
26
|
+
<%-
|
27
|
+
fields << 'edit_path'
|
28
|
+
fields << 'show_path' if options[:show_route]
|
29
|
+
-%>
|
30
|
+
expect(result).to eq(
|
31
|
+
list: [
|
32
|
+
{
|
33
|
+
<%- fields.sort.each do |field| -%>
|
34
|
+
<%- if field == 'edit_path' -%>
|
35
|
+
edit_path: edit_<%= options[:namespace] %>_<%= options[:table].singularize %>_path(<%= options[:table].singularize %>),
|
36
|
+
<%- elsif field == 'show_path' -%>
|
37
|
+
show_path: <%= options[:table].singularize %>_path(<%= options[:table].singularize %>,
|
38
|
+
<%- elsif field.start_with?('percentage') -%>
|
39
|
+
<%= field.sub('_cents', '') %>: <%= Templaty::Helper.data_wrap(data[field][:formatted]) %>,
|
40
|
+
<%- elsif field.end_with?('_cents') -%>
|
41
|
+
<%= field.sub('_cents', '') %>: <%= Templaty::Helper.data_wrap(data[field][:formatted]) %>,
|
42
|
+
<%- else -%>
|
43
|
+
<%= field %>: <%= Templaty::Helper.data_wrap(data[field][:formatted]) %>,
|
44
|
+
<%- end -%>
|
45
|
+
<%- end -%>
|
46
|
+
},
|
47
|
+
],
|
48
|
+
|
49
|
+
total: 1
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'support/factory_bot'
|
4
|
+
require 'support/shared/logged'
|
5
|
+
|
6
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#gridy' do
|
7
|
+
it 'redirects' do
|
8
|
+
get :gridy, xhr: true
|
9
|
+
|
10
|
+
expect(response.status).to be 401
|
11
|
+
end
|
12
|
+
end
|
data/lib/generators/templaty/templates/crud/spec/controllers/namespace/model/index_spec.rb.erb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'support/factory_bot'
|
4
|
+
require 'support/shared/logged'
|
5
|
+
|
6
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#index' do
|
7
|
+
context 'when unlogged' do
|
8
|
+
it 'redirects' do
|
9
|
+
get :index
|
10
|
+
|
11
|
+
expect(response.status).to be 302
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when logged' do
|
16
|
+
include_context 'when_logged', permissions: [['<%= options[:namespace] %>/<%= options[:table] %>', :index]], with_plan: true
|
17
|
+
|
18
|
+
it 'success' do
|
19
|
+
get :index
|
20
|
+
|
21
|
+
expect(response.status).to be(200)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'support/factory_bot'
|
4
|
+
require 'support/shared/logged'
|
5
|
+
|
6
|
+
RSpec.describe <%= options[:namespace].classify %>::<%= options[:table].classify.pluralize %>Controller, '#new' do
|
7
|
+
context 'when unlogged' do
|
8
|
+
it 'redirects' do
|
9
|
+
get :new
|
10
|
+
|
11
|
+
expect(response.status).to be 302
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when logged' do
|
16
|
+
include_context 'when_logged', permissions: [['<%= options[:namespace] %>/<%= options[:table] %>', :new]], with_plan: true
|
17
|
+
|
18
|
+
it 'loads the role' do
|
19
|
+
get :new
|
20
|
+
|
21
|
+
expect(assigns(:<%= options[:table].singularize %>)).to be_kind_of(<%= options[:table].classify%>)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|