Skip to content

Instantly share code, notes, and snippets.

@litch
Last active December 11, 2015 07:59
Show Gist options
  • Save litch/4570359 to your computer and use it in GitHub Desktop.
Save litch/4570359 to your computer and use it in GitHub Desktop.
One of the most frustrating things I run into in development is that sometimes, when I have been doing my testing, (even FE testing) and making changes to FE code, and pushing to production and start getting 500's because some element in my production dataset is nil that is not nil in my factories.  So now I just cobbled together a test method t…
require_relative '../features_helper'
describe "as an admin", js: true do
it 'crawls the site with a tiny data set' do
default_url_options[:host] = "127.0.0.1:6543"
sign_in(:admin)
objects = [
create(:customer),
create(:job),
create(:employee),
create(:purchase_order),
create(:po_request),
create(:vendor),
create(:timesheet),
]
objects.each do |object|
ap "Exploring #{object.class.name}"
nilled_attrs = []
object.attributes.keys.each do |attribute|
next if ["id", "created_at", "updated_at"].include?(attribute)
old_value = object.send(attribute.to_sym)
object.send("#{attribute}=".to_sym, nil)
if object.valid?
nilled_attrs << attribute
else
object.send("#{attribute}=".to_sym, old_value)
end
end
object.save
ap "nilled out #{nilled_attrs.join(", ")}"
{show: url_for(object), index: url_for(object.class), new: url_for([:new, object]), edit: url_for([:edit, object])}.each do |method, url|
if (object.class.name.pluralize+"Controller").constantize.send(:instance_methods, false).include?(method)
ap "Visiting #{url}"
visit url
expect(page).to_not have_content("Internal Server Error")
end
end
end
end
end
"Exploring Customer"
"nilled out description, prefix"
"Visiting http://127.0.0.1:6543/customers/1"
"Visiting http://127.0.0.1:6543/customers"
"Visiting http://127.0.0.1:6543/customers/new.1"
"Visiting http://127.0.0.1:6543/customers/1/edit"
"Exploring Job"
"nilled out supervisor_id, job_site_id, one_call_valid_until_date, description, job_number, start_date, end_date, projected_end_date, no_dig_test_needed, location_requested"
"Visiting http://127.0.0.1:6543/jobs/1"
"Visiting http://127.0.0.1:6543/jobs"
"Visiting http://127.0.0.1:6543/jobs/new.1"
"Visiting http://127.0.0.1:6543/jobs/1/edit"
"Exploring Employee"
"nilled out hire_date, title, active, work_truck_id, company_phone_serial, user_id, hourly_rate, drh_fuel_system_num, fuel_man_card_num, comdata_card_num, check_1099, date_1099, auto, child_support, ins, loan_amount, loan_payback"
"Visiting http://127.0.0.1:6543/employees/2"
An error occurred in an after hook
ActionView::Template::Error: undefined method `strftime' for nil:NilClass
occurred at /Users/litch/code/project-oilfield/app/views/employees/show.html.haml:14:in `_app_views_employees_show_html_haml__696395862962300194_70317308233200'
F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment