Skip to content

Commit

Permalink
same_org? spec
Browse files Browse the repository at this point in the history
  • Loading branch information
thejonroberts committed Aug 26, 2024
1 parent 1ac966b commit 04054e0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions spec/policies/application_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:casa_admin) { build_stubbed(:casa_admin, casa_org: casa_org) }
let(:supervisor) { build_stubbed(:supervisor, casa_org: casa_org) }
let(:volunteer) { build_stubbed(:volunteer, casa_org: casa_org) }
let(:all_casa_admin) { build_stubbed(:all_casa_admin) }

permissions :see_reports_page? do
it "allows casa_admins" do
Expand Down Expand Up @@ -87,4 +88,47 @@
end
end
end

describe "#same_org?" do
let(:record) { double }

context "record with same casa_org" do
before { allow(record).to receive(:casa_org).and_return(casa_org) }

[:volunteer, :casa_admin, :supervisor].each do |user_type|
it "returns true for #{user_type}" do
user = send(user_type)
expect(subject.new(user, record).same_org?).to be true
end
end

context "all_casa_admin user" do
it "raises a no method error for all_casa_admin.casa_org" do
expect{ subject.new(all_casa_admin, record).same_org? }.to raise_error(NoMethodError)
end
end
end

context "record with different casa_org" do
before { allow(record).to receive(:casa_org).and_return(build_stubbed(:casa_org)) }

[:volunteer, :casa_admin, :supervisor].each do |user_type|
it "returns false for #{user_type}" do
user = send(user_type)
expect(subject.new(user, record).same_org?).to be false
end
end
end

context "called with a class instead of a record" do
let(:klass) { CasaCase }

[:volunteer, :casa_admin, :supervisor, :all_casa_admin].each do |user_type|
it "raises a no method error for #{user_type}" do
user = send(user_type)
expect { subject.new(user, klass).same_org? }.to raise_error(NoMethodError)
end
end
end
end
end

0 comments on commit 04054e0

Please sign in to comment.