Skip to content
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: 2 additions & 0 deletions app/controllers/addresses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class AddressesController < ApplicationController
end
2 changes: 2 additions & 0 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class OrganizationsController < ApplicationController
end
8 changes: 8 additions & 0 deletions app/models/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Address < ApplicationRecord
belongs_to :organization

validates :street, presence: true
validates :city, presence: true
validates :state, presence: true
validates :zip, presence: true
end
2 changes: 2 additions & 0 deletions app/models/facilitator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Facilitator < ApplicationRecord
has_one :user
has_many :facilitator_organizations, dependent: :restrict_with_exception
has_many :organizations, through: :facilitator_organizations

CONTACT_TYPES = ["Work", "Personal"].freeze
PERMITTED_PARAMS = [
Expand Down
4 changes: 4 additions & 0 deletions app/models/facilitator_organization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class FacilitatorOrganization < ApplicationRecord
belongs_to :facilitator
belongs_to :organization
end
9 changes: 9 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Organization < ApplicationRecord
has_many :addresses, dependent: :destroy
has_many :facilitator_organizations, dependent: :restrict_with_exception
has_many :facilitators, through: :facilitator_organizations

validates :name, presence: true
validates :agency_type, presence: true
validates :phone, presence: true
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
resources :users
resources :user_forms
resources :facilitators
resources :organizations

get 'reports/:id/edit_story', to: 'reports#edit_story', as: 'reports_edit_story'
put 'reports/update_story/:id', to: 'reports#update_story', as: 'reports_update_story'
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20250912174408_create_organizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreateOrganizations < ActiveRecord::Migration[6.1]
def change
create_table :organizations do |t|
t.string :name, null: false
t.boolean :is_active, default: true
t.date :start_date
t.date :close_date
t.string :website_url
t.string :agency_type, null: false
t.string :agency_type_other
t.string :phone, null: false
t.text :mission
t.string :project_id

t.timestamps
end
end
end
19 changes: 19 additions & 0 deletions db/migrate/20250912184522_create_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateAddresses < ActiveRecord::Migration[6.1]
def change
create_table :addresses do |t|
t.references :organization, null: false, foreign_key: true
t.string :street, null: false
t.string :city, null: false
t.string :state, null: false
t.string :zip, null: false
t.string :country
t.string :locality
t.string :county
t.integer :la_city_council_district
t.integer :la_supervisorial_district
t.integer :la_service_planning_area

t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20250913000000_create_facilitator_organizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateFacilitatorOrganizations < ActiveRecord::Migration[6.1]
def change
create_table :facilitator_organizations do |t|
t.references :facilitator, null: false, foreign_key: true
t.references :organization, null: false, foreign_key: true

t.timestamps
end

add_index :facilitator_organizations, [:facilitator_id, :organization_id],
unique: true, name: 'index_facilitator_organizations_on_ids'
end
end
48 changes: 47 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2025_09_13_171135) do
ActiveRecord::Schema.define(version: 2025_09_13_171135) do

create_table "addresses", charset: "utf8mb3", force: :cascade do |t|
t.bigint "organization_id", null: false
t.string "street", null: false
t.string "city", null: false
t.string "state", null: false
t.string "zip", null: false
t.string "country"
t.string "locality"
t.string "county"
t.integer "la_city_council_district"
t.integer "la_supervisorial_district"
t.integer "la_service_planning_area"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["organization_id"], name: "index_addresses_on_organization_id"
end

create_table "admins", id: :integer, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.datetime "created_at", precision: nil
t.datetime "current_sign_in_at", precision: nil
Expand Down Expand Up @@ -138,6 +156,16 @@
t.datetime "updated_at", null: false
end

create_table "facilitator_organizations", charset: "utf8mb3", force: :cascade do |t|
t.bigint "facilitator_id", null: false
t.bigint "organization_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["facilitator_id", "organization_id"], name: "index_facilitator_organizations_on_ids", unique: true
t.index ["facilitator_id"], name: "index_facilitator_organizations_on_facilitator_id"
t.index ["organization_id"], name: "index_facilitator_organizations_on_organization_id"
end

create_table "facilitators", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "city", null: false
t.string "country", null: false
Expand Down Expand Up @@ -285,6 +313,21 @@
t.datetime "updated_at", precision: nil, null: false
end

create_table "organizations", charset: "utf8mb3", force: :cascade do |t|
t.string "name", null: false
t.boolean "is_active", default: true
t.date "start_date"
t.date "close_date"
t.string "website_url"
t.string "agency_type", null: false
t.string "agency_type_other"
t.string "phone", null: false
t.text "mission"
t.string "project_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "permissions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.integer "legacy_id"
Expand Down Expand Up @@ -672,11 +715,14 @@
t.index ["windows_type_id"], name: "index_workshops_on_windows_type_id"
end

add_foreign_key "addresses", "organizations"
add_foreign_key "age_ranges", "windows_types"
add_foreign_key "bookmark_annotations", "bookmarks"
add_foreign_key "bookmarks", "users"
add_foreign_key "categories", "metadata"
add_foreign_key "event_registrations", "events"
add_foreign_key "facilitator_organizations", "facilitators"
add_foreign_key "facilitator_organizations", "organizations"
add_foreign_key "form_builders", "windows_types"
add_foreign_key "form_field_answer_options", "answer_options"
add_foreign_key "form_field_answer_options", "form_fields"
Expand Down
17 changes: 17 additions & 0 deletions spec/factories/addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FactoryBot.define do
factory :address do
association :organization

street { Faker::Address.street_address }
city { Faker::Address.city }
state { Faker::Address.state_abbr }
zip { Faker::Address.zip_code }

country { Faker::Address.country}
locality { ["LA City", "LA County", "Southern CA", "Northern CA", "Central CA", "Orange County", "Outside CA", "Outside USA"].sample }
county { Faker::Address.state }
la_city_council_district { Faker::Number.between(from: 1, to: 15) }
la_supervisorial_district { Faker::Number.between(from: 1, to: 5) }
la_service_planning_area { Faker::Number.between(from: 1, to: 8) }
end
end
6 changes: 6 additions & 0 deletions spec/factories/facilitators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
mailing_address_type { 'Personal' }
phone_number { Faker::PhoneNumber.phone_number }
phone_number_type { 'Personal' }

trait :with_organization do
after(:create) do |facilitator|
facilitator.organizations << create(:organization)
end
end
end
end
25 changes: 25 additions & 0 deletions spec/factories/organizations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FactoryBot.define do
factory :organization do
name { Faker::Company.name }
start_date { Faker::Date.between(from: 2.years.ago, to: 1.year.ago) }
close_date { nil }
website_url { Faker::Internet.url }
agency_type { ["Non-Profit", "Government", "For-Profit", "Other"].sample }
agency_type_other { nil }
phone { Faker::PhoneNumber.phone_number }
mission { Faker::Company.catch_phrase }
project_id { Faker::Number.number(digits: 4).to_s }

trait :with_facilitator do
after(:create) do |organization|
organization.facilitators << create(:facilitator)
end
end

trait :with_workshop do
after(:create) do |organization|
organization.workshops << create(:workshop)
end
end
end
end
71 changes: 71 additions & 0 deletions spec/models/address_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'rails_helper'

RSpec.describe Address, type: :model do
describe 'associations' do
it { should belong_to(:organization) }
end

describe 'validations' do
let(:address) { build(:address) }

it 'is valid with valid attributes' do
expect(address).to be_valid
end

it 'requires a street' do
address.street = nil
expect(address).not_to be_valid
expect(address.errors[:street]).to include("can't be blank")
end

it 'requires a city' do
address.city = nil
expect(address).not_to be_valid
expect(address.errors[:city]).to include("can't be blank")
end

it 'requires a state' do
address.state = nil
expect(address).not_to be_valid
expect(address.errors[:state]).to include("can't be blank")
end

it 'requires a zip' do
address.zip = nil
expect(address).not_to be_valid
expect(address.errors[:zip]).to include("can't be blank")
end

it 'requires an organization' do
address.organization = nil
expect(address).not_to be_valid
expect(address.errors[:organization]).to include("must exist")
end
end

describe 'optional fields' do
let(:address) { build(:address) }

it 'allows country to be nil' do
address.country = nil
expect(address).to be_valid
end

it 'allows locality to be nil' do
address.locality = nil
expect(address).to be_valid
end

it 'allows county to be nil' do
address.county = nil
expect(address).to be_valid
end

it 'allows LA-specific fields to be nil' do
address.la_city_council_district = nil
address.la_supervisorial_district = nil
address.la_service_planning_area = nil
expect(address).to be_valid
end
end
end
8 changes: 8 additions & 0 deletions spec/models/facilitator_organization_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rails_helper'

RSpec.describe FacilitatorOrganization, type: :model do
describe 'associations' do
it { should belong_to(:facilitator) }
it { should belong_to(:organization) }
end
end
2 changes: 2 additions & 0 deletions spec/models/facilitator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
RSpec.describe Facilitator, type: :model do
describe 'associations' do
it { should have_one(:user) }
it { should have_many(:facilitator_organizations).dependent(:restrict_with_exception) }
it { should have_many(:organizations).through(:facilitator_organizations) }
end

describe 'validations' do
Expand Down
Loading