hot-glue 0.2.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -2
  3. data/Gemfile.lock +4 -24
  4. data/LICENCE +11 -4
  5. data/README.md +0 -524
  6. data/app/helpers/hot_glue/controller_helper.rb +8 -5
  7. data/app/views/layouts/_flash_notices.erb +12 -0
  8. data/lib/generators/hot_glue/install_generator.rb +110 -1
  9. data/lib/generators/hot_glue/markup_templates/erb.rb +68 -29
  10. data/lib/generators/hot_glue/markup_templates/haml.rb +5 -3
  11. data/lib/generators/hot_glue/scaffold_generator.rb +223 -58
  12. data/lib/generators/hot_glue/templates/capybara_login.rb +8 -0
  13. data/lib/generators/hot_glue/templates/controller.rb.erb +41 -32
  14. data/lib/generators/hot_glue/templates/erb/_form.erb +1 -1
  15. data/lib/generators/hot_glue/templates/erb/_line.erb +3 -2
  16. data/lib/generators/hot_glue/templates/erb/_list.erb +24 -8
  17. data/lib/generators/hot_glue/templates/erb/_show.erb +24 -4
  18. data/lib/generators/hot_glue/templates/erb/create.turbo_stream.erb +4 -4
  19. data/lib/generators/hot_glue/templates/erb/destroy.turbo_stream.erb +2 -2
  20. data/lib/generators/hot_glue/templates/erb/edit.erb +3 -13
  21. data/lib/generators/hot_glue/templates/erb/index.erb +11 -9
  22. data/lib/generators/hot_glue/templates/erb/update.turbo_stream.erb +5 -2
  23. data/lib/generators/hot_glue/templates/haml/_line.haml +1 -1
  24. data/lib/generators/hot_glue/templates/haml/_list.haml +6 -2
  25. data/lib/generators/hot_glue/templates/haml/create.turbo_stream.haml +3 -3
  26. data/lib/generators/hot_glue/templates/haml/destroy.turbo_stream.haml +1 -1
  27. data/lib/generators/hot_glue/templates/haml/edit.haml +0 -2
  28. data/lib/generators/hot_glue/templates/haml/index.haml +2 -3
  29. data/lib/generators/hot_glue/templates/system_spec.rb.erb +146 -47
  30. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_dark_knight.scss +158 -0
  31. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_bootstrap.scss +154 -0
  32. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_los_gatos.scss +182 -0
  33. data/lib/generators/hot_glue/templates/themes/hotglue_scaffold_like_mountain_view.scss +179 -0
  34. data/lib/hot-glue.rb +1 -2
  35. data/lib/hotglue/version.rb +1 -1
  36. metadata +15 -33
@@ -1,19 +1,35 @@
1
- <\%= turbo_frame_tag "<%= plural %>-list" do %>
2
- <div class="container-fluid "><%= singular %>-table
3
- <div class="row">
1
+ <\%= turbo_frame_tag "<%= plural %>-list" <%= nested_for_turbo_id_list_constructor %> do %>
2
+ <div class="<%= @container_name %> scaffold-list">
3
+ <% unless @nested_args.any? %><h4><%= plural.gsub("_", " ").upcase %></h4><% end %>
4
+
5
+ <% unless @no_create %><%= '<%= render partial: "' + ((@namespace+"/" if @namespace) || "") + plural + '/new_button", locals: {' + nested_assignments + '}' + '%\>'.gsub('\\',"") %><% end %>
6
+
7
+ <div class="row scaffold-row">
4
8
  <%= list_column_headings %>
5
- <div class='col buttons-col'></div>
9
+ <% if @downnest_children.any? %>
10
+ <% each_downnest_width = @downnest_children.count == 1 ? 40 : (60/@downnest_children.count).floor %>
11
+ <% @downnest_children.each do |downnest| %>
12
+ <div class="col scaffold-col-heading" style="flex-basis: <%= each_downnest_width %>%;">
13
+ <h4>
14
+ <%= downnest.titleize %>
15
+ </h4>
16
+ </div>
17
+ <% end %>
18
+ <% end %>
19
+
20
+ <div class='col scaffold-col-heading scaffold-col-heading-buttons' style="flex-basis: 150px"></div>
6
21
  </div>
