Skip to content

Commit 9c0419b

Browse files
committed
stub authorization in request test
1 parent 541631a commit 9c0419b

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

spec/request/request_for_comments_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
RSpec.describe 'POST /request_for_comments/:rfc_id/report', type: :request do
66
before do
7+
login_as(create(:learner))
78
codeocean_config = instance_double(CodeOcean::Config)
89
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
910
allow(codeocean_config).to receive(:read).and_return({
@@ -12,9 +13,6 @@
1213
end
1314

1415
it 'sends an email to let admins know about the report' do
15-
user = create(:learner)
16-
password = attributes_for(:learner).fetch(:password)
17-
login_as(user, password)
1816
rfc = create(:rfc)
1917

2018
expect { post(report_request_for_comment_path(rfc)) }

spec/support/authentication.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def sign_in(user, password)
77
end
88

99
module RequestLoginHelper
10-
def login_as(user, password)
11-
post(sessions_url, params: {email: user.email, password:})
10+
def login_as(user)
11+
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user)
1212
end
1313
end
1414

0 commit comments

Comments
 (0)