Skip to content

Commit

Permalink
remove seeds from tests in github
Browse files Browse the repository at this point in the history
  • Loading branch information
dcordz committed Jan 6, 2025
1 parent 3453672 commit c1f2700
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
bundle exec rails db:create
bundle exec rails db:migrate
bundle exec rails db:schema:load
bundle exec rails db:seed
- name: Set up certs
run: | # multi-line run command: https://stackoverflow.com/a/66809682/6410635
Expand Down
6 changes: 6 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@
"localhost:3001",
"127.0.0.1:3001"
]

# Log to STDOUT by default
# config.logger = ActiveSupport::Logger.new(STDOUT)
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
end
6 changes: 6 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true

# Log to STDOUT by default
# config.logger = ActiveSupport::Logger.new(STDOUT)
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
end
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions db/seeds/models/legislator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def initialize(j, sway_locale)
party: Legislator.to_party_char_from_name(j.fetch("partyName"))
).present?
Rails.logger.info("SKIP Seeding Congressional Legislator #{bioguide_id}. Already exists by external_id, district.name and party char.")
puts "SKIP Seeding Congressional Legislator #{bioguide_id}. Already exists by external_id, district.name and party char."
return
end

Expand Down Expand Up @@ -87,16 +86,13 @@ def seed
sig { returns(Legislator) }
def legislator
Rails.logger.info("Seeding #{sway_locale.city.titleize} Legislator #{external_id}")
puts "Seeding #{sway_locale.city.titleize} Legislator #{external_id}"

l = Legislator.find_or_initialize_by(
external_id:,
first_name:,
last_name:
)

Legislator.find_by(district: district)&.update_attribute(:active, false)

l.address = address
l.district = district
l.title = title
Expand Down
2 changes: 0 additions & 2 deletions lib/tasks/assign_new_user_legislators.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ namespace :sway do
desc "De-activates all UserLegislators and assigns new ones to each user. Run after each election."
task assign_new_user_legislators: :environment do
Rails.logger.info("assign_new_user_legislators.rake - de-activate all UserLegislators")
puts "assign_new_user_legislators.rake - de-activate all UserLegislators"
UserLegislator.update_all(active: false)

User.all.each do |user|
user.sway_locales.each do |sway_locale|
Rails.logger.info("assign_new_user_legislators.rake - Updating UserLegislators for User: #{user.id}, SwayLocale: #{sway_locale.name}")
puts "assign_new_user_legislators.rake - Updating UserLegislators for User: #{user.id}, SwayLocale: #{sway_locale.name}"
SwayRegistrationService.new(user, user.address, sway_locale, invited_by_id: nil).create_user_legislators
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/deactivate_old_legislators.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace :sway do
# Call like: ./bin/rake "sway:deactivate_old_legislators[[2024]]"

desc "De-activates all Legislators that do not have an election_year within the passed array of election years."
task :deactivate_old_legislators, [:election_years] => [:environment] do |task, args|
election_years = JSON.parse(args[:election_years])

Rails.logger.info("deactivate_old_legislators.rake - de-activate all Legislators in election years: #{election_years}")

ids = Legislator.where(active: true).filter { |legislator| !election_years.include?(legislator.election_year) }.map(&:id)
Legislator.where(id: ids).update_all(active: false)
end
end
6 changes: 3 additions & 3 deletions lib/tasks/sway.rake
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ namespace :sway do
end

def backup_db(attempt = 0)
puts "sway.rake -> backup_db attempt #{attempt}"
Rails.logger.info("sway.rake -> backup_db attempt #{attempt}")

if File.exist? "storage/production.sqlite3"
puts "sway.rake -> Uploading production.sqlite3 to google storage as backup."
Rails.logger.info("sway.rake -> Uploading production.sqlite3 to google storage as backup.")
upload_file(bucket_name: "sway-sqlite", bucket_file_path: "production.sqlite3",
local_file_path: "/rails/storage/production.sqlite3")
elsif attempt < 5
sleep 1
backup_db(attempt + 1)
# else
# puts 'Getting production.sqlite3 from google storage backup.'
# Rails.logger.info('Getting production.sqlite3 from google storage backup.')
# download_file(bucket_name: 'sway-sqlite', bucket_file_path: 'production.sqlite3',
# local_file_path: 'storage/production.sqlite3')
end
Expand Down

0 comments on commit c1f2700

Please sign in to comment.