7
22
 
8
23
  <\% if <%= plural %>.empty? %>
9
- <div>
10
- None
11
- </div>
24
+ <div>
25
+ None
26
+ </div>
12
27
  <\% end %>
13
28
  <\% <%= plural %>.each do |<%= singular %>| %>
14
- <\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %> <%= nested_assignments_with_leading_comma %> } %>
29
+ <\%= render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %><%= nested_assignments_with_leading_comma if @nestable %><%= ", nested_for: nested_for" if @nestable %> } %>
15
30
  <\% end %>
16
31
 
17
32
  <%= @no_paginate ? "" : paginate %>
33
+ </div>
18
34
  </div>
19
35
  <\% end %>
@@ -1,8 +1,28 @@
1
1
  <%= all_line_fields %>
2
- <div class="col">
2
+
3
+ <% if @downnest_children.any? %>
4
+ <% each_downnest_width = @downnest_children.count == 1 ? 33 : (53/@downnest_children.count).floor %>
5
+ <% @downnest_children.each do |downnest| %>
6
+ <div class="<%= @col_identifier %> scaffold-downnest" style="flex-basis: <%= each_downnest_width %>%" >
7
+ <\%= render partial: "<%= namespace_with_trailing_dash %><%= downnest %>/list", locals: {
8
+ nested_for: "<% if @nested_args.any? %>#{nested_for + "__" if nested_for}<% end %><%= @singular %>-#{<%= @singular %>.id}",
9
+ <%= @singular %>: <%= @singular %><%= nest_assignments_operator(false, true) %>,
10
+ <%= downnest %>: <%= @singular %>.<%= downnest %>} %>
11
+ </div>
12
+ <% end %>
13
+ <% end %>
14
+
15
+ <div class="<%= @col_identifier %> scaffold-line-buttons" style="flex-basis: 150px;">
3
16
  <% if destroy_action %>
4
- <\%= button_to "Delete".html_safe, <%= path_helper_singular %>(<%= path_helper_args %>), method: :delete, data: <%= delete_confirmation_syntax %>, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary " %>
17
+ <\%= form_with url: <%= path_helper_singular %>(<%= path_helper_args %>), html: {style: "display: inline-block;"}, method: :delete do |f| %>
18
+ <\%= f.submit "Delete".html_safe, data: <%= delete_confirmation_syntax %>, class: "delete-<%= singular %>-button btn btn-primary btn-sm" %>
19
+ <\% end %>
20
+ <% end %>
21
+
22
+
23
+ <%= magic_button_output %>
24
+
25
+ <% unless @no_edit %>
26
+ <\%= 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 btn-sm" %>
5
27
  <% 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
28
  </div>
@@ -1,13 +1,13 @@
1
1
  <\% if @<%= singular %>.errors.none? %>
2
- <\%= turbo_stream.replace "<%= plural %>-list" do %>
3
- <\%= render partial: "list", locals: {<%= plural %>: @<%= plural %>} %>
2
+ <\%= turbo_stream.replace "<%= plural %>-list<%= nested_for_turbo_nested_constructor %>" do %>
3
+ <\%= render partial: "list", locals: {<%= plural %>: @<%= plural %><%= nested_for_assignments_constructor %><%= nest_assignments_operator(true, true) %>} %>
4
4
  <\% end %>
5
5
  <\% end %>
6
6
  <\%= turbo_stream.replace "<%= singular %>-new" do %>
7
7
  <\% if @<%= singular %>.errors.none? %>
