Skip to content

Commit

Permalink
Create Standard Court Order per organization basis [#5781]
Browse files Browse the repository at this point in the history
  • Loading branch information
dalmaboros committed Jun 19, 2024
1 parent 7635f19 commit 3c4d569
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/models/standard_court_order.rb
Original file line number Diff line number Diff line change
@@ -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)
#
10 changes: 10 additions & 0 deletions db/migrate/20240619005250_create_standard_court_orders.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 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.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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/standard_court_orders.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/models/standard_court_order_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3c4d569

Please sign in to comment.