hot-glue 0.0.8 → 0.2.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -1
  3. data/Gemfile.lock +21 -18
  4. data/README.md +84 -50
  5. data/app/helpers/hot_glue/controller_helper.rb +1 -1
  6. data/db/migrate/20210306223305_create_ghis.rb +9 -0
  7. data/db/schema.rb +1 -1
  8. data/lib/generators/hot_glue/install_generator.rb +0 -2
  9. data/lib/generators/hot_glue/markup_templates/base.rb +7 -0
  10. data/lib/generators/hot_glue/markup_templates/erb.rb +228 -0
  11. data/lib/generators/hot_glue/markup_templates/haml.rb +223 -0
  12. data/lib/generators/hot_glue/markup_templates/slim.rb +9 -0
  13. data/lib/generators/hot_glue/scaffold_generator.rb +172 -280
  14. data/lib/generators/hot_glue/templates/controller.rb.erb +12 -10
  15. data/lib/generators/hot_glue/templates/erb/_errors.erb +11 -0
  16. data/lib/generators/hot_glue/templates/erb/_flash_notices.erb +12 -0
  17. data/lib/generators/hot_glue/templates/erb/_form.erb +8 -0
  18. data/lib/generators/hot_glue/templates/erb/_line.erb +10 -0
  19. data/lib/generators/hot_glue/templates/erb/_list.erb +19 -0
  20. data/lib/generators/hot_glue/templates/erb/_new_button.erb +3 -0
  21. data/lib/generators/hot_glue/templates/erb/_new_form.erb +8 -0
  22. data/lib/generators/hot_glue/templates/erb/_show.erb +8 -0
  23. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +18 -0
  24. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +3 -0
  25. data/lib/generators/hot_glue/templates/erb/edit.erb +30 -0
  26. data/lib/generators/hot_glue/templates/erb/edit.turbo_stream.erb +3 -0
  27. data/lib/generators/hot_glue/templates/erb/index.erb +10 -0
  28. data/lib/generators/hot_glue/templates/erb/new.erb +1 -0
  29. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +10 -0
  30. data/lib/generators/hot_glue/templates/{_errors.haml → haml/_errors.haml} +0 -0
  31. data/lib/generators/hot_glue/templates/{_flash_notices.haml → haml/_flash_notices.haml} +0 -0
  32. data/lib/generators/hot_glue/templates/{_form.haml → haml/_form.haml} +1 -0
  33. data/lib/generators/hot_glue/templates/{_line.haml → haml/_line.haml} +0 -0
  34. data/lib/generators/hot_glue/templates/{_list.haml → haml/_list.haml} +0 -0
  35. data/lib/generators/hot_glue/templates/{_new_button.haml → haml/_new_button.haml} +0 -0
  36. data/lib/generators/hot_glue/templates/{_new_form.haml → haml/_new_form.haml} +0 -3
  37. data/lib/generators/hot_glue/templates/haml/_show.haml +7 -0
  38. data/lib/generators/hot_glue/templates/{create.turbo_stream.haml → haml/create.turbo_stream.haml} +0 -0
  39. data/lib/generators/hot_glue/templates/{destroy.turbo_stream.haml → haml/destroy.turbo_stream.haml} +0 -0
  40. data/lib/generators/hot_glue/templates/{edit.haml → haml/edit.haml} +0 -0
  41. data/lib/generators/hot_glue/templates/{edit.turbo_stream.haml → haml/edit.turbo_stream.haml} +0 -0
  42. data/lib/generators/hot_glue/templates/{index.haml → haml/index.haml} +0 -0
  43. data/lib/generators/hot_glue/templates/{new.haml → haml/new.haml} +0 -0
  44. data/lib/generators/hot_glue/templates/haml/update.turbo_stream.haml +9 -0
  45. data/lib/generators/hot_glue/templates/system_spec.rb.erb +115 -76
  46. data/lib/hot-glue.rb +6 -20
  47. data/lib/hotglue/version.rb +1 -1
  48. metadata +45 -27
  49. data/db/migrate/20210306223305_create_hgis.rb +0 -9
  50. data/lib/generators/hot_glue/templates/_show.haml +0 -7
  51. data/lib/generators/hot_glue/templates/request_spec.rb.erb +0 -110
  52. data/lib/generators/hot_glue/templates/update.turbo_stream.haml +0 -5