8
- <\%= render partial: "new_button" %>
8
+ <\%= render partial: "new_button", locals: {<%= nest_assignments_operator(true, false) %>} %>
9
9
  <\% else %>
10
- <\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %>} %>
10
+ <\%= render partial: "new_form", locals: {<%= singular %>: @<%= singular %> <%= nest_assignments_operator(true, true) %> } %>
11
11
  <\% end %>
12
12
  <\% end %>
13
13
  <\%= turbo_stream.replace "flash_notices" do %>
@@ -1,3 +1,3 @@
1
- <\%= turbo_stream.replace "<%=plural%>-list" do %>
2
- <\%= render partial: "list", locals: {<%=plural%>: @<%=plural%>} %>
1
+ <\%= turbo_stream.replace "<%= plural %>-list<%= nested_for_turbo_nested_constructor %>" do %>
2
+ <\%= render partial: "list", locals: {<%=plural%>: @<%=plural%> <%= nested_for_assignments_constructor %> <%= nest_assignments_operator(true, true) %>} %>
3
3
  <\% end %>
@@ -5,24 +5,14 @@
5
5
  <div class="cell editable" style="position: relative;">
6
6
 
7
7
  <\% if @<%= singular %>.errors.any? %>
8
- <\%= render(partial: "#{controller.namespace}errors", locals: {resource: @<%= singular%> }) %>
8
+ <\%= render(partial: "<%= namespace_with_trailing_dash %>errors", locals: {resource: @<%= singular %> }) %>
9
9
  <\% end %>
10
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 %>
11
+ <h2>Editing <\%= @<%= @singular %>.<%= display_class %> %></h2>
19
12
  <\%= form_with model: <%= "@" + singular%>, url: <%= path_helper_singular %>(<%= path_arity %>) do |f| %>
20
13
  <\%= render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f} %>
21
14
  <\% 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>
15
+
26
16
  </div>
27
17
 
28
18
  <\% end %>
@@ -1,10 +1,12 @@
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>
1
+ <div class="<%= @container_name %>">
2
+ <% if @layout == "bootstrap" %><div class="row"> <div class="col-md-12">
3
+ <% else %>
4
+ <div class=' scaffold-index-<%= plural %>'>
5
+ <% end %>
6
+
7
+ <div class="clearfix"></div>
8
+ <\%= render partial: '<%= list_path_partial %>',
9
+ locals: {<%= plural %>: @<%= plural %><%= nested_for_assignments_constructor %><%= nest_assignments_operator(true, true) if @nestable %> } \%>
10
+
11
+ <% if @layout == "bootstrap" %></div></div><% else %></div><% end %>
10
12
  </div>
@@ -1,6 +1,9 @@
1
- <\%= turbo_stream.replace "<%= singular%>__#{@<%= singular %>.id}" do %>
2
- <\%= render partial: 'line', locals: {<%= singular %>: @<%= singular %> <%= nested_assignments_with_leading_comma %> } %>
1
+ <% if !@display_list_after_update %><\%= turbo_stream.replace "<%= singular%>__#{@<%= singular %>.id}" do %>
2
+ <\%= render partial: 'line', locals: {<%= singular %>: @<%= singular %> <%= nest_assignments_operator(true,true) %> } %>
3
+ <\% end %><% else %><\%= turbo_stream.replace "<%= plural %>-list" do %>
4
+ <\%= render partial: '<%= list_path_partial %>', locals: {<%= plural %>: @<%= plural %><%= nest_assignments_operator(true, true) if @nestable %><%= nested_for_assignments_constructor %> } \%>
3
5
  <\% end %>
6
+ <% end %>
4
7
 
5
8
  <\%= turbo_stream.replace "flash_notices" do %>
6
9
  <\%= render partial: "layouts/flash_notices" %>
@@ -1,6 +1,6 @@
1
1
  = turbo_frame_tag "<%= singular %>__#{<%= singular %>.id}" do
2
2
  .row{'data-id': <%= singular %>.id, 'data-edit': 'false'}
