Skip to content

Commit 078120b

Browse files
authored
Add avo_sign_as helper (#5045)
Solves #4791
1 parent 39ece2e commit 078120b

13 files changed

+50
-235
lines changed

test/application_system_test_case.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
44
include OauthHelpers
5+
include AvoHelpers
56
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
67
end

test/helpers/avo_helpers.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module AvoHelpers
2+
def avo_sign_in_as(user)
3+
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
4+
provider: "github",
5+
uid: "1",
6+
credentials: {
7+
token: user.oauth_token,
8+
expires: false
9+
},
10+
info: {
11+
name: user.login
12+
}
13+
)
14+
15+
@ip_address = create(:ip_address, ip_address: "127.0.0.1")
16+
17+
stub_github_info_request(user.info_data)
18+
19+
visit avo.root_path
20+
click_button "Log in with GitHub"
21+
22+
page.assert_text user.login
23+
end
24+
end

test/system/avo/events_test.rb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,8 @@ class Avo::EventsSystemTest < ApplicationSystemTestCase
55

66
include ActiveJob::TestHelper
77

8-
def sign_in_as(user)
9-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
10-
provider: "github",
11-
uid: "1",
12-
credentials: {
13-
token: user.oauth_token,
14-
expires: false
15-
},
16-
info: {
17-
name: user.login
18-
}
19-
)
20-
@ip_address = create(:ip_address, ip_address: "127.0.0.1")
21-
stub_github_info_request(user.info_data)
22-
23-
visit avo.root_path
24-
click_button "Log in with GitHub"
25-
26-
page.assert_text user.login
27-
end
28-
298
test "user events" do
30-
sign_in_as(create(:admin_github_user, :is_admin))
9+
avo_sign_in_as(create(:admin_github_user, :is_admin))
3110

3211
visit avo.root_path
3312
click_link "Events user events"
@@ -46,7 +25,7 @@ def sign_in_as(user)
4625
end
4726

4827
test "rubygem events" do
49-
sign_in_as(create(:admin_github_user, :is_admin))
28+
avo_sign_in_as(create(:admin_github_user, :is_admin))
5029

5130
visit avo.root_path
5231
click_link "Events rubygem events"

test/system/avo/manual_changes_test.rb

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,9 @@
33
class Avo::ManualChangesSystemTest < ApplicationSystemTestCase
44
make_my_diffs_pretty!
55

6-
def sign_in_as(user)
7-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
8-
provider: "github",
9-
uid: "1",
10-
credentials: {
11-
token: user.oauth_token,
12-
expires: false
13-
},
14-
info: {
15-
name: user.login
16-
}
17-
)
18-
19-
stub_github_info_request(user.info_data)
20-
21-
visit avo.root_path
22-
click_button "Log in with GitHub"
23-
24-
page.assert_text user.login
25-
end
26-
276
test "auditing changes" do
287
admin_user = create(:admin_github_user, :is_admin)
29-
sign_in_as admin_user
8+
avo_sign_in_as admin_user
309

3110
Admin::LogTicketPolicy.any_instance.stubs(:avo_create?).returns(true)
3211
Admin::LogTicketPolicy.any_instance.stubs(:avo_update?).returns(true)

test/system/avo/oidc_api_key_roles_test.rb

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,9 @@
33
class Avo::OIDCApiKeyRolesSystemTest < ApplicationSystemTestCase
44
make_my_diffs_pretty!
55

6-
def sign_in_as(user)
7-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
8-
provider: "github",
9-
uid: "1",
10-
credentials: {
11-
token: user.oauth_token,
12-
expires: false
13-
},
14-
info: {
15-
name: user.login
16-
}
17-
)
18-
19-
stub_github_info_request(user.info_data)
20-
21-
visit avo.root_path
22-
click_button "Log in with GitHub"
23-
24-
page.assert_text user.login
25-
end
26-
276
test "manually changing roles" do
287
admin_user = create(:admin_github_user, :is_admin)
29-
sign_in_as admin_user
8+
avo_sign_in_as admin_user
309

3110
provider = create(:oidc_provider)
3211
user = create(:user)