@@ -1,7 +1,6 @@
1
1
  class <%= controller_class_name %> < <%= controller_descends_from %>
2
2
  <% unless @auth_identifier == '' || @auth.nil? %>before_action :authenticate_<%= @auth_identifier %>!<% end %>
3
- <% if any_nested? %> <% @nested_args.each do |arg| %>
4
- before_action :load_<%= arg %><% end %> <% end %>
3
+
5
4
  before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
6
5
  helper :hot_glue
7
6
  include HotGlue::ControllerHelper
@@ -11,22 +10,23 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
11
10
  <% end %>
12
11
 
13
12
  <% if any_nested? %><% nest_chain = [] %> <% @nested_args.each { |arg|
14
- this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "@#{nest_chain.last}.#{arg}s"
15
- nest_chain << arg %>def load_<%= arg %>
16
- @<%= arg %> = <%= this_scope %>.find(params[:<%= arg %>_id])
13
+ this_scope = nest_chain.empty? ? "#{@auth ? auth_object : class_name}.#{arg}s" : "#{nest_chain.last}.#{arg}s"
14
+ nest_chain << arg %>
15
+ def <%= arg %>
16
+ @<%= arg %> ||= <%= this_scope %>.find(params[:<%= arg %>_id])
17
17
  end<% } %><% end %>
18
18
 
19
19
  <% if !@self_auth %>
20
20
  def load_<%= singular_name %>
21
- @<%= singular_name %> = <%= object_scope %>.find(params[:id])
21
+ @<%= singular_name %> = <%= object_scope.gsub("@",'') %>.find(params[:id])
22
22
  end
23
23
  <% else %>
24
24
  def load_<%= singular_name %>
25
- @<%= singular_name %> = <%= auth_object %>
25
+ @<%= singular_name %> = <%= auth_object.gsub("@",'') %>
26
26
  end<% end %>
27
27
 
28
28
  def load_all_<%= plural %>
29
- <% if !@self_auth %>@<%= plural_name %> = <%= object_scope %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
29
+ <% if !@self_auth %>@<%= plural_name %> = <%= object_scope.gsub("@",'') %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
30
30
  <% else %>@<%= plural_name %> = [<%= auth_object %>]<% end %>
31
31
  end
32
32
 
@@ -81,8 +81,10 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
81
81
  end
82
82
 
83
83
  def update
84
- if !@<%= singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>))
85
- flash[:alert] = "<%= singular_name.titlecase %> could not be saved"
84
+ if @<%= singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params<%= @auth ? ', ' + @auth : '' %>))
85
+ flash[:notice] = "Saved #{@<%= singular %>.<%= display_class %>}"
86
+ else
87
+ flash[:alert] = "<%= singular_name.titlecase %> could not be saved."
86
88
  end
87
89
  respond_to do |format|
88
90
  format.turbo_stream
