From 50651f584bc5e8b8fc8eaec74483160bbdf47fc3 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Thu, 8 Feb 2018 11:40:20 -0600 Subject: [PATCH 1/4] adds buggy code for controllers --- .../draft/resource/resource_generator.rb | 47 ++++++++- .../templates/controllers/controller.rb | 97 +++++++++++++++++-- 2 files changed, 136 insertions(+), 8 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 84d8c20c..c29f979d 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -9,6 +9,7 @@ class ResourceGenerator < Rails::Generators::NamedBase class_option :skip_validation_alerts, type: :boolean, default: false, desc: "Skip validation failure alerts" class_option :skip_post, type: :boolean, default: false, desc: "Skip HTTP POST verb" class_option :skip_redirect, type: :boolean, default: false, desc: "Skip redirecting after create, update, and destroy" + class_option :buggy, type: :boolean, default: false, desc: "Creates buggy resources for RCAV and Golden Seven practice" def generate_controller return if skip_controller? @@ -78,6 +79,32 @@ def golden_seven_routes RUBY end + def buggy_routes + log :route, "Buggy routes" + + route <<-RUBY.gsub(/^ /, "") + + # Routes for the #{singular_table_name.humanize} resource: + + # CREATE + get("/#{plural_table_name}/new", { :controller => "#{plural_table_name}", :action => "new_form" }) + #{skip_post? ? "get" : "post"}("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) + + # READ + get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) + get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) + + # UPDATE + get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) + #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) + + # DELETE + get("/delete_#{singular_table_name}/:id_to_remove", { :controller => "#{plural_table_name}", :action => "destroy_row" }) + + #------------------------------ + RUBY + end + def read_only_routes log :route, "Index and show routes" @@ -105,7 +132,7 @@ def read_only? end def skip_validation_alerts? - options[:skip_validation_alerts] + options[:skip_validation_alerts] || options[:skip_redirect] end def skip_post? @@ -116,6 +143,10 @@ def skip_redirect? options[:skip_redirect] end + def buggy? + options[:buggy] + end + def route(routing_code) sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/ @@ -140,5 +171,19 @@ def view_filename_with_extensions(name) filename = File.join(folders, filename) if folders.any? filename end + + def create_bug?(likelihood_hash) + if likelihood_hash.fetch(:likelihood) == :high + return rand(10) > 3 + elsif likelihood_hash.fetch(:likelihood) == :low + return rand(10) > 7 + elsif likelihood_hash.fetch(:likelihood) == :none + return false + elsif likelihood_hash.fetch(:likelihood) == :total + return true + else + return rand(10) > 5 + end + end end end diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 8a8b0c6c..fe7a5927 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,12 +1,36 @@ +<% total_bugs = rand(2) + 4 -%> +<% bugs_created = 0 -%> class <%= plural_table_name.camelize %>Controller < ApplicationController def index +<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> + <% bug_option = rand(2) + 1 -%> + <% if bug_option == 1 -%> +@<%= plural_table_name.underscore %> = <%= class_name.singularize.downcase %>.all + <% elsif bug_option == 2 -%> +<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all + <% end -%> + <% bugs_created += 1 -%> +<% else -%> @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all +<% end -%> render("<%= singular_table_name.underscore %>_templates/index.html.erb") end def show - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_display]) +<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% bug_option = rand(3) + 1 -%> +<% if bug_option == 1 -%> + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) +<% elsif bug_option == 2 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize.downcase %>.find(params.fetch("id_to_display")) +<% elsif bug_option == 3 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(id_to_display)) +<% end -%> +<% bugs_created += 1 -%> +<% else -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) +<% end -%> render("<%= singular_table_name.underscore %>_templates/show.html.erb") end @@ -15,14 +39,35 @@ def new_form <% unless skip_validation_alerts? -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% end -%> + render("<%= singular_table_name.underscore %>_templates/new_form.html.erb") end def create_row +<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% bug_option = rand(3) + 1 -%> +<% if bug_option == 1 -%> + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.new +<% attributes.each do |attribute| -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>") +<% end -%> +<% elsif bug_option == 2 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new +<% attributes.each do |attribute| -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("the_<%= attribute.column_name %>") +<% end -%> +<% elsif bug_option == 3 -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new - <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>] + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(<%= attribute.column_name %>) +<% end -%> +<% end -%> +<% bugs_created += 1 -%> +<% else -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new +<% attributes.each do |attribute| -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>") +<% end -%> <% end -%> <% unless skip_validation_alerts? -%> @@ -47,16 +92,40 @@ def create_row end def edit_form - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:prefill_with_id]) +<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% bug_option = rand(3) + 1 -%> +<% if bug_option == 1 -%> + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) +<% elsif bug_option == 2 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize.downcase %>.find(params.fetch("id_to_display")) +<% elsif bug_option == 3 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(id_to_display)) +<% end -%> +<% bugs_created += 1 -%> +<% else -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) +<% end -%> render("<%= singular_table_name.underscore %>_templates/edit_form.html.erb") end def update_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_modify]) +<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% bug_option = rand(3) + 1 -%> +<% if bug_option == 1 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new +<% elsif bug_option == 2 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize.downcase %>.find(params.fetch("id_to_modify")) +<% elsif bug_option == 3 -%> + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(id_to_modify)) +<% end -%> +<% bugs_created += 1 -%> +<% else -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_modify")) +<% end -%> <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>] + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>") <% end -%> <% unless skip_validation_alerts? -%> @@ -79,9 +148,21 @@ def update_row end def destroy_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_remove]) +<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% bug_option = rand(2) + 1 -%> +<% if bug_option == 1 -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove")) +<% elsif bug_option == 2 -%> + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove")) + + <%= singular_table_name.underscore %>.destroy +<% end -%> +<% bugs_created += 1 -%> +<% else -%> + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove")) @<%= singular_table_name.underscore %>.destroy +<% end -%> <% unless skip_validation_alerts? -%> redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") @@ -96,3 +177,5 @@ def destroy_row <% end -%> end end + +<% puts "#{bugs_created} controller bugs created" %> From bdced3501164edea5791359c6f827dc58f962b04 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Thu, 8 Feb 2018 23:49:05 -0600 Subject: [PATCH 2/4] adds buggy routes --- .../draft/resource/resource_generator.rb | 204 ++++++++++++++++-- 1 file changed, 190 insertions(+), 14 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index c29f979d..2ef86265 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -38,9 +38,9 @@ def generate_routes return if skip_controller? if read_only? - read_only_routes + buggy? ? buggy_read_only_routes : read_only_routes else - golden_seven_routes + buggy? ? buggy_golden_seven_routes : golden_seven_routes end end @@ -79,32 +79,208 @@ def golden_seven_routes RUBY end - def buggy_routes - log :route, "Buggy routes" + def buggy_golden_seven_routes + log :route, "Buggy Golden Seven routes" + total_bugs = rand(2) + 4 + bug_count = 0 + + if create_bug(likelihood: :high) && bug_count < total_bugs + new_form_route = buggy_new_form_route + bug_count += 1 + else + new_form_route = <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/new", { :controller => "#{plural_table_name}", :action => "new_form" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + create_row_route = buggy_create_row_route + bug_count += 1 + else + create_row_route = <<-RUBY.gsub(/^ /, "") + #{skip_post? ? "get" : "post"}("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + index_route = buggy_index_route + bug_count += 1 + else + index_route = <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + show_route = buggy_show_route + bug_count += 1 + else + show_route = <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + edit_form_route = buggy_edit_form_route + bug_count += 1 + else + edit_form_route = <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + update_route = buggy_update_route + bug_count += 1 + else + update_route = <<-RUBY.gsub(/^ /, "") + #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + destroy_row_route = buggy_destroy_row_route + bug_count += 1 + else + destroy_row_route = <<-RUBY.gsub(/^ /, "") + get("/delete_#{singular_table_name}/:id_to_remove", { :controller => "#{plural_table_name}", :action => "destroy_row" }) + RUBY + end route <<-RUBY.gsub(/^ /, "") # Routes for the #{singular_table_name.humanize} resource: # CREATE - get("/#{plural_table_name}/new", { :controller => "#{plural_table_name}", :action => "new_form" }) - #{skip_post? ? "get" : "post"}("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) - + #{new_form_route} #{create_row_route} # READ - get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) - get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) - + #{index_route} #{show_route} # UPDATE - get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) - #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) - + #{edit_form_route} #{update_route} # DELETE - get("/delete_#{singular_table_name}/:id_to_remove", { :controller => "#{plural_table_name}", :action => "destroy_row" }) + #{destroy_row_route} + RUBY + puts "#{bug_count} route bugs created" + end + + def buggy_read_only_routes + log :route, "Buggy index and show routes" + + total_bugs = 2 + bug_count = 0 + + if create_bug(likelihood: :high) && bug_count < total_bugs + index_route = buggy_index_route + bug_count += 1 + else + index_route = <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) + RUBY + end + + if create_bug(likelihood: :high) && bug_count < total_bugs + show_route = buggy_show_route + bug_count += 1 + else + show_route = <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) + RUBY + end + + route <<-RUBY.gsub(/^ /, "") + # Routes for the #{singular_table_name.humanize} resource: + + # READ + #{index_route} #{show_route} #------------------------------ RUBY end + def buggy_new_form_route + bug_option = rand(2) + 1 + if bug_option == 1 + <<-RUBY.gsub(/^ /, "") + get("/new_#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "new_form" }) + RUBY + elsif bug_option == 2 + <<-RUBY.gsub(/^ /, "") + get("/new_#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "new" }) + RUBY + end + end + + def buggy_create_row_route + <<-RUBY.gsub(/^ /, "") + #{skip_post? ? "get" : "post"}("/create_#{singular_table_name}", { controller => "#{plural_table_name}", action => "create_row" }) + RUBY + end + + def buggy_index_route + bug_option = rand(2) + 1 + if bug_option == 1 + <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "#{plural_table_name}" }) + RUBY + elsif bug_option == 2 + <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}", { :controller => #{plural_table_name}, :action => index }) + RUBY + end + end + + def buggy_show_route + bug_option = rand(2) + 1 + if bug_option == 1 + <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) + RUBY + elsif bug_option == 2 + <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/:id_to_display", { controller => "#{plural_table_name}", :action => "show" }) + RUBY + end + end + + def buggy_edit_form_route + bug_option = rand(2) + 1 + if bug_option == 1 + <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) + RUBY + elsif bug_option == 2 + <<-RUBY.gsub(/^ /, "") + get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => #{plural_table_name}, :action => "edit" }) + RUBY + end + end + + def buggy_update_route + bug_option = rand(2) + 1 + if bug_option == 1 + <<-RUBY.gsub(/^ /, "") + #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) + RUBY + elsif bug_option == 2 + <<-RUBY.gsub(/^ /, "") + #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/id_to_modify", { controller => "#{plural_table_name}", action => "update_row" }) + RUBY + end + end + + def buggy_destroy_row_route + bug_option = rand(2) + 1 + if bug_option == 1 + <<-RUBY.gsub(/^ /, "") + get("/delete_#{singular_table_name}/id_to_remove", { :controller => "#{plural_table_name}", :action => "destroy_row" }) + RUBY + elsif bug_option == 2 + <<-RUBY.gsub(/^ /, "") + get("/delete_#{singular_table_name}/:id_to_remove", { controller => "#{plural_table_name}", action => "destroy" }) + RUBY + end + end + def read_only_routes log :route, "Index and show routes" From d316504c8b4382f353527da53bac8ce8c3b1c283 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Fri, 9 Feb 2018 12:37:47 -0600 Subject: [PATCH 3/4] changes variable names --- .../draft/resource/resource_generator.rb | 22 +++++----- .../templates/controllers/controller.rb | 41 ++++++++++--------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 2ef86265..05a3d8c8 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -81,10 +81,10 @@ def golden_seven_routes def buggy_golden_seven_routes log :route, "Buggy Golden Seven routes" - total_bugs = rand(2) + 4 + max_route_bugs = rand(2) + 4 bug_count = 0 - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs new_form_route = buggy_new_form_route bug_count += 1 else @@ -93,7 +93,7 @@ def buggy_golden_seven_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs create_row_route = buggy_create_row_route bug_count += 1 else @@ -102,7 +102,7 @@ def buggy_golden_seven_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs index_route = buggy_index_route bug_count += 1 else @@ -111,7 +111,7 @@ def buggy_golden_seven_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs show_route = buggy_show_route bug_count += 1 else @@ -120,7 +120,7 @@ def buggy_golden_seven_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs edit_form_route = buggy_edit_form_route bug_count += 1 else @@ -129,7 +129,7 @@ def buggy_golden_seven_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs update_route = buggy_update_route bug_count += 1 else @@ -138,7 +138,7 @@ def buggy_golden_seven_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs destroy_row_route = buggy_destroy_row_route bug_count += 1 else @@ -166,10 +166,10 @@ def buggy_golden_seven_routes def buggy_read_only_routes log :route, "Buggy index and show routes" - total_bugs = 2 + max_route_bugs = 2 bug_count = 0 - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs index_route = buggy_index_route bug_count += 1 else @@ -178,7 +178,7 @@ def buggy_read_only_routes RUBY end - if create_bug(likelihood: :high) && bug_count < total_bugs + if create_bug?(likelihood: :high) && bug_count < max_route_bugs show_route = buggy_show_route bug_count += 1 else diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index fe7a5927..1693dd33 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,15 +1,15 @@ -<% total_bugs = rand(2) + 4 -%> -<% bugs_created = 0 -%> +<% max_controller_bugs = rand(2) + 4 -%> +<% controller_bugs = 0 -%> class <%= plural_table_name.camelize %>Controller < ApplicationController def index -<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% if buggy? && controller_bugs < max_controller_bugs && create_bug?(likelihood: :high) -%> <% bug_option = rand(2) + 1 -%> <% if bug_option == 1 -%> @<%= plural_table_name.underscore %> = <%= class_name.singularize.downcase %>.all <% elsif bug_option == 2 -%> <%= plural_table_name.underscore %> = <%= class_name.singularize %>.all <% end -%> - <% bugs_created += 1 -%> + <% controller_bugs += 1 -%> <% else -%> @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all <% end -%> @@ -18,7 +18,7 @@ def index end def show -<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% if buggy? && controller_bugs < max_controller_bugs && create_bug?(likelihood: :high) -%> <% bug_option = rand(3) + 1 -%> <% if bug_option == 1 -%> <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) @@ -27,7 +27,7 @@ def show <% elsif bug_option == 3 -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(id_to_display)) <% end -%> -<% bugs_created += 1 -%> +<% controller_bugs += 1 -%> <% else -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) <% end -%> @@ -44,7 +44,7 @@ def new_form end def create_row -<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% if buggy? && controller_bugs < max_controller_bugs && create_bug?(likelihood: :high) -%> <% bug_option = rand(3) + 1 -%> <% if bug_option == 1 -%> <%= singular_table_name.underscore %> = <%= class_name.singularize %>.new @@ -62,7 +62,7 @@ def create_row @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(<%= attribute.column_name %>) <% end -%> <% end -%> -<% bugs_created += 1 -%> +<% controller_bugs += 1 -%> <% else -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> @@ -92,25 +92,25 @@ def create_row end def edit_form -<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% if buggy? && controller_bugs < max_controller_bugs && create_bug?(likelihood: :high) -%> <% bug_option = rand(3) + 1 -%> <% if bug_option == 1 -%> - <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("prefill_with_id")) <% elsif bug_option == 2 -%> - @<%= singular_table_name.underscore %> = <%= class_name.singularize.downcase %>.find(params.fetch("id_to_display")) + @<%= singular_table_name.underscore %> = <%= class_name.singularize.downcase %>.find(params.fetch("prefill_with_id")) <% elsif bug_option == 3 -%> - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(id_to_display)) + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(prefill_with_id)) <% end -%> -<% bugs_created += 1 -%> +<% controller_bugs += 1 -%> <% else -%> - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("prefill_with_id")) <% end -%> render("<%= singular_table_name.underscore %>_templates/edit_form.html.erb") end def update_row -<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% if buggy? && controller_bugs < max_controller_bugs && create_bug?(likelihood: :high) -%> <% bug_option = rand(3) + 1 -%> <% if bug_option == 1 -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new @@ -119,7 +119,7 @@ def update_row <% elsif bug_option == 3 -%> <%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch(id_to_modify)) <% end -%> -<% bugs_created += 1 -%> +<% controller_bugs += 1 -%> <% else -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_modify")) <% end -%> @@ -148,7 +148,7 @@ def update_row end def destroy_row -<% if buggy? && bugs_created < total_bugs && create_bug?(likelihood: :high) -%> +<% if buggy? && controller_bugs < max_controller_bugs && create_bug?(likelihood: :high) -%> <% bug_option = rand(2) + 1 -%> <% if bug_option == 1 -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove")) @@ -157,7 +157,7 @@ def destroy_row <%= singular_table_name.underscore %>.destroy <% end -%> -<% bugs_created += 1 -%> +<% controller_bugs += 1 -%> <% else -%> @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove")) @@ -177,5 +177,6 @@ def destroy_row <% end -%> end end - -<% puts "#{bugs_created} controller bugs created" %> +<% if buggy? -%> + <% puts "#{controller_bugs} controller bugs created" -%> +<% end -%> From d8dd0681f122c29d2cb2c94caa76a31aca90b42f Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Fri, 9 Feb 2018 12:37:54 -0600 Subject: [PATCH 4/4] adds view bugs --- .../templates/views/edit_form.html.erb | 26 ++++++++++++++++++- .../resource/templates/views/index.html.erb | 18 ++++++++++++- .../templates/views/new_form.html.erb | 21 ++++++++++++++- .../resource/templates/views/show.html.erb | 20 +++++++++++++- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/edit_form.html.erb b/lib/generators/draft/resource/templates/views/edit_form.html.erb index eb6f78b0..6c70a26e 100644 --- a/lib/generators/draft/resource/templates/views/edit_form.html.erb +++ b/lib/generators/draft/resource/templates/views/edit_form.html.erb @@ -1,3 +1,5 @@ +<% total_bugs = rand(2) + 4 -%> +<% max_edit_form_bugs = 0 -%> <% unless skip_validation_alerts? -%> <%% if @<%= singular_table_name %>.errors.any? %> @@ -18,8 +20,17 @@
- +<% if buggy? && max_edit_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> +<% max_edit_form_bugs += 1 -%> +<% bug_option = rand(2) + 1 -%> +<% if bug_option == 1 -%> +
method="post"<% end -%>> +<% elsif bug_option == 2 -%> + method="post"<% end -%>> +<% end -%> +<% else -%> method="post"<% end -%>> +<% end -%> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> @@ -37,9 +48,19 @@ <% if attribute.field_type == :text_area -%> +<% if buggy? && max_edit_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + +<% max_edit_form_bugs += 1 -%> +<% else -%> +<% end -%> +<% else -%> +<% if buggy? && max_edit_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + +<% max_edit_form_bugs += 1 -%> <% else -%> +<% end -%> <% end -%> <% end -%> @@ -55,3 +76,6 @@ Go back +<% if buggy? -%> + <% puts "#{max_edit_form_bugs} edit_form bugs created" -%> +<% end -%> diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 2caca9d1..abb96adf 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -1,3 +1,5 @@ +<% total_bugs = rand(3) -%> +<% max_index_form_bugs = 0 -%>

