Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
* We had removed the "Oakland" prefix from our tables/models some time
ago
* The Election object is joined in some places, we need to create it in
order for much data to show up
* The calculations table gets copied over or already exists somehow? I
didn't investigate but it seems fine to not create it if it already
exists.
* Added a couple better error messages
  • Loading branch information
tdooner committed Feb 26, 2020
1 parent 0066dfa commit 38103e3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/calculators/candidate_opposing_expenditures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions spec/calculators/candidate_supporting_expenditures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -24,15 +24,15 @@
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

describe 'deduplicating 496 expenditures with 460 within a day of the deadline' do
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',
)
Expand All @@ -41,7 +41,7 @@
end

let(:candidate) do
OaklandCandidate.create(
Candidate.create(
election_name: 'oakland-2018',
Office: 'OUSD District 4',
Candidate: 'Gary Yee',
Expand All @@ -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
12 changes: 9 additions & 3 deletions spec/calculators/referendum_contributions_by_origin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand Down
22 changes: 17 additions & 5 deletions spec/calculators/referendum_supporters_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand All @@ -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',
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion spec/calculators/total_contributions_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions spec/helpers/import_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 38103e3

Please sign in to comment.