diff --git a/Makefile b/Makefile index 79a392930..05c276f8b 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ do-import-spreadsheets: import-data: 496 497 A-Contributions B1-Loans B2-Loans C-Contributions \ D-Expenditure E-Expenditure F-Expenses F461P5-Expenditure F465P3-Expenditure \ F496P3-Contributions G-Expenditure H-Loans I-Contributions Summary - echo 'CREATE TABLE "calculations" (id SERIAL PRIMARY KEY, subject_id integer, subject_type varchar(30), name varchar(40), value jsonb);' | psql $(DATABASE_NAME) + echo 'CREATE TABLE IF NOT EXISTS "calculations" (id SERIAL PRIMARY KEY, subject_id integer, subject_type varchar(30), name varchar(40), value jsonb);' | psql $(DATABASE_NAME) ./bin/remove_duplicate_transactions ./bin/make_view diff --git a/spec/calculators/candidate_opposing_expenditures_spec.rb b/spec/calculators/candidate_opposing_expenditures_spec.rb index 198cb785a..afb8e2a2f 100644 --- a/spec/calculators/candidate_opposing_expenditures_spec.rb +++ b/spec/calculators/candidate_opposing_expenditures_spec.rb @@ -5,7 +5,7 @@ RSpec.describe CandidateOpposingExpenditure do describe 'For 2016 candidate Dan Kalb' do let(:dan_kalb) do - OaklandCandidate.create( + Candidate.create( election_name: 'oakland-2016', Candidate: 'Dan Kalb', Committee_Name: 'Re-Elect Dan Kalb Oakland City Council 2016', diff --git a/spec/calculators/candidate_supporting_expenditures_spec.rb b/spec/calculators/candidate_supporting_expenditures_spec.rb index f5b43b855..c14002e7f 100644 --- a/spec/calculators/candidate_supporting_expenditures_spec.rb +++ b/spec/calculators/candidate_supporting_expenditures_spec.rb @@ -3,7 +3,7 @@ RSpec.describe CandidateSupportingExpenditure do describe 'for Huber Trenado' do let(:huber_trenado) do - OaklandCandidate.create( + Candidate.create( election_name: 'oakland-2016', Candidate: 'Huber Trenado', Committee_Name: 'Huber Trenado for OUSD School Board 2016', @@ -24,7 +24,7 @@ subject { huber_trenado.calculation(:total_supporting_independent) } it 'calculates the correct value' do - expect(subject).to eq(99_288.96) + expect(subject).to be_within(0.1).of(99_288.96) end end @@ -32,7 +32,7 @@ before do import_test_case('spec/fixtures/deduplicate_460_497_within_1_day_of_deadline') - OaklandCommittee.create( + Committee.create( Filer_ID: '1331137', Filer_NamL: 'FAMILIES AND EDUCATORS FOR PUBLIC EDUCATION, SPONSORED BY GREAT OAKLAND PUBLIC SCHOOLS', ) @@ -41,7 +41,7 @@ end let(:candidate) do - OaklandCandidate.create( + Candidate.create( election_name: 'oakland-2018', Office: 'OUSD District 4', Candidate: 'Gary Yee', @@ -56,7 +56,7 @@ subject { candidate.calculation(:support_list).first } it 'does not duplicate between 460 and 496' do - expect(subject['Total']).to eq(56_394.73) + expect(subject['Total']).to be_within(0.1).of(56_394.73) end end end diff --git a/spec/calculators/referendum_contributions_by_origin_spec.rb b/spec/calculators/referendum_contributions_by_origin_spec.rb index c607c1a1c..74c8f8f66 100644 --- a/spec/calculators/referendum_contributions_by_origin_spec.rb +++ b/spec/calculators/referendum_contributions_by_origin_spec.rb @@ -8,14 +8,20 @@ # these committees need to be created before the test is run, but after the # test case is imported - OaklandCommittee.create( + Election.create( + name: 'oakland-2016', + location: 'Oakland', + date: '2016-11-06', + title: 'Oakland Test Election', + ) + Committee.create( Ballot_Measure_Election: 'oakland-2016', Filer_ID: '1385949', Filer_NamL: 'Causa Justa :: Just Cause (nonprofit 501(c)(3))', Ballot_Measure: 'JJ', Support_Or_Oppose: 'S' ) - OaklandCommittee.create( + Committee.create( Ballot_Measure_Election: 'oakland-2016', Filer_ID: '1364564', Filer_NamL: 'Committee to Protect Oakland Renters - Yes on Measure JJ, sponsored by labor and community organizations', @@ -27,7 +33,7 @@ end let(:ballot_measure) do - OaklandReferendum.create( + Referendum.create( election_name: 'oakland-2016', Measure_number: 'JJ', Short_Title: 'Just Cause for Eviction and Rent Adjustment' diff --git a/spec/calculators/referendum_supporters_calculator_spec.rb b/spec/calculators/referendum_supporters_calculator_spec.rb index 80e74253a..73f281e14 100644 --- a/spec/calculators/referendum_supporters_calculator_spec.rb +++ b/spec/calculators/referendum_supporters_calculator_spec.rb @@ -7,14 +7,20 @@ before do import_test_case('spec/fixtures/deduplicate_committee_expenses') - OaklandCommittee.create( + Election.create( + name: 'oakland-june-2018', + location: 'Oakland', + date: '2018-06-01', + title: 'Oakland Test Election', + ) + Committee.create( Filer_ID: '1400467', Filer_NamL: 'Protect Oakland Libraries - Yes on D 2018', Ballot_Measure: 'D', Support_Or_Oppose: 'S' ) - OaklandNameToNumber.create( + NameToNumber.create( election_name: 'oakland-june-2018', Measure_Name: 'Supporting a parcel tax measure for the Oakland Public Library on a 2018 ballot.', Measure_Number: 'D', @@ -24,7 +30,7 @@ end let(:ballot_measure) do - OaklandReferendum.create( + Referendum.create( election_name: 'oakland-june-2018', Measure_number: 'D', Short_Title: 'Library Parcel Tax' @@ -45,7 +51,13 @@ before do import_test_case('spec/fixtures/referendum_supporters_without_expenditures_are_included') - OaklandCommittee.create( + Election.create( + name: 'oakland-2018', + location: 'Oakland', + date: '2016-11-06', + title: 'Oakland Test Election', + ) + Committee.create( Filer_ID: '1410941', Filer_NamL: 'Committee for Better Choices, No on Measure AA', Ballot_Measure: 'AA', @@ -57,7 +69,7 @@ end let(:ballot_measure) do - OaklandReferendum.create( + Referendum.create( election_name: 'oakland-2018', Measure_number: 'AA', Short_Title: "Oakland Children's Initiative", diff --git a/spec/calculators/total_contributions_calculator_spec.rb b/spec/calculators/total_contributions_calculator_spec.rb index 2f796e5e4..d95537ae3 100644 --- a/spec/calculators/total_contributions_calculator_spec.rb +++ b/spec/calculators/total_contributions_calculator_spec.rb @@ -4,7 +4,7 @@ RSpec.describe TotalContributionsCalculator do let(:cat_brooks) do - OaklandCandidate.create( + Candidate.create( election_name: 'oakland-2018', Candidate: 'Cat Brooks', Committee_Name: 'Sheilagh Polk “Cat Brooks” for Mayor 2018', diff --git a/spec/helpers/import_test_case.rb b/spec/helpers/import_test_case.rb index 54652cf02..8912e6733 100644 --- a/spec/helpers/import_test_case.rb +++ b/spec/helpers/import_test_case.rb @@ -6,14 +6,17 @@ def import_test_case(path) # reset db `env DATABASE_NAME=#{database_name} make dropdb createdb` + raise "Test setup failed. You might need to install the `build-essential` package." unless $?.success? # copy over schema puts 'Copying over schema...' `pg_dump --clean --if-exists --no-owner --schema-only disclosure-backend | psql #{database_name}` + raise "Test setup failed. You might need to install Postgresql command line binaries." unless $?.success? # import tables puts "Importing test case in #{path}..." `env CSV_PATH=#{path} DATABASE_NAME=#{database_name} make import-data` + raise "Test setup failed. You might need to install python dependencies." unless $?.success? ActiveRecord::Base.establish_connection "postgresql:///#{database_name}" end