All <%= plural_table_name.humanize.downcase %>

@@ -31,16 +33,27 @@ - +<% if buggy? && max_index_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + <%% <%= plural_table_name %>.each do |<%= singular_table_name %>| %> +<% else -%> <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> +<% end -%> +<% if buggy? && max_index_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + <%%= @<%= singular_table_name %>.id %> +<% else -%> <%%= <%= singular_table_name %>.id %> +<% end -%> <% attributes.each do |attribute| -%> +<% if buggy? && max_index_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> +<% else -%> <%%= <%= singular_table_name %>.<%= attribute.column_name %> %> +<% end -%> <% end -%> @@ -60,3 +73,6 @@ <%% end %> +<% if buggy? -%> + <% puts "#{max_index_form_bugs} index page bugs created" -%> +<% end -%> diff --git a/lib/generators/draft/resource/templates/views/new_form.html.erb b/lib/generators/draft/resource/templates/views/new_form.html.erb index bdffdd12..2b132847 100644 --- a/lib/generators/draft/resource/templates/views/new_form.html.erb +++ b/lib/generators/draft/resource/templates/views/new_form.html.erb @@ -1,3 +1,5 @@ +<% total_bugs = rand(2) + 4 -%> +<% max_new_form_bugs = 0 -%> <% unless skip_validation_alerts? -%> <%% if @<%= singular_table_name %>.errors.any? %> @@ -18,8 +20,12 @@
- +<% if buggy? && max_new_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + method="post"<% end -%>> +<% max_new_form_bugs += 1 -%> +<% else -%> method="post"<% end -%>> +<% end -%> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> @@ -37,9 +43,19 @@ <% if attribute.field_type == :text_area -%> +<% if buggy? && max_new_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + +<% max_new_form_bugs += 1 -%> +<% else -%> +<% end -%> +<% else -%> +<% if buggy? && max_new_form_bugs < total_bugs && create_bug?(likelihood: :high) -%> + value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> +<% max_new_form_bugs += 1 -%> <% else -%> value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> +<% end -%> <% end -%> <% end -%> @@ -55,3 +71,6 @@ Go back +<% if buggy? -%> + <% puts "#{max_new_form_bugs} new_form bugs created" -%> +<% end -%> diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index ad19cebf..08063a06 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,10 +1,18 @@ +<% total_bugs = rand(2) + 4 -%> +<% max_show_bugs = 0 -%>

<%= singular_table_name.humanize %> #<%%= @<%= singular_table_name %>.id %> details

- +<% if buggy? && max_show_bugs < total_bugs && create_bug?(likelihood: :high) -%> + + Edit <%= singular_table_name.humanize.downcase %> + +<% max_show_bugs += 1 -%> +<% else -%> Edit <%= singular_table_name.humanize.downcase %> +<% end -%>
@@ -34,13 +42,23 @@ <% unless read_only? -%> +<% if buggy? && max_show_bugs < total_bugs && create_bug?(likelihood: :high) -%> + + Delete <%= singular_table_name.humanize.downcase %> + +<% max_show_bugs += 1 -%> +<% else -%> Delete <%= singular_table_name.humanize.downcase %> <% end -%> +<% end -%>
Go back +<% if buggy? -%> + <% puts "#{max_show_bugs} show page bugs created" -%> +<% end -%>