diff options
Diffstat (limited to 'spec')
17 files changed, 337 insertions, 94 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 2d2b911749b..25e91dfdedd 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -3,11 +3,10 @@ require 'spec_helper' RSpec.describe ApplicationExperiment, :experiment do - subject { described_class.new('namespaced/stub') } + subject { described_class.new('namespaced/stub', **context) } - let(:feature_definition) do - { name: 'namespaced_stub', type: 'experiment', group: 'group::adoption', default_enabled: false } - end + let(:context) { {} } + let(:feature_definition) { { name: 'namespaced_stub', type: 'experiment', default_enabled: false } } around do |example| Feature::Definition.definitions[:namespaced_stub] = Feature::Definition.new('namespaced_stub.yml', feature_definition) @@ -25,7 +24,7 @@ RSpec.describe ApplicationExperiment, :experiment do expect { experiment('namespaced/stub') { } }.not_to raise_error end - describe "enabled" do + describe "#enabled?" do before do allow(subject).to receive(:enabled?).and_call_original @@ -57,103 +56,100 @@ RSpec.describe ApplicationExperiment, :experiment do end end - describe "publishing results" do - it "doesn't record, track or push data to the client if we shouldn't track", :snowplow do + describe "#publish" do + it "doesn't track or publish to the client or database if we can't track", :snowplow do allow(subject).to receive(:should_track?).and_return(false) - subject.record! - expect(subject).not_to receive(:record_experiment) - expect(subject).not_to receive(:track) - expect(Gon).not_to receive(:push) + expect(subject).not_to receive(:publish_to_client) + expect(subject).not_to receive(:publish_to_database) - subject.publish(:action) + subject.publish expect_no_snowplow_event end - describe 'recording the experiment' do - it 'does not record the experiment if we do not tell it to' do - expect(subject).not_to receive(:record_experiment) - - subject.publish - end - - it 'records the experiment if we tell it to' do - subject.record! - - expect(subject).to receive(:record_experiment) - - subject.publish - end - end - it "tracks the assignment" do expect(subject).to receive(:track).with(:assignment) subject.publish end - it "pushes the experiment knowledge into the client using Gon" do - expect(Gon).to receive(:push).with({ experiment: { 'namespaced/stub' => subject.signature } }, true) + it "publishes the to the client" do + expect(subject).to receive(:publish_to_client) subject.publish end - it "handles when Gon raises exceptions (like when it can't be pushed into)" do - expect(Gon).to receive(:push).and_raise(NoMethodError) + it "publishes to the database if we've opted for that" do + subject.record! + + expect(subject).to receive(:publish_to_database) - expect { subject.publish }.not_to raise_error + subject.publish end - end - it "can exclude from within the block" do - expect(described_class.new('namespaced/stub') { |e| e.exclude! }).to be_excluded - end + describe "#publish_to_client" do + it "adds the data into Gon" do + signature = { key: '86208ac54ca798e11f127e8b23ec396a', variant: 'control' } + expect(Gon).to receive(:push).with({ experiment: { 'namespaced/stub' => hash_including(signature) } }, true) - describe 'recording the experiment subject' do - using RSpec::Parameterized::TableSyntax + subject.publish_to_client + end - subject { described_class.new('namespaced/stub', nil, **context) } + it "handles when Gon raises exceptions (like when it can't be pushed into)" do + expect(Gon).to receive(:push).and_raise(NoMethodError) - before do - subject.record! + expect { subject.publish_to_client }.not_to raise_error + end end - context 'when providing a compatible context' do - where(:context_key, :object_type) do - :namespace | :namespace - :group | :namespace - :project | :project - :user | :user - :actor | :user + describe "#publish_to_database" do + using RSpec::Parameterized::TableSyntax + let(:context) { { context_key => context_value }} + + before do + subject.record! end - with_them do - let(:context) { { context_key => build(object_type) }} + context "when there's a usable subject" do + where(:context_key, :context_value, :object_type) do + :namespace | build(:namespace) | :namespace + :group | build(:namespace) | :namespace + :project | build(:project) | :project + :user | build(:user) | :user + :actor | build(:user) | :user + end - it 'records the experiment and the experiment subject from the context' do - expect { subject.publish }.to change(Experiment, :count).by(1) + with_them do + it "creates an experiment and experiment subject record" do + expect { subject.publish_to_database }.to change(Experiment, :count).by(1) - expect(Experiment.last.name).to eq('namespaced/stub') - expect(ExperimentSubject.last.send(object_type)).to eq(context[context_key]) + expect(Experiment.last.name).to eq('namespaced/stub') + expect(ExperimentSubject.last.send(object_type)).to eq(context[context_key]) + end end end - end - context 'when providing an incompatible or no context' do - where(context_hash: [{ foo: :bar }, {}]) + context "when there's not a usable subject" do + where(:context_key, :context_value) do + :namespace | nil + :foo | :bar + end - with_them do - let(:context) { context_hash } + with_them do + it "doesn't create an experiment record" do + expect { subject.publish_to_database }.not_to change(Experiment, :count) + end - it 'does not record the experiment' do - expect { subject.publish }.not_to change(Experiment, :count) + it "doesn't create an experiment subject record" do + expect { subject.publish_to_database }.not_to change(ExperimentSubject, :count) + end end end end end - describe "tracking events", :snowplow do + describe "#track", :snowplow do it "doesn't track if we shouldn't track" do allow(subject).to receive(:should_track?).and_return(false) @@ -185,7 +181,13 @@ RSpec.describe ApplicationExperiment, :experiment do end end - describe "variant resolution" do + describe "#key_for" do + it "generates MD5 hashes" do + expect(subject.key_for(foo: :bar)).to eq('6f9ac12afdb9b58c2f19a136d09f9153') + end + end + + context "when resolving variants" do it "uses the default value as specified in the yaml" do expect(Feature).to receive(:enabled?).with('namespaced_stub', subject, type: :experiment, default_enabled: :yaml) diff --git a/spec/features/projects/releases/user_views_edit_release_spec.rb b/spec/features/projects/releases/user_views_edit_release_spec.rb index 024c0a227c5..561b283ee15 100644 --- a/spec/features/projects/releases/user_views_edit_release_spec.rb +++ b/spec/features/projects/releases/user_views_edit_release_spec.rb @@ -4,9 +4,11 @@ require 'spec_helper' RSpec.describe 'User edits Release', :js do let_it_be(:project) { create(:project, :repository) } - let_it_be(:release) { create(:release, :with_milestones, milestones_count: 1, project: project, name: 'The first release' ) } let_it_be(:user) { create(:user) } + let(:release) { create(:release, :with_milestones, milestones_count: 1, project: project, name: 'The first release' ) } + let(:release_link) { create(:release_link, release: release) } + before do project.add_developer(user) @@ -68,6 +70,14 @@ RSpec.describe 'User edits Release', :js do expect(release.description).to eq('Updated Release notes') end + it 'does not affect the asset link' do + fill_out_form_and_click 'Save changes' + + expected_filepath = release_link.filepath + release_link.reload + expect(release_link.filepath).to eq(expected_filepath) + end + it 'redirects to the previous page when "Cancel" is clicked when the url includes a back_url query parameter' do back_path = project_releases_path(project, params: { page: 2 }) visit edit_project_release_path(project, release, params: { back_url: back_path }) diff --git a/spec/frontend/cycle_analytics/formatted_stage_count_spec.js b/spec/frontend/cycle_analytics/formatted_stage_count_spec.js new file mode 100644 index 00000000000..19f1a7187b3 --- /dev/null +++ b/spec/frontend/cycle_analytics/formatted_stage_count_spec.js @@ -0,0 +1,34 @@ +import { shallowMount } from '@vue/test-utils'; +import Component from '~/cycle_analytics/components/formatted_stage_count.vue'; + +describe('Formatted Stage Count', () => { + let wrapper = null; + + const createComponent = (stageCount = null) => { + wrapper = shallowMount(Component, { + propsData: { + stageCount, + }, + }); + }; + + beforeEach(() => { + createComponent(); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it.each` + stageCount | expectedOutput + ${null} | ${'-'} + ${1} | ${'1 item'} + ${10} | ${'10 items'} + ${1000} | ${'1000 items'} + ${1001} | ${'1000+ items'} + `('returns "$expectedOutput" for stageCount=$stageCount', ({ stageCount, expectedOutput }) => { + createComponent(stageCount); + expect(wrapper.text()).toContain(expectedOutput); + }); +}); diff --git a/spec/frontend/releases/__snapshots__/util_spec.js.snap b/spec/frontend/releases/__snapshots__/util_spec.js.snap index 0de2ec5cd89..b2580d47549 100644 --- a/spec/frontend/releases/__snapshots__/util_spec.js.snap +++ b/spec/frontend/releases/__snapshots__/util_spec.js.snap @@ -212,24 +212,28 @@ Object { "count": undefined, "links": Array [ Object { + "directAssetPath": "/binaries/awesome-app-3", "id": "gid://gitlab/Releases::Link/13", "linkType": "image", "name": "Image", "url": "https://example.com/image", }, Object { + "directAssetPath": "/binaries/awesome-app-2", "id": "gid://gitlab/Releases::Link/12", "linkType": "package", "name": "Package", "url": "https://example.com/package", }, Object { + "directAssetPath": "/binaries/awesome-app-1", "id": "gid://gitlab/Releases::Link/11", "linkType": "runbook", "name": "Runbook", "url": "http://localhost/releases-namespace/releases-project/runbook", }, Object { + "directAssetPath": "/binaries/linux-amd64", "id": "gid://gitlab/Releases::Link/10", "linkType": "other", "name": "linux-amd64 binaries", diff --git a/spec/frontend/sentry/index_spec.js b/spec/frontend/sentry/index_spec.js index 13b9b9e909c..d1f098112e8 100644 --- a/spec/frontend/sentry/index_spec.js +++ b/spec/frontend/sentry/index_spec.js @@ -7,6 +7,8 @@ describe('SentryConfig options', () => { const gitlabUrl = 'gitlabUrl'; const environment = 'test'; const revision = 'revision'; + const featureCategory = 'my_feature_category'; + let indexReturnValue; beforeEach(() => { @@ -16,6 +18,7 @@ describe('SentryConfig options', () => { current_user_id: currentUserId, gitlab_url: gitlabUrl, revision, + feature_category: featureCategory, }; process.env.HEAD_COMMIT_SHA = revision; @@ -34,6 +37,7 @@ describe('SentryConfig options', () => { release: revision, tags: { revision, + feature_category: featureCategory, }, }); }); diff --git a/spec/frontend/sentry/sentry_config_spec.js b/spec/frontend/sentry/sentry_config_spec.js index 1f5097ef2a8..9f67b681b8d 100644 --- a/spec/frontend/sentry/sentry_config_spec.js +++ b/spec/frontend/sentry/sentry_config_spec.js @@ -72,11 +72,13 @@ describe('SentryConfig', () => { release: 'revision', tags: { revision: 'revision', + feature_category: 'my_feature_category', }, }; beforeEach(() => { jest.spyOn(Sentry, 'init').mockImplementation(); + jest.spyOn(Sentry, 'setTags').mockImplementation(); sentryConfig.options = options; sentryConfig.IGNORE_ERRORS = 'ignore_errors'; @@ -89,7 +91,6 @@ describe('SentryConfig', () => { expect(Sentry.init).toHaveBeenCalledWith({ dsn: options.dsn, release: options.release, - tags: options.tags, sampleRate: 0.95, whitelistUrls: options.whitelistUrls, environment: 'test', @@ -98,6 +99,10 @@ describe('SentryConfig', () => { }); }); + it('should call Sentry.setTags', () => { + expect(Sentry.setTags).toHaveBeenCalledWith(options.tags); + }); + it('should set environment from options', () => { sentryConfig.options.environment = 'development'; @@ -106,7 +111,6 @@ describe('SentryConfig', () => { expect(Sentry.init).toHaveBeenCalledWith({ dsn: options.dsn, release: options.release, - tags: options.tags, sampleRate: 0.95, whitelistUrls: options.whitelistUrls, environment: 'development', diff --git a/spec/graphql/types/release_asset_link_type_spec.rb b/spec/graphql/types/release_asset_link_type_spec.rb index 6800d5459c4..0c903b8d27a 100644 --- a/spec/graphql/types/release_asset_link_type_spec.rb +++ b/spec/graphql/types/release_asset_link_type_spec.rb @@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ReleaseAssetLink'] do it 'has the expected fields' do expected_fields = %w[ - id name url external link_type direct_asset_url + id name url external link_type direct_asset_url direct_asset_path ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/snippets/blob_type_spec.rb b/spec/graphql/types/snippets/blob_type_spec.rb index 60c0db8e551..e20b001ba7f 100644 --- a/spec/graphql/types/snippets/blob_type_spec.rb +++ b/spec/graphql/types/snippets/blob_type_spec.rb @@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do include GraphqlHelpers it 'has the correct fields' do - expected_fields = [:rich_data, :plain_data, + expected_fields = [:rich_data, :plain_data, :raw_plain_data, :raw_path, :size, :binary, :name, :path, :simple_viewer, :rich_viewer, :mode, :external_storage, :rendered_as_text] @@ -18,6 +18,7 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do { 'richData' => be_nullable, 'plainData' => be_nullable, + 'rawPlainData' => be_nullable, 'rawPath' => be_non_null, 'size' => be_non_null, 'binary' => be_non_null, diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb index 18d8418ca23..095500cdc53 100644 --- a/spec/lib/banzai/reference_parser/base_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb @@ -78,12 +78,31 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do describe '#referenced_by' do context 'when references_relation is implemented' do - it 'returns a collection of objects' do - links = Nokogiri::HTML.fragment("<a data-foo='#{user.id}'></a>") - .children + context 'and ids_only is set to false' do + it 'returns a collection of objects' do + links = Nokogiri::HTML.fragment("<a data-foo='#{user.id}'></a>") + .children - expect(subject).to receive(:references_relation).and_return(User) - expect(subject.referenced_by(links)).to eq([user]) + expect(subject).to receive(:references_relation).and_return(User) + expect(subject.referenced_by(links)).to eq([user]) + end + end + + context 'and ids_only is set to true' do + it 'returns a collection of id values without performing a db query' do + links = Nokogiri::HTML.fragment("<a data-foo='1'></a><a data-foo='2'></a>").children + + expect(subject).not_to receive(:references_relation) + expect(subject.referenced_by(links, ids_only: true)).to eq(%w(1 2)) + end + + context 'and the html fragment does not contain any attributes' do + it 'returns an empty array' do + links = Nokogiri::HTML.fragment("no links").children + + expect(subject.referenced_by(links, ids_only: true)).to eq([]) + end + end end end @@ -188,7 +207,7 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do dummy = Class.new(described_class) do self.reference_type = :test - def gather_references(nodes) + def gather_references(nodes, ids_only: false) nodes end end @@ -222,7 +241,7 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do nodes.select { |n| n.id > 5 } end - def referenced_by(nodes) + def referenced_by(nodes, ids_only: false) nodes.map(&:id) end end diff --git a/spec/lib/gitlab/database/postgresql_adapter/dump_schema_versions_mixin_spec.rb b/spec/lib/gitlab/database/postgresql_adapter/dump_schema_versions_mixin_spec.rb index ca9f4af9187..fc6a235eabd 100644 --- a/spec/lib/gitlab/database/postgresql_adapter/dump_schema_versions_mixin_spec.rb +++ b/spec/lib/gitlab/database/postgresql_adapter/dump_schema_versions_mixin_spec.rb @@ -4,30 +4,61 @@ require 'spec_helper' RSpec.describe Gitlab::Database::PostgresqlAdapter::DumpSchemaVersionsMixin do let(:schema_migration) { double('schema_migration', all_versions: versions) } + let(:db_name) { 'primary' } + let(:versions) { %w(5 2 1000 200 4 93 2) } - let(:instance) do - Object.new.extend(described_class) + let(:instance_class) do + klass = Class.new do + def dump_schema_information + original_dump_schema_information + end + + def original_dump_schema_information + end + end + + klass.prepend(described_class) + + klass end + let(:instance) { instance_class.new } + before do allow(instance).to receive(:schema_migration).and_return(schema_migration) + + # pool is from ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + allow(instance).to receive_message_chain(:pool, :db_config, :name).and_return(db_name) end - context 'when version files exist' do - let(:versions) { %w(5 2 1000 200 4 93 2) } + context 'when database name is primary' do + context 'when version files exist' do + it 'touches version files' do + expect(Gitlab::Database::SchemaVersionFiles).to receive(:touch_all).with(versions) + expect(instance).not_to receive(:original_dump_schema_information) - it 'touches version files' do - expect(Gitlab::Database::SchemaVersionFiles).to receive(:touch_all).with(versions) + instance.dump_schema_information + end + end - instance.dump_schema_information + context 'when version files do not exist' do + let(:versions) { [] } + + it 'does not touch version files' do + expect(Gitlab::Database::SchemaVersionFiles).not_to receive(:touch_all) + expect(instance).not_to receive(:original_dump_schema_information) + + instance.dump_schema_information + end end end - context 'when version files do not exist' do - let(:versions) { [] } + context 'when database name is ci' do + let(:db_name) { 'ci' } it 'does not touch version files' do expect(Gitlab::Database::SchemaVersionFiles).not_to receive(:touch_all) + expect(instance).to receive(:original_dump_schema_information) instance.dump_schema_information end diff --git a/spec/lib/gitlab/database/postgresql_database_tasks/load_schema_versions_mixin_spec.rb b/spec/lib/gitlab/database/postgresql_database_tasks/load_schema_versions_mixin_spec.rb new file mode 100644 index 00000000000..8bd4ea66200 --- /dev/null +++ b/spec/lib/gitlab/database/postgresql_database_tasks/load_schema_versions_mixin_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Database::PostgresqlDatabaseTasks::LoadSchemaVersionsMixin do + let(:db_name) { 'primary' } + + let(:instance_class) do + klass = Class.new do + def structure_load + original_structure_load + end + + def original_structure_load + end + end + + klass.prepend(described_class) + + klass + end + + let(:instance) { instance_class.new } + + before do + # connection is available in ActiveRecord::Tasks::PostgreSQLDatabaseTasks + allow(instance).to receive_message_chain(:connection, :pool, :db_config, :name).and_return(db_name) + end + + context 'when database is primary' do + it 'loads version files' do + expect(Gitlab::Database::SchemaVersionFiles).to receive(:load_all) + expect(instance).to receive(:original_structure_load) + + instance.structure_load + end + end + + context 'when the database is ci' do + let(:db_name) { 'ci' } + + it 'does not load version files' do + expect(Gitlab::Database::SchemaVersionFiles).not_to receive(:load_all) + expect(instance).to receive(:original_structure_load) + + instance.structure_load + end + end +end diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 2e7b2c344f1..d71befccdfa 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -41,6 +41,45 @@ RSpec.describe Gitlab::Database do end end + describe '.has_config?' do + context 'two tier database config' do + before do + allow(Gitlab::Application).to receive_message_chain(:config, :database_configuration, :[]).with(Rails.env) + .and_return({ "adapter" => "postgresql", "database" => "gitlabhq_test" }) + end + + it 'returns false for primary' do + expect(described_class.has_config?(:primary)).to eq(false) + end + + it 'returns false for ci' do + expect(described_class.has_config?(:ci)).to eq(false) + end + end + + context 'three tier database config' do + before do + allow(Gitlab::Application).to receive_message_chain(:config, :database_configuration, :[]).with(Rails.env) + .and_return({ + "primary" => { "adapter" => "postgresql", "database" => "gitlabhq_test" }, + "ci" => { "adapter" => "postgresql", "database" => "gitlabhq_test_ci" } + }) + end + + it 'returns true for primary' do + expect(described_class.has_config?(:primary)).to eq(true) + end + + it 'returns true for ci' do + expect(described_class.has_config?(:ci)).to eq(true) + end + + it 'returns false for non-existent' do + expect(described_class.has_config?(:nonexistent)).to eq(false) + end + end + end + describe '.adapter_name' do it 'returns the name of the adapter' do expect(described_class.adapter_name).to be_an_instance_of(String) diff --git a/spec/migrations/active_record/schema_spec.rb b/spec/migrations/active_record/schema_spec.rb index 8199f55f5fc..4a505c51a16 100644 --- a/spec/migrations/active_record/schema_spec.rb +++ b/spec/migrations/active_record/schema_spec.rb @@ -7,10 +7,10 @@ require 'spec_helper' RSpec.describe ActiveRecord::Schema, schema: :latest do let(:all_migrations) do - migrations_paths = %w[db/migrate db/post_migrate] - .map { |path| Rails.root.join(*path, '*') } + migrations_directories = %w[db/migrate db/post_migrate].map { |path| Rails.root.join(path).to_s } + migrations_paths = migrations_directories.map { |path| File.join(path, '*') } - migrations = Dir[*migrations_paths] + migrations = Dir[*migrations_paths] - migrations_directories migrations.map { |migration| File.basename(migration).split('_').first.to_i }.sort end diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb index 38bdf3b9364..466a2b55e76 100644 --- a/spec/presenters/blob_presenter_spec.rb +++ b/spec/presenters/blob_presenter_spec.rb @@ -121,16 +121,26 @@ RSpec.describe BlobPresenter do end end - describe '#plain_data' do + describe '#raw_plain_data' do let(:blob) { repository.blob_at('HEAD', file) } - subject { described_class.new(blob).plain_data } + context 'when blob is text' do + let(:file) { 'files/ruby/popen.rb' } + + it 'does not include html in the content' do + expect(presenter.raw_plain_data.include?('</span>')).to be_falsey + end + end + end + + describe '#plain_data' do + let(:blob) { repository.blob_at('HEAD', file) } context 'when blob is binary' do let(:file) { 'files/images/logo-black.png' } it 'returns nil' do - expect(subject).to be_nil + expect(presenter.plain_data).to be_nil end end @@ -138,7 +148,7 @@ RSpec.describe BlobPresenter do let(:file) { 'README.md' } it 'returns plain content' do - expect(subject).to include('<span id="LC1" class="line" lang="markdown">') + expect(presenter.plain_data).to include('<span id="LC1" class="line" lang="markdown">') end end @@ -146,7 +156,7 @@ RSpec.describe BlobPresenter do let(:file) { 'files/ruby/regex.rb' } it 'returns highlighted syntax content' do - expect(subject) + expect(presenter.plain_data) .to include '<span id="LC1" class="line" lang="ruby"><span class="k">module</span> <span class="nn">Gitlab</span>' end end @@ -155,7 +165,7 @@ RSpec.describe BlobPresenter do let(:file) { 'LICENSE' } it 'returns plain text highlighted content' do - expect(subject).to include('<span id="LC1" class="line" lang="plaintext">The MIT License (MIT)</span>') + expect(presenter.plain_data).to include('<span id="LC1" class="line" lang="plaintext">The MIT License (MIT)</span>') end end end diff --git a/spec/presenters/snippet_blob_presenter_spec.rb b/spec/presenters/snippet_blob_presenter_spec.rb index 42eca6b5a49..1a5130dcdf6 100644 --- a/spec/presenters/snippet_blob_presenter_spec.rb +++ b/spec/presenters/snippet_blob_presenter_spec.rb @@ -120,6 +120,27 @@ RSpec.describe SnippetBlobPresenter do end end + describe '#raw_plain_data' do + context "with a plain file" do + subject { described_class.new(blob, current_user: user) } + + it 'shows raw data for non binary files' do + expect(subject.raw_plain_data).to eq(blob.data) + end + end + + context "with a binary file" do + let(:file) { 'files/images/logo-black.png' } + let(:blob) { blob_at(file) } + + subject { described_class.new(blob, current_user: user) } + + it 'returns nil' do + expect(subject.raw_plain_data).to be_nil + end + end + end + describe '#raw_url' do subject { described_class.new(blob, current_user: user).raw_url } diff --git a/spec/requests/api/graphql/mutations/packages/destroy_package_spec.rb b/spec/requests/api/graphql/mutations/packages/destroy_spec.rb index e5ced419ecf..e5ced419ecf 100644 --- a/spec/requests/api/graphql/mutations/packages/destroy_package_spec.rb +++ b/spec/requests/api/graphql/mutations/packages/destroy_spec.rb diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index b95d94e3784..2f7aaf3f7f8 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -488,6 +488,21 @@ RSpec.describe Issues::UpdateService, :mailer do end end end + + it 'verifies the number of queries' do + update_issue(description: "- [ ] Task 1 #{user.to_reference}") + + baseline = ActiveRecord::QueryRecorder.new do + update_issue(description: "- [x] Task 1 #{user.to_reference}") + end + + recorded = ActiveRecord::QueryRecorder.new do + update_issue(description: "- [x] Task 1 #{user.to_reference}\n- [ ] Task 2 #{user.to_reference}") + end + + expect(recorded.count).to eq(baseline.count - 1) + expect(recorded.cached_count).to eq(0) + end end context 'when description changed' do |