test/system/avo/oidc_providers_test.rb

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,9 @@
33
class Avo::OIDCProvidersSystemTest < ApplicationSystemTestCase
44
make_my_diffs_pretty!
55

6-
def sign_in_as(user)
7-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
8-
provider: "github",
9-
uid: "1",
10-
credentials: {
11-
token: user.oauth_token,
12-
expires: false
13-
},
14-
info: {
15-
name: user.login
16-
}
17-
)
18-
19-
stub_github_info_request(user.info_data)
20-
21-
visit avo.root_path
22-
click_button "Log in with GitHub"
23-
24-
page.assert_text user.login
25-
end
26-
276
test "refreshing provider" do
287
admin_user = create(:admin_github_user, :is_admin)
29-
sign_in_as admin_user
8+
avo_sign_in_as admin_user
309

3110
provider = create(:oidc_provider, issuer: "https://token.actions.githubusercontent.com", configuration: nil, jwks: nil)
3211

test/system/avo/rubygems_test.rb

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,9 @@ class Avo::RubygemsSystemTest < ApplicationSystemTestCase
55

66
include ActiveJob::TestHelper
77

8-
def sign_in_as(user)
9-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
10-
provider: "github",
11-
uid: "1",
12-
credentials: {
13-
token: user.oauth_token,
14-
expires: false
15-
},
16-
info: {
17-
name: user.login
18-
}
19-
)
20-
21-
create(:ip_address, ip_address: "127.0.0.1")
22-
23-
stub_github_info_request(user.info_data)
24-
25-
visit avo.root_path
26-
click_button "Log in with GitHub"
27-
28-
page.assert_text user.login
29-
end
30-
318
test "release reserved namespace" do
329
admin_user = create(:admin_github_user, :is_admin)
33-
sign_in_as admin_user
10+
avo_sign_in_as admin_user
3411

3512
rubygem = create(:rubygem, created_at: 40.days.ago)
3613
rubygem_attributes = rubygem.attributes.with_indifferent_access
@@ -88,7 +65,7 @@ def sign_in_as(user)
8865
test "Yank a rubygem" do
8966
Minitest::Test.make_my_diffs_pretty!
9067
admin_user = create(:admin_github_user, :is_admin)
91-
sign_in_as admin_user
68+
avo_sign_in_as admin_user
9269

9370
security_user = create(:user, email: "[email protected]")
9471
rubygem = create(:rubygem)
@@ -163,7 +140,7 @@ def sign_in_as(user)
163140

164141
test "Yank all version of rubygem" do
165142
admin_user = create(:admin_github_user, :is_admin)
166-
sign_in_as admin_user
143+
avo_sign_in_as admin_user
167144

168145
security_user = create(:user, email: "[email protected]")
169146
rubygem = create(:rubygem)
@@ -252,7 +229,7 @@ def sign_in_as(user)
252229

253230
test "add owner" do
254231
admin_user = create(:admin_github_user, :is_admin)
255-
sign_in_as admin_user
232+
avo_sign_in_as admin_user
256233

257234
security_user = create(:user, email: "[email protected]")
258235
rubygem = create(:rubygem)
@@ -332,7 +309,7 @@ def sign_in_as(user)
332309

333310
test "upload versions file" do
334311
admin_user = create(:admin_github_user, :is_admin)
335-
sign_in_as admin_user
312+
avo_sign_in_as admin_user
336313

337314
visit avo.resources_rubygems_path
338315

@@ -353,7 +330,7 @@ def sign_in_as(user)
353330

354331
test "upload names file" do
355332
admin_user = create(:admin_github_user, :is_admin)
356-
sign_in_as admin_user
333+
avo_sign_in_as admin_user
357334

358335
visit avo.resources_rubygems_path
359336

@@ -374,7 +351,7 @@ def sign_in_as(user)
374351

375352
test "upload info file" do
376353
admin_user = create(:admin_github_user, :is_admin)
377-
sign_in_as admin_user
354+
avo_sign_in_as admin_user
378355

379356
version = create(:version)
380357
visit avo.resources_rubygem_path(version.rubygem)

