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

Create placement_type and placement with models #4702

Merged
merged 1 commit into from
Mar 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
26 changes: 26 additions & 0 deletions app/models/placement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Placement < ApplicationRecord
belongs_to :placement_type
belongs_to :creator, class_name: "User"
end

# == Schema Information
#
# Table name: placements
#
# id :bigint not null, primary key
# placement_started_at :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# creator_id :bigint not null
# placement_type_id :bigint not null
#
# Indexes
#
# index_placements_on_creator_id (creator_id)
# index_placements_on_placement_type_id (placement_type_id)
#
# Foreign Keys
#
# fk_rails_... (creator_id => users.id)
# fk_rails_... (placement_type_id => placement_types.id)
#
23 changes: 23 additions & 0 deletions app/models/placement_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class PlacementType < ApplicationRecord
belongs_to :casa_org
validates :name, presence: true
end

# == Schema Information
#
# Table name: placement_types
#
# id :bigint not null, primary key
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
# casa_org_id :bigint not null
#
# Indexes
#
# index_placement_types_on_casa_org_id (casa_org_id)
#
# Foreign Keys
#
# fk_rails_... (casa_org_id => casa_orgs.id)
#
9 changes: 9 additions & 0 deletions db/migrate/20230326225216_create_placement_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreatePlacementTypes < ActiveRecord::Migration[7.0]
def change
create_table :placement_types do |t|
t.string :name, null: false
t.references :casa_org, null: false, foreign_key: true
t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20230326225230_create_placements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreatePlacements < ActiveRecord::Migration[7.0]
def change
create_table :placements do |t|
# Add table placement_type: name, casa_org_id. Add table placement: placement_id, casa_case_id, started_at, created_by_id (links to user table)
t.datetime :placement_started_at, null: false
t.references :placement_type, null: false, foreign_key: true
t.references :creator, foreign_key: {to_table: :users}, null: false
t.timestamps
end
end
end
23 changes: 22 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

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

Expand Down Expand Up @@ -420,6 +420,24 @@
t.index ["patch_note_type_id"], name: "index_patch_notes_on_patch_note_type_id"
end

create_table "placement_types", force: :cascade do |t|
t.string "name", null: false
t.bigint "casa_org_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["casa_org_id"], name: "index_placement_types_on_casa_org_id"
end

create_table "placements", force: :cascade do |t|
t.datetime "placement_started_at", null: false
t.bigint "placement_type_id", null: false
t.bigint "creator_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["creator_id"], name: "index_placements_on_creator_id"
t.index ["placement_type_id"], name: "index_placements_on_placement_type_id"
end

create_table "preference_sets", force: :cascade do |t|
t.bigint "user_id"
t.jsonb "case_volunteer_columns", default: "{}", null: false
Expand Down Expand Up @@ -549,6 +567,9 @@
add_foreign_key "other_duties", "users", column: "creator_id"
add_foreign_key "patch_notes", "patch_note_groups"
add_foreign_key "patch_notes", "patch_note_types"
add_foreign_key "placement_types", "casa_orgs"
add_foreign_key "placements", "placement_types"
add_foreign_key "placements", "users", column: "creator_id"
add_foreign_key "preference_sets", "users"
add_foreign_key "sent_emails", "casa_orgs"
add_foreign_key "sent_emails", "users"
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/placement_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :placement_type do
sequence(:name) { |n| "Placement Type #{n}" }
casa_org
end
end
7 changes: 7 additions & 0 deletions spec/factories/placements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :placement do
placement_type
placement_started_at { DateTime.now }
creator { association :user }
end
end
8 changes: 8 additions & 0 deletions spec/models/placement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "rails_helper"

RSpec.describe Placement, type: :model do
let!(:object) { create(:placement) }

it { is_expected.to belong_to(:placement_type) }
it { is_expected.to belong_to(:creator) }
end
8 changes: 8 additions & 0 deletions spec/models/placement_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "rails_helper"

RSpec.describe PlacementType, type: :model do
let!(:object) { create(:placement_type) }

it { is_expected.to validate_presence_of(:name) }
it { is_expected.to belong_to(:casa_org) }
end