@@ -0,0 +1,11 @@
1
+ <\%= turbo_frame_tag "errors" do %>
2
+ <\% if resource.errors.any? %>
3
+ <div id="error_explanation">
4
+ <\% resource.errors.full_messages.each do |message| %>
5
+ <div class="alert alert-danger">
6
+ <\%= message %>
7
+ </div>
8
+ <\% end %>
9
+ </div>
10
+ <\% end %>
11
+ <\% end %>
@@ -0,0 +1,12 @@
1
+ <%= turbo_frame_tag "flash_notices" do %>
2
+ <% unless notice.nil? %>
3
+ <div class="alert alert-notice alert-dismissible">
4
+ <%= notice %>
5
+ </div>
6
+ <% end %>
7
+ <% unless alert.nil? %>
8
+ <div class="alert alert-danger alert-dismissible">
9
+ <%= alert %>
10
+ </div>
11
+ <% end %>
12
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <div class="row">
2
+ <%= all_form_fields %>
3
+
4
+ <div class="col">
5
+ <\%= link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"} %>
6
+ <\%= f.submit "Save", class: "btn btn-primary pull-right" %>
7
+ </div>
8
+ </div>
@@ -0,0 +1,10 @@
1
+
2
+ <\%= turbo_frame_tag "<%= singular %>__#{ <%= singular %>.id }" do %>
3
+ <div class='row' data-id='<\%= <%= singular %>.id %>' data-edit='false'>
4
+ <\%= render partial: '<%= show_path_partial %>', locals: { <%= singular %>: <%= singular %>} %>
5
+ </div>
6
+ <\% end %>
7
+
8
+
9
+
10
+
@@ -0,0 +1,19 @@
1
+ <\%= turbo_frame_tag "<%= plural %>-list" do %>
2
+ <div class="container-fluid "><%= singular %>-table
3
+ <div class="row">
4
+ <%= list_column_headings %>
5
+ <div class='col buttons-col'></div>
6
+ </div>
7
+
8
+ <\% if <%= plural %>.empty? %>
9
+ <div>
10
+ None
11
+ </div>
12
+ <\% end %>
13
+ <\% <%= plural %>.each do |<%= singular %>| %>
14
+ <\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %> <%= nested_assignments_with_leading_comma %> } %>
15
+ <\% end %>
16
+
17
+ <%= @no_paginate ? "" : paginate %>
18
+ </div>
19
+ <\% end %>
@@ -0,0 +1,3 @@
1
+ <\%= turbo_frame_tag "<%= singular %>-new" do %>
2
+ <\%= link_to "New <%= singular.titlecase %>", <%= new_path_name %>, disable_with: "Loading...", class: "new-<%= singular %>-button btn btn-primary pull-right" %>
3
+ <\% end %>
@@ -0,0 +1,8 @@
1
+ <\%= turbo_frame_tag "<%= singular %>-new" do %>
2
+ <h3>
3
+ New <%= singular.titlecase %>
4
+ </h3>
5
+ <\%= form_with model: <%= singular %>, url: <%= path_helper_plural %>(<%= nested_objects_arity %>), method: "post" do |f| %>
6
+ <\%= render partial: "<%= namespace_with_slash + @plural %>/form", locals: { <%= singular %>: <%= singular %>, f: f} %>
7
+ <\% end %>
8
+ <\% end %>
@@ -0,0 +1,8 @@
1
+ <%= all_line_fields %>
2
+ <div class="col">
3
+ <% if destroy_action %>
4
+ <\%= link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_singular %>(<%= path_helper_args %>), method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary " %>
5
+ <% end %>
6
+ &nbsp;
7
+ <\%= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_singular %>(<%= path_helper_args %>), <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary " %>
8
+ </div>
@@ -0,0 +1,18 @@
1
+ <\% if @<%= singular %>.errors.none? %>
2
+ <\%= turbo_stream.replace "<%= plural %>-list" do %>
3
+ <\%= render partial: "list", locals: {<%= plural %>: @<%= plural %>} %>
4
+ <\% end %>
5
+ <\% end %>
6
+ <\%= turbo_stream.replace "<%= singular %>-new" do %>
7
+ <\% if @<%= singular %>.errors.none? %>
8
+ <\%= render partial: "new_button" %>
9
+ <\% else %>
10
+ <\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %>} %>
11
+ <\% end %>
12
+ <\% end %>
13
+ <\%= turbo_stream.replace "flash_notices" do %>
14
+ <\%= render partial: "layouts/flash_notices" %>
15
+ <\% if @<%= singular %>.errors.any? %>
16
+ <\%= render partial: "errors", locals: {resource: @<%= singular %>} %>
17
+ <\% end %>
18
+ <\% end %>
@@ -0,0 +1,3 @@
1
+ <\%= turbo_stream.replace "<%=plural%>-list" do %>
2
+ <\%= render partial: "list", locals: {<%=plural%>: @<%=plural%>} %>
3
+ <\% end %>
@@ -0,0 +1,30 @@
1
+ <\%= link_to "<i class='fa fa-arrow-circle-left 2x'></i> Back to list".html_safe, <%= path_helper_plural %> %>
2
+
3
+ <\%= turbo_frame_tag "<%= singular %>__#{<%= "@" + singular %>.id}" do %>
4
+
5
+ <div class="cell editable" style="position: relative;">
6
+
7
+ <\% if @<%= singular %>.errors.any? %>
8
+ <\%= render(partial: "#{controller.namespace}errors", locals: {resource: @<%= singular%> }) %>
9
+ <\% end %>
10
+
11
+ <h2>Editing</h2>
12
+ <% if eval("@" + singular).try(:to_label) %>
13
+ <%="@" + singular%>.to_label
14
+ <% elsif eval("@" + singular).try(:name) %>
15
+ <%="@" + singular%>.name %>
16
+ <% else %>
17
+ (no name)
18
+ <% end %>
19
+ <\%= form_with model: <%= "@" + singular%>, url: <%= path_helper_singular %>(<%= path_arity %>) do |f| %>
20
+ <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f} %>
21
+ <\% end %>
22
+ <i class='fa fa-times-circle fa-2x'
23
+ data-name='close-<%= singular %>__<\% <%= "@" + singular %>.id %> }'
24
+ data-row-id=<%= "@" + singular %>.id,
25
+ data-role='close-button'></i>
26
+ </div>
27
+
28
+ <\% end %>
29
+
30
+
@@ -0,0 +1,3 @@
1
+ <\%= turbo_stream.replace "<%= singular%>__#{@<%= singular %>.id}" do %>
2
+ <\%= render 'edit' %>
3
+ <\% end %>
@@ -0,0 +1,10 @@
1
+ <div class="container-fluid">
2
+ <div class="row">
3
+ <div class="col-md-12">
4
+ <\%= render partial: "new_button" %>
5
+ <div class="clearfix"></div>
6
+ <\%= render partial: '<%= list_path_partial %>',
7
+ locals: {<%= plural %>: @<%= plural %>} \%>
8
+ </div>
9
+ </div>
10
+ </div>
@@ -0,0 +1 @@
1
+ <\%= render partial: "new_form", locals: {<%= singular %>: @<%=singular%>} %>
@@ -0,0 +1,10 @@
1
+ <\%= turbo_stream.replace "<%= singular%>__#{@<%= singular %>.id}" do %>
2
+ <\%= render partial: 'line', locals: {<%= singular %>: @<%= singular %> <%= nested_assignments_with_leading_comma %> } %>
3
+ <\% end %>
4
+
5
+ <\%= turbo_stream.replace "flash_notices" do %>
6
+ <\%= render partial: "layouts/flash_notices" %>
7
+ <\% if @<%= singular %>.errors.any? %>
8
+ <\%= render partial: "errors", locals: {resource: @<%= singular %>} %>
9
+ <\% end %>
10
+ <\% end %>
@@ -1,4 +1,5 @@
1
1
  .row