test/system/avo/sendgrid_events_test.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,9 @@
33
class Avo::SendgridEventsSystemTest < ApplicationSystemTestCase
44
include ActiveJob::TestHelper
55

6-
def sign_in_as(user)
7-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
8-
provider: "github",
9-
uid: "1",
10-
credentials: {
11-
token: user.oauth_token,
12-
expires: false
13-
},
14-
info: {
15-
name: user.login
16-
}
17-
)
18-
stub_github_info_request(user.info_data)
19-
20-
visit avo.root_path
21-
click_button "Log in with GitHub"
22-
23-
page.assert_text user.login
24-
end
25-
266
test "search for event" do
277
user = FactoryBot.create(:admin_github_user, :is_admin)
28-
sign_in_as(user)
8+
avo_sign_in_as(user)
299

3010
visit avo.resources_sendgrid_events_path
3111

test/system/avo/users_test.rb

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,10 @@ class Avo::UsersSystemTest < ApplicationSystemTestCase
55

66
include ActiveJob::TestHelper
77

8-
def sign_in_as(user)
9-
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
10-
provider: "github",
11-
uid: "1",
12-
credentials: {
13-
token: user.oauth_token,
14-
expires: false
15-
},
16-
info: {
17-
name: user.login
18-
}
19-
)
20-
@ip_address = create(:ip_address, ip_address: "127.0.0.1")
21-
stub_github_info_request(user.info_data)
22-
23-
visit avo.root_path
24-
click_button "Log in with GitHub"
25-
26-
page.assert_text user.login
27-
end
28-
298
test "reset mfa" do
309
Minitest::Test.make_my_diffs_pretty!
3110
admin_user = create(:admin_github_user, :is_admin)
32-
sign_in_as admin_user
11+
avo_sign_in_as admin_user
3312

3413
user = create(:user)
3514
user.enable_totp!(ROTP::Base32.random_base32, :ui_and_api)
@@ -102,7 +81,7 @@ def sign_in_as(user)
10281
test "block user" do
10382
Minitest::Test.make_my_diffs_pretty!
10483
admin_user = create(:admin_github_user, :is_admin)
105-
sign_in_as admin_user
84+
avo_sign_in_as admin_user
10685

10786
user = create(:user)
10887
user.enable_totp!(ROTP::Base32.random_base32, :ui_and_api)
@@ -200,7 +179,7 @@ def sign_in_as(user)
200179
test "reset api key" do
201180
perform_enqueued_jobs do
202181
admin_user = create(:admin_github_user, :is_admin)
203-
sign_in_as admin_user
182+
avo_sign_in_as admin_user
204183

205184
user = create(:user)
206185
user_attributes = user.attributes.with_indifferent_access
@@ -267,7 +246,7 @@ def sign_in_as(user)
267246

268247
test "Yank rubygems" do
269248
admin_user = create(:admin_github_user, :is_admin)
270-
sign_in_as admin_user
249+
avo_sign_in_as admin_user
271250
security_user = create(:user, email: "[email protected]")
272251

273252
ownership = create(:ownership)
@@ -366,7 +345,7 @@ def sign_in_as(user)
366345

367346
test "yank user" do
368347
admin_user = create(:admin_github_user, :is_admin)
369-
sign_in_as admin_user
348+
avo_sign_in_as admin_user
370349
security_user = create(:user, email: "[email protected]")
371350

372351
user = create(:user)
@@ -510,7 +489,7 @@ def sign_in_as(user)
510489
test "change user email" do
511490
perform_enqueued_jobs do
512491
admin_user = create(:admin_github_user, :is_admin)
513-
sign_in_as admin_user
492+
avo_sign_in_as admin_user
514493

515494
user = create(:user)
516495
user_attributes = user.attributes.with_indifferent_access
@@ -588,7 +567,7 @@ def sign_in_as(user)
588567

589568
test "create user" do
590569
admin_user = create(:admin_github_user, :is_admin)
591-
sign_in_as admin_user
570+
avo_sign_in_as admin_user
592571

593572
visit avo.resources_users_path
594573

0 commit comments

Comments
 (0)