From 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 18 Jan 2023 19:00:14 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-8-stable-ee --- spec/support/helpers/api_helpers.rb | 9 +++++-- spec/support/helpers/cycle_analytics_helpers.rb | 2 +- spec/support/helpers/database/database_helpers.rb | 30 ++++------------------ .../helpers/database/table_schema_helpers.rb | 4 ++- spec/support/helpers/features/members_helpers.rb | 16 ++++++++++++ .../helpers/features/web_ide_spec_helpers.rb | 10 +++++--- spec/support/helpers/listbox_helpers.rb | 24 +++++++++++++++++ spec/support/helpers/listbox_input_helper.rb | 18 ------------- spec/support/helpers/login_helpers.rb | 2 ++ spec/support/helpers/migrations_helpers.rb | 6 ++--- spec/support/helpers/navbar_structure_helper.rb | 5 ++-- spec/support/helpers/query_recorder.rb | 4 +-- spec/support/helpers/usage_data_helpers.rb | 5 ++-- 13 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 spec/support/helpers/listbox_helpers.rb delete mode 100644 spec/support/helpers/listbox_input_helper.rb (limited to 'spec/support/helpers') diff --git a/spec/support/helpers/api_helpers.rb b/spec/support/helpers/api_helpers.rb index 62bb9576695..a9d7c6af959 100644 --- a/spec/support/helpers/api_helpers.rb +++ b/spec/support/helpers/api_helpers.rb @@ -19,7 +19,7 @@ module ApiHelpers # => "/api/v2/issues?foo=bar&private_token=..." # # Returns the relative path to the requested API resource - def api(path, user = nil, version: API::API.version, personal_access_token: nil, oauth_access_token: nil, job_token: nil, access_token: nil) + def api(path, user = nil, version: API::API.version, personal_access_token: nil, oauth_access_token: nil, job_token: nil, access_token: nil, admin_mode: false) full_path = "/api/#{version}#{path}" if oauth_access_token @@ -31,7 +31,12 @@ module ApiHelpers elsif access_token query_string = "access_token=#{access_token.token}" elsif user - personal_access_token = create(:personal_access_token, user: user) + personal_access_token = if admin_mode && user.admin? + create(:personal_access_token, :admin_mode, user: user) + else + create(:personal_access_token, user: user) + end + query_string = "private_token=#{personal_access_token.token}" end diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb index 6d41d7b7414..632f3ea28ee 100644 --- a/spec/support/helpers/cycle_analytics_helpers.rb +++ b/spec/support/helpers/cycle_analytics_helpers.rb @@ -92,7 +92,7 @@ module CycleAnalyticsHelpers end def create_value_stream_group_aggregation(group) - aggregation = Analytics::CycleAnalytics::Aggregation.safe_create_for_group(group) + aggregation = Analytics::CycleAnalytics::Aggregation.safe_create_for_namespace(group) Analytics::CycleAnalytics::AggregatorService.new(aggregation: aggregation).execute end diff --git a/spec/support/helpers/database/database_helpers.rb b/spec/support/helpers/database/database_helpers.rb index f3b2a2a6147..ecc42041e93 100644 --- a/spec/support/helpers/database/database_helpers.rb +++ b/spec/support/helpers/database/database_helpers.rb @@ -4,9 +4,7 @@ module Database module DatabaseHelpers # In order to directly work with views using factories, # we can swapout the view for a table of identical structure. - def swapout_view_for_table(view, connection: nil) - connection ||= ActiveRecord::Base.connection - + def swapout_view_for_table(view, connection:) connection.execute(<<~SQL.squish) CREATE TABLE #{view}_copy (LIKE #{view}); DROP VIEW #{view}; @@ -28,21 +26,20 @@ module Database # with_statement_timeout(0.1) do # model.select('pg_sleep(0.11)') # end - def with_statement_timeout(timeout) + def with_statement_timeout(timeout, connection:) # Force a positive value and a minimum of 1ms for very small values. timeout = (timeout * 1000).abs.ceil raise ArgumentError, 'Using a timeout of `0` means to disable statement timeout.' if timeout == 0 - previous_timeout = ActiveRecord::Base.connection - .exec_query('SHOW statement_timeout')[0].fetch('statement_timeout') + previous_timeout = connection.select_value('SHOW statement_timeout') - set_statement_timeout("#{timeout}ms") + connection.execute(format(%(SET LOCAL statement_timeout = '%s'), timeout)) yield ensure begin - set_statement_timeout(previous_timeout) + connection.execute(format(%(SET LOCAL statement_timeout = '%s'), previous_timeout)) rescue ActiveRecord::StatementInvalid # After a transaction was canceled/aborted due to e.g. a statement # timeout commands are ignored and will raise in PG::InFailedSqlTransaction. @@ -50,22 +47,5 @@ module Database # for the currrent transaction which will be closed anyway. end end - - # Set statement timeout for the current transaction. - # - # Note, that it does not restore the previous statement timeout. - # Use `with_statement_timeout` instead. - # - # @param timeout - Statement timeout in seconds - # - # Example: - # - # set_statement_timeout(0.1) - # model.select('pg_sleep(0.11)') - def set_statement_timeout(timeout) - ActiveRecord::Base.connection.execute( - format(%(SET LOCAL statement_timeout = '%s'), timeout) - ) - end end end diff --git a/spec/support/helpers/database/table_schema_helpers.rb b/spec/support/helpers/database/table_schema_helpers.rb index 472eaa45b4b..815c37e00e5 100644 --- a/spec/support/helpers/database/table_schema_helpers.rb +++ b/spec/support/helpers/database/table_schema_helpers.rb @@ -3,7 +3,9 @@ module Database module TableSchemaHelpers def connection - ActiveRecord::Base.connection + # We use ActiveRecord::Base.connection here because this is mainly used for database migrations + # where we override the connection on ActiveRecord::Base.connection + ActiveRecord::Base.connection # rubocop:disable Database/MultipleDatabases end def expect_table_to_be_replaced(original_table:, replacement_table:, archived_table:) diff --git a/spec/support/helpers/features/members_helpers.rb b/spec/support/helpers/features/members_helpers.rb index bdadcb8af43..2d3f0902a3c 100644 --- a/spec/support/helpers/features/members_helpers.rb +++ b/spec/support/helpers/features/members_helpers.rb @@ -56,6 +56,22 @@ module Spec click_button 'Search' end end + + def user_action_dropdown + '[data-testid="user-action-dropdown"]' + end + + def show_actions + within user_action_dropdown do + find('button').click + end + end + + def show_actions_for_username(user) + within find_username_row(user) do + show_actions + end + end end end end diff --git a/spec/support/helpers/features/web_ide_spec_helpers.rb b/spec/support/helpers/features/web_ide_spec_helpers.rb index 551749a43de..4793c9479fe 100644 --- a/spec/support/helpers/features/web_ide_spec_helpers.rb +++ b/spec/support/helpers/features/web_ide_spec_helpers.rb @@ -13,14 +13,18 @@ module WebIdeSpecHelpers include Spec::Support::Helpers::Features::SourceEditorSpecHelpers + # Open the IDE from anywhere by first visiting the given project's page def ide_visit(project) visit project_path(project) - wait_for_requests + ide_visit_from_link + end - click_link('Web IDE') + # Open the IDE from the current page by clicking the Web IDE link + def ide_visit_from_link(link_sel = 'Web IDE') + new_tab = window_opened_by { click_link(link_sel) } - wait_for_requests + switch_to_window new_tab end def ide_tree_body diff --git a/spec/support/helpers/listbox_helpers.rb b/spec/support/helpers/listbox_helpers.rb new file mode 100644 index 00000000000..5fcd05f31fb --- /dev/null +++ b/spec/support/helpers/listbox_helpers.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module ListboxHelpers + def select_from_listbox(text, from:, exact_item_text: false) + click_button from + select_listbox_item(text, exact_text: exact_item_text) + end + + def select_listbox_item(text, exact_text: false) + find('.gl-listbox-item[role="option"]', text: text, exact_text: exact_text).click + end + + def expect_listbox_item(text) + expect(page).to have_css('.gl-listbox-item[role="option"]', text: text) + end + + def expect_no_listbox_item(text) + expect(page).not_to have_css('.gl-listbox-item[role="option"]', text: text) + end + + def expect_listbox_items(items) + expect(find_all('.gl-listbox-item[role="option"]').map(&:text)).to eq(items) + end +end diff --git a/spec/support/helpers/listbox_input_helper.rb b/spec/support/helpers/listbox_input_helper.rb deleted file mode 100644 index ca7fbac5daa..00000000000 --- a/spec/support/helpers/listbox_input_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module ListboxInputHelper - include WaitForRequests - - def listbox_input(value, from:) - open_listbox_input(from) do - find('[role="option"]', text: value).click - end - end - - def open_listbox_input(selector) - page.within(selector) do - page.find('button[aria-haspopup="listbox"]').click - yield - end - end -end diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index 44237b821c3..5fde80e6dc9 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -101,6 +101,8 @@ module LoginHelpers fill_in "user_password", with: (password || user.password) check 'user_remember_me' if remember + wait_for_all_requests + find('[data-testid="sign-in-button"]:enabled').click if two_factor_auth diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index e1d28a807e3..6fc5904fc83 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -104,7 +104,7 @@ module MigrationsHelpers # We stub this way because we can't stub on # `current_application_settings` due to `method_missing` is # depending on current_application_settings... - allow(ActiveRecord::Base.connection) + allow(Gitlab::Database::Migration::V1_0::MigrationRecord.connection) .to receive(:active?) .and_return(false) allow(Gitlab::Runtime) @@ -158,10 +158,10 @@ module MigrationsHelpers end def migrate! - open_transactions = ActiveRecord::Base.connection.open_transactions + open_transactions = Gitlab::Database::Migration::V1_0::MigrationRecord.connection.open_transactions allow_next_instance_of(described_class) do |migration| allow(migration).to receive(:transaction_open?) do - ActiveRecord::Base.connection.open_transactions > open_transactions + Gitlab::Database::Migration::V1_0::MigrationRecord.connection.open_transactions > open_transactions end end diff --git a/spec/support/helpers/navbar_structure_helper.rb b/spec/support/helpers/navbar_structure_helper.rb index e1ed3ffacec..48c6e590e1b 100644 --- a/spec/support/helpers/navbar_structure_helper.rb +++ b/spec/support/helpers/navbar_structure_helper.rb @@ -91,9 +91,8 @@ module NavbarStructureHelper new_nav_item: { nav_item: _('Observability'), nav_sub_items: [ - _('Dashboards'), - _('Explore'), - _('Manage Dashboards') + _('Explore telemetry data'), + _('Data sources') ] } ) diff --git a/spec/support/helpers/query_recorder.rb b/spec/support/helpers/query_recorder.rb index dd124ed9c7f..5be9ba9ae1e 100644 --- a/spec/support/helpers/query_recorder.rb +++ b/spec/support/helpers/query_recorder.rb @@ -19,9 +19,7 @@ module ActiveRecord def record(&block) # force replacement of bind parameters to give tests the ability to check for ids - ActiveRecord::Base.connection.unprepared_statement do - ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) - end + ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) end def show_backtrace(values, duration) diff --git a/spec/support/helpers/usage_data_helpers.rb b/spec/support/helpers/usage_data_helpers.rb index 78ceaf297a8..438f0d129b9 100644 --- a/spec/support/helpers/usage_data_helpers.rb +++ b/spec/support/helpers/usage_data_helpers.rb @@ -116,8 +116,9 @@ module UsageDataHelpers ).freeze def stub_usage_data_connections - allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) - allow(::Ci::ApplicationRecord.connection).to receive(:transaction_open?).and_return(false) if ::Ci::ApplicationRecord.connection_class? + Gitlab::Database.database_base_models_with_gitlab_shared.each_value do |base_model| + allow(base_model.connection).to receive(:transaction_open?).and_return(false) + end allow(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(false) end -- cgit v1.2.1