diff --git a/test/integration/gems_test.rb b/test/integration/gems_test.rb index 4a16312365f..362838d64aa 100644 --- a/test/integration/gems_test.rb +++ b/test/integration/gems_test.rb @@ -66,181 +66,4 @@ class GemsTest < ActionDispatch::IntegrationTest assert_response :success end -end - -class GemsSystemTest < SystemTest - setup do - @user = create(:user) - @rubygem = create(:rubygem, name: "sandworm", number: "1.0.0") - @version = create(:version, rubygem: @rubygem, number: "1.1.1") - end - - test "version navigation" do - visit rubygem_version_path(@rubygem.slug, "1.0.0") - click_link "Next version →" - - assert_equal page.current_path, rubygem_version_path(@rubygem.slug, "1.1.1") - click_link "← Previous version" - - assert_equal page.current_path, rubygem_version_path(@rubygem.slug, "1.0.0") - end - - test "subscribe to a gem" do - visit rubygem_path(@rubygem.slug, as: @user.id) - - assert page.has_css?("a#subscribe") - - click_link "Subscribe" - - assert page.has_content? "Unsubscribe" - assert_equal @user.subscribed_gems.first, @rubygem - end - - test "unsubscribe to a gem" do - create(:subscription, rubygem: @rubygem, user: @user) - - visit rubygem_path(@rubygem.slug, as: @user.id) - - assert page.has_css?("a#unsubscribe") - - click_link "Unsubscribe" - - assert page.has_content? "Subscribe" - assert_empty @user.subscribed_gems - end - - test "shows enable MFA instructions when logged in as owner with MFA disabled" do - create(:ownership, rubygem: @rubygem, user: @user) - - visit rubygem_path(@rubygem.slug, as: @user.id) - - assert page.has_selector?(".gem__users__mfa-disabled .gem__users a") - assert page.has_content? "Please consider enabling multi-factor" - end - - test "shows owners without mfa when logged in as owner" do - @user.enable_totp!("some-seed", "ui_and_api") - user_without_mfa = create(:user) - - create(:ownership, rubygem: @rubygem, user: @user) - create(:ownership, rubygem: @rubygem, user: user_without_mfa) - - visit rubygem_path(@rubygem.slug, as: @user.id) - - assert page.has_selector?(".gem__users__mfa-disabled .gem__users a") - assert page.has_selector?(".gem__users__mfa-text.mfa-warn") - end - - test "show mfa enabled when logged in as owner but everyone has mfa enabled" do - @user.enable_totp!("some-seed", "ui_and_api") - user_with_mfa = create(:user) - user_with_mfa.enable_totp!("some-seed", "ui_and_api") - - create(:ownership, rubygem: @rubygem, user: @user) - create(:ownership, rubygem: @rubygem, user: user_with_mfa) - - visit rubygem_path(@rubygem.slug, as: @user.id) - - assert page.has_no_selector?(".gem__users__mfa-text.mfa-warn") - assert page.has_selector?(".gem__users__mfa-text.mfa-info") - end - - test "does not show owners without mfa when not logged in as owner" do - @user.enable_totp!("some-seed", "ui_and_api") - user_without_mfa = create(:user) - - create(:ownership, rubygem: @rubygem, user: @user) - create(:ownership, rubygem: @rubygem, user: user_without_mfa) - - visit rubygem_path(@rubygem.slug) - - assert page.has_no_selector?(".gem__users__mfa-disabled .gem__users a") - assert page.has_no_selector?(".gem__users__mfa-text.mfa-warn") - assert page.has_no_selector?(".gem__users__mfa-text.mfa-info") - end - - test "shows github link when source_code_uri is set" do - github_link = "http://github.com/user/project" - create(:version, number: "3.0.1", rubygem: @rubygem, metadata: { "source_code_uri" => github_link }) - - visit rubygem_path(@rubygem.slug) - - assert page.has_selector?(".github-btn") - end - - test "shows github link when homepage_uri is set" do - github_link = "http://github.com/user/project" - create(:version, number: "3.0.1", rubygem: @rubygem, metadata: { "homepage_uri" => github_link }) - - visit rubygem_path(@rubygem.slug) - - assert page.has_selector?(".github-btn") - end - - test "does not show github link when homepage_uri is not github" do - notgithub_link = "http://notgithub.com/user/project" - create(:version, number: "3.0.1", rubygem: @rubygem, metadata: { "homepage_uri" => notgithub_link }) - - visit rubygem_path(@rubygem.slug) - - assert page.has_no_selector?(".github-btn") - end - - test "shows both mfa headers if latest AND viewed version require MFA" do - @version.update_attribute :metadata, { "rubygems_mfa_required" => "true" } - create(:version, :mfa_required, rubygem: @rubygem, number: "0.1.1") - - visit rubygem_version_path(@rubygem.slug, "0.1.1") - - assert page.has_content? "New versions require MFA" - assert page.has_content? "Version published with MFA" - end - - test "shows 'new' mfa header only if latest requires MFA but viewed version doesn't" do - @version.update_attribute :metadata, { "rubygems_mfa_required" => "true" } - create(:version, rubygem: @rubygem, number: "0.1.1") - - visit rubygem_version_path(@rubygem.slug, "0.1.1") - - assert page.has_content? "New versions require MFA" - refute page.has_content? "Version published with MFA" - end - - test "shows 'version' mfa header only if latest does not require MFA but viewed version does" do - @version.update_attribute :metadata, { "rubygems_mfa_required" => "false" } - create(:version, :mfa_required, rubygem: @rubygem, number: "0.1.1") - - visit rubygem_version_path(@rubygem.slug, "0.1.1") - - refute page.has_content? "New versions require MFA" - assert page.has_content? "Version published with MFA" - end - - test "does not show either mfa header if neither latest or viewed version require MFA" do - @version.update_attribute :metadata, { "rubygems_mfa_required" => "false" } - create(:version, rubygem: @rubygem, number: "0.1.1") - - visit rubygem_version_path(@rubygem.slug, "0.1.1") - - refute page.has_content? "New versions require MFA" - refute page.has_content? "Version published with MFA" - end - - test "shows both mfa headers if MFA enabled for latest version and viewing latest version" do - @version.update_attribute :metadata, { "rubygems_mfa_required" => "true" } - - visit rubygem_path(@rubygem.slug) - - assert page.has_content? "New versions require MFA" - assert page.has_content? "Version published with MFA" - end - - test "shows neither mfa header if MFA disabled for latest version and viewing latest version" do - @version.update_attribute :metadata, { "rubygems_mfa_required" => "false" } - - visit rubygem_path(@rubygem.slug) - - refute page.has_content? "New versions require MFA" - refute page.has_content? "Version published with MFA" - end -end +end \ No newline at end of file diff --git a/test/system/gems_system_test.rb b/test/system/gems_system_test.rb new file mode 100644 index 00000000000..a8b89b54a6f --- /dev/null +++ b/test/system/gems_system_test.rb @@ -0,0 +1,178 @@ +require "application_system_test_case" + +class GemsSystemTest < ApplicationSystemTestCase + setup do + @user = create(:user) + @rubygem = create(:rubygem, name: "sandworm", number: "1.0.0") + @version = create(:version, rubygem: @rubygem, number: "1.1.1") + end + + test "version navigation" do + visit rubygem_version_path(@rubygem.slug, "1.0.0") + click_link "Next version →" + + assert_equal page.current_path, rubygem_version_path(@rubygem.slug, "1.1.1") + click_link "← Previous version" + + assert_equal page.current_path, rubygem_version_path(@rubygem.slug, "1.0.0") + end + + test "subscribe to a gem" do + visit rubygem_path(@rubygem.slug, as: @user.id) + + assert page.has_css?("a#subscribe") + + click_link "Subscribe" + + assert page.has_content? "Unsubscribe" + assert_equal @user.subscribed_gems.first, @rubygem + end + + test "unsubscribe to a gem" do + create(:subscription, rubygem: @rubygem, user: @user) + + visit rubygem_path(@rubygem.slug, as: @user.id) + + assert page.has_css?("a#unsubscribe") + + click_link "Unsubscribe" + + assert page.has_content? "Subscribe" + assert_empty @user.subscribed_gems + end + + test "shows enable MFA instructions when logged in as owner with MFA disabled" do + create(:ownership, rubygem: @rubygem, user: @user) + + visit rubygem_path(@rubygem.slug, as: @user.id) + + assert page.has_selector?(".gem__users__mfa-disabled .gem__users a") + assert page.has_content? "Please consider enabling multi-factor" + end + + test "shows owners without mfa when logged in as owner" do + @user.enable_totp!("some-seed", "ui_and_api") + user_without_mfa = create(:user) + + create(:ownership, rubygem: @rubygem, user: @user) + create(:ownership, rubygem: @rubygem, user: user_without_mfa) + + visit rubygem_path(@rubygem.slug, as: @user.id) + + assert page.has_selector?(".gem__users__mfa-disabled .gem__users a") + assert page.has_selector?(".gem__users__mfa-text.mfa-warn") + end + + test "show mfa enabled when logged in as owner but everyone has mfa enabled" do + @user.enable_totp!("some-seed", "ui_and_api") + user_with_mfa = create(:user) + user_with_mfa.enable_totp!("some-seed", "ui_and_api") + + create(:ownership, rubygem: @rubygem, user: @user) + create(:ownership, rubygem: @rubygem, user: user_with_mfa) + + visit rubygem_path(@rubygem.slug, as: @user.id) + + assert page.has_no_selector?(".gem__users__mfa-text.mfa-warn") + assert page.has_selector?(".gem__users__mfa-text.mfa-info") + end + + test "does not show owners without mfa when not logged in as owner" do + @user.enable_totp!("some-seed", "ui_and_api") + user_without_mfa = create(:user) + + create(:ownership, rubygem: @rubygem, user: @user) + create(:ownership, rubygem: @rubygem, user: user_without_mfa) + + visit rubygem_path(@rubygem.slug) + + assert page.has_no_selector?(".gem__users__mfa-disabled .gem__users a") + assert page.has_no_selector?(".gem__users__mfa-text.mfa-warn") + assert page.has_no_selector?(".gem__users__mfa-text.mfa-info") + end + + test "shows github link when source_code_uri is set" do + github_link = "http://github.com/user/project" + create(:version, number: "3.0.1", rubygem: @rubygem, metadata: { "source_code_uri" => github_link }) + + visit rubygem_path(@rubygem.slug) + + assert page.has_selector?(".github-btn") + end + + test "shows github link when homepage_uri is set" do + github_link = "http://github.com/user/project" + create(:version, number: "3.0.1", rubygem: @rubygem, metadata: { "homepage_uri" => github_link }) + + visit rubygem_path(@rubygem.slug) + + assert page.has_selector?(".github-btn") + end + + test "does not show github link when homepage_uri is not github" do + notgithub_link = "http://notgithub.com/user/project" + create(:version, number: "3.0.1", rubygem: @rubygem, metadata: { "homepage_uri" => notgithub_link }) + + visit rubygem_path(@rubygem.slug) + + assert page.has_no_selector?(".github-btn") + end + + test "shows both mfa headers if latest AND viewed version require MFA" do + @version.update_attribute :metadata, { "rubygems_mfa_required" => "true" } + create(:version, :mfa_required, rubygem: @rubygem, number: "0.1.1") + + visit rubygem_version_path(@rubygem.slug, "0.1.1") + + assert page.has_content? "New versions require MFA" + assert page.has_content? "Version published with MFA" + end + + test "shows 'new' mfa header only if latest requires MFA but viewed version doesn't" do + @version.update_attribute :metadata, { "rubygems_mfa_required" => "true" } + create(:version, rubygem: @rubygem, number: "0.1.1") + + visit rubygem_version_path(@rubygem.slug, "0.1.1") + + assert page.has_content? "New versions require MFA" + refute page.has_content? "Version published with MFA" + end + + test "shows 'version' mfa header only if latest does not require MFA but viewed version does" do + @version.update_attribute :metadata, { "rubygems_mfa_required" => "false" } + create(:version, :mfa_required, rubygem: @rubygem, number: "0.1.1") + + visit rubygem_version_path(@rubygem.slug, "0.1.1") + + refute page.has_content? "New versions require MFA" + assert page.has_content? "Version published with MFA" + end + + test "does not show either mfa header if neither latest or viewed version require MFA" do + @version.update_attribute :metadata, { "rubygems_mfa_required" => "false" } + create(:version, rubygem: @rubygem, number: "0.1.1") + + visit rubygem_version_path(@rubygem.slug, "0.1.1") + + refute page.has_content? "New versions require MFA" + refute page.has_content? "Version published with MFA" + end + + test "shows both mfa headers if MFA enabled for latest version and viewing latest version" do + @version.update_attribute :metadata, { "rubygems_mfa_required" => "true" } + + visit rubygem_path(@rubygem.slug) + + assert page.has_content? "New versions require MFA" + assert page.has_content? "Version published with MFA" + end + + test "shows neither mfa header if MFA disabled for latest version and viewing latest version" do + @version.update_attribute :metadata, { "rubygems_mfa_required" => "false" } + + visit rubygem_path(@rubygem.slug) + + refute page.has_content? "New versions require MFA" + refute page.has_content? "Version published with MFA" + end +end diff --git a/test/integration/notification_settings_test.rb b/test/system/notification_settings_test.rb similarity index 97% rename from test/integration/notification_settings_test.rb rename to test/system/notification_settings_test.rb index 9c377ef51b4..c4512a67ebf 100644 --- a/test/integration/notification_settings_test.rb +++ b/test/system/notification_settings_test.rb @@ -1,7 +1,7 @@ -require "test_helper" +require "application_system_test_case" require "capybara/minitest" -class NotificationSettingsTest < SystemTest +class NotificationSettingsTest < ApplicationSystemTestCase include Capybara::Minitest::Assertions test "changing email notification settings" do diff --git a/test/integration/owner_test.rb b/test/system/owner_test.rb similarity index 99% rename from test/integration/owner_test.rb rename to test/system/owner_test.rb index e13015369cc..f000244e462 100644 --- a/test/integration/owner_test.rb +++ b/test/system/owner_test.rb @@ -1,6 +1,6 @@ -require "test_helper" +require "application_system_test_case" -class OwnerTest < SystemTest +class OwnerTest < ApplicationSystemTestCase include ActiveJob::TestHelper include RubygemsHelper diff --git a/test/integration/ownership_call_test.rb b/test/system/ownership_call_test.rb similarity index 97% rename from test/integration/ownership_call_test.rb rename to test/system/ownership_call_test.rb index 484e3428b78..824b5861cef 100644 --- a/test/integration/ownership_call_test.rb +++ b/test/system/ownership_call_test.rb @@ -1,7 +1,7 @@ -require "test_helper" +require "application_system_test_case" require "helpers/adoption_helpers" -class OwnershipCallsTest < SystemTest +class OwnershipCallsTest < ApplicationSystemTestCase include ActionMailer::TestHelper include AdoptionHelpers