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 authored and elasticspoon committed Aug 10, 2024
1 parent fddbc40 commit 5424aa9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,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 @@ -739,6 +747,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 5424aa9

Please sign in to comment.