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

Independent cities #3603

Merged
merged 8 commits into from
May 30, 2023
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,4 @@ RUBY VERSION
ruby 3.1.2p20

BUNDLED WITH
2.4.12
2.4.13
4 changes: 2 additions & 2 deletions app/controllers/partners/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ class ProfilesController < BaseController
def show; end

def edit
@counties = County.all
@counties = County.in_category_name_order
@client_share_total = current_partner.profile.client_share_total
end

def update
@counties = County.all
@counties = County.in_category_name_order
result = PartnerProfileUpdateService.new(current_partner, partner_params, profile_params).call
if result.success?
flash[:success] = "Details were successfully updated."
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class ProfilesController < ApplicationController
def edit
@partner = current_organization.partners.find(params[:id])

@counties = County.all
@counties = County.in_category_name_order
@client_share_total = @partner.profile.client_share_total
end

def update
@counties = County.all
@counties = County.in_category_name_order
@partner = current_organization.partners.find(params[:id])
result = PartnerProfileUpdateService.new(@partner, edit_partner_params, edit_profile_params).call
if result.success?
Expand Down
7 changes: 7 additions & 0 deletions app/models/county.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
# Table name: counties
#
# id :bigint not null, primary key
# category :enum default("US_County"), not null
# name :string
# region :string
# created_at :datetime not null
# updated_at :datetime not null
#
class County < ApplicationRecord
has_many :served_areas, class_name: "Partners::ServedArea", dependent: :destroy

SORT_ORDER = %w[US_County Other]

def self.in_category_name_order
County.in_order_of(:category, SORT_ORDER).order(:name)
end
end
10 changes: 10 additions & 0 deletions db/migrate/20230523175242_add_category_to_counties.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddCategoryToCounties < ActiveRecord::Migration[7.0]
def change
safety_assured do
create_enum :category, ["US_County", "Other"]
change_table :counties do |t|
t.enum :category, enum_type: "category", default: "US_County", null: false
end
end
end
end
8 changes: 8 additions & 0 deletions db/migrate/20230523191422_trim_counties_region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class TrimCountiesRegion < ActiveRecord::Migration[7.0]
def change
County.find_each do |county|
county.region = county.region.strip
county.save!
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class LoadUSCountiesAndEquivalents < ActiveRecord::Migration[7.0]
def up
Rake::Task['db:load_us_counties'].invoke
end

def down
end
end
8 changes: 6 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_04_21_202218) do

ActiveRecord::Schema[7.0].define(version: 2023_05_23_192243) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

# Custom types defined in this database.
# Note that some types may not work with other database engines. Be careful if changing database.
create_enum "category", ["US_County", "Other"]

create_table "account_requests", force: :cascade do |t|
t.string "name", null: false
t.string "email", null: false
Expand Down Expand Up @@ -189,6 +192,7 @@
t.string "region"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.enum "category", default: "US_County", null: false, enum_type: "category"
t.index ["name", "region"], name: "index_counties_on_name_and_region", unique: true
t.index ["name"], name: "index_counties_on_name"
t.index ["region"], name: "index_counties_on_region"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3198,4 +3198,44 @@
"Zapata County, Texas", Texas
"Zavala County, Texas", Texas
"Ziebach County, South Dakota", South Dakota
"Other US County, other US region", other US region
"Other US County, other US region", other US region,Other
"Baltimore, Maryland", Maryland
"St. Louis, Missouri", Missouri
"Carson City, Nevada", Nevada
"Alexandria, Virginia", Virginia
"Bristol, Virginia", Virginia
"Buena Vista, Virginia", Virginia
"Charlottesville, Virginia", Virginia
"Chesapeake, Virginia", Virginia
"Colonial Heights, Virginia", Virginia
"Covington, Virginia", Virginia
"Danville, Virginia", Virginia
"Emporia, Virginia", Virginia
"Fairfax, Virginia", Virginia
"Falls Church, Virginia", Virginia
"Franklin, Virginia", Virginia
"Fredericksburg, Virginia", Virginia
"Galax, Virginia", Virginia
"Hampton, Virginia", Virginia
"Harrisonburg, Virginia", Virginia
"Hopewell, Virginia", Virginia
"Lexington, Virginia", Virginia
"Lynchburg, Virginia", Virginia
"Manassas, Virginia", Virginia
"Manassas Park, Virginia", Virginia
"Martinsville, Virginia", Virginia
"Newport News, Virginia", Virginia
"Norfolk, Virginia", Virginia
"Norton, Virginia", Virginia
"Petersburg, Virginia", Virginia
"Poquoson, Virginia", Virginia
"Portsmouth, Virginia", Virginia
"Radford, Virginia", Virginia
"Richmond, Virginia", Virginia
"Roanoke, Virginia", Virginia
"Salem, Virginia", Virginia
"Staunton, Virginia", Virginia
"Suffolk, Virginia", Virginia
"Virginia Beach, Virginia", Virginia
"Waynesboro, Virginia", Virginia
"Williamsburg, Virginia", Virginia
11 changes: 5 additions & 6 deletions lib/tasks/load_us_counties.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ require 'csv'
namespace :db do
desc "Load US Counties"
task :load_us_counties => :environment do
if County.none?
puts 'loading US counties. '
puts 'loading US counties and equivalents. '
counties = []
CSV.foreach("lib//assets//us_county_list.csv") do |row|
counties<< {name: row[0], region: row[1]}
CSV.foreach("lib//assets//us_county_and_equivalent_list.csv") do |row|
category = row[2] ? row[2].strip.presence : "US_County"
counties << { name: row[0], region: row[1].strip, category: category }
end
County.upsert_all( counties)
end
County.upsert_all( counties, unique_by: [:name, :region])
end
end
2 changes: 2 additions & 0 deletions spec/factories/counties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Table name: counties
#
# id :bigint not null, primary key
# category :enum default("US_County"), not null
# name :string
# region :string
# created_at :datetime not null
Expand All @@ -12,5 +13,6 @@
factory :county do
sequence(:name) { |n| "County #{n}" }
region { Faker::Address.state }
category { "US_County" }
end
end
1 change: 1 addition & 0 deletions spec/models/county_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Table name: counties
#
# id :bigint not null, primary key
# category :enum default("US_County"), not null
# name :string
# region :string
# created_at :datetime not null
Expand Down