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
6 changes: 6 additions & 0 deletions app/controllers/casa_orgs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class CasaOrgsController < ApplicationController
before_action :authenticate_user!, :must_be_admin
before_action :set_casa_org, only: %i[edit update]
before_action :set_contact_type_data, only: %i[edit update]
before_action :set_hearing_types, only: %i[edit update]
before_action :must_be_admin
before_action :require_organization!

Expand Down Expand Up @@ -35,4 +37,8 @@ def set_contact_type_data
@contact_type_groups = @casa_org.contact_type_groups
@contact_types = ContactType.for_organization(@casa_org)
end

def set_hearing_types
@hearing_types = HearingType.for_organization(@casa_org)
end
end
43 changes: 43 additions & 0 deletions app/controllers/hearing_types_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class HearingTypesController < ApplicationController
before_action :authenticate_user!, :must_be_admin
before_action :set_hearing_type, except: [:new, :create]

def new
@hearing_type = HearingType.new
end

def create
@hearing_type = HearingType.new(hearing_type_params)

respond_to do |format|
if @hearing_type.save
format.html { redirect_to edit_casa_org_path(current_organization), notice: "Hearing Type was successfully created." }
else
format.html { render :new }
end
end
end

def edit
end

def update
if @hearing_type.update(hearing_type_params)
redirect_to edit_casa_org_path(current_organization), notice: "Hearing Type was successfully updated."
else
render :edit
end
end

private

def set_hearing_type
@hearing_type = HearingType.find(params[:id])
end

def hearing_type_params
params.require(:hearing_type).permit(:name, :active).merge(
casa_org: current_organization
)
end
end
24 changes: 24 additions & 0 deletions app/models/hearing_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class HearingType < ApplicationRecord
has_paper_trail

belongs_to :casa_org

validates :name, presence: true, uniqueness: { scope: %i[casa_org] }
validates :active, presence: true

scope :for_organization, ->(org) { where(casa_org: org) }
end

# == Schema Information
#
# Table name: hearing_types
#
# id :bigint not null, primary key
# active :boolean default(TRUE), not null
# name :string not null
# casa_org_id :bigint not null
#
# Indexes
#
# index_hearing_types_on_casa_org_id (casa_org_id)
#
1 change: 1 addition & 0 deletions app/views/casa_orgs/_contact_types.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</td>
<td scope="row">
<%= contact_type.active? ? "Yes" : "No" %>
</td>
<td>
<%= link_to "Edit", edit_contact_type_path(contact_type) %>
</td>
Expand Down
32 changes: 32 additions & 0 deletions app/views/casa_orgs/_hearing_types.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="row">
<div class="col-sm-12 dashboard-table-header pt-2 pb-2">
<h3>Hearing Types</h3>
<%= link_to "New Hearing Type", new_hearing_type_path, class: "btn btn-primary" %>
</div>
</div>

<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>

<tbody>
<% @hearing_types.each do |hearing_type| %>
<tr id="hearing_type-<%= hearing_type.id %>">
<td scope="row">
<%= hearing_type.name %>
</td>
<td scope="row">
<%= hearing_type.active %>
</td>
<td>
<%= link_to "Edit", edit_hearing_type_path(hearing_type) %>
</td>
</tr>
<% end %>
</tbody>
</table>
8 changes: 8 additions & 0 deletions app/views/casa_orgs/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@
<%= render "contact_types" %>
</div>
</div>

<h1 class="pt-5">Manage Court Details</h1>

<div class="card card-container">
<div class="card-body">
<%= render "hearing_types" %>
Comment thread
haydenrou marked this conversation as resolved.
</div>
</div>
22 changes: 22 additions & 0 deletions app/views/hearing_types/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= link_to 'Back', :back %>

<h1><%= title %></h1>

<div class="card card-container">
<div class="card-body">
<%= form_with(model: hearing_type, local: true) do |form| %>
<%= render "/shared/error_messages", resource: hearing_type %>
<div class="field form-group">
<%= form.label :name %>
<%= form.text_field :name, class: "form-control" %>
</div>
<div class="field form-group">
<%= form.check_box :active %>
<%= form.label :active %>
</div>
<div class="actions">
<%= form.submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/hearing_types/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form", locals: { title: "Edit Hearing Type", hearing_type: @hearing_type } %>
1 change: 1 addition & 0 deletions app/views/hearing_types/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "form", locals: { title: "New Hearing Type", hearing_type: @hearing_type } %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
resources :casa_orgs, only: %i[edit update]
resources :contact_type_groups, only: %i[new create edit update]
resources :contact_types, only: %i[new create edit update]
resources :hearing_types, only: %i[new create edit update]

resources :supervisors, except: %i[destroy]
resources :supervisor_volunteers, only: %i[create] do
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20201005191326_create_hearing_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateHearingTypes < ActiveRecord::Migration[6.0]
def change
create_table :hearing_types do |t|
t.references :casa_org, null: false
t.string :name, null: false
t.boolean :active, null: false, default: true
end
end
end
9 changes: 8 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.define(version: 2020_10_04_165322) do
ActiveRecord::Schema.define(version: 2020_10_05_191326) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -125,6 +125,13 @@
t.index ["contact_type_group_id"], name: "index_contact_types_on_contact_type_group_id"
end

create_table "hearing_types", force: :cascade do |t|
t.bigint "casa_org_id", null: false
t.string "name", null: false
t.boolean "active", default: true, null: false
t.index ["casa_org_id"], name: "index_hearing_types_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
7 changes: 7 additions & 0 deletions spec/factories/hearing_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :hearing_type do
casa_org { create(:casa_org) }
name { "Emergency Hearing" }
active { true }
end
end
7 changes: 7 additions & 0 deletions spec/models/hearing_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "rails_helper"

RSpec.describe HearingType, type: :model do
it { is_expected.to belong_to(:casa_org) }
it { is_expected.to validate_presence_of(:active) }
it { is_expected.to validate_presence_of(:name) }
end
27 changes: 27 additions & 0 deletions spec/system/create_hearing_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "rails_helper"

RSpec.describe "Create Hearing Type Spec", type: :system do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org_id: organization.id) }
let(:hearing_type) { create(:hearing_type, casa_org: organization, name: "Spec Test Hearing Type") }

before do
sign_in admin

visit new_hearing_type_path
end

it "errors with invalid name" do
fill_in "Name", with: ""
click_on "Submit"

expect(page).to have_text("Name can't be blank")
end

it "creates with valid data" do
fill_in "Name", with: "Emergency Hearing Type"
click_on "Submit"

expect(page).to have_text("Hearing Type was successfully created.")
end
end
23 changes: 23 additions & 0 deletions spec/system/edit_casa_org_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "rails_helper"

RSpec.describe "Edit Casa Org", type: :system do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org_id: organization.id) }
let!(:hearing_type) { create(:hearing_type, casa_org: organization, name: "Spec Test Hearing Type") }

before do
sign_in admin

visit edit_casa_org_path(organization)
end

it "loads casa org edit page" do
expect(page).to have_text "Editing CASA Organization"
expect(page).to_not have_text "sign in before continuing"
end

it "has hearing types content" do
expect(page).to have_text("Spec Test Hearing Type")
expect(page).to have_text(hearing_type.name)
end
end