From 3c4d569e324ebea68e9c916c93b697a94210e285 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Tue, 18 Jun 2024 20:23:41 -0500 Subject: [PATCH] Create Standard Court Order per organization basis [#5781] --- app/models/standard_court_order.rb | 24 +++++++++++++++++++ ...0619005250_create_standard_court_orders.rb | 10 ++++++++ db/schema.rb | 11 ++++++++- spec/factories/standard_court_orders.rb | 6 +++++ spec/models/standard_court_order_spec.rb | 14 +++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 app/models/standard_court_order.rb create mode 100644 db/migrate/20240619005250_create_standard_court_orders.rb create mode 100644 spec/factories/standard_court_orders.rb create mode 100644 spec/models/standard_court_order_spec.rb diff --git a/app/models/standard_court_order.rb b/app/models/standard_court_order.rb new file mode 100644 index 0000000000..9233e7583f --- /dev/null +++ b/app/models/standard_court_order.rb @@ -0,0 +1,24 @@ +class StandardCourtOrder < ApplicationRecord + belongs_to :casa_org + + validates :value, uniqueness: {scope: :casa_org_id, case_sensitive: false}, presence: true +end + +# == Schema Information +# +# Table name: standard_court_orders +# +# id :bigint not null, primary key +# value :string +# created_at :datetime not null +# updated_at :datetime not null +# casa_org_id :bigint not null +# +# Indexes +# +# index_standard_court_orders_on_casa_org_id (casa_org_id) +# +# Foreign Keys +# +# fk_rails_... (casa_org_id => casa_orgs.id) +# diff --git a/db/migrate/20240619005250_create_standard_court_orders.rb b/db/migrate/20240619005250_create_standard_court_orders.rb new file mode 100644 index 0000000000..870d6b029a --- /dev/null +++ b/db/migrate/20240619005250_create_standard_court_orders.rb @@ -0,0 +1,10 @@ +class CreateStandardCourtOrders < ActiveRecord::Migration[7.1] + def change + create_table :standard_court_orders do |t| + t.string :value + t.references :casa_org, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 54347dcdbd..f188a7cd87 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_31_172823) do +ActiveRecord::Schema[7.1].define(version: 2024_06_19_005250) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -597,6 +597,14 @@ t.datetime "updated_at", null: false end + create_table "standard_court_orders", force: :cascade do |t| + t.string "value" + 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_standard_court_orders_on_casa_org_id" + end + create_table "supervisor_volunteers", force: :cascade do |t| t.bigint "supervisor_id", null: false t.bigint "volunteer_id", null: false @@ -729,6 +737,7 @@ add_foreign_key "preference_sets", "users" add_foreign_key "sent_emails", "casa_orgs" add_foreign_key "sent_emails", "users" + add_foreign_key "standard_court_orders", "casa_orgs" add_foreign_key "supervisor_volunteers", "users", column: "supervisor_id" add_foreign_key "supervisor_volunteers", "users", column: "volunteer_id" add_foreign_key "user_reminder_times", "users" diff --git a/spec/factories/standard_court_orders.rb b/spec/factories/standard_court_orders.rb new file mode 100644 index 0000000000..f30869ded2 --- /dev/null +++ b/spec/factories/standard_court_orders.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :standard_court_order do + value { "Some standard court order" } + casa_org { CasaOrg.first || create(:casa_org) } + end +end diff --git a/spec/models/standard_court_order_spec.rb b/spec/models/standard_court_order_spec.rb new file mode 100644 index 0000000000..d6780b1a87 --- /dev/null +++ b/spec/models/standard_court_order_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe StandardCourtOrder, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:casa_org) } + end + + describe 'validations' do + subject { FactoryBot.build(:standard_court_order) } + + it { is_expected.to validate_presence_of(:value) } + it { is_expected.to validate_uniqueness_of(:value).scoped_to(:casa_org_id).case_insensitive } + end +end