-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple Netfile Agencies
First steps of #75. * Remove hardcoding of "COAK" Netfile agency and replace with a table that stores agencies * Create database columns to keep track of which subscribers are subscribed to which Netfile agencies * Create database columns to keep track of which filings came from which Netfile agencies * Update alert mailer to only show subscribers the filings from their agency
- Loading branch information
Showing
23 changed files
with
185 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ | |
/yarn-error.log | ||
yarn-debug.log* | ||
.yarn-integrity | ||
.idea |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class NetfileAgency < ApplicationRecord | ||
def self.create_supported_agencies | ||
find_or_create_by(netfile_id: 13, shortcut: 'COAK', name: 'Oakland, City of') | ||
find_or_create_by(netfile_id: 52, shortcut: 'SFO', name: 'San Francisco Ethics Commission') | ||
end | ||
|
||
def self.coak | ||
@_coak ||= find_by(shortcut: 'COAK') | ||
end | ||
|
||
def self.sfo | ||
@_sfo ||= find_by(shortcut: 'SFO') | ||
end | ||
|
||
def self.each_supported_agency(&block) | ||
block.call(coak) | ||
block.call(sfo) | ||
end | ||
|
||
def self.by_netfile_id(id) | ||
@_by_id ||= all.index_by(&:netfile_id) | ||
@_by_id.fetch(id) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class AddAgencyIdToFilings < ActiveRecord::Migration[7.0] | ||
def up | ||
create_table :netfile_agencies do |t| | ||
t.integer :netfile_id | ||
t.string :shortcut | ||
t.string :name | ||
|
||
t.index :netfile_id, unique: true | ||
t.index :shortcut, unique: true | ||
end | ||
|
||
oakland = NetfileAgency.create(netfile_id: 13, shortcut: 'COAK', name: 'Oakland, City of') | ||
_sf = NetfileAgency.create(netfile_id: 52, shortcut: 'SFO', name: 'San Francisco Ethics Commission') | ||
|
||
change_table :filings do |t| | ||
t.references :netfile_agency, default: oakland.id | ||
end | ||
|
||
change_table :alert_subscribers do |t| | ||
t.references :netfile_agency, default: oakland.id | ||
end | ||
end | ||
|
||
def down | ||
remove_reference :netfile_filings, :agency | ||
remove_reference :netfile_alert_subscribers, :agency | ||
drop_table :netfile_agencies | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
let!(:alert_subscriber) do | ||
AlertSubscriber.create!( | ||
email: '[email protected]', | ||
confirmed_at: Time.now | ||
confirmed_at: Time.now, | ||
netfile_agency: NetfileAgency.coak | ||
) | ||
end | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
expect(subscriber.token).to be_present | ||
expect(subscriber.confirmed_at).to be_nil | ||
expect(subscriber.unsubscribed_at).to be_nil | ||
expect(subscriber.netfile_agency).to eq(NetfileAgency.coak) | ||
end | ||
|
||
it 'sends a AlertSubscriberMailer.confirm email' do | ||
|
@@ -53,7 +54,7 @@ | |
end | ||
|
||
describe '#edit' do | ||
let(:alert_subscriber) { AlertSubscriber.create(email: '[email protected]') } | ||
let(:alert_subscriber) { AlertSubscriber.create(email: '[email protected]', netfile_agency: NetfileAgency.coak) } | ||
let(:request_token) { nil } | ||
|
||
subject { get :edit, params: { id: alert_subscriber.id, token: request_token } } | ||
|
@@ -72,7 +73,7 @@ | |
end | ||
|
||
describe '#destroy' do | ||
let!(:alert_subscriber) { AlertSubscriber.create(email: '[email protected]') } | ||
let!(:alert_subscriber) { AlertSubscriber.create(email: '[email protected]', netfile_agency: NetfileAgency.coak) } | ||
let(:request_token) { nil } | ||
|
||
subject { post :destroy, params: { id: alert_subscriber.id, token: request_token } } | ||
|
@@ -99,7 +100,7 @@ | |
describe '#confirm' do | ||
render_views | ||
|
||
let!(:alert_subscriber) { AlertSubscriber.create(email: '[email protected]') } | ||
let!(:alert_subscriber) { AlertSubscriber.create(email: '[email protected]', netfile_agency: NetfileAgency.coak) } | ||
let(:request_token) { nil } | ||
|
||
subject { post :confirm, params: { id: alert_subscriber.id, token: request_token } } | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
let(:subscriber) do | ||
AlertSubscriber.create( | ||
email: '[email protected]', | ||
confirmed_at: Time.now | ||
confirmed_at: Time.now, | ||
netfile_agency: NetfileAgency.coak, | ||
) | ||
end | ||
let!(:admin_user) { AdminUser.create(email: '[email protected]', password: 'secretpassword') } | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'rails_helper' | ||
|
||
describe DisclosureEmailer do | ||
describe '#send_email' do | ||
let(:today) { Date.parse('2022-10-01') } | ||
let(:subscribed_agency) { NetfileAgency.coak } | ||
let(:filing_agency) { NetfileAgency.coak } | ||
let!(:subscriber) do | ||
AlertSubscriber.create( | ||
email: '[email protected]', | ||
confirmed_at: Time.now, | ||
netfile_agency: subscribed_agency, | ||
) | ||
end | ||
let(:filed_at) { today.beginning_of_day.change(hour: 10) } | ||
let!(:filing) { Filing.create(filer_id: 123, filed_at: filed_at, form: 30, netfile_agency: filing_agency) } | ||
let!(:valid_filing) { Filing.create(filer_id: 123, filed_at: today.beginning_of_day.change(hour: 10), form: 30, netfile_agency: subscribed_agency) } | ||
|
||
subject { described_class.new(today).send_email } | ||
|
||
before do | ||
allow(AlertMailer).to receive(:daily_alert).and_return(double(deliver_now: nil)) | ||
allow_any_instance_of(DisclosureEmailer).to receive(:puts) | ||
end | ||
|
||
context 'with a filing for the appropriate date and agency' do | ||
it 'includes that filing' do | ||
subject | ||
expect(AlertMailer) | ||
.to have_received(:daily_alert) | ||
.with(subscriber, today, include(filing), anything) | ||
end | ||
end | ||
|
||
context 'when the filing is for a different date' do | ||
let(:filed_at) { today - 1.day } | ||
|
||
it 'excludes the filing' do | ||
subject | ||
expect(AlertMailer) | ||
.to have_received(:daily_alert) | ||
.with(subscriber, today, exclude(filing), anything) | ||
end | ||
end | ||
|
||
context 'when the filing is for a different agency' do | ||
let(:filing_agency) { NetfileAgency.sfo } | ||
|
||
it 'excludes the filing' do | ||
subject | ||
expect(AlertMailer) | ||
.to have_received(:daily_alert) | ||
.with(subscriber, today, exclude(filing), anything) | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.