3
- = render partial: "<%= show_path_partial %>", locals: {<%= singular %>: <%= singular %>}
3
+ = render partial: "<%= show_path_partial %>", locals: {<%= singular %>: <%= singular %> <%= nest_assignments_operator(false, true) %>}
4
4
 
5
5
 
6
6
 
@@ -1,5 +1,9 @@
1
1
  = turbo_frame_tag "<%= plural %>-list" do
2
- .container-fluid.<%= singular %>-table
2
+ %div{class: "<%= @container_name %> <%= singular %>-table"}
3
+ .row
4
+ .col-md-12
5
+ <%= '= render partial: "' + (@namespace+"/" if @namespace) + plural + '/new_button", locals: {' + nested_assignments + '}' unless @no_create %>
6
+
3
7
  .row
4
8
  <%= list_column_headings %>
5
9
  .col
@@ -7,5 +11,5 @@
7
11
  - if <%= plural %>.empty?
8
12
  None
9
13
  - <%= plural %>.each do |<%= singular %>|
10
- = render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %> <%= nested_assignments_with_leading_comma %> }
14
+ = render partial: '<%= line_path_partial %>', locals: {<%= singular %>: <%= singular %><%= nested_assignments_with_leading_comma if @nest %> }
11
15
  <%= @no_paginate ? "" : paginate %>
@@ -1,12 +1,12 @@
1
1
  - if @<%= singular %>.errors.none?
2
2
  = turbo_stream.replace "<%= plural %>-list" do
3
- = render partial: "list", locals: {<%= plural %>: @<%= plural %>}
3
+ = render partial: "list", locals: {<%= plural %>: @<%= plural %> <%= nest_assignments_operator(true, true) %>}
4
4
 
5
5
  = turbo_stream.replace "<%= singular %>-new" do
6
6
  - if @<%= singular %>.errors.none?
7
- = render partial: "new_button"
7
+ = render partial: "new_button", locals: {<%= nest_assignments_operator(true, false) %> }
8
8
  - else
9
- = render partial: "new_form", locals: {<%= singular %>: @<%= singular %>}
9
+ = render partial: "new_form", locals: {<%= singular %>: @<%= singular %> <%= nest_assignments_operator(true, true) %>}
10
10
 
11
11
  = turbo_stream.replace "flash_notices" do
12
12
  = render partial: "layouts/flash_notices"
@@ -1,2 +1,2 @@
1
1
  = turbo_stream.replace "<%=plural%>-list" do
2
- = render partial: "list", locals: {<%=plural%>: @<%=plural%>}
2
+ = render partial: "list", locals: {<%=plural%>: @<%=plural%> <%= nest_assignments_operator(true, true) %>}
@@ -17,5 +17,3 @@
17
17
  = form_with model: <%= "@" + singular%>, url: <%= path_helper_singular %>(<%= path_arity %>) do |f|
18
18
  = render partial: "form", locals: {:<%= singular %> => <%= "@" + singular%>, f: f}
19
19
 
20
- %i.fa.fa-times-circle.fa-2x{ 'data-name' => 'close-invoice__#{@invoice.id}', 'data-row-id' => <%= "@" + singular %>.id, 'data-role' => 'close-button'}
21
-
@@ -1,9 +1,8 @@
1
- .container-fluid
1
+ %div{class: "#{@container_name }"}
2
2
  .row
3
3
  .col-md-12
4
- = render partial: "new_button"
5
4
  .clearfix
6
- = render partial: "<%= list_path_partial %>", locals: {<%= plural %>: @<%= plural %>}
5
+ = render partial: "<%= list_path_partial %>", locals: {<%= plural %>: @<%= plural %> <%= nest_assignments_operator(true, true) %>}
7
6
 
8
7
 
9
8
 
@@ -2,46 +2,77 @@ require 'rails_helper'
2
2
 
3
3
  describe "interaction for <%= controller_class_name %>", type: :feature do
4
4
  include HotGlue::ControllerHelper
5
- <% unless @auth.nil? %>let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
6
-
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 %> )}
10
-
11
- <%= objest_nest_factory_setup %>
12
-
5
+ <% unless @god %>let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
6
+ <%= @columns.map { |col|
7
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
8
+ case type
9
+ when :integer
10
+ if col.to_s.ends_with?("_id")
11
+ assoc = "#{col.to_s.gsub('_id','')}"
12
+ "let!(:#{assoc}1) {create(:#{assoc}, name: FFaker::Name.name)}"
13
+ end
14
+ else
15
+ end
16
+ }.compact.join("\n")
17
+ %>
18
+ <% item1_addOns = ""
19
+ if (eval(@singular_class).instance_methods.include?(display_class.to_s))
20
+ item1_addOns << "#{display_class}: FFaker::Name.name"
21
+ end
22
+
23
+ item1_addOns << ", " + @columns.map { |col|
24
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
25
+ case type
26
+ when :string
27
+ "#{col}: FFaker::Movie.title"
28
+ when :text
29
+ "#{col}: FFaker::Lorem.paragraphs(10).join(" ")"
30
+
31
+ when :float
32
+ "#{col}: rand(1)*10000"
33
+ when :boolean
34
+ "#{col}: !!rand(2).floor"
35
+ when :time
36
+ "#{col}: Time.current + rand(5000).seconds"
37
+ when :date
38
+ "#{col}: Date.current + rand(50).days"
39
+ when :datetime
40
+ "#{col}: DateTime.current + rand(1000).seconds"
41
+ when :integer
42
+ if col.to_s.ends_with?("_id")
43
+ # shoould the assoication be on here
44
+ else
45
+ "#{col}: rand(100)"
46
+ end
47
+ end
48
+ }.compact.join(", \n ")
49
+ %>let!(:<%= singular %>1) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> <%= item1_addOns %> )}
50
+ <%= objest_nest_factory_setup %> <% unless @god %>
13
51
  before(:each) do
14
52
  login_as(<%= @auth %>)
15
- end
53
+ end <% end %>
16
54
 
17
55
  describe "index" do
18
56
  it "should show me the list" do
19
57
  visit <%= path_helper_plural %>
20
-
21
58
  <%=
22
59
  @columns.map { |col|
23
60
  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
61
  case type
29
62
  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
-
63
+ " " + ["expect(page).to have_content(#{singular}#{1}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ').gsub(' ', ' ') + timezonize(current_timezone) )"].join("\n ")
64
+ when :integer
65
+ if !col.ends_with?("_id")
66
+ " " + ["expect(page).to have_content(#{singular}#{1}.#{col})"].join("\n ")
67
+ end
35
68
  end
36
69
 
37
70
  }.join("\n")
38
-
39
71
  %>
40
-
41
72
  end
42
73
  end
43
74
 
44
- describe "new & create" do
75
+ <% unless @no_create %> describe "new & create" do
45
76
  it "should create a new <%= singular.titlecase %>" do
46
77
  visit <%= path_helper_plural %>
47
78
  click_link "New <%= singular.titlecase %>"
@@ -50,17 +81,34 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
50
81
  <%=
