Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions #30

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run RSpec tests
on: [push]
jobs:
run-rspec-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
# Not needed with a .ruby-version file
ruby-version: 3.3.1
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true
- name: Set up database
env:
RAILS_ENV: test
VAPID_PUBLIC_KEY: BCUWtDYeou4CLLwWUu44NylAkAkPYNobTJ7wuWhvjBb0YF4JhJAT_GeUrOjJvoXvcTO4ehmeCHyP0QH2mS5cyj4 # testing only
VAPID_PRIVATE_KEY: WE83Oc3c1GaC08gcEM2YKddtTpx0DdrjEfTHONVqR0s # testing only
SWAY_DATABASE_PASSWORD: testing123! # testing only
run: | # multi-line run command: https://stackoverflow.com/a/66809682/6410635
bundle exec rails db:create
bundle exec rails db:migrate
bundle exec rails db:schema:load
bundle exec rails db:seed
- name: Run tests
env:
RAILS_ENV: test
VAPID_PUBLIC_KEY: BCUWtDYeou4CLLwWUu44NylAkAkPYNobTJ7wuWhvjBb0YF4JhJAT_GeUrOjJvoXvcTO4ehmeCHyP0QH2mS5cyj4 # testing only
VAPID_PRIVATE_KEY: WE83Oc3c1GaC08gcEM2YKddtTpx0DdrjEfTHONVqR0s # testing only
SWAY_DATABASE_PASSWORD: testing123! # testing only
run: | # multi-line run command: https://stackoverflow.com/a/66809682/6410635
bundle exec rspec
29 changes: 0 additions & 29 deletions .github/workflows/tauri-build.yml

This file was deleted.

124 changes: 0 additions & 124 deletions .github/workflows/tauri-publish.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
!/storage/seeds/data/locales.json
!/storage/seeds/data/united_states/congress
!/storage/seeds/data/united_states/maryland/baltimore
!/storage/geojson/baltimore-maryland-united_states.geojson
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep
Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ GEM
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
net-http
faraday_curl (0.0.2)
faraday (>= 0.9.0)
ffi (1.16.3)
geocoder (1.8.3)
base64 (>= 0.1.0)
Expand Down Expand Up @@ -520,7 +518,6 @@ DEPENDENCIES
factory_bot_rails
faker
faraday
faraday_curl
geocoder
google-cloud-storage (~> 1.51)
hotwire-livereload (~> 1.3)
Expand Down
2 changes: 1 addition & 1 deletion app/models/sway_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def find_or_create_by_normalized!(**kwargs)
end

sig { returns(T::Boolean) }
def is_congress?
def congress?
city_name == 'congress' && region_name == 'congress'
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def sway_locales

sig { returns(T.nilable(SwayLocale)) }
def default_sway_locale
sway_locales.filter { |s| !s.is_congress? }.first || sway_locales.first
sway_locales.filter { |s| !s.congress? }.first || sway_locales.first
end

sig { params(sway_locale: SwayLocale).returns(T::Array[UserLegislator]) }
Expand Down
2 changes: 1 addition & 1 deletion app/services/congress_legislator_vote_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(bill_id)

sig { void }
def run
nil unless @bill.sway_locale.is_congress?
nil unless @bill.sway_locale.congress?

senate
house
Expand Down
2 changes: 1 addition & 1 deletion lib/sway_geocode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class << self

sig { params(sway_locale: SwayLocale, address: Address).returns(T.any(Congress, Local)) }
def build(sway_locale, address)
sway_locale.is_congress? ? Congress.new(address) : Local.new(sway_locale, address)
sway_locale.congress? ? Congress.new(address) : Local.new(sway_locale, address)
end

class Congress
Expand Down
8 changes: 4 additions & 4 deletions spec/models/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
end

