Skip to content

Instantly share code, notes, and snippets.

View lukes's full-sized avatar

Luke Duncalfe lukes

View GitHub Profile

I'm trying to run the rails test suite but I keep getting this error:

$ bundle exec rake postgresql:build_databases
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.
@lukes
lukes / find_invalid_records_in_rails.rake
Last active July 18, 2022 23:43
Find invalid records in Rails.
namespace :db do
desc "Outputs any invalid data records"
task :invalid_records => :environment do
puts "\n** Testing record validating in #{Rails.env.capitalize} environment**\n"
ActiveRecord::Base.send(:subclasses).each do |model|
puts "#{model} records (#{model.count})"
next if model.count == 0
invalid = model.all.reject(&:valid?)
if invalid.size.zero?
{
"name":"Afghanistan", // english name
"country-code":"004", // unique numeric code
"alpha-2":"AF", // unique 2-character code
"alpha-3":"AFG", // unique 3-character code
"sub-region-code":"034", // geographical sub-region code
"region-code":"142", // macro geographical (continental) region code
"iso 3166-2":"ISO 3166-2:AF" // ISO 3166-2 code for principle subdivision
}