51
82
  @columns.map { |col|
52
83
  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
55
- #
56
-
57
84
  case type
58
85
  when :datetime
86
+ " " + "new_#{col} = DateTime.current + (rand(100).days) \n" +
87
+ ' ' + "find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
88
+
59
89
  when :integer
60
- " " + 'find("input#' + singular + '_' + col.to_s + '").fill_in(with: rand(10))'
90
+
91
+ if col.to_s.ends_with?("_id")
92
+ assoc = col.to_s.gsub('_id','')
93
+ " #{col}_selector = find(\"[name='#{singular}[#{col}]']\").click \n" +
94
+ " #{col}_selector.first('option', text: #{assoc}1.name).select_option"
95
+ else
96
+ " new_#{col} = rand(10) \n" +
97
+ " find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
98
+
99
+ end
100
+
101
+ when :enum
102
+ " list_of_#{col.to_s} = #{singular_class}.defined_enums['#{col.to_s}'].keys \n" +
103
+ " " + "new_#{col.to_s} = list_of_#{col.to_s}[rand(list_of_#{col.to_s}.length)].to_s \n" +
104
+ ' find("select[name=\'' + singular + '[' + col.to_s + ']\'] option[value=\'#{new_' + col.to_s + '}\']").select_option'
105
+
106
+ when :boolean
107
+ " new_#{col} = rand(2).floor \n" +
108
+ " find(\"[name='#{singular}[#{col}]'][value='\#{new_" + col.to_s + "}']\").choose"
61
109
  else
62
110
  " " + "new_#{col} = 'new_test-email@nowhere.com' \n" +
63
- ' ' + 'find("input#' + singular + '_' + col.to_s + '").fill_in(with: new_' + col.to_s + ')'
111
+ " find(\"[name='#{singular}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
64
112
  end
65
113
 
66
114
  }.join("\n")
@@ -75,41 +123,82 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
75
123
 
76
124
  case type
77
125
  when :datetime
126
+ " expect(page).to have_content(new_#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y') + \" @ \" +
127
+ new_#{col}.in_time_zone(current_timezone).strftime('%l').strip + \":\" +
128
+ new_#{col}.in_time_zone(current_timezone).strftime('%M %p').strip + \" \" +
129
+ timezonize(current_timezone))"
78
130
  when :integer
131
+ if col.to_s.ends_with?("_id")
132
+ # shoould the assoication be on here
133
+ else
134
+ "expect(page).to have_content(new_#{col})"
135
+ end
79
136
  else
80
137
  "expect(page).to have_content(new_#{col})"
81
138
  end
82
139
 
83
- }.join("\n")
140
+ }.compact.join("\n ")
84
141
  %>
85
142
 
86
143
  end
87
- end
144
+ end<% end %>
88
145
 
89
- describe "show" do
90
- it "should return a view form" do
91
- visit <%= path_helper_plural %>
92
-
93
- end
94
- end
95
146
 
96
147
  describe "edit & update" do
97
148
  it "should return an editable form" do
98
149
  visit <%= path_helper_plural %>
99
150
  find("a.edit-<%= singular %>-button[href='/<%= namespace_with_slash %><%= plural %>/#{<%= singular %>1.id}/edit']").click
100
151
 
101
- expect(page).to have_content("Editing #{<%= singular %>.<%= "abc" %>}")
152
+ expect(page).to have_content("Editing #{<%= singular %>1.<%= @display_class %> || "(no name)"}")
102
153
  <%=
