draft_generators 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +6 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rubocop.yml +637 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +24 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/draft_generators.gemspec +120 -0
- data/lib/devise_customization_service.rb +95 -0
- data/lib/draft_generators.rb +8 -0
- data/lib/generators/draft/devise/devise_generator.rb +92 -0
- data/lib/generators/draft/devise/views/templates/confirmations/new.html.erb +49 -0
- data/lib/generators/draft/devise/views/templates/mailer/confirmation_instructions.html.erb +5 -0
- data/lib/generators/draft/devise/views/templates/mailer/email_changed.html.erb +7 -0
- data/lib/generators/draft/devise/views/templates/mailer/password_change.html.erb +3 -0
- data/lib/generators/draft/devise/views/templates/mailer/reset_password_instructions.html.erb +8 -0
- data/lib/generators/draft/devise/views/templates/mailer/unlock_instructions.html.erb +7 -0
- data/lib/generators/draft/devise/views/templates/passwords/edit.html.erb +83 -0
- data/lib/generators/draft/devise/views/templates/passwords/new.html.erb +49 -0
- data/lib/generators/draft/devise/views/templates/registrations/edit.html.erb +159 -0
- data/lib/generators/draft/devise/views/templates/registrations/new.html.erb +113 -0
- data/lib/generators/draft/devise/views/templates/registrations_with_sentinels/edit.html.erb +160 -0
- data/lib/generators/draft/devise/views/templates/registrations_with_sentinels/new.html.erb +102 -0
- data/lib/generators/draft/devise/views/templates/sessions/new.html.erb +51 -0
- data/lib/generators/draft/devise/views/templates/shared/_links.html.erb +25 -0
- data/lib/generators/draft/devise/views/templates/unlocks/new.html.erb +49 -0
- data/lib/generators/draft/devise/views/views_generator.rb +41 -0
- data/lib/generators/draft/layout/USAGE +49 -0
- data/lib/generators/draft/layout/layout_generator.rb +66 -0
- data/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb +10 -0
- data/lib/generators/draft/layout/templates/_flashes.html.erb +23 -0
- data/lib/generators/draft/layout/templates/_navbar.html.erb +75 -0
- data/lib/generators/draft/layout/templates/layout.html.erb +40 -0
- data/lib/generators/draft/model/USAGE +14 -0
- data/lib/generators/draft/model/model_generator.rb +42 -0
- data/lib/generators/draft/resource/USAGE +11 -0
- data/lib/generators/draft/resource/resource_generator.rb +172 -0
- data/lib/generators/draft/resource/templates/controllers/controller.rb +97 -0
- data/lib/generators/draft/resource/templates/controllers/read_only_controller.rb +13 -0
- data/lib/generators/draft/resource/templates/specs/crud_spec.rb +300 -0
- data/lib/generators/draft/resource/templates/specs/factories.rb +32 -0
- data/lib/generators/draft/resource/templates/views/association_new_form.html.erb +67 -0
- data/lib/generators/draft/resource/templates/views/create_row.html.erb +13 -0
- data/lib/generators/draft/resource/templates/views/destroy_row.html.erb +13 -0
- data/lib/generators/draft/resource/templates/views/edit_form.html.erb +72 -0
- data/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb +85 -0
- data/lib/generators/draft/resource/templates/views/index.html.erb +102 -0
- data/lib/generators/draft/resource/templates/views/new_form.html.erb +73 -0
- data/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb +86 -0
- data/lib/generators/draft/resource/templates/views/show.html.erb +90 -0
- data/lib/generators/draft/resource/templates/views/update_row.html.erb +9 -0
- data/lib/generators/draft/scaffold/scaffold_controller_generator.rb +16 -0
- data/lib/generators/draft/scaffold/scaffold_erb_generator.rb +25 -0
- data/lib/generators/draft/scaffold/scaffold_generator.rb +15 -0
- data/lib/generators/draft/scaffold/templates/_card.html.erb +37 -0
- data/lib/generators/draft/scaffold/templates/_form.html.erb +44 -0
- data/lib/generators/draft/scaffold/templates/_list_item.html.erb +13 -0
- data/lib/generators/draft/scaffold/templates/_table_row.html.erb +23 -0
- data/lib/generators/draft/scaffold/templates/edit.html.erb +17 -0
- data/lib/generators/draft/scaffold/templates/index.html.erb +71 -0
- data/lib/generators/draft/scaffold/templates/new.html.erb +17 -0
- data/lib/generators/draft/scaffold/templates/show.html.erb +5 -0
- data/lib/rails_tag_service.rb +47 -0
- metadata +197 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
class <%= plural_table_name.camelize %>Controller < ApplicationController
|
2
|
+
def index
|
3
|
+
@<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all
|
4
|
+
|
5
|
+
render("<%= singular_table_name.underscore %>_templates/index.html.erb")
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display"))
|
10
|
+
|
11
|
+
render("<%= singular_table_name.underscore %>_templates/show.html.erb")
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_form
|
15
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new
|
16
|
+
|
17
|
+
render("<%= singular_table_name.underscore %>_templates/new_form.html.erb")
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_row
|
21
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new
|
22
|
+
|
23
|
+
<% attributes.each do |attribute| -%>
|
24
|
+
@<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>")
|
25
|
+
<% end -%>
|
26
|
+
|
27
|
+
<% unless skip_validation_alerts? -%>
|
28
|
+
if @<%= singular_table_name.underscore %>.valid?
|
29
|
+
@<%= singular_table_name.underscore %>.save
|
30
|
+
|
31
|
+
redirect_back(:fallback_location => "/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully.")
|
32
|
+
else
|
33
|
+
render("<%= singular_table_name.underscore %>_templates/new_form_with_errors.html.erb")
|
34
|
+
end
|
35
|
+
<% else -%>
|
36
|
+
@<%= singular_table_name.underscore %>.save
|
37
|
+
|
38
|
+
<% unless skip_redirect? -%>
|
39
|
+
redirect_to("/<%= @plural_table_name.underscore %>")
|
40
|
+
<% else -%>
|
41
|
+
@current_count = <%= class_name.singularize %>.count
|
42
|
+
|
43
|
+
render("<%= singular_table_name.underscore %>_templates/create_row.html.erb")
|
44
|
+
<% end -%>
|
45
|
+
<% end -%>
|
46
|
+
end
|
47
|
+
|
48
|
+
def edit_form
|
49
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("prefill_with_id"))
|
50
|
+
|
51
|
+
render("<%= singular_table_name.underscore %>_templates/edit_form.html.erb")
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_row
|
55
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_modify"))
|
56
|
+
|
57
|
+
<% attributes.each do |attribute| -%>
|
58
|
+
@<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>")
|
59
|
+
<% end -%>
|
60
|
+
|
61
|
+
<% unless skip_validation_alerts? -%>
|
62
|
+
if @<%= singular_table_name.underscore %>.valid?
|
63
|
+
@<%= singular_table_name.underscore %>.save
|
64
|
+
|
65
|
+
redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.")
|
66
|
+
else
|
67
|
+
render("<%= singular_table_name.underscore %>_templates/edit_form_with_errors.html.erb")
|
68
|
+
end
|
69
|
+
<% else -%>
|
70
|
+
@<%= singular_table_name.underscore %>.save
|
71
|
+
|
72
|
+
<% unless skip_redirect? -%>
|
73
|
+
redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}")
|
74
|
+
<% else -%>
|
75
|
+
render("<%= singular_table_name.underscore %>_templates/update_row.html.erb")
|
76
|
+
<% end -%>
|
77
|
+
<% end -%>
|
78
|
+
end
|
79
|
+
|
80
|
+
def destroy_row
|
81
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove"))
|
82
|
+
|
83
|
+
@<%= singular_table_name.underscore %>.destroy
|
84
|
+
|
85
|
+
<% unless skip_validation_alerts? -%>
|
86
|
+
redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.")
|
87
|
+
<% else -%>
|
88
|
+
<% unless skip_redirect? -%>
|
89
|
+
redirect_to("/<%= @plural_table_name.underscore %>")
|
90
|
+
<% else -%>
|
91
|
+
@remaining_count = <%= class_name.singularize %>.count
|
92
|
+
|
93
|
+
render("<%= singular_table_name.underscore %>_templates/destroy_row.html.erb")
|
94
|
+
<% end -%>
|
95
|
+
<% end -%>
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= plural_table_name.camelize %>Controller < ApplicationController
|
2
|
+
def index
|
3
|
+
@<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all
|
4
|
+
|
5
|
+
render("<%= singular_table_name.underscore %>_templates/index.html.erb")
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
@<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display"))
|
10
|
+
|
11
|
+
render("<%= singular_table_name.underscore %>_templates/show.html.erb")
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
feature "<%= plural_table_name.humanize.upcase %>" do
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
describe "/<%= plural_table_name %>" do
|
6
|
+
it "has the <%= attribute.human_name.downcase %> of every row", points: 5 do
|
7
|
+
test_<%= plural_table_name %> = create_list(:<%= singular_table_name %>, 5)
|
8
|
+
|
9
|
+
visit "/<%= plural_table_name %>"
|
10
|
+
|
11
|
+
test_<%= plural_table_name %>.each do |current_<%= singular_table_name %>|
|
12
|
+
expect(page).to have_content(current_<%= singular_table_name %>.<%= attribute.column_name %>)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
<% end -%>
|
18
|
+
describe "/<%= plural_table_name %>" do
|
19
|
+
it "has a link to the details page of every row", points: 5 do
|
20
|
+
test_<%= plural_table_name %> = create_list(:<%= singular_table_name %>, 5)
|
21
|
+
|
22
|
+
visit "/<%= plural_table_name %>"
|
23
|
+
|
24
|
+
test_<%= plural_table_name %>.each do |current_<%= singular_table_name %>|
|
25
|
+
expect(page).to have_css("a[href*='#{current_<%= singular_table_name %>.id}']", text: "Show details")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
<% attributes.each do |attribute| -%>
|
31
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]" do
|
32
|
+
it "has the correct <%= attribute.human_name.downcase %>", points: 3 do
|
33
|
+
<%= singular_table_name %>_to_show = create(:<%= singular_table_name %>)
|
34
|
+
|
35
|
+
visit "/<%= plural_table_name %>"
|
36
|
+
find("a[href*='#{<%= singular_table_name %>_to_show.id}']", text: "Show details").click
|
37
|
+
|
38
|
+
expect(page).to have_content(<%= singular_table_name %>_to_show.<%= attribute.column_name %>)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
<% end -%>
|
43
|
+
describe "/<%= plural_table_name %>" do
|
44
|
+
it "has a link to the new <%= singular_table_name.humanize.downcase %> page", points: 2 do
|
45
|
+
visit "/<%= plural_table_name %>"
|
46
|
+
|
47
|
+
expect(page).to have_css("a", text: "Add a new <%= singular_table_name.humanize.downcase %>")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
<% attributes.each do |attribute| -%>
|
52
|
+
describe "/<%= plural_table_name %>/new" do
|
53
|
+
it "saves the <%= attribute.human_name.downcase %> when submitted", points: 2, hint: h("label_for_input") do
|
54
|
+
visit "/<%= plural_table_name %>"
|
55
|
+
click_on "Add a new <%= singular_table_name.humanize.downcase %>"
|
56
|
+
|
57
|
+
<% case attribute.type -%>
|
58
|
+
<% when :belongs_to, :references -%>
|
59
|
+
test_<%= attribute.name %> = create(:<%= attribute.name %>)
|
60
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.name %>.id
|
61
|
+
<% when :boolean -%>
|
62
|
+
test_<%= attribute.column_name %> = <%= !attribute.default %>
|
63
|
+
check "<%= attribute.human_name %>"
|
64
|
+
<% when :date -%>
|
65
|
+
test_<%= attribute.column_name %> = 2.weeks.from_now.to_date
|
66
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
67
|
+
<% when :datetime -%>
|
68
|
+
test_<%= attribute.column_name %> = 2.days.from_now.to_datetime.beginning_of_minute
|
69
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
70
|
+
<% when :decimal -%>
|
71
|
+
test_<%= attribute.column_name %> = rand.round(4) * 100
|
72
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
73
|
+
<% when :integer, :primary_key -%>
|
74
|
+
test_<%= attribute.column_name %> = rand(1000)
|
75
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
76
|
+
<% when :string, :text -%>
|
77
|
+
test_<%= attribute.column_name %> = "A fake <%= attribute.human_name.downcase %> I'm typing at #{Time.now}"
|
78
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
79
|
+
<% when :time -%>
|
80
|
+
test_<%= attribute.column_name %> = 2.hours.from_now.to_time.round.change(year: 2000, month: 1, day: 1)
|
81
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
82
|
+
<% when :timestamp -%>
|
83
|
+
test_<%= attribute.column_name %> = 2.days.from_now.to_datetime.beginning_of_minute
|
84
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
85
|
+
<% else -%>
|
86
|
+
test_<%= attribute.column_name %> = "A fake <%= attribute.human_name.downcase %> I'm typing at #{Time.now}"
|
87
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
88
|
+
<% end -%>
|
89
|
+
|
90
|
+
click_on "Create <%= singular_table_name.humanize.downcase %>"
|
91
|
+
|
92
|
+
last_<%= singular_table_name %> = <%= singular_table_name.camelize %>.order(created_at: :asc).last
|
93
|
+
<% case attribute.type -%>
|
94
|
+
<% when :belongs_to, :references -%>
|
95
|
+
expect(last_<%= singular_table_name %>.<%= attribute.name %>).to eq(test_<%= attribute.name %>)
|
96
|
+
<% else -%>
|
97
|
+
expect(last_<%= singular_table_name %>.<%= attribute.column_name %>).to eq(test_<%= attribute.column_name %>)
|
98
|
+
<% end -%>
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
<% end -%>
|
103
|
+
<% unless skip_redirect? -%>
|
104
|
+
describe "/<%= plural_table_name %>/new" do
|
105
|
+
it "redirects to the index when submitted", points: 2, hint: h("redirect_vs_render") do
|
106
|
+
visit "/<%= plural_table_name %>"
|
107
|
+
click_on "Add a new <%= singular_table_name.humanize.downcase %>"
|
108
|
+
|
109
|
+
click_on "Create <%= singular_table_name.humanize.downcase %>"
|
110
|
+
|
111
|
+
expect(page).to have_current_path("/<%= plural_table_name %>")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "/<%= plural_table_name %>/new" do
|
116
|
+
it "redirects to the details page with a notice", points: 3, hint: h("copy_must_match") do
|
117
|
+
visit "/<%= plural_table_name %>"
|
118
|
+
|
119
|
+
expect(page).to_not have_content("<%= singular_table_name.humanize %> created successfully.")
|
120
|
+
|
121
|
+
click_on "Add a new <%= singular_table_name.humanize.downcase %>"
|
122
|
+
click_on "Create <%= singular_table_name.humanize.downcase %>"
|
123
|
+
|
124
|
+
expect(page).to have_content("<%= singular_table_name.humanize %> created successfully.")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
<% end -%>
|
129
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]" do
|
130
|
+
it "has a 'Delete <%= singular_table_name.humanize.downcase %>' link", points: 2 do
|
131
|
+
<%= singular_table_name %>_to_delete = create(:<%= singular_table_name %>)
|
132
|
+
|
133
|
+
visit "/<%= plural_table_name %>"
|
134
|
+
find("a[href*='#{<%= singular_table_name %>_to_delete.id}']", text: "Show details").click
|
135
|
+
|
136
|
+
expect(page).to have_css("a", text: "Delete")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "/delete_<%= singular_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]" do
|
141
|
+
it "removes a row from the table", points: 5 do
|
142
|
+
<%= singular_table_name %>_to_delete = create(:<%= singular_table_name %>)
|
143
|
+
|
144
|
+
visit "/<%= plural_table_name %>"
|
145
|
+
find("a[href*='#{<%= singular_table_name %>_to_delete.id}']", text: "Show details").click
|
146
|
+
click_on "Delete <%= singular_table_name.humanize.downcase %>"
|
147
|
+
|
148
|
+
expect(<%= singular_table_name.camelize %>.exists?(<%= singular_table_name %>_to_delete.id)).to be(false)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
<% unless skip_redirect? -%>
|
153
|
+
describe "/delete_<%= singular_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]" do
|
154
|
+
it "redirects to the index", points: 3, hint: h("redirect_vs_render") do
|
155
|
+
<%= singular_table_name %>_to_delete = create(:<%= singular_table_name %>)
|
156
|
+
|
157
|
+
visit "/<%= plural_table_name %>"
|
158
|
+
find("a[href*='#{<%= singular_table_name %>_to_delete.id}']", text: "Show details").click
|
159
|
+
click_on "Delete <%= singular_table_name.humanize.downcase %>"
|
160
|
+
|
161
|
+
expect(page).to have_current_path("/<%= plural_table_name %>")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "/delete_<%= singular_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]" do
|
166
|
+
it "redirects to the index with a notice", points: 3, hint: h("copy_must_match") do
|
167
|
+
<%= singular_table_name %>_to_delete = create(:<%= singular_table_name %>)
|
168
|
+
|
169
|
+
visit "/<%= plural_table_name %>"
|
170
|
+
find("a[href*='#{<%= singular_table_name %>_to_delete.id}']", text: "Show details").click
|
171
|
+
|
172
|
+
expect(page).to_not have_content("<%= singular_table_name.humanize %> deleted successfully.")
|
173
|
+
|
174
|
+
click_on "Delete <%= singular_table_name.humanize.downcase %>"
|
175
|
+
|
176
|
+
expect(page).to have_content("<%= singular_table_name.humanize %> deleted successfully.")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
<% end -%>
|
181
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]" do
|
182
|
+
it "has an 'Edit <%= singular_table_name.humanize.downcase %>' link", points: 5 do
|
183
|
+
<%= singular_table_name %>_to_edit = create(:<%= singular_table_name %>)
|
184
|
+
|
185
|
+
visit "/<%= plural_table_name %>"
|
186
|
+
find("a[href*='#{<%= singular_table_name %>_to_edit.id}']", text: "Show details").click
|
187
|
+
|
188
|
+
expect(page).to have_css("a", text: "Edit <%= singular_table_name.humanize.downcase %>")
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
<% attributes.each do |attribute| -%>
|
193
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]/edit" do
|
194
|
+
it "has <%= attribute.human_name.downcase %> pre-populated", points: 3, hint: h("value_attribute") do
|
195
|
+
<%= singular_table_name %>_to_edit = create(:<%= singular_table_name %>)
|
196
|
+
|
197
|
+
visit "/<%= plural_table_name %>"
|
198
|
+
find("a[href*='#{<%= singular_table_name %>_to_edit.id}']", text: "Show details").click
|
199
|
+
click_on "Edit <%= singular_table_name.humanize.downcase %>"
|
200
|
+
|
201
|
+
<% case attribute.field_type -%>
|
202
|
+
<% when :check_box -%>
|
203
|
+
<% when :text_area -%>
|
204
|
+
expect(page).to have_content(<%= singular_table_name %>_to_edit.<%= attribute.column_name %>)
|
205
|
+
<% else -%>
|
206
|
+
expect(page).to have_css("input[value='#{<%= singular_table_name %>_to_edit.<%= attribute.column_name %>}']")
|
207
|
+
<% end -%>
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
<% end -%>
|
212
|
+
<% attributes.each do |attribute| -%>
|
213
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]/edit" do
|
214
|
+
it "updates <%= attribute.human_name.downcase %> when submitted", points: 5, hint: h("label_for_input button_type") do
|
215
|
+
<%= singular_table_name %>_to_edit = create(:<%= singular_table_name %>, <%= attribute.column_name %>: "Boring old <%= attribute.human_name.downcase %>")
|
216
|
+
|
217
|
+
visit "/<%= plural_table_name %>"
|
218
|
+
find("a[href*='#{<%= singular_table_name %>_to_edit.id}']", text: "Show details").click
|
219
|
+
click_on "Edit <%= singular_table_name.humanize.downcase %>"
|
220
|
+
|
221
|
+
<% case attribute.type -%>
|
222
|
+
<% when :belongs_to, :references -%>
|
223
|
+
test_<%= attribute.name %> = create(:<%= attribute.name %>)
|
224
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.name %>.id
|
225
|
+
<% when :boolean -%>
|
226
|
+
test_<%= attribute.column_name %> = true
|
227
|
+
check "<%= attribute.human_name %>"
|
228
|
+
<% when :date -%>
|
229
|
+
test_<%= attribute.column_name %> = 2.weeks.from_now.to_date
|
230
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
231
|
+
<% when :datetime -%>
|
232
|
+
test_<%= attribute.column_name %> = 2.days.from_now.to_datetime.beginning_of_minute
|
233
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
234
|
+
<% when :decimal -%>
|
235
|
+
test_<%= attribute.column_name %> = rand.round(4) * 100
|
236
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
237
|
+
<% when :integer, :primary_key -%>
|
238
|
+
test_<%= attribute.column_name %> = rand(1000)
|
239
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
240
|
+
<% when :string, :text -%>
|
241
|
+
test_<%= attribute.column_name %> = "Exciting new <%= attribute.human_name.downcase %> at #{Time.now}"
|
242
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
243
|
+
<% when :time -%>
|
244
|
+
test_<%= attribute.column_name %> = 2.hours.from_now.to_time.round.change(year: 2000, month: 1, day: 1)
|
245
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
246
|
+
<% when :timestamp -%>
|
247
|
+
test_<%= attribute.column_name %> = 2.days.from_now.to_datetime.beginning_of_minute
|
248
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
249
|
+
<% else -%>
|
250
|
+
test_<%= attribute.column_name %> = "Exciting new <%= attribute.human_name.downcase %> at #{Time.now}"
|
251
|
+
fill_in "<%= attribute.human_name %>", with: test_<%= attribute.column_name %>
|
252
|
+
<% end -%>
|
253
|
+
|
254
|
+
click_on "Update <%= singular_table_name.humanize.downcase %>"
|
255
|
+
|
256
|
+
<%= singular_table_name %>_as_revised = <%= singular_table_name.camelize %>.find(<%= singular_table_name %>_to_edit.id)
|
257
|
+
|
258
|
+
<% case attribute.type -%>
|
259
|
+
<% when :belongs_to, :references -%>
|
260
|
+
expect(<%= singular_table_name %>_as_revised.<%= attribute.name %>).to eq(test_<%= attribute.name %>)
|
261
|
+
<% else -%>
|
262
|
+
expect(<%= singular_table_name %>_as_revised.<%= attribute.column_name %>).to eq(test_<%= attribute.column_name %>)
|
263
|
+
<% end -%>
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
<% end -%>
|
268
|
+
<% unless skip_redirect? -%>
|
269
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]/edit" do
|
270
|
+
it "redirects to the details page", points: 3, hint: h("embed_vs_interpolate redirect_vs_render") do
|
271
|
+
<%= singular_table_name %>_to_edit = create(:<%= singular_table_name %>)
|
272
|
+
|
273
|
+
visit "/<%= plural_table_name %>"
|
274
|
+
find("a[href*='#{<%= singular_table_name %>_to_edit.id}']", text: "Show details").click
|
275
|
+
details_page_path = page.current_path
|
276
|
+
|
277
|
+
click_on "Edit <%= singular_table_name.humanize.downcase %>"
|
278
|
+
click_on "Update <%= singular_table_name.humanize.downcase %>"
|
279
|
+
|
280
|
+
expect(page).to have_current_path(details_page_path, only_path: true)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "/<%= plural_table_name %>/[<%= singular_table_name.humanize.upcase %> ID]/edit" do
|
285
|
+
it "redirects to the details page with a notice", points: 3, hint: h("copy_must_match") do
|
286
|
+
<%= singular_table_name %>_to_edit = create(:<%= singular_table_name %>)
|
287
|
+
|
288
|
+
visit "/<%= plural_table_name %>"
|
289
|
+
find("a[href*='#{<%= singular_table_name %>_to_edit.id}']", text: "Show details").click
|
290
|
+
|
291
|
+
expect(page).to_not have_content("<%= singular_table_name.humanize %> updated successfully.")
|
292
|
+
|
293
|
+
click_on "Edit <%= singular_table_name.humanize.downcase %>"
|
294
|
+
click_on "Update <%= singular_table_name.humanize.downcase %>"
|
295
|
+
|
296
|
+
expect(page).to have_content("<%= singular_table_name.humanize %> updated successfully.")
|
297
|
+
end
|
298
|
+
end
|
299
|
+
<% end -%>
|
300
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copy this file into your spec/support folder; create one if you don't have it.
|
2
|
+
# https://github.com/firstdraft/increasing_random/blob/master/increasing_random.rb
|
3
|
+
|
4
|
+
|
5
|
+
FactoryBot.define do
|
6
|
+
factory :<%= singular_table_name %> do
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
<% case attribute.type -%>
|
9
|
+
<% when :belongs_to, :references -%>
|
10
|
+
association :<%= attribute.name %>
|
11
|
+
<% when :boolean -%>
|
12
|
+
<%= attribute.column_name %> false
|
13
|
+
<% when :date -%>
|
14
|
+
sequence(:<%= attribute.column_name %>, Date.today)
|
15
|
+
<% when :datetime -%>
|
16
|
+
<%= attribute.column_name %> Time.now
|
17
|
+
<% when :decimal -%>
|
18
|
+
<%= attribute.column_name %> 42.42
|
19
|
+
<% when :integer -%>
|
20
|
+
sequence(:<%= attribute.column_name %>) { |n| n }
|
21
|
+
<% when :string, :text -%>
|
22
|
+
sequence(:<%= attribute.column_name %>) { |n| "Some fake <%= attribute.human_name.downcase %> #{n}" }
|
23
|
+
<% when :time -%>
|
24
|
+
<%= attribute.column_name %> Time.now.beginning_of_day
|
25
|
+
<% when :timestamp -%>
|
26
|
+
<%= attribute.column_name %> Time.now
|
27
|
+
<% else -%>
|
28
|
+
sequence(:<%= attribute.column_name %>) { |n| "Some fake <%= attribute.human_name.downcase %> #{n}" }
|
29
|
+
<% end -%>
|
30
|
+
<% end -%>
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<% if with_sentinels? -%>
|
2
|
+
<!-- Form <%= singular_table_name %> start -->
|
3
|
+
<% end -%>
|
4
|
+
<form action="/<%= new_form_create_path %>"<% unless skip_post? -%> method="post"<% end -%>>
|
5
|
+
<% if with_sentinels? -%>
|
6
|
+
<!-- Form <%= singular_table_name %> end -->
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
<% attributes.each do |attribute| -%>
|
10
|
+
<% if with_sentinels? -%>
|
11
|
+
<!-- Label and input for <%= attribute.column_name %> start -->
|
12
|
+
<% end -%>
|
13
|
+
<% if attribute.type == :hidden -%>
|
14
|
+
<% if with_sentinels? -%>
|
15
|
+
<!-- Input for <%= attribute.column_name %> start -->
|
16
|
+
<% end -%>
|
17
|
+
<input type="hidden" name="<%= attribute.column_name %>" value="<%%= <%= new_form_hidden_variable %> %>">
|
18
|
+
<% if with_sentinels? -%>
|
19
|
+
<!-- Input for <%= attribute.column_name %> end -->
|
20
|
+
<% end -%>
|
21
|
+
<% elsif attribute.field_type == :check_box -%>
|
22
|
+
<div class="form-group">
|
23
|
+
<label for="<%= attribute.column_name %>">
|
24
|
+
<%= attribute.column_name.humanize %>
|
25
|
+
</label>
|
26
|
+
<% if with_sentinels? -%>
|
27
|
+
<!-- Input for <%= attribute.column_name %> start -->
|
28
|
+
<% end -%>
|
29
|
+
<input id="<%= attribute.column_name %>" class="form-check-input" name="<%= attribute.column_name %>" type="checkbox" <% unless skip_validation_alerts? -%><%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>>
|
30
|
+
<% if with_sentinels? -%>
|
31
|
+
<!-- Input for <%= attribute.column_name %> end -->
|
32
|
+
<% end -%>
|
33
|
+
</div>
|
34
|
+
<% else -%>
|
35
|
+
<div class="form-group">
|
36
|
+
<label for="<%= attribute.column_name %>">
|
37
|
+
<%= attribute.column_name.humanize %>
|
38
|
+
</label>
|
39
|
+
|
40
|
+
<% if attribute.field_type == :text_area -%>
|
41
|
+
<% if with_sentinels? -%>
|
42
|
+
<!-- Input for <%= attribute.column_name %> start -->
|
43
|
+
<% end -%>
|
44
|
+
<textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control" rows="3"><% unless skip_validation_alerts? -%><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%></textarea>
|
45
|
+
<% if with_sentinels? -%>
|
46
|
+
<!-- Input for <%= attribute.column_name %> end -->
|
47
|
+
<% end -%>
|
48
|
+
<% else -%>
|
49
|
+
<% if with_sentinels? -%>
|
50
|
+
<!-- Input for <%= attribute.column_name %> start -->
|
51
|
+
<% end -%>
|
52
|
+
<input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control"<% unless skip_validation_alerts? -%> value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>>
|
53
|
+
<% if with_sentinels? -%>
|
54
|
+
<!-- Input for <%= attribute.column_name %> end -->
|
55
|
+
<% end -%>
|
56
|
+
<% end -%>
|
57
|
+
</div>
|
58
|
+
<% if with_sentinels? -%>
|
59
|
+
<!-- Label and input for <%= attribute.column_name %> end -->
|
60
|
+
<% end -%>
|
61
|
+
<% end -%>
|
62
|
+
|
63
|
+
<% end -%>
|
64
|
+
<button class="btn btn-block btn-outline-secondary">
|
65
|
+
Create <%= singular_table_name.humanize.downcase %>
|
66
|
+
</button>
|
67
|
+
</form>
|