describe '#sway_locale' do
context 'what an address accesses its sway_locale' do
context 'when an address accesses its sway_locale' do
let(:address) do
Address.new(
street: Faker::Address.street_address(include_secondary: false),
Expand All @@ -70,10 +70,10 @@

it 'returns a SwayLocale, creating it if necessary' do
start_sway_locale_count = SwayLocale.count
sway_locales = address.sway_locales
end_sway_locale_count = start_sway_locale_count + 2
address.sway_locales
end_sway_locale_count = start_sway_locale_count + 2 # local + state, congress is created by seeds

expect(SwayLocale.count).to equal end_sway_locale_count
expect(SwayLocale.count).to eql(end_sway_locale_count)

expect(address.sway_locales.present?).to be_truthy

Expand Down
15 changes: 8 additions & 7 deletions spec/services/congress_legislator_vote_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
expect(LegislatorVote.count).to eql(0)

address = build(:address, region_code: 'MD')
sway_locale = build(

sway_locale = SwayLocale.default_locale.presence || build(
:sway_locale,
CONGRESS
)

district = build(:district, sway_locale:)

senator = build(:legislator, address:, district:, title: 'Sen.', external_id: 'V000128', first_name: 'Chris',
last_name: 'Van Hollen')
representative = build(:legislator, address:, district:, first_name: 'Kweisi', last_name: 'Mfume',
external_id: 'M000687', title: 'Rep.')
senator = Legislator.find_by(external_id: 'V000128').presence || build(:legislator, address:, district:, title: 'Sen.', external_id: 'V000128', first_name: 'Chris',
last_name: 'Van Hollen')
representative = Legislator.find_by(external_id: 'M000687').presence || build(:legislator, address:, district:, first_name: 'Kweisi', last_name: 'Mfume',
external_id: 'M000687', title: 'Rep.')

bill = build(:bill, sway_locale:, external_id: 'hr815')
bill = Bill.find_by(external_id: 'hr815').presence || create(:bill, sway_locale:, external_id: 'hr815')
create(:vote, bill:)

expect(LegislatorVote.count).to eql(2)
expect(LegislatorVote.count).to eql(510)
expect(LegislatorVote.where(legislator: senator).first&.support).to eql('FOR')
expect(LegislatorVote.where(legislator: representative).first&.support).to eql('FOR')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/services/sway_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
postal_code: '21202')
_user_address = create(:user_address, user:, address:)

address.sway_locales.filter { |s| s.is_congress? || s.has_geojson? }.each do |s|
address.sway_locales.filter { |s| s.congress? || s.has_geojson? }.each do |s|
sway_registration_service = SwayRegistrationService.new(
user,
address,
Expand All @@ -38,7 +38,7 @@
postal_code: '21202')
_invited_user_user_address = create(:user_address, user: invited_user, address: invited_user_address)

address.sway_locales.filter { |s| s.is_congress? || s.has_geojson? }.each_with_index do |s, i|
address.sway_locales.filter { |s| s.congress? || s.has_geojson? }.each_with_index do |s, i|
allow_any_instance_of(Census::Congress).to receive(:request).and_return(congress_json)

sway_registration_service = SwayRegistrationService.new(
Expand Down
21 changes: 21 additions & 0 deletions storage/geojson/baltimore-maryland-united_states.geojson

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions storage/seeds/data/locales.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"id": -1,
"city": "baltimore",
"region": "maryland",
"regionCode": "MD",
"country": "united_states",
"districts": [
"MD0",
"MD1",
"MD2",
"MD3",
"MD4",
"MD5",
"MD6",
"MD7",
"MD8",
"MD9",
"MD10",
"MD11",
"MD12",
"MD13",
"MD14"
],
"name": "baltimore-maryland-united_states",
"icon_path": "logo.svg",
"currentSessionStartDateISO": "2020-12-10",
"time_zone": "America/New_York"
},
{
"id": -1,
"city": "congress",
"region": "congress",
"regionCode": "",
"country": "united_states",
"districts": [],
"name": "congress-congress-united_states",
"currentSessionStartDateISO": "2021-01-03",
"time_zone": "America/New_York",
"icon_path": "logo.svg"
}
]
Loading