2
2
  <%= all_form_fields %>
3
3
  .col
4
+ = link_to "Cancel", <%= path_helper_plural %>, {class: "btn btn-secondary"}
4
5
  = f.submit "Save", class: "btn btn-primary pull-right"
@@ -5,6 +5,3 @@
5
5
  = form_with model: <%= singular %>, url: <%= path_helper_plural %>(<%= nested_objects_arity %>), method: "post" do |f|
6
6
  = render partial: "<%=namespace_with_slash%><%= @plural %>/form", locals: {<%= singular %>: <%= singular %>, f: f}
7
7
 
8
- .row
9
- .col-md-12
10
- = f.submit "Save", class: "btn btn-primary pull-right"
@@ -0,0 +1,7 @@
1
+ <%= all_line_fields %>
2
+ .col
3
+ <% if destroy_action %>
4
+ = link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_singular %>(<%= path_helper_args %>), method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
5
+ <% end %>
6
+ &nbsp;
7
+ = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_singular %>(<%= path_helper_args %>), <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
@@ -0,0 +1,9 @@
1
+
2
+ = turbo_stream.replace "<%= singular%>__#{@<%= singular %>.id}" do
3
+ = render partial: 'line', locals: {<%= singular %>: @<%= singular %> <%= nested_assignments_with_leading_comma %> }
4
+
5
+
6
+ = turbo_stream.replace "flash_notices" do
7
+ = render partial: "layouts/flash_notices"
8
+ - if @<%= singular %>.errors.any?
9
+ = render partial: "errors", locals: {resource: @<%= singular %>}
@@ -1,108 +1,147 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe "interaction for <%= controller_class_name %>", type: :feature do
4
- <% unless @auth.nil? %> let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
5
- let(:<%= singular %>) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
4
+ include HotGlue::ControllerHelper
5
+ <% unless @auth.nil? %>let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
6
6
 