103
154
  @columns.map { |col|
104
155
  type = eval("#{singular_class}.columns_hash['#{col}']").type
105
-
156
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
157
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
106
158
  case type
107
159
  when :datetime
108
160
  when :integer
109
- else
110
- " " + "new_#{col.to_s} = Faker::Name.new \n" +
161
+ if !col.to_s.ends_with?("_id")
162
+ " new_#{col} = rand(10000).floor \n" +
163
+ " find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s})"
164
+ end
165
+ when :text
166
+ if sql_type == "text"
167
+ " " + "new_#{col.to_s} = FFaker::Lorem.paragraphs(3).join \n" +
168
+ ' find("textarea[name=\'' + singular + '[' + col.to_s + ']\']").fill_in(with: new_' + col.to_s + ')'
169
+
170
+ else # unreachable?
171
+ " " + "new_#{col.to_s} = FFaker::Name.name \n" +
172
+ ' find("input[name=\'' + singular + '[' + col.to_s + ']\']").fill_in(with: new_' + col.to_s + ')'
173
+ end
174
+ when :string
175
+ if sql_type == "varchar"
176
+ " " + "new_#{col.to_s} = FFaker::Name.name \n" +
177
+ ' find("input[name=\'' + singular + '[' + col.to_s + ']\']").fill_in(with: new_' + col.to_s + ')'
178
+ else
179
+ " " + "new_#{col.to_s} = FFaker::Lorem.paragraphs(1).join \n" +
180
+ ' find("input[name=\'' + singular + '[' + col.to_s + ']\']").fill_in(with: new_' + col.to_s + ')'
181
+ end
182
+ when :boolean
183
+ " new_#{col} = rand(2).floor \n" +
184
+ " find(\"[name='#{singular}[#{col}]'][value='\#{new_#{col}}']\").choose"
185
+ when :float
186
+ " new_#{col} = rand(1)*5000 \n" +
187
+ " find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
188
+ when :date
189
+ " new_#{col} = Date.current + rand(100).days \n" +
190
+ " find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
191
+ when :time
192
+ " new_#{col} = Time.current + rand(144).hours \n" +
193
+ " find(\"[name='#{singular}[#{col}]']\").fill_in(with: new_#{col.to_s })"
194
+ when :enum
195
+ " list_of_#{col.to_s} = #{singular_class}.defined_enums['#{col.to_s}'].keys \n" +
196
+ " " + "new_#{col.to_s} = list_of_#{col.to_s}[rand(list_of_#{col.to_s}.length)].to_s \n" +
197
+ ' find("select[name=\'' + singular + '[' + col.to_s + ']\'] option[value=\'#{new_' + col.to_s + '}\']").select_option'
111
198
 
112
- ' find("input[name=\'' + singular + '[' + col.to_s + ']\'").fill_in(with: new_' + col.to_s + ')'
199
+ else
200
+ " " + "new_#{col.to_s} = FFaker::Name.name \n" +
201
+ ' find("input[name=\'' + singular + '[' + col.to_s + ']\']").fill_in(with: new_' + col.to_s + ')'
113
202
 
114
203
  end
115
204
  }.join("\n")
@@ -123,26 +212,36 @@ describe "interaction for <%= controller_class_name %>", type: :feature do
123
212
  type = eval("#{singular_class}.columns_hash['#{col}']").type
124
213
  case type
125
214
  when :datetime
126
- when :integer
215
+ # TODO: implement me
216
+ when :time
217
+ # TODO: implement me
218
+ when :date
219
+ # TODO: implement me
220
+ when :boolean
221
+ # TODO: implement me
127
222
  else
223
+ unless type==:integer && col.to_s.ends_with?("_id")
128
224
  ' expect(page).to have_content(new_' + col.to_s + ')'
225
+ end
129
226
  end
130
- }.join("\n")
227
+ }.compact.join("\n")
131
228
  %>
132
229
 
133
230
  end
134
231
  end
135
232
  end
136
233
 
137
- describe "destroy" do
234
+ <% unless @no_delete %> describe "destroy" do
138
235
  it "should destroy" do
139
236
  visit <%= path_helper_plural %>
140
237
  accept_alert do
141
- find("a.delete-<%= singular %>-button[href='<%= namespace_with_dash %>/<%= plural %>/#{<%= singular %>1.id}']").click
238
+ find("form[action='<%= namespace_with_dash %>/<%= plural %>/#{<%= singular %>1.id}'] > input.delete-<%= singular %>-button").click
142
239
  end
143
- expect(page).to_not have_content(<%= singular %>1.email)
240
+ # find("form[action='<%= namespace_with_dash %>/<%= plural %>/#{<%= singular %>1.id}'] > input.delete-<%= singular %>-button").click
241
+
242
+ expect(page).to_not have_content(<%= singular %>1.<%= @display_class %>)
144
243
  expect(<%= singular_class %>.where(id: <%= singular %>1.id).count).to eq(0)
145
244
  end
146
- end
245
+ end<% end %>
147
246
  end
148
247