sun-sword 0.0.13 → 0.0.14
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/Gemfile.lock +1 -1
- data/lib/generators/sun_sword/frontend_generator.rb +2 -4
- data/lib/generators/sun_sword/frontend_generator_spec.rb +0 -6
- data/lib/generators/sun_sword/scaffold_generator.rb +24 -0
- data/lib/generators/sun_sword/scaffold_generator_spec.rb +5 -6
- data/lib/generators/sun_sword/templates_frontend/config/devise.rb +1 -1
- data/lib/generators/sun_sword/templates_scaffold/controllers/controller.rb.tt +12 -10
- data/lib/generators/sun_sword/templates_scaffold/controllers/controller_spec.rb.tt +59 -32
- data/lib/generators/sun_sword/templates_scaffold/views/index.html.erb.tt +32 -30
- data/lib/sun_sword/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e4ddac73f4a2f50ec6923ddc5f5f69e9bcc547be9e17d55c60bc6ecc993d4d0
|
|
4
|
+
data.tar.gz: dcfe5d73943110eb8b165991e7677b0594db726522c23b1ca483140714e6e525
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f48f2974b697c84430061f2a4cb75e0512e3cfc7001bb599edb7894a56a3ef352efc5de33b5fe96def472fda01f665f7c5aed7b890c190e728748ea6066c71fe
|
|
7
|
+
data.tar.gz: 9c12c9c9d150325af5840927e5ca6c8063fdb32a7249f7ab8c03ffe3ebeebebce78a50974cc5756928f70655b3ead5777d8d372caa96f27f5157e6c135cd2b2f
|
data/Gemfile.lock
CHANGED
|
@@ -55,13 +55,12 @@ module SunSword
|
|
|
55
55
|
|
|
56
56
|
def add_to_gemfile
|
|
57
57
|
gem_dependencies = <<~RUBY
|
|
58
|
+
|
|
58
59
|
# --- SunSword Package frontend
|
|
59
60
|
group :development do
|
|
60
61
|
gem "listen"
|
|
61
62
|
end
|
|
62
|
-
|
|
63
|
-
gem "rails-controller-testing"
|
|
64
|
-
end
|
|
63
|
+
|
|
65
64
|
gem 'turbo-rails'
|
|
66
65
|
gem 'vite_rails'
|
|
67
66
|
RUBY
|
|
@@ -109,7 +108,6 @@ module SunSword
|
|
|
109
108
|
end
|
|
110
109
|
|
|
111
110
|
def generate_controllers_tests
|
|
112
|
-
run 'rails g controller tests stimulus turbo_drive turbo_frame frame_content update_content'
|
|
113
111
|
template 'controllers/tests_controller.rb', File.join(path_app, 'controllers/tests_controller.rb')
|
|
114
112
|
template 'controllers/tests_controller_spec.rb', File.join(path_app, 'controllers/tests_controller_spec.rb')
|
|
115
113
|
template 'controllers/application_controller.rb.tt', File.join(path_app, 'controllers/application_controller.rb')
|
|
@@ -398,12 +398,6 @@ RSpec.describe SunSword::FrontendGenerator, type: :generator do
|
|
|
398
398
|
allow(generator).to receive(:say)
|
|
399
399
|
end
|
|
400
400
|
|
|
401
|
-
it 'runs rails generator command' do
|
|
402
|
-
generator.send(:generate_controllers_tests)
|
|
403
|
-
|
|
404
|
-
expect(generator).to have_received(:run).with('rails g controller tests stimulus turbo_drive turbo_frame frame_content update_content')
|
|
405
|
-
end
|
|
406
|
-
|
|
407
401
|
it 'calls template for controller files' do
|
|
408
402
|
generator.send(:generate_controllers_tests)
|
|
409
403
|
|
|
@@ -67,6 +67,11 @@ module SunSword
|
|
|
67
67
|
@scope_class = @scope_path.camelize
|
|
68
68
|
@scope_subject = @scope_path.singularize
|
|
69
69
|
@model_class = model_name.camelize.constantize
|
|
70
|
+
|
|
71
|
+
# Column metadata
|
|
72
|
+
@columns_meta = columns_meta
|
|
73
|
+
@columns_meta_hash = @columns_meta.index_by { |c| c[:name] }
|
|
74
|
+
|
|
70
75
|
@subject_class = @variable_subject.camelize
|
|
71
76
|
@fields = contract_fields
|
|
72
77
|
@form_fields = @controllers.form_fields
|
|
@@ -394,6 +399,25 @@ module SunSword
|
|
|
394
399
|
@model_class.columns.reject { |column| skip_contract_fields.include?(column.name.to_s) }.map { |column| [column.name.to_s, column.type.to_s] }
|
|
395
400
|
end
|
|
396
401
|
|
|
402
|
+
def columns_meta
|
|
403
|
+
@model_class.columns.map do |c|
|
|
404
|
+
{
|
|
405
|
+
name: c.name.to_s,
|
|
406
|
+
type: c.type,
|
|
407
|
+
sql_type: (c.respond_to?(:sql_type) ? c.sql_type : nil),
|
|
408
|
+
null: (c.respond_to?(:null) ? c.null : nil),
|
|
409
|
+
default: (c.respond_to?(:default) ? c.default : nil),
|
|
410
|
+
precision: (c.respond_to?(:precision) ? c.precision : nil),
|
|
411
|
+
scale: (c.respond_to?(:scale) ? c.scale : nil),
|
|
412
|
+
limit: (c.respond_to?(:limit) ? c.limit : nil)
|
|
413
|
+
}
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
def get_column_meta(field)
|
|
418
|
+
@columns_meta_hash[field.to_s] || {}
|
|
419
|
+
end
|
|
420
|
+
|
|
397
421
|
def strong_params
|
|
398
422
|
# pakai controllers.form_fields kalau ada, kalau tidak jatuh ke kolom model (contract_fields)
|
|
399
423
|
raw_fields = @controllers&.form_fields || contract_fields
|
|
@@ -507,9 +507,9 @@ RSpec.describe SunSword::ScaffoldGenerator, type: :generator do
|
|
|
507
507
|
expect(content).to include('POST #create')
|
|
508
508
|
expect(content).to include('PATCH #update')
|
|
509
509
|
expect(content).to include('DELETE #destroy')
|
|
510
|
-
expect(content).to include('
|
|
511
|
-
expect(content).to include('
|
|
512
|
-
expect(content).to include('
|
|
510
|
+
expect(content).to include('stub_use_case(')
|
|
511
|
+
expect(content).to include('response: :success')
|
|
512
|
+
expect(content).to include('response: :failure')
|
|
513
513
|
end
|
|
514
514
|
end
|
|
515
515
|
|
|
@@ -554,7 +554,7 @@ RSpec.describe SunSword::ScaffoldGenerator, type: :generator do
|
|
|
554
554
|
controller_spec_path = File.join(destination_root, 'app', 'controllers', 'admin', 'test_models_controller_spec.rb')
|
|
555
555
|
content = File.read(controller_spec_path)
|
|
556
556
|
expect(content).to include('RSpec.describe Admin::TestModelsController')
|
|
557
|
-
expect(content).to include('
|
|
557
|
+
expect(content).to include('UseCases::Admin')
|
|
558
558
|
end
|
|
559
559
|
end
|
|
560
560
|
end
|
|
@@ -597,9 +597,8 @@ RSpec.describe SunSword::ScaffoldGenerator, type: :generator do
|
|
|
597
597
|
|
|
598
598
|
controller_spec_path = File.join(destination_root, 'engines', 'admin', 'app', 'controllers', 'admin', 'test_models_controller_spec.rb')
|
|
599
599
|
content = File.read(controller_spec_path)
|
|
600
|
-
expect(content).to include('
|
|
600
|
+
expect(content).to include('stub_use_case(')
|
|
601
601
|
expect(content).to include('create(:')
|
|
602
|
-
expect(content).to include('build(:')
|
|
603
602
|
end
|
|
604
603
|
end
|
|
605
604
|
end
|
|
@@ -302,7 +302,7 @@ Devise.setup do |config|
|
|
|
302
302
|
# apps is `200 OK` and `302 Found` respectively, but new apps are generated with
|
|
303
303
|
# these new defaults that match Hotwire/Turbo behavior.
|
|
304
304
|
# Note: These might become the new default in future versions of Devise.
|
|
305
|
-
config.responder.error_status = :
|
|
305
|
+
config.responder.error_status = :unprocessable_content
|
|
306
306
|
config.responder.redirect_status = :see_other
|
|
307
307
|
|
|
308
308
|
# ==> Configuration for :registerable
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Template for the controller (controllers/controller.rb.tt)
|
|
2
|
-
class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::") %>Controller < ApplicationController
|
|
2
|
+
class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::") %>Controller < <%= [@engine_scope_class].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>ApplicationController
|
|
3
3
|
before_action :set_<%= @variable_subject %>, only: %i[edit update]
|
|
4
4
|
layout :set_layouts
|
|
5
5
|
|
|
@@ -14,7 +14,9 @@ class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
|
14
14
|
render '<%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_") + "/" %><%= [@engine_mount_path, @scope_path, "index"].reject { |c| c.empty? }.join("/") %>'
|
|
15
15
|
end
|
|
16
16
|
matcher.failure do |errors|
|
|
17
|
-
|
|
17
|
+
@<%= @variable_subject.pluralize %> = Hashie::Mash.new({ response: [] })
|
|
18
|
+
flash.now[:error] = errors.pluck(:message).join(", ")
|
|
19
|
+
render '<%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_") + "/" %><%= [@engine_mount_path, @scope_path, "index"].reject { |c| c.empty? }.join("/") %>'
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
@@ -29,7 +31,7 @@ class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
|
29
31
|
@<%= @variable_subject %> = response
|
|
30
32
|
end
|
|
31
33
|
matcher.failure do |errors|
|
|
32
|
-
redirect_to
|
|
34
|
+
redirect_to <%= [@scope_path].reject { |c| c.empty? }.join("_") %>_url, success: errors
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
@@ -50,11 +52,11 @@ class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
|
50
52
|
result = use_case.new(contract).result
|
|
51
53
|
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
|
52
54
|
matcher.success do |response|
|
|
53
|
-
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_")
|
|
55
|
+
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_").sub(/(.+)/, '\1_') %><%= [@scope_path.singularize].reject { |c| c.empty? }.join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully created.'
|
|
54
56
|
end
|
|
55
57
|
matcher.failure do |errors|
|
|
56
58
|
@<%= @variable_subject %> = build_form_errors(<%= @variable_subject %>_params, <%= @model_class %>.new, errors)
|
|
57
|
-
render '<%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_") + "/" %><%= [@engine_mount_path, @scope_path, "new"].reject { |c| c.empty? }.join("/") %>', status: :
|
|
59
|
+
render '<%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_") + "/" %><%= [@engine_mount_path, @scope_path, "new"].reject { |c| c.empty? }.join("/") %>', status: :unprocessable_content
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
end
|
|
@@ -66,11 +68,11 @@ class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
|
66
68
|
result = use_case.new(contract).result
|
|
67
69
|
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
|
68
70
|
matcher.success do |response|
|
|
69
|
-
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_")
|
|
71
|
+
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_").sub(/(.+)/, '\1_') %><%= [@scope_path.singularize].reject { |c| c.empty? }.join("_") %>_url(id: response.id), success: '<%= @subject_class %> was successfully updated.'
|
|
70
72
|
end
|
|
71
73
|
matcher.failure do |errors|
|
|
72
74
|
@<%= @variable_subject %> = build_form_errors(<%= @variable_subject %>_params, <%= @model_class %>.find(params[:id]), errors)
|
|
73
|
-
render '<%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_") + "/" %><%= [@engine_mount_path, @scope_path, "edit"].reject { |c| c.empty? }.join("/") %>', status: :
|
|
75
|
+
render '<%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_") + "/" %><%= [@engine_mount_path, @scope_path, "edit"].reject { |c| c.empty? }.join("/") %>', status: :unprocessable_content
|
|
74
76
|
end
|
|
75
77
|
end
|
|
76
78
|
end
|
|
@@ -82,10 +84,10 @@ class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
|
82
84
|
result = use_case.new(contract).result
|
|
83
85
|
Dry::Matcher::ResultMatcher.call(result) do |matcher|
|
|
84
86
|
matcher.success do |response|
|
|
85
|
-
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_")
|
|
87
|
+
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_").sub(/(.+)/, '\1_') %><%= [@scope_path].reject { |c| c.empty? }.join("_") %>_url, notice: '<%= @subject_class %> was successfully destroyed.'
|
|
86
88
|
end
|
|
87
89
|
matcher.failure do |errors|
|
|
88
|
-
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_")
|
|
90
|
+
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_").sub(/(.+)/, '\1_') %><%= [@scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> could not be destroyed.'
|
|
89
91
|
end
|
|
90
92
|
end
|
|
91
93
|
end
|
|
@@ -107,7 +109,7 @@ class <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::")
|
|
|
107
109
|
<%else -%>
|
|
108
110
|
@<%= @variable_subject %> = <%= @model_class %>.find_by(id: params[:id])
|
|
109
111
|
<%end -%>
|
|
110
|
-
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_")
|
|
112
|
+
redirect_to <%= [@route_scope_path.singularize].reject { |c| c.empty? }.join("_").sub(/(.+)/, '\1_') %><%= [@scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> not found.' if @<%= @variable_subject %>.nil?
|
|
111
113
|
end
|
|
112
114
|
|
|
113
115
|
# Only allow a list of trusted parameters through.
|
|
@@ -3,10 +3,36 @@
|
|
|
3
3
|
require 'rails_helper'
|
|
4
4
|
|
|
5
5
|
RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.join("::") %>Controller, type: :controller do
|
|
6
|
+
<% if @engine_scope_class.present? -%>
|
|
7
|
+
routes { <%= @engine_scope_class%>::Engine.routes }
|
|
8
|
+
<% end -%>
|
|
9
|
+
|
|
6
10
|
<% if @resource_owner_id.present? -%>
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
let(:<%= @resource_owner %>) { create(:<%= @resource_owner %>)}
|
|
12
|
+
let(:<%= @resource_owner_id %>) { <%= @resource_owner %>.id }
|
|
13
|
+
<% end -%>
|
|
14
|
+
<% @fields.each do |field| -%>
|
|
15
|
+
<% next if @resource_owner_id.present? && field[0] == @resource_owner_id -%>
|
|
16
|
+
<% field_meta = columns_meta.find { |col| col[:name] == field[0] } -%>
|
|
17
|
+
<% if field_meta && field_meta[:type] == :uuid -%>
|
|
18
|
+
let(:<%= field[0].delete_suffix("_id") %>) { create(:<%= field[0].delete_suffix("_id") %>, <%= @resource_owner %>: <%= @resource_owner %>) }
|
|
19
|
+
let(:<%= field[0] %>) { <%= field[0].delete_suffix("_id") %>.id }
|
|
9
20
|
<% end -%>
|
|
21
|
+
<% end -%>
|
|
22
|
+
<%
|
|
23
|
+
explicit_params = []
|
|
24
|
+
if @resource_owner_id.present?
|
|
25
|
+
explicit_params << "#{@resource_owner_id}: #{@resource_owner}.id"
|
|
26
|
+
end
|
|
27
|
+
@fields.each do |field|
|
|
28
|
+
next if @resource_owner_id.present? && field[0] == @resource_owner_id
|
|
29
|
+
field_meta = columns_meta.find { |col| col[:name] == field[0] }
|
|
30
|
+
if field_meta && field_meta[:type] == :uuid
|
|
31
|
+
explicit_params << "#{field[0]}: #{field[0].delete_suffix('_id')}.id"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
create_params_str = explicit_params.any? ? ", #{explicit_params.join(', ')}" : ''
|
|
35
|
+
-%>
|
|
10
36
|
|
|
11
37
|
let(:valid_attributes) do
|
|
12
38
|
{
|
|
@@ -28,22 +54,23 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
28
54
|
|
|
29
55
|
let(:invalid_attributes) do
|
|
30
56
|
{
|
|
31
|
-
<% @fields.
|
|
32
|
-
<% next if
|
|
33
|
-
|
|
57
|
+
<% @fields.each_with_index do |field, index| -%>
|
|
58
|
+
<% next if @resource_owner_id.present? && field == @resource_owner_id -%>
|
|
59
|
+
<% is_last = index == @fields.length - 1 || (@resource_owner_id.present? && index == @fields.length - 1) -%>
|
|
60
|
+
<%= field[0] %>: 'nil'<%= is_last ? '' : ',' %>
|
|
34
61
|
<% end -%>
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
}
|
|
63
|
+
end
|
|
37
64
|
|
|
38
65
|
<% if @resource_owner_id.present? -%>
|
|
39
66
|
before do
|
|
40
|
-
allow(controller).to receive(:<%= @resource_owner_id %>).and_return(
|
|
67
|
+
allow(controller).to receive(:<%= @resource_owner_id %>).and_return(<%= @resource_owner %>.id)
|
|
41
68
|
end
|
|
42
69
|
|
|
43
70
|
<% end -%>
|
|
44
71
|
describe 'GET #index' do
|
|
45
72
|
context 'when use case succeeds' do
|
|
46
|
-
let(:<%= @variable_subject.pluralize %>) { create_list(:<%= @variable_subject %>, 3) }
|
|
73
|
+
let(:<%= @variable_subject.pluralize %>) { create_list(:<%= @variable_subject %>, 3<%= create_params_str %>) }
|
|
47
74
|
|
|
48
75
|
before do
|
|
49
76
|
stub_use_case(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('list')].reject { |c| c.empty? }.join("::") %>, <%= @variable_subject.pluralize %>, response: :success)
|
|
@@ -58,7 +85,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
58
85
|
end
|
|
59
86
|
|
|
60
87
|
it 'calls use case with correct contract' do
|
|
61
|
-
expect(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('list')].reject { |c| c.empty? }.join("::") %>).to receive(:contract!)<%= @resource_owner_id.present? ? "\n .with(hash_including(#{@resource_owner_id}:
|
|
88
|
+
expect(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('list')].reject { |c| c.empty? }.join("::") %>).to receive(:contract!)<%= @resource_owner_id.present? ? "\n .with(hash_including(#{@resource_owner_id}: #{@resource_owner}.id))" : '' %>
|
|
62
89
|
|
|
63
90
|
get :index
|
|
64
91
|
end
|
|
@@ -75,14 +102,14 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
75
102
|
it 'redirects to root path with error' do
|
|
76
103
|
get :index
|
|
77
104
|
|
|
78
|
-
expect(response).to redirect_to(
|
|
105
|
+
expect(response).to redirect_to(<%= @variable_subject.pluralize %>_url)
|
|
79
106
|
expect(flash[:success]).to eq('Error loading <%= @variable_subject.pluralize %>')
|
|
80
107
|
end
|
|
81
108
|
end
|
|
82
109
|
end
|
|
83
110
|
|
|
84
111
|
describe 'GET #show' do
|
|
85
|
-
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%=
|
|
112
|
+
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%= create_params_str %>) }
|
|
86
113
|
|
|
87
114
|
context 'when use case succeeds' do
|
|
88
115
|
let(:use_case_instance) { instance_double(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('fetch', '_by_id')].reject { |c| c.empty? }.join("::") %>) }
|
|
@@ -101,7 +128,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
101
128
|
|
|
102
129
|
it 'calls use case with correct contract' do
|
|
103
130
|
expect(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('fetch', '_by_id')].reject { |c| c.empty? }.join("::") %>).to receive(:contract!)
|
|
104
|
-
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}:
|
|
131
|
+
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}: #{@resource_owner}.id, " : '' %>id: <%= @variable_subject %>.id))
|
|
105
132
|
|
|
106
133
|
get :show, params: { id: <%= @variable_subject %>.id }
|
|
107
134
|
end
|
|
@@ -115,10 +142,10 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
115
142
|
stub_use_case(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('fetch', '_by_id')].reject { |c| c.empty? }.join("::") %>, failure_result, response: :failure)
|
|
116
143
|
end
|
|
117
144
|
|
|
118
|
-
it 'redirects to
|
|
145
|
+
it 'redirects to <%= @variable_subject.pluralize %> path with error' do
|
|
119
146
|
get :show, params: { id: 'non-existent' }
|
|
120
147
|
|
|
121
|
-
expect(response).to redirect_to(
|
|
148
|
+
expect(response).to redirect_to(<%= @variable_subject.pluralize %>_url)
|
|
122
149
|
expect(flash[:success]).to eq('<%= @subject_class %> not found')
|
|
123
150
|
end
|
|
124
151
|
end
|
|
@@ -134,12 +161,12 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
134
161
|
end
|
|
135
162
|
|
|
136
163
|
describe 'GET #edit' do
|
|
137
|
-
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%=
|
|
164
|
+
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%= create_params_str %>) }
|
|
138
165
|
|
|
139
166
|
context 'when <%= @variable_subject %> exists<%= @resource_owner_id.present? ? " and belongs to owner" : '' %>' do
|
|
140
167
|
before do
|
|
141
168
|
allow(<%= @model_class %>).to receive(:find_by)
|
|
142
|
-
.with(<%= @resource_owner_id.present? ? "id: #{@variable_subject}.id, #{@resource_owner_id}:
|
|
169
|
+
.with(<%= @resource_owner_id.present? ? "id: #{@variable_subject}.id, #{@resource_owner_id}: #{@resource_owner}.id" : "id: #{@variable_subject}.id" %>)
|
|
143
170
|
.and_return(<%= @variable_subject %>)
|
|
144
171
|
end
|
|
145
172
|
|
|
@@ -154,7 +181,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
154
181
|
context 'when <%= @variable_subject %> does not exist<%= @resource_owner_id.present? ? " or does not belong to owner" : '' %>' do
|
|
155
182
|
before do
|
|
156
183
|
allow(<%= @model_class %>).to receive(:find_by)
|
|
157
|
-
.with(<%= @resource_owner_id.present? ? "id: 'non-existent', #{@resource_owner_id}:
|
|
184
|
+
.with(<%= @resource_owner_id.present? ? "id: 'non-existent', #{@resource_owner_id}: #{@resource_owner}.id" : "id: 'non-existent'" %>)
|
|
158
185
|
.and_return(nil)
|
|
159
186
|
end
|
|
160
187
|
|
|
@@ -186,7 +213,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
186
213
|
|
|
187
214
|
it 'calls use case with correct contract' do
|
|
188
215
|
expect(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('create')].reject { |c| c.empty? }.join("::") %>).to receive(:contract!)
|
|
189
|
-
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}:
|
|
216
|
+
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}: #{@resource_owner}.id, " : '' %>**valid_attributes.stringify_keys))
|
|
190
217
|
|
|
191
218
|
post :create, params: { models_<%= @subject_class.underscore %>: valid_attributes }
|
|
192
219
|
end
|
|
@@ -204,7 +231,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
204
231
|
it 'does not create and renders new with errors' do
|
|
205
232
|
post :create, params: { models_<%= @subject_class.underscore %>: invalid_attributes }
|
|
206
233
|
|
|
207
|
-
expect(response).to have_http_status(:
|
|
234
|
+
expect(response).to have_http_status(:unprocessable_content)
|
|
208
235
|
expect(response).to render_template('<%= [@route_scope_path, @scope_path, 'new'].reject { |c| c.empty? }.join("/") %>')
|
|
209
236
|
expect(assigns(:<%= @variable_subject %>)).to be_a(<%= @model_class %>)
|
|
210
237
|
end
|
|
@@ -219,12 +246,12 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
219
246
|
end
|
|
220
247
|
|
|
221
248
|
describe 'PATCH #update' do
|
|
222
|
-
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%=
|
|
249
|
+
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%= create_params_str %>) }
|
|
223
250
|
let(:updated_attributes) { { <%= @fields.first.first %>: 'Updated Value' } }
|
|
224
251
|
|
|
225
252
|
before do
|
|
226
253
|
allow(<%= @model_class %>).to receive(:find_by)
|
|
227
|
-
.with(<%= @resource_owner_id.present? ? "id: #{@variable_subject}.id, #{@resource_owner_id}:
|
|
254
|
+
.with(<%= @resource_owner_id.present? ? "id: #{@variable_subject}.id, #{@resource_owner_id}: #{@resource_owner}.id" : "id: #{@variable_subject}.id" %>)
|
|
228
255
|
.and_return(<%= @variable_subject %>)
|
|
229
256
|
end
|
|
230
257
|
|
|
@@ -232,7 +259,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
232
259
|
let(:updated_<%= @variable_subject %>) { <%= @variable_subject %>.tap { |obj| obj.<%= @fields.first.first %> = 'Updated Value' } }
|
|
233
260
|
|
|
234
261
|
before do
|
|
235
|
-
stub_use_case(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].reject { |c| c.empty? }.join("::") %>,
|
|
262
|
+
stub_use_case(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].reject { |c| c.empty? }.join("::") %>, updated_<%= @variable_subject %>, response: :success)
|
|
236
263
|
end
|
|
237
264
|
|
|
238
265
|
it 'updates and redirects with success message' do
|
|
@@ -244,7 +271,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
244
271
|
|
|
245
272
|
it 'calls use case with correct contract' do
|
|
246
273
|
expect(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('update')].reject { |c| c.empty? }.join("::") %>).to receive(:contract!)
|
|
247
|
-
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}:
|
|
274
|
+
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}: #{@resource_owner}.id, " : '' %>id: <%= @variable_subject %>.id, **updated_attributes.stringify_keys))
|
|
248
275
|
|
|
249
276
|
patch :update, params: { id: <%= @variable_subject %>.id, models_<%= @subject_class.underscore %>: updated_attributes }
|
|
250
277
|
end
|
|
@@ -263,7 +290,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
263
290
|
it 'does not update and renders edit with errors' do
|
|
264
291
|
patch :update, params: { id: <%= @variable_subject %>.id, models_<%= @subject_class.underscore %>: invalid_attributes }
|
|
265
292
|
|
|
266
|
-
expect(response).to have_http_status(:
|
|
293
|
+
expect(response).to have_http_status(:unprocessable_content)
|
|
267
294
|
expect(response).to render_template('<%= [@route_scope_path, @scope_path, 'edit'].reject { |c| c.empty? }.join("/") %>')
|
|
268
295
|
expect(assigns(:<%= @variable_subject %>)).to eq(<%= @variable_subject %>)
|
|
269
296
|
end
|
|
@@ -271,7 +298,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
271
298
|
end
|
|
272
299
|
|
|
273
300
|
describe 'DELETE #destroy' do
|
|
274
|
-
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%=
|
|
301
|
+
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%= create_params_str %>) }
|
|
275
302
|
|
|
276
303
|
context 'when deletion succeeds' do
|
|
277
304
|
let(:success_result) { true }
|
|
@@ -289,7 +316,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
289
316
|
|
|
290
317
|
it 'calls use case with correct contract' do
|
|
291
318
|
expect(<%= [@usecase_domain].reject { |c| c.empty? }.join("::").sub(/(.+)/, '\1::') %>UseCases::<%= [@route_scope_class, @scope_class, build_usecase_filename('destroy')].reject { |c| c.empty? }.join("::") %>).to receive(:contract!)
|
|
292
|
-
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}:
|
|
319
|
+
.with(hash_including(<%= @resource_owner_id.present? ? "#{@resource_owner_id}: #{@resource_owner}.id, " : '' %>id: <%= @variable_subject %>.id))
|
|
293
320
|
|
|
294
321
|
delete :destroy, params: { id: <%= @variable_subject %>.id }
|
|
295
322
|
end
|
|
@@ -317,17 +344,17 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
317
344
|
params = { <%= @fields.first.first %>: 'Test' }
|
|
318
345
|
result = controller.send(:build_contract, params)
|
|
319
346
|
|
|
320
|
-
expect(result).to include(<%= @resource_owner_id.present? ? "#{@resource_owner_id}:
|
|
347
|
+
expect(result).to include(<%= @resource_owner_id.present? ? "#{@resource_owner_id}: #{@resource_owner}.id, " : '' %><%= @fields.first.first %>: 'Test')
|
|
321
348
|
end
|
|
322
349
|
end
|
|
323
350
|
|
|
324
351
|
describe '#set_<%= @variable_subject %>' do
|
|
325
352
|
context 'when <%= @variable_subject %> exists' do
|
|
326
|
-
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%=
|
|
353
|
+
let(:<%= @variable_subject %>) { create(:<%= @variable_subject %><%= create_params_str %>) }
|
|
327
354
|
|
|
328
355
|
before do
|
|
329
356
|
allow(<%= @model_class %>).to receive(:find_by)
|
|
330
|
-
.with(<%= @resource_owner_id.present? ? "id: #{@variable_subject}.id, #{@resource_owner_id}:
|
|
357
|
+
.with(<%= @resource_owner_id.present? ? "id: #{@variable_subject}.id, #{@resource_owner_id}: #{@resource_owner}.id" : "id: #{@variable_subject}.id" %>)
|
|
331
358
|
.and_return(<%= @variable_subject %>)
|
|
332
359
|
end
|
|
333
360
|
|
|
@@ -343,7 +370,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
343
370
|
context 'when <%= @variable_subject %> does not exist' do
|
|
344
371
|
before do
|
|
345
372
|
allow(<%= @model_class %>).to receive(:find_by)
|
|
346
|
-
.with(<%= @resource_owner_id.present? ? "id: 'non-existent', #{@resource_owner_id}:
|
|
373
|
+
.with(<%= @resource_owner_id.present? ? "id: 'non-existent', #{@resource_owner_id}: #{@resource_owner}.id" : "id: 'non-existent'" %>)
|
|
347
374
|
.and_return(nil)
|
|
348
375
|
end
|
|
349
376
|
|
|
@@ -354,7 +381,7 @@ RSpec.describe <%= [@engine_scope_class, @scope_class].reject { |c| c.empty? }.j
|
|
|
354
381
|
controller.send(:set_<%= @variable_subject %>)
|
|
355
382
|
|
|
356
383
|
expect(controller.instance_variable_get(:@<%= @variable_subject %>)).to be_nil
|
|
357
|
-
expect(controller).to have_received(:redirect_to).with(<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '
|
|
384
|
+
expect(controller).to have_received(:redirect_to).with(<%= [@route_scope_path, @scope_path].reject { |c| c.empty? }.join("_") %>_url, error: '<%= @subject_class %> not found.')
|
|
358
385
|
end
|
|
359
386
|
end
|
|
360
387
|
end
|
|
@@ -16,37 +16,39 @@
|
|
|
16
16
|
<%% end %>
|
|
17
17
|
</div>
|
|
18
18
|
</div>
|
|
19
|
-
|
|
20
|
-
<div class="
|
|
21
|
-
<
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</thead>
|
|
30
|
-
<tbody class="min-w-full divide-y divide-gray-100">
|
|
31
|
-
<%% @<%= @variable_subject.pluralize %>.response.each do |<%= @variable_subject %>| %>
|
|
32
|
-
<tr class="even:bg-gray-50">
|
|
33
|
-
<%@controllers.list_fields.each do |field| -%>
|
|
34
|
-
<td class="class-td">
|
|
35
|
-
<div class="flex items-center">
|
|
36
|
-
<div>
|
|
37
|
-
<div class="text-sm text-gray-900"><%%= <%= @variable_subject %>.<%=field %> %></div>
|
|
38
|
-
</div>
|
|
39
|
-
</div>
|
|
40
|
-
</td>
|
|
41
|
-
<%end-%>
|
|
42
|
-
<td class="class-td text-center">
|
|
43
|
-
<%%= render "components/link_action", key: "<%= [@route_scope_path, @scope_subject].reject { |c| c.empty? }.join("_") %>", value: <%= @variable_subject %>, actions: [:show, :edit, :destroy] %>
|
|
44
|
-
</td>
|
|
19
|
+
<%% if @<%= @variable_subject.pluralize %>.response.present? %>
|
|
20
|
+
<div class="overflow-x-auto sm:flex-auto">
|
|
21
|
+
<div class="inline-block min-w-full align-middle">
|
|
22
|
+
<table class="min-w-full divide-y divide-gray-300">
|
|
23
|
+
<thead>
|
|
24
|
+
<tr>
|
|
25
|
+
<%% <%= @controllers.list_fields.map { |tc| [tc.titleize.to_s, '']} + [["Action", "text-center"]]%>.each do |title, attr_class| %>
|
|
26
|
+
<th scope="col" class="class-tr <%%= attr_class %>"><%%= title %></th>
|
|
27
|
+
<%% end %>
|
|
28
|
+
</th>
|
|
45
29
|
</tr>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
</thead>
|
|
31
|
+
<tbody class="min-w-full divide-y divide-gray-100">
|
|
32
|
+
<%% @<%= @variable_subject.pluralize %>.response.each do |<%= @variable_subject %>| %>
|
|
33
|
+
<tr class="even:bg-gray-50">
|
|
34
|
+
<%@controllers.list_fields.each do |field| -%>
|
|
35
|
+
<td class="class-td">
|
|
36
|
+
<div class="flex items-center">
|
|
37
|
+
<div>
|
|
38
|
+
<div class="text-sm text-gray-900"><%%= <%= @variable_subject %>.<%=field %> %></div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</td>
|
|
42
|
+
<%end-%>
|
|
43
|
+
<td class="class-td text-center">
|
|
44
|
+
<%%= render "components/link_action", key: "<%= [@route_scope_path, @scope_subject].reject { |c| c.empty? }.join("_") %>", value: <%= @variable_subject %>, actions: [:show, :edit, :destroy] %>
|
|
45
|
+
</td>
|
|
46
|
+
</tr>
|
|
47
|
+
<%% end %>
|
|
48
|
+
</tbody>
|
|
49
|
+
</table>
|
|
50
|
+
</div>
|
|
49
51
|
</div>
|
|
50
|
-
|
|
52
|
+
<%% end %>
|
|
51
53
|
</div>
|
|
52
54
|
</div>
|
data/lib/sun_sword/version.rb
CHANGED