Last active
September 28, 2022 08:53
-
-
Save garethrees/bba5244fa42ff629bccdf93014435e87 to your computer and use it in GitHub Desktop.
Alaveteli Pro Sample Data – WARNING: Takes a few hours to run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/rails' | |
require 'factory_bot' | |
require Rails.root.join('spec', 'support', 'load_file_fixtures') | |
require Rails.root.join('spec', 'support', 'email_helpers') | |
RSpec.configure do |config| | |
config.fixture_path = "#{::Rails.root}/spec/fixtures" | |
end | |
factory_users = User.pluck(:id) - [1,2,3,4,5,6,7] | |
User.destroy_all(id: factory_users) | |
factory_bodies = (PublicBody.pluck(:id) - [1,2,3,4,5,6,7,8]) | |
PublicBody.destroy_all(id: factory_bodies) | |
RECORDS = [0,1,3,10,50] | |
users = FactoryGirl.create_list(:pro_user, 10) | |
bodies = PublicBody.all | |
users.each do |user| | |
# Public Requests | |
RECORDS.sample.times do | |
FactoryGirl.create(:info_request_with_incoming, user: user, public_body: bodies.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:attention_requested_request, user: user, public_body: bodies.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:requires_admin_request, user: user, public_body: bodies.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:successful_request, user: user, public_body: bodies.sample) | |
end | |
# Private Requests | |
RECORDS.sample.times do | |
FactoryGirl.create(:embargoed_request, user: user, public_body: bodies.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:embargo_expiring_request, user: user, public_body: bodies.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:overdue_request, user: user, public_body: bodies.sample) | |
end | |
# Comments | |
requests = InfoRequest.all | |
RECORDS.sample.times do | |
FactoryGirl.create(:visible_comment, user: user, info_request: requests.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:attention_requested, user: user, info_request: requests.sample) | |
end | |
RECORDS.sample.times do | |
FactoryGirl.create(:embargoed_comment, user: user, info_request: user.reload.info_requests.sample) | |
end | |
Comment.all.each do |comment| | |
comment.info_request.log_event("comment", { :comment_id => comment.id }) | |
end | |
end | |
# User making lots of batch requests | |
batch_user = FactoryGirl. | |
create(:pro_user, name: 'Batch User', | |
email: 'batch-user-1@example.com', | |
can_make_batch_requests: true, | |
no_limit: true) | |
30.times do |i| | |
draft = FactoryGirl.create(:draft_info_request_batch, | |
public_bodies: PublicBody.all, | |
user: batch_user) | |
batch = InfoRequestBatch.from_draft(draft) | |
example_info_request = batch.example_request | |
embargo = example_info_request.embargo | |
outgoing_message = example_info_request.outgoing_messages.first | |
batch.save! | |
draft.destroy! | |
batch.create_batch! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment