Skip to content

Commit 72cf79f

Browse files
committed
use config for condition
1 parent b2afed9 commit 72cf79f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

app/policies/report_policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def reports_other_user?
2020
end
2121

2222
def receiver_available?
23-
ReportMailer.default_params.fetch(:to).present?
23+
CodeOcean::Config.new(:code_ocean).read.dig(:content_moderation, :report_emails).present?
2424
end
2525
end

spec/policies/report_policy_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
it 'dose not allow reports when no report email is configured' do
1616
user = build_stubbed(:external_user)
1717

18-
allow(ReportMailer).to receive(:default_params).and_return(ReportMailer.default_params.merge(to: []))
18+
codeocean_config = instance_double(CodeOcean::Config)
19+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
20+
allow(codeocean_config).to receive(:read).and_return({})
1921

2022
expect(policy).not_to permit(user, Comment.new)
2123
end
@@ -45,7 +47,9 @@
4547
it 'dose not allow reports when no report email is configured' do
4648
user = build_stubbed(:external_user)
4749

48-
allow(ReportMailer).to receive(:default_params).and_return(ReportMailer.default_params.merge(to: []))
50+
codeocean_config = instance_double(CodeOcean::Config)
51+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
52+
allow(codeocean_config).to receive(:read).and_return({})
4953

5054
expect(policy).not_to permit(user, Comment.new)
5155
end

0 commit comments

Comments
 (0)