usgo / gocongress

Annual US Go Congress Website
https://www.gocongress.org
MIT License
20 stars 17 forks source link

Added find_or_create_by to fix RAILS_ENV=test bin/rails db:seed #280

Closed michaelhiiva closed 3 years ago

michaelhiiva commented 3 years ago

Summary

Adds find_or_create_by to create keys if not a record cannot be found. This will fix the error from $ rails db:test:prepare.

Error

shell> $ RAILS_ENV=test bin/rails db:seed
rails aborted!
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_years_on_year"
DETAIL:  Key (year)=(2011) already exists.
/home/michael/projects/usgo/development/gocongress-earthschlange/db/seeds.rb:2:in `<main>'
bin/rails:4:in `<main>'

Caused by:
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_years_on_year"
DETAIL:  Key (year)=(2011) already exists.
/home/michael/projects/usgo/development/gocongress-earthschlange/db/seeds.rb:2:in `<main>'
bin/rails:4:in `<main>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
neagle commented 3 years ago

Looks good -- thanks, Michael!