7
- <%= objest_nest_factory_setup %>
7
+ let!(:<%= singular %>1) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
8
+ let!(:<%= singular %>2) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
9
+ let!(:<%= singular %>3) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
8
10
 
9
- before(:each) do
10
- @request.env["devise.mapping"] = Devise.mappings[:account]
11
+ <%= objest_nest_factory_setup %>
11
12
 
12
- sign_in <%= @auth %>, scope: :<%= @auth %>
13
+ before(:each) do
14
+ login_as(<%= @auth %>)
13
15
  end
14
16
 
15
17
  describe "index" do
16
- it "should respond" do
17
- get :index, xhr: true, format: 'js', params: {
18
- <%= objest_nest_params_by_id_for_specs %>
19
- }
20
- end
18
+ it "should show me the list" do
19
+ visit <%= path_helper_plural %>
20
+
21
+ <%=
22
+ @columns.map { |col|
23
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
24
+ # limit = eval("#{singular_class}.columns_hash['#{col}']").limit
25
+ # sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
26
+ #
27
+
28
+ case type
29
+ when :datetime
30
+ " " + ["expect(page).to have_content(#{singular}#{rand(3)+1}.#{col}.in_time_zone(#{ @auth }.timezone).strftime('%m/%d/%Y @ %l:%M %p ').gsub(' ', ' ') + timezonize(#{ @auth }.timezone) )"].join("\n ")
31
+
32
+ else
33
+ " " + ["expect(page).to have_content(#{singular}#{rand(3)+1}.#{col})"].join("\n ")
34
+
21
35
  end
22
36
 
23
- describe "new" do
24
- it "should show form" do
25
- get :new, xhr: true, format: 'js', params: {
26
- <%= objest_nest_params_by_id_for_specs %>
27
- }
37
+ }.join("\n")
38
+
39
+ %>
40
+
28
41
  end
29
42
  end
30
43
 
31
- describe "create" do
32
- it "should create a new <%= singular %>" do
33
- expect {
34
- post :create, xhr: true, format: 'js', params: {
35
- <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
36
- <%= singular %>: {
37
- <%= columns_spec_with_sample_data %>
38
- }}
39
- }.to change { <%= @singular_class %>.all.count }.by(1)
40
- assert_response :ok
41
- end
44
+ describe "new & create" do
45
+ it "should create a new <%= singular.titlecase %>" do
46
+ visit <%= path_helper_plural %>
47
+ click_link "New <%= singular.titlecase %>"
48
+ expect(page).to have_selector(:xpath, './/h3[contains(., "New <%= singular.titlecase %>")]')
42
49
 
43
- # it "should not create if there are errors" do
44
- # post :create, xhr: true, format: 'js', params: {id: <%= singular %>.id,
45
- # <%= singular %>: {skin_id: nil}}
50
+ <%=
51
+ @columns.map { |col|
52
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
53
+ # limit = eval("#{singular_class}.columns_hash['#{col}']").limit
54
+ # sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
46
55
  #
47
- # expect(controller).to set_flash.now[:alert].to(/Oops, your <%= singular %> could not be saved/)
48
- # end
49
- end
50
56
 
51
- describe "edit" do
52
- it "should return an editable form" do
53
- get :edit, xhr: true, format: 'js', params: {
54
- <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
55
- id: <%= singular %>.id
56
- }
57
- assert_response :ok
57
+ case type
58
+ when :datetime
59
+ when :integer
60
+ " " + 'find("input#' + singular + '_' + col.to_s + '").fill_in(with: rand(10))'
61
+ else
62
+ " " + "new_#{col} = 'new_test-email@nowhere.com' \n" +
63
+ ' ' + 'find("input#' + singular + '_' + col.to_s + '").fill_in(with: new_' + col.to_s + ')'
64
+ end
65
+
66
+ }.join("\n")
67
+
68
+ %>
69
+ click_button "Save"
70
+ expect(page).to have_content("Successfully created")
71
+
72
+ <%=
73
+ @columns.map { |col|
74
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
75
+
76
+ case type
77
+ when :datetime
78
+ when :integer
79
+ else
80
+ "expect(page).to have_content(new_#{col})"
81
+ end
82
+
83
+ }.join("\n")
84
+ %>
85
+
58
86
  end
59
87
  end
60
88
 
61
89
  describe "show" do
62
90
  it "should return a view form" do
63
- get :show, xhr: true, format: 'js', params: {
64
- <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
65
- id: <%= singular %>.id
66
- }
67
- assert_response :ok
91
+ visit <%= path_helper_plural %>
92
+
68
93
  end
69
94
  end
70
95
 
71
- describe "update" do
72
- it "should update" do
73
- put :update, xhr: true, format: 'js',
74
- params: {
75
- <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
76
- id: <%= singular %>.id,
77
- <%= singular %>: {
78
- <%= columns_spec_with_sample_data %>
79
- }}
80
-
81
- assert_response :ok
82
- end
96
+ describe "edit & update" do
97
+ it "should return an editable form" do
98
+ visit <%= path_helper_plural %>
99
+ find("a.edit-<%= singular %>-button[href='/<%= namespace_with_slash %><%= plural %>/#{<%= singular %>1.id}/edit']").click
83
100
 
84
- # it "should not update if invalid" do
85
- # put :update, xhr: true, format: 'js',
86
- # params: {
87
- # id: <%= singular %>.id,
88
- # <%= singular %>: {
89
- # <%= columns_spec_with_sample_data %>
90
- # }}
91
- #
92
- # assert_response :ok
93
- #
94
- # expect(controller).to set_flash.now[:alert].to(/Oops, your <%= singular %> could not be saved/)
95
- # end
101
+ expect(page).to have_content("Editing #{<%= singular %>1.<%= derrive_reference_name(singular_class) %>}")
102
+ <%=
103
+ @columns.map { |col|
104
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
105
+
106
+ case type
107
+ when :datetime
108
+ when :integer
109
+ else
110
+ " " + "new_#{col.to_s} = Faker::Name.new \n" +
111
+
112
+ ' find("input[name=\'' + singular + '[' + col.to_s + ']\'").fill_in(with: new_' + col.to_s + ')'
113
+
114
+ end
115
+ }.join("\n")
116
+ %>
117
+ click_button "Save"
118
+ within("turbo-frame#<%= singular %>__#{<%= singular %>1.id} ") do
119
+
120
+
121
+ <%=
122
+ @columns.map { |col|
123
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
124
+ case type
125
+ when :datetime
126
+ when :integer
127
+ else
128
+ ' expect(page).to have_content(new_' + col.to_s + ')'
129
+ end
130
+ }.join("\n")
131
+ %>
132
+
133
+ end
134
+ end
96
135
  end
97
136
 
98
- describe "#destroy" do
137
+ describe "destroy" do
99
138
  it "should destroy" do
100
- post :destroy, format: 'js', params: {
101
- <%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
102
- id: <%= singular %>.id
103
- }
104
- assert_response :ok
105
- expect(<%= @singular_class %>.count).to be(0)
139
+ visit <%= path_helper_plural %>
140
+ accept_alert do
141
+ find("a.delete-<%= singular %>-button[href='<%= namespace_with_dash %>/<%= plural %>/#{<%= singular %>1.id}']").click
142
+ end
143
+ expect(page).to_not have_content(<%= singular %>1.email)
144
+ expect(<%= singular_class %>.where(id: <%= singular %>1.id).count).to eq(0)
106
145
  end
107
146
  end
108
147
  end