Skip to content

Commit

Permalink
reduce number of policy spec runs (same specs)
Browse files Browse the repository at this point in the history
  • Loading branch information
thejonroberts committed Oct 10, 2024
1 parent 570d7f3 commit 8c70ea0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 55 deletions.
34 changes: 18 additions & 16 deletions spec/policies/additional_expense_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,42 +85,44 @@
context "when user is a visitor" do
let(:user) { nil }

it { is_expected.not_to include(additional_expense) }
it { is_expected.not_to include(other_org_additional_expense) }
it "returns no expenses" do
is_expected.not_to include(additional_expense, other_org_additional_expense)
end
end

context "when user is a volunteer" do
let(:user) { volunteer }

it { is_expected.to include(additional_expense) }
it { is_expected.to include(draft_additional_expense) }
it { is_expected.not_to include(same_case_volunteer_additional_expense) }
it { is_expected.not_to include(other_org_additional_expense) }
it "includes expenses for contacts created by volunteer only" do
is_expected.to include(additional_expense, draft_additional_expense)
is_expected.not_to include(same_case_volunteer_additional_expense, other_org_additional_expense)
end
end

context "when user is a supervisor" do
let(:user) { supervisor }

it { is_expected.to include(additional_expense) }
it { is_expected.to include(draft_additional_expense) }
it { is_expected.to include(same_case_volunteer_additional_expense) }
it { is_expected.not_to include(other_org_additional_expense) }
it "includes same org expenses only" do
is_expected.to include(additional_expense, draft_additional_expense, same_case_volunteer_additional_expense)
is_expected.not_to include(other_org_additional_expense)
end
end

context "when user is a casa_admin" do
let(:user) { casa_admin }

it { is_expected.to include(additional_expense) }
it { is_expected.to include(draft_additional_expense) }
it { is_expected.to include(same_case_volunteer_additional_expense) }
it { is_expected.not_to include(other_org_additional_expense) }
it "includes same org expenses only" do
is_expected.to include(additional_expense, draft_additional_expense, draft_additional_expense)
is_expected.not_to include(other_org_additional_expense)
end
end

context "when user is an all_casa_admin" do
let(:user) { all_casa_admin }

it { is_expected.not_to include(additional_expense) }
it { is_expected.not_to include(other_org_additional_expense) }
it "returns no expenses" do
is_expected.not_to include(additional_expense, other_org_additional_expense)
end
end
end
end
45 changes: 23 additions & 22 deletions spec/policies/case_contact_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,49 +210,50 @@
context "when user is a visitor" do
let(:user) { nil }

it { is_expected.not_to include(case_contact) }
it { is_expected.not_to include(other_org_case_contact) }
it "returns no case contacts" do
is_expected.not_to include(case_contact, other_org_case_contact)
end
end

context "when user is a volunteer" do
let(:user) { volunteer }

it { is_expected.to include(case_contact) }
it { is_expected.to include(draft_case_contact) }

it { is_expected.not_to include(same_case_volunteer_case_contact) }
it { is_expected.not_to include(unassigned_case_case_contact) }
it { is_expected.not_to include(other_org_case_contact) }
it "returns case contacts created by the volunteer" do
is_expected.to include(case_contact, draft_case_contact)
is_expected
.not_to include(same_case_volunteer_case_contact, unassigned_case_case_contact, other_org_case_contact)
end
end

context "when user is a supervisor" do
let(:user) { supervisor }

it { is_expected.to include(case_contact) }
it { is_expected.to include(draft_case_contact) }
it { is_expected.to include(same_case_volunteer_case_contact) }
# should supervisors see contacts for volunteers they are not assigned to?
it { is_expected.to include(unassigned_case_case_contact) }
it "returns same org case contacts" do
is_expected
.to include(case_contact, draft_case_contact, same_case_volunteer_case_contact, unassigned_case_case_contact)
is_expected.not_to include(other_org_case_contact)

it { is_expected.not_to include(other_org_case_contact) }
pending "should supervisors see contacts for volunteers they are not assigned to?"
is_expected.not_to include(unassigned_case_case_contact)
end
end

context "when user is a casa_admin" do
let(:user) { casa_admin }

it { is_expected.to include(case_contact) }
it { is_expected.to include(draft_case_contact) }
it { is_expected.to include(same_case_volunteer_case_contact) }
it { is_expected.to include(unassigned_case_case_contact) }

it { is_expected.not_to include(other_org_case_contact) }
it "returns same org case contacts" do
is_expected
.to include(case_contact, draft_case_contact, same_case_volunteer_case_contact, unassigned_case_case_contact)
is_expected.not_to include(other_org_case_contact)
end
end

context "when user is an all_casa_admin" do
let(:user) { create :all_casa_admin }

it { is_expected.not_to include(case_contact) }
it { is_expected.not_to include(other_org_case_contact) }
it "returns no case contacts" do
is_expected.not_to include(case_contact, other_org_case_contact)
end
end
end
end
42 changes: 25 additions & 17 deletions spec/policies/contact_topic_answer_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
let(:other_org_contact_topic) { create :contact_topic, casa_org: other_org }
let(:other_org_casa_case) { create :casa_case, casa_org: other_org }
let(:other_org_case_contact) { create :case_contact, casa_case: other_org_casa_case, creator: other_org_volunteer }
let(:other_org_contact_topic_answer) { create :contact_topic_answer, case_contact: other_org_case_contact, contact_topic: other_org_contact_topic }
let(:other_org_contact_topic_answer) do
create :contact_topic_answer, case_contact: other_org_case_contact, contact_topic: other_org_contact_topic
end

subject { described_class }

Expand All @@ -50,13 +52,15 @@
is_expected.to permit(supervisor, contact_topic_answer)
is_expected.to permit(supervisor, draft_contact_topic_answer)
is_expected.to permit(supervisor, same_case_volunteer_contact_topic_answer)

is_expected.not_to permit(supervisor, other_org_contact_topic_answer)
end

it "permits same org casa admins" do
is_expected.to permit(casa_admin, contact_topic_answer)
is_expected.to permit(casa_admin, draft_contact_topic_answer)
is_expected.to permit(casa_admin, same_case_volunteer_contact_topic_answer)

is_expected.not_to permit(casa_admin, other_org_contact_topic_answer)
end

Expand All @@ -78,42 +82,46 @@
context "when user is a visitor" do
let(:user) { nil }

it { is_expected.not_to include(contact_topic_answer) }
it { is_expected.not_to include(other_org_contact_topic_answer) }
it "returns no contact topic answers" do
is_expected.not_to include(contact_topic_answer, other_org_contact_topic_answer)
end
end

context "when user is a volunteer" do
let(:user) { volunteer }

it { is_expected.to include(contact_topic_answer) }
it { is_expected.to include(draft_contact_topic_answer) }
it { is_expected.not_to include(same_case_volunteer_contact_topic_answer) }
it { is_expected.not_to include(other_org_contact_topic_answer) }
it "returns contact topic answers of contacts created by the volunteer" do
is_expected.to include(contact_topic_answer, draft_contact_topic_answer)
is_expected.not_to include(same_case_volunteer_contact_topic_answer, other_org_contact_topic_answer)
end
end

context "when user is a supervisor" do
let(:user) { supervisor }

it { is_expected.to include(contact_topic_answer) }
it { is_expected.to include(draft_contact_topic_answer) }
it { is_expected.to include(same_case_volunteer_contact_topic_answer) }
it { is_expected.not_to include(other_org_contact_topic_answer) }
it "returns same org contact topic answers" do
is_expected
.to include(contact_topic_answer, draft_contact_topic_answer, same_case_volunteer_contact_topic_answer)
is_expected.not_to include(other_org_contact_topic_answer)
end
end

context "when user is a casa_admin" do
let(:user) { casa_admin }

it { is_expected.to include(contact_topic_answer) }
it { is_expected.to include(draft_contact_topic_answer) }
it { is_expected.to include(same_case_volunteer_contact_topic_answer) }
it { is_expected.not_to include(other_org_contact_topic_answer) }
it "includes same org contact topic answers" do
is_expected
.to include(contact_topic_answer, draft_contact_topic_answer, same_case_volunteer_contact_topic_answer)
is_expected.not_to include(other_org_contact_topic_answer)
end
end

context "when user is an all_casa_admin" do
let(:user) { all_casa_admin }

it { is_expected.not_to include(contact_topic_answer) }
it { is_expected.not_to include(other_org_contact_topic_answer) }
it "returns no contact topic answers" do
is_expected.not_to include(contact_topic_answer, other_org_contact_topic_answer)
end
end
end
end

0 comments on commit 8c70ea0

Please sign in to comment.