Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/diffs/components/app_spec.js18
-rw-r--r--spec/initializers/action_cable_subscription_adapter_identifier_spec.rb3
-rw-r--r--spec/lib/click_house/models/audit_event_spec.rb132
-rw-r--r--spec/lib/click_house/models/base_model_spec.rb117
-rw-r--r--spec/lib/gitlab/redis/pubsub_spec.rb8
-rw-r--r--spec/support/helpers/cycle_analytics_helpers.rb25
-rw-r--r--spec/support/helpers/listbox_helpers.rb4
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb10
-rw-r--r--spec/tooling/danger/rubocop_inline_disable_suggestion_spec.rb18
-rw-r--r--spec/workers/every_sidekiq_worker_spec.rb4
10 files changed, 311 insertions, 28 deletions
diff --git a/spec/frontend/diffs/components/app_spec.js b/spec/frontend/diffs/components/app_spec.js
index 212def72b90..e874345cdd3 100644
--- a/spec/frontend/diffs/components/app_spec.js
+++ b/spec/frontend/diffs/components/app_spec.js
@@ -769,6 +769,15 @@ describe('diffs/components/app', () => {
beforeEach(() => {
createComponent();
+
+ store.state.diffs.diffFiles = [
+ {
+ file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a',
+ highlighted_diff_lines: [],
+ viewer: { manuallyCollapsed: true },
+ },
+ ];
+
loadSpy = jest.spyOn(wrapper.vm, 'loadCollapsedDiff').mockResolvedValue('resolved');
});
@@ -787,5 +796,14 @@ describe('diffs/components/app', () => {
expect(loadSpy).toHaveBeenCalledWith({ file: store.state.diffs.diffFiles[0] });
});
+
+ it('does nothing when file is not collapsed', () => {
+ store.state.diffs.diffFiles[0].viewer.manuallyCollapsed = false;
+ window.location.hash = '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_0_1';
+
+ eventHub.$emit('doneLoadingBatches');
+
+ expect(loadSpy).not.toHaveBeenCalledWith({ file: store.state.diffs.diffFiles[0] });
+ });
});
});
diff --git a/spec/initializers/action_cable_subscription_adapter_identifier_spec.rb b/spec/initializers/action_cable_subscription_adapter_identifier_spec.rb
index dd2bf298611..cf82fd751dd 100644
--- a/spec/initializers/action_cable_subscription_adapter_identifier_spec.rb
+++ b/spec/initializers/action_cable_subscription_adapter_identifier_spec.rb
@@ -27,8 +27,7 @@ RSpec.describe 'ActionCableSubscriptionAdapterIdentifier override' do
sub = ActionCable.server.pubsub.send(:redis_connection)
- expect(sub.is_a?(::Gitlab::Redis::MultiStore)).to eq(true)
- expect(sub.secondary_store.connection[:id]).to eq('unix:///home/localuser/redis/redis.socket/0')
+ expect(sub.connection[:id]).to eq('unix:///home/localuser/redis/redis.socket/0')
expect(ActionCable.server.config.cable[:id]).to be_nil
end
end
diff --git a/spec/lib/click_house/models/audit_event_spec.rb b/spec/lib/click_house/models/audit_event_spec.rb
new file mode 100644
index 00000000000..ea3f1a6cbd4
--- /dev/null
+++ b/spec/lib/click_house/models/audit_event_spec.rb
@@ -0,0 +1,132 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ClickHouse::Models::AuditEvent, feature_category: :audit_events do
+ let(:instance) { described_class.new }
+
+ describe '#by_entity_type' do
+ it 'builds the correct SQL' do
+ expected_sql = <<~SQL
+ SELECT * FROM "audit_events" WHERE "audit_events"."entity_type" = 'Project'
+ SQL
+
+ result_sql = instance.by_entity_type("Project").to_sql
+
+ expect(result_sql.strip).to eq(expected_sql.strip)
+ end
+ end
+
+ describe '#by_entity_id' do
+ it 'builds the correct SQL' do
+ expected_sql = <<~SQL
+ SELECT * FROM "audit_events" WHERE "audit_events"."entity_id" = 42
+ SQL
+
+ result_sql = instance.by_entity_id(42).to_sql
+
+ expect(result_sql.strip).to eq(expected_sql.strip)
+ end
+ end
+
+ describe '#by_author_id' do
+ it 'builds the correct SQL' do
+ expected_sql = <<~SQL
+ SELECT * FROM "audit_events" WHERE "audit_events"."author_id" = 5
+ SQL
+
+ result_sql = instance.by_author_id(5).to_sql
+
+ expect(result_sql.strip).to eq(expected_sql.strip)
+ end
+ end
+
+ describe '#by_entity_username' do
+ let_it_be(:user) { create(:user, username: 'Dummy') }
+
+ it 'builds the correct SQL' do
+ expected_sql = <<~SQL
+ SELECT * FROM "audit_events" WHERE "audit_events"."entity_id" = #{user.id}
+ SQL
+
+ result_sql = instance.by_entity_username('Dummy').to_sql
+
+ expect(result_sql.strip).to eq(expected_sql.strip)
+ end
+ end
+
+ describe '#by_author_username' do
+ let_it_be(:user) { create(:user, username: 'Dummy') }
+
+ it 'builds the correct SQL' do
+ expected_sql = <<~SQL
+ SELECT * FROM "audit_events" WHERE "audit_events"."author_id" = #{user.id}
+ SQL
+
+ result_sql = instance.by_author_username('Dummy').to_sql
+
+ expect(result_sql.strip).to eq(expected_sql.strip)
+ end
+ end
+
+ describe 'class methods' do
+ before do
+ allow(described_class).to receive(:new).and_return(instance)
+ end
+
+ describe '.by_entity_type' do
+ it 'calls the corresponding instance method' do
+ expect(instance).to receive(:by_entity_type).with("Project")
+
+ described_class.by_entity_type("Project")
+ end
+ end
+
+ describe '.by_entity_id' do
+ it 'calls the corresponding instance method' do
+ expect(instance).to receive(:by_entity_id).with(42)
+
+ described_class.by_entity_id(42)
+ end
+ end
+
+ describe '.by_author_id' do
+ it 'calls the corresponding instance method' do
+ expect(instance).to receive(:by_author_id).with(5)
+
+ described_class.by_author_id(5)
+ end
+ end
+
+ describe '.by_entity_username' do
+ it 'calls the corresponding instance method' do
+ expect(instance).to receive(:by_entity_username).with('Dummy')
+
+ described_class.by_entity_username('Dummy')
+ end
+ end
+
+ describe '.by_author_username' do
+ it 'calls the corresponding instance method' do
+ expect(instance).to receive(:by_author_username).with('Dummy')
+
+ described_class.by_author_username('Dummy')
+ end
+ end
+ end
+
+ describe 'method chaining' do
+ it 'builds the correct SQL with chained methods' do
+ expected_sql = <<~SQL.lines(chomp: true).join(' ')
+ SELECT * FROM "audit_events"
+ WHERE "audit_events"."entity_type" = 'Project'
+ AND "audit_events"."author_id" = 1
+ SQL
+
+ instance = described_class.new
+ result_sql = instance.by_entity_type("Project").by_author_id(1).to_sql
+
+ expect(result_sql.strip).to eq(expected_sql.strip)
+ end
+ end
+end
diff --git a/spec/lib/click_house/models/base_model_spec.rb b/spec/lib/click_house/models/base_model_spec.rb
new file mode 100644
index 00000000000..376300d7781
--- /dev/null
+++ b/spec/lib/click_house/models/base_model_spec.rb
@@ -0,0 +1,117 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ClickHouse::Models::BaseModel, feature_category: :database do
+ let(:table_name) { "dummy_table" }
+ let(:query_builder) { instance_double("ClickHouse::QueryBuilder") }
+ let(:updated_query_builder) { instance_double("ClickHouse::QueryBuilder") }
+
+ let(:dummy_class) do
+ Class.new(described_class) do
+ def self.table_name
+ "dummy_table"
+ end
+ end
+ end
+
+ describe '#to_sql' do
+ it 'delegates to the query builder' do
+ expect(query_builder).to receive(:to_sql).and_return("SELECT * FROM dummy_table")
+
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(dummy_instance.to_sql).to eq("SELECT * FROM dummy_table")
+ end
+ end
+
+ describe '#where' do
+ it 'returns a new instance with refined query' do
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(query_builder).to receive(:where).with({ foo: "bar" }).and_return(updated_query_builder)
+
+ new_instance = dummy_instance.where(foo: "bar")
+
+ expect(new_instance).to be_a(dummy_class)
+ expect(new_instance).not_to eq(dummy_instance)
+ end
+ end
+
+ describe '#order' do
+ it 'returns a new instance with an order clause' do
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(query_builder).to receive(:order).with(:created_at, :asc).and_return(updated_query_builder)
+
+ new_instance = dummy_instance.order(:created_at)
+
+ expect(new_instance).to be_a(dummy_class)
+ expect(new_instance).not_to eq(dummy_instance)
+ end
+
+ context "when direction is also passed" do
+ it 'returns a new instance with an order clause' do
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(query_builder).to receive(:order).with(:created_at, :desc).and_return(updated_query_builder)
+
+ new_instance = dummy_instance.order(:created_at, :desc)
+
+ expect(new_instance).to be_a(dummy_class)
+ expect(new_instance).not_to eq(dummy_instance)
+ end
+ end
+ end
+
+ describe '#limit' do
+ it 'returns a new instance with a limit clause' do
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(query_builder).to receive(:limit).with(10).and_return(updated_query_builder)
+
+ new_instance = dummy_instance.limit(10)
+
+ expect(new_instance).to be_a(dummy_class)
+ expect(new_instance).not_to eq(dummy_instance)
+ end
+ end
+
+ describe '#offset' do
+ it 'returns a new instance with an offset clause' do
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(query_builder).to receive(:offset).with(5).and_return(updated_query_builder)
+
+ new_instance = dummy_instance.offset(5)
+
+ expect(new_instance).to be_a(dummy_class)
+ expect(new_instance).not_to eq(dummy_instance)
+ end
+ end
+
+ describe '#select' do
+ it 'returns a new instance with selected fields' do
+ dummy_instance = dummy_class.new(query_builder)
+
+ expect(query_builder).to receive(:select).with(:id, :name).and_return(updated_query_builder)
+
+ new_instance = dummy_instance.select(:id, :name)
+
+ expect(new_instance).to be_a(dummy_class)
+ expect(new_instance).not_to eq(dummy_instance)
+ end
+ end
+
+ describe '.table_name' do
+ it 'raises a NotImplementedError for the base model' do
+ expect do
+ described_class.table_name
+ end.to raise_error(NotImplementedError, "Subclasses must define a `table_name` class method")
+ end
+
+ it 'does not raise an error for the subclass' do
+ expect(dummy_class.table_name).to eq(table_name)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/redis/pubsub_spec.rb b/spec/lib/gitlab/redis/pubsub_spec.rb
deleted file mode 100644
index e196d02116e..00000000000
--- a/spec/lib/gitlab/redis/pubsub_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Redis::Pubsub, feature_category: :redis do
- include_examples "redis_new_instance_shared_examples", 'pubsub', Gitlab::Redis::SharedState
- include_examples "redis_shared_examples"
-end
diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb
index 5f60f8a6bfa..890fefcc7de 100644
--- a/spec/support/helpers/cycle_analytics_helpers.rb
+++ b/spec/support/helpers/cycle_analytics_helpers.rb
@@ -1,6 +1,10 @@
# frozen_string_literal: true
+require_relative './listbox_helpers'
+
module CycleAnalyticsHelpers
+ include ::ListboxHelpers
+
def toggle_value_stream_dropdown
page.find('[data-testid="dropdown-value-streams"]').click
end
@@ -16,8 +20,8 @@ module CycleAnalyticsHelpers
within last_stage do
find('[name*="custom-stage-name-"]').fill_in with: "Cool custom stage - name #{index}"
- select_dropdown_option_by_value "custom-stage-start-event-", :merge_request_created
- select_dropdown_option_by_value "custom-stage-end-event-", :merge_request_merged
+ select_dropdown_option_by_value "custom-stage-start-event-", 'Merge request created'
+ select_dropdown_option_by_value "custom-stage-end-event-", 'Merge request merged'
end
end
@@ -34,8 +38,8 @@ module CycleAnalyticsHelpers
within last_stage do
find('[name*="custom-stage-name-"]').fill_in with: "Cool custom label stage - name #{index}"
- select_dropdown_option_by_value "custom-stage-start-event-", :issue_label_added
- select_dropdown_option_by_value "custom-stage-end-event-", :issue_label_removed
+ select_dropdown_option_by_value "custom-stage-start-event-", 'Issue label was added'
+ select_dropdown_option_by_value "custom-stage-end-event-", 'Issue label was removed'
select_event_label("[data-testid*='custom-stage-start-event-label-']")
select_event_label("[data-testid*='custom-stage-end-event-label-']")
@@ -102,19 +106,14 @@ module CycleAnalyticsHelpers
select_value_stream(custom_value_stream_name)
end
- def toggle_dropdown(field)
- page.within("[data-testid*='#{field}']") do
- find('.dropdown-toggle').click
+ def select_dropdown_option_by_value(name, value)
+ page.within("[data-testid*='#{name}']") do
+ toggle_listbox
wait_for_requests
-
- expect(find('.dropdown-menu')).to have_selector('.dropdown-item')
end
- end
- def select_dropdown_option_by_value(name, value, elem = '.dropdown-item')
- toggle_dropdown name
- page.find("[data-testid*='#{name}'] .dropdown-menu").find("#{elem}[value='#{value}']").click
+ select_listbox_item(value)
end
def create_commit_referencing_issue(issue, branch_name: generate(:branch))
diff --git a/spec/support/helpers/listbox_helpers.rb b/spec/support/helpers/listbox_helpers.rb
index 7a734d2b097..a8a4c079e3c 100644
--- a/spec/support/helpers/listbox_helpers.rb
+++ b/spec/support/helpers/listbox_helpers.rb
@@ -14,6 +14,10 @@ module ListboxHelpers
find('.gl-new-dropdown-item', text: text, exact_text: exact_text).click
end
+ def toggle_listbox
+ find('.gl-new-dropdown-toggle').click
+ end
+
def expect_listbox_item(text)
expect(page).to have_css('.gl-new-dropdown-item[role="option"]', text: text)
end
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index c2e53da8d4b..8f5654d32a9 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
Rake.application.rake_require 'active_record/railties/databases'
Rake.application.rake_require 'tasks/seed_fu'
Rake.application.rake_require 'tasks/gitlab/db'
+ Rake.application.rake_require 'tasks/gitlab/db/lock_writes'
end
before do
@@ -14,6 +15,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
allow(Rake::Task['db:migrate']).to receive(:invoke).and_return(true)
allow(Rake::Task['db:schema:load']).to receive(:invoke).and_return(true)
allow(Rake::Task['db:seed_fu']).to receive(:invoke).and_return(true)
+ allow(Rake::Task['gitlab:db:lock_writes']).to receive(:invoke).and_return(true)
stub_feature_flags(disallow_database_ddl_feature_flags: false)
end
@@ -142,6 +144,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
expect(Rake::Task['db:migrate']).to receive(:invoke)
expect(Rake::Task['db:schema:load']).not_to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).not_to receive(:invoke)
expect(Rake::Task['db:seed_fu']).not_to receive(:invoke)
run_rake_task('gitlab:db:configure')
@@ -153,6 +156,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
allow(connection).to receive(:tables).and_return([])
expect(Rake::Task['db:schema:load']).to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).to receive(:invoke)
expect(Rake::Task['db:seed_fu']).to receive(:invoke)
expect(Rake::Task['db:migrate']).not_to receive(:invoke)
@@ -165,6 +169,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
allow(connection).to receive(:tables).and_return(['default'])
expect(Rake::Task['db:schema:load']).to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).to receive(:invoke)
expect(Rake::Task['db:seed_fu']).to receive(:invoke)
expect(Rake::Task['db:migrate']).not_to receive(:invoke)
@@ -177,6 +182,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
allow(connection).to receive(:tables).and_return([])
expect(Rake::Task['db:schema:load']).to receive(:invoke).and_raise('error')
+ expect(Rake::Task['gitlab:db:lock_writes']).not_to receive(:invoke)
expect(Rake::Task['db:seed_fu']).not_to receive(:invoke)
expect(Rake::Task['db:migrate']).not_to receive(:invoke)
@@ -201,6 +207,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
expect(Gitlab::Database).to receive(:add_post_migrate_path_to_rails).and_call_original
expect(Rake::Task['db:schema:load']).to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).to receive(:invoke)
expect(Rake::Task['db:seed_fu']).to receive(:invoke)
expect(Rake::Task['db:migrate']).not_to receive(:invoke)
@@ -217,6 +224,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
expect(Rake::Task['db:migrate']).to receive(:invoke)
expect(Gitlab::Database).not_to receive(:add_post_migrate_path_to_rails)
expect(Rake::Task['db:schema:load']).not_to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).not_to receive(:invoke)
expect(Rake::Task['db:seed_fu']).not_to receive(:invoke)
run_rake_task('gitlab:db:configure')
@@ -280,6 +288,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
expect(Rake::Task['db:migrate:main']).not_to receive(:invoke)
expect(Rake::Task['db:migrate:ci']).not_to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).to receive(:invoke)
expect(Rake::Task['db:seed_fu']).to receive(:invoke)
run_rake_task('gitlab:db:configure')
@@ -299,6 +308,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_categor
expect(Rake::Task['db:schema:load:main']).not_to receive(:invoke)
expect(Rake::Task['db:schema:load:ci']).not_to receive(:invoke)
+ expect(Rake::Task['gitlab:db:lock_writes']).not_to receive(:invoke)
expect(Rake::Task['db:seed_fu']).not_to receive(:invoke)
run_rake_task('gitlab:db:configure')
diff --git a/spec/tooling/danger/rubocop_inline_disable_suggestion_spec.rb b/spec/tooling/danger/rubocop_inline_disable_suggestion_spec.rb
index 94dd5192d74..7af5df1e3bd 100644
--- a/spec/tooling/danger/rubocop_inline_disable_suggestion_spec.rb
+++ b/spec/tooling/danger/rubocop_inline_disable_suggestion_spec.rb
@@ -73,6 +73,20 @@ RSpec.describe Tooling::Danger::RubocopInlineDisableSuggestion, feature_category
show_out_of_pipeline_minutes_notification?(project, namespace)
end
+
+ def show_my_new_dot?(project, namespace)
+ return false unless ::Gitlab.com? # rubocop: todo Gitlab/AvoidGitlabInstanceChecks -- Reason for disabling
+ return false if notification_dot_acknowledged?
+
+ show_out_of_pipeline_minutes_notification?(project, namespace)
+ end
+
+ def show_my_bad_dot?(project, namespace)
+ return false unless ::Gitlab.com? # rubocop: todo Gitlab/AvoidGitlabInstanceChecks --
+ return false if notification_dot_acknowledged?
+
+ show_out_of_pipeline_minutes_notification?(project, namespace)
+ end
RUBY
end
@@ -86,6 +100,8 @@ RSpec.describe Tooling::Danger::RubocopInlineDisableSuggestion, feature_category
+ return false unless ::Gitlab.com? # rubocop: disable Gitlab/AvoidGitlabInstanceChecks
+ return false unless ::Gitlab.com? # rubocop:todo Gitlab/AvoidGitlabInstanceChecks
+ return false unless ::Gitlab.com? # rubocop: todo Gitlab/AvoidGitlabInstanceChecks
+ + return false unless ::Gitlab.com? # rubocop: todo Gitlab/AvoidGitlabInstanceChecks -- Reason for disabling
+ + return false unless ::Gitlab.com? # rubocop: todo Gitlab/AvoidGitlabInstanceChecks --
DIFF
end
@@ -102,7 +118,7 @@ RSpec.describe Tooling::Danger::RubocopInlineDisableSuggestion, feature_category
end
it 'adds comments at the correct lines', :aggregate_failures do
- [3, 7, 13, 20, 27, 34, 41].each do |line_number|
+ [3, 7, 13, 20, 27, 34, 41, 55].each do |line_number|
expect(rubocop).to receive(:markdown).with(template, file: filename, line: line_number)
end
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb
index 4855967d462..94fe0e72ff8 100644
--- a/spec/workers/every_sidekiq_worker_spec.rb
+++ b/spec/workers/every_sidekiq_worker_spec.rb
@@ -325,10 +325,6 @@ RSpec.describe 'Every Sidekiq worker', feature_category: :shared do
'Groups::ScheduleBulkRepositoryShardMovesWorker' => 3,
'Groups::UpdateRepositoryStorageWorker' => 3,
'Groups::UpdateStatisticsWorker' => 3,
- 'HashedStorage::MigratorWorker' => 3,
- 'HashedStorage::ProjectMigrateWorker' => 3,
- 'HashedStorage::ProjectRollbackWorker' => 3,
- 'HashedStorage::RollbackerWorker' => 3,
'ImportIssuesCsvWorker' => 3,
'ImportSoftwareLicensesWorker' => 3,
'IncidentManagement::AddSeveritySystemNoteWorker' => 3,