Skip to content

Commit

Permalink
fix: topic policy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticspoon committed Feb 21, 2024
1 parent d847305 commit 6e216d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def same_org?
case record
when CasaOrg
user.casa_org == record
when CasaAdmin, CasaCase, Volunteer, Supervisor, HearingType, ContactTypeGroup
when CasaAdmin, CasaCase, Volunteer, Supervisor, HearingType, ContactTypeGroup, ContactTopic
user.casa_org == record.casa_org
when CourtDate, CaseContact
user.casa_org == record&.casa_case&.casa_org
Expand Down
19 changes: 6 additions & 13 deletions app/policies/contact_topic_policy.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
# TODO: I have no clue what the policy should be
class ContactTopicPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end

alias_method :create?, :is_admin?
alias_method :destroy?, :is_admin?
alias_method :edit?, :is_admin?
alias_method :new?, :is_admin?
alias_method :show?, :is_admin?
alias_method :update?, :is_admin?
alias_method :create?, :is_admin_same_org?
alias_method :destroy?, :is_admin_same_org?
alias_method :edit?, :is_admin_same_org?
alias_method :new?, :is_admin_same_org?
alias_method :show?, :is_admin_same_org?
alias_method :update?, :is_admin_same_org?
end
11 changes: 7 additions & 4 deletions spec/policies/contact_topic_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

RSpec.describe ContactTopicPolicy, type: :policy do
subject { described_class }
# let(:contact_topic){build(:contact_topic, casa_org: organization)}
let(:contact_topic) { build(:contact_topic, casa_org: organization) }

let(:organization) { build(:casa_org) }
let(:casa_admin) { build(:casa_admin, casa_org: organization) }
let(:casa_admin) { create(:casa_admin, casa_org: organization) }
let(:volunteer) { build(:volunteer, casa_org: organization) }
let(:supervisor) { build(:supervisor, casa_org: organization) }

# permissions :edit? do
permissions :create?, :edit?, :new?, :show?, :destroy?, :update? do
it "allows same org casa_admins" do
is_expected.to permit(casa_admin)
is_expected.to permit(casa_admin, contact_topic)
end

it "does not permit supervisor" do
is_expected.to_not permit(supervisor)
is_expected.to_not permit(supervisor, contact_topic)
end

it "does not permit volunteer" do
is_expected.to_not permit(volunteer)
is_expected.to_not permit(volunteer, contact_topic)
end
end
end
8 changes: 4 additions & 4 deletions spec/requests/contact_topics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# adjust the attributes here as well.
let(:casa_org) { create(:casa_org) }
let(:is_active) { nil }
let(:contact_topic) { create(:contact_topic) }
let(:contact_topic) { create(:contact_topic, casa_org:) }
let(:attributes) { {casa_org_id: casa_org.id} }
let(:admin) { create(:casa_admin, casa_org:) }
let(:admin) { create(:casa_admin, casa_org: casa_org) }
let(:contact_topic_question) { build(:contact_topic_question) }
let(:contact_topic_detail) { build(:contact_topic_detail) }

Expand Down Expand Up @@ -81,7 +81,7 @@

describe "PATCH /update" do
context "with valid parameters" do
let!(:contact_topic) { create(:contact_topic) }
let!(:contact_topic) { create(:contact_topic, casa_org:) }

let(:new_attributes) do
{
Expand Down Expand Up @@ -124,7 +124,7 @@
end

describe "DELETE /destroy" do
let!(:contact_topic) { create(:contact_topic) }
let!(:contact_topic) { create(:contact_topic, casa_org: casa_org) }
it "does not destroy the requested contact_topic" do
expect do
delete contact_topic_url(contact_topic)
Expand Down

0 comments on commit 6e216d3

Please sign in to comment.