Skip to content

Commit

Permalink
feat: added drafts page for supes and admins (rubyforgood#6002)
Browse files Browse the repository at this point in the history
* feat: added drafts page for supes and admins

* feat: add tests
  • Loading branch information
elasticspoon authored Aug 21, 2024
1 parent 8ec0e37 commit 70d011f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
6 changes: 1 addition & 5 deletions app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index
def drafts
authorize CaseContact

@case_contacts = case_contact_drafts
@case_contacts = current_organization.case_contacts.not_active
end

def new
Expand Down Expand Up @@ -116,10 +116,6 @@ def additional_expense_params
@additional_expense_params ||= AdditionalExpenseParamsService.new(params).calculate
end

def case_contact_drafts
CaseContact.where(creator: current_user).not_active
end

def set_case_contact
if current_organization.case_contacts.exists?(params[:id])
@case_contact = authorize(current_organization.case_contacts.find(params[:id]))
Expand Down
2 changes: 1 addition & 1 deletion app/policies/case_contact_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def additional_expenses_allowed?
alias_method :index?, :admin_or_supervisor_or_volunteer?
alias_method :new?, :admin_or_supervisor_or_volunteer?
alias_method :show?, :is_creator_or_casa_admin?
alias_method :drafts?, :admin_or_supervisor_or_volunteer?
alias_method :drafts?, :admin_or_supervisor?
alias_method :update?, :is_creator_or_supervisor_or_casa_admin?
alias_method :edit?, :is_creator_or_supervisor_or_casa_admin?
alias_method :restore?, :is_admin?
Expand Down
1 change: 1 addition & 0 deletions app/views/case_contacts/drafts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "case_contacts/case_contact", collection: @case_contacts, as: :contact %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
end

get "case_contacts/leave", to: "case_contacts#leave", as: "leave_case_contacts_form"
get "case_contacts/drafts", to: "case_contacts#drafts"
resources :case_contacts, except: %i[create update show] do
member do
post :restore
Expand Down
2 changes: 1 addition & 1 deletion spec/policies/case_contact_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
end
end

permissions :update? do
permissions :update?, :drafts? do
it "allows casa_admins" do
is_expected.to permit(casa_admin, case_contact)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/requests/case_contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@
it { is_expected.to have_http_status(:redirect) }
end

describe "GET /drafts" do
subject(:request) do
get case_contacts_drafts_path

response
end

it { is_expected.to have_http_status(:success) }

context "when user is volunteer" do
before { sign_in volunteer }

it { is_expected.to have_http_status(:redirect) }
end
end

describe "DELETE /destroy" do
let(:case_contact) { create(:case_contact) }

Expand Down
27 changes: 27 additions & 0 deletions spec/system/case_contacts/drafts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "rails_helper"

RSpec.describe "case_contacts/drafts", js: true, type: :system do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org: organization) }

context "with case contacts" do
let!(:casa_case) { create(:casa_case, casa_org: organization) }
let!(:other_org_case) { create(:case_contact, notes: "NOTE_A") }
let!(:past_contact) { create(:case_contact, casa_case: casa_case, occurred_at: 3.weeks.ago, notes: "NOTE_B") }
let!(:past_contact_draft) { create(:case_contact, :started_status, casa_case: casa_case, occurred_at: 3.weeks.ago, notes: "NOTE_C") }
let!(:recent_contact) { create(:case_contact, casa_case: casa_case, occurred_at: 3.days.ago, notes: "NOTE_D") }
let!(:recent_contact_draft) { create(:case_contact, :started_status, casa_case: casa_case, occurred_at: 3.days.ago, notes: "NOTE_E") }

it "shows only same orgs drafts" do
sign_in admin

visit case_contacts_drafts_path

expect(page).to_not have_content("NOTE_A")
expect(page).to_not have_content("NOTE_B")
expect(page).to have_content("NOTE_C")
expect(page).to_not have_content("NOTE_D")
expect(page).to have_content("NOTE_E")
end
end
end

0 comments on commit 70d011f

Please sign in to comment.