-
-
Notifications
You must be signed in to change notification settings - Fork 531
Create hearing types per organization #1000
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1b6036
CRUD for hearing types
haydenrou 22394da
add specs for hearing types
haydenrou b02bc02
amend name of hearing type factory
haydenrou 9b67488
Merge branch 'master' into create-hearing-types
haydenrou b353672
add feature specs for hearing types
haydenrou 6ec22e2
Merge branch 'create-hearing-types' of github.com:haydenrou/casa into…
haydenrou 6054d95
fix specs
haydenrou 433f9b7
Merge remote-tracking branch 'main/master' into create-hearing-types
haydenrou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.