Commit ceab19b4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'organize-shared-examples' into 'master'

Organize the shared context and examples

See merge request gitlab-org/gitlab!23323
parents a721489c 077ee7f4
...@@ -5,6 +5,14 @@ require 'spec_helper' ...@@ -5,6 +5,14 @@ require 'spec_helper'
describe Gitlab::Email::Receiver do describe Gitlab::Email::Receiver do
include_context :email_shared_context include_context :email_shared_context
shared_examples 'correctly finds the mail key' do
specify do
expect(Gitlab::Email::Handler).to receive(:for).with(an_instance_of(Mail::Message), 'gitlabhq/gitlabhq+auth_token').and_return(handler)
receiver.execute
end
end
context 'when the email contains a valid email address in a header' do context 'when the email contains a valid email address in a header' do
let(:handler) { double(:handler) } let(:handler) { double(:handler) }
......
...@@ -16,6 +16,40 @@ describe Gitlab::MailRoom do ...@@ -16,6 +16,40 @@ describe Gitlab::MailRoom do
} }
end end
shared_examples_for 'only truthy if both enabled and address are truthy' do |target_proc|
context 'with both enabled and address as truthy values' do
it 'is truthy' do
stub_config(enabled: true, address: 'localhost')
expect(target_proc.call).to be_truthy
end
end
context 'with address only as truthy' do
it 'is falsey' do
stub_config(enabled: false, address: 'localhost')
expect(target_proc.call).to be_falsey
end
end
context 'with enabled only as truthy' do
it 'is falsey' do
stub_config(enabled: true, address: nil)
expect(target_proc.call).to be_falsey
end
end
context 'with neither address nor enabled as truthy' do
it 'is falsey' do
stub_config(enabled: false, address: nil)
expect(target_proc.call).to be_falsey
end
end
end
before do before do
described_class.reset_config! described_class.reset_config!
allow(File).to receive(:exist?).and_return true allow(File).to receive(:exist?).and_return true
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require 'fast_spec_helper'
require 'support/shared_examples/malicious_regexp_shared_examples' require 'support/shared_examples/lib/gitlab/malicious_regexp_shared_examples'
require 'support/helpers/stub_feature_flags' require 'support/helpers/stub_feature_flags'
describe Gitlab::UntrustedRegexp::RubySyntax do describe Gitlab::UntrustedRegexp::RubySyntax do
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require 'fast_spec_helper'
require 'support/shared_examples/malicious_regexp_shared_examples' require 'support/shared_examples/lib/gitlab/malicious_regexp_shared_examples'
describe Gitlab::UntrustedRegexp do describe Gitlab::UntrustedRegexp do
describe '#initialize' do describe '#initialize' do
......
...@@ -27,7 +27,42 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do ...@@ -27,7 +27,42 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
let(:build) { create(:ci_build, :running, :trace_live, pipeline: pipeline, project: parent) } let(:build) { create(:ci_build, :running, :trace_live, pipeline: pipeline, project: parent) }
let(:subjects) { build.trace_chunks } let(:subjects) { build.trace_chunks }
it_behaves_like 'fast destroyable' describe 'Forbid #destroy and #destroy_all' do
it 'does not delete database rows and associted external data' do
expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0
expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`')
expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`') # rubocop: disable DestroyAll
expect(subjects.count).to be > 0
expect(external_data_counter).to be > 0
end
end
describe '.fast_destroy_all' do
it 'deletes database rows and associted external data' do
expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0
expect { subjects.fast_destroy_all }.not_to raise_error
expect(subjects.count).to eq(0)
expect(external_data_counter).to eq(0)
end
end
describe '.use_fast_destroy' do
it 'performs cascading delete with fast_destroy_all' do
expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0
expect { parent.destroy }.not_to raise_error
expect(subjects.count).to eq(0)
expect(external_data_counter).to eq(0)
end
end
def external_data_counter def external_data_counter
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::SharedState.with do |redis|
......
...@@ -176,6 +176,35 @@ describe Projects::UpdatePagesService do ...@@ -176,6 +176,35 @@ describe Projects::UpdatePagesService do
describe 'maximum pages artifacts size' do describe 'maximum pages artifacts size' do
let(:metadata) { spy('metadata') } let(:metadata) { spy('metadata') }
shared_examples 'pages size limit is' do |size_limit|
context "when size is below the limit" do
before do
allow(metadata).to receive(:total_size).and_return(size_limit - 1.megabyte)
end
it 'updates pages correctly' do
subject.execute
expect(deploy_status.description).not_to be_present
expect(project.pages_metadatum).to be_deployed
end
end
context "when size is above the limit" do
before do
allow(metadata).to receive(:total_size).and_return(size_limit + 1.megabyte)
end
it 'limits the maximum size of gitlab pages' do
subject.execute
expect(deploy_status.description)
.to match(/artifacts for pages are too large/)
expect(deploy_status).to be_script_failure
end
end
end
before do before do
file = fixture_file_upload('spec/fixtures/pages.zip') file = fixture_file_upload('spec/fixtures/pages.zip')
metafile = fixture_file_upload('spec/fixtures/pages.zip.meta') metafile = fixture_file_upload('spec/fixtures/pages.zip.meta')
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
# Requires a reference: # Requires a reference:
# let(:reference) { '#42' } # let(:reference) { '#42' }
shared_examples 'a reference containing an element node' do RSpec.shared_examples 'a reference containing an element node' do
let(:inner_html) { 'element <code>node</code> inside' } let(:inner_html) { 'element <code>node</code> inside' }
let(:reference_with_element) { %{<a href="#{reference}">#{inner_html}</a>} } let(:reference_with_element) { %{<a href="#{reference}">#{inner_html}</a>} }
...@@ -18,7 +18,7 @@ end ...@@ -18,7 +18,7 @@ end
# subject { create(:user) } # subject { create(:user) }
# let(:reference) { subject.to_reference } # let(:reference) { subject.to_reference }
# let(:subject_name) { 'user' } # let(:subject_name) { 'user' }
shared_examples 'user reference or project reference' do RSpec.shared_examples 'user reference or project reference' do
shared_examples 'it contains a data- attribute' do shared_examples 'it contains a data- attribute' do
it 'includes a data- attribute' do it 'includes a data- attribute' do
doc = reference_filter("Hey #{reference}") doc = reference_filter("Hey #{reference}")
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'valid cluster create params' do RSpec.shared_context 'valid cluster create params' do
let(:params) do let(:params) do
{ {
name: 'test-cluster', name: 'test-cluster',
...@@ -16,7 +16,7 @@ shared_context 'valid cluster create params' do ...@@ -16,7 +16,7 @@ shared_context 'valid cluster create params' do
end end
end end
shared_context 'invalid cluster create params' do RSpec.shared_context 'invalid cluster create params' do
let(:params) do let(:params) do
{ {
name: 'test-cluster', name: 'test-cluster',
...@@ -31,7 +31,7 @@ shared_context 'invalid cluster create params' do ...@@ -31,7 +31,7 @@ shared_context 'invalid cluster create params' do
end end
end end
shared_examples 'create cluster service success' do RSpec.shared_examples 'create cluster service success' do
it 'creates a cluster object and performs a worker' do it 'creates a cluster object and performs a worker' do
expect(ClusterProvisionWorker).to receive(:perform_async) expect(ClusterProvisionWorker).to receive(:perform_async)
...@@ -53,7 +53,7 @@ shared_examples 'create cluster service success' do ...@@ -53,7 +53,7 @@ shared_examples 'create cluster service success' do
end end
end end
shared_examples 'create cluster service error' do RSpec.shared_examples 'create cluster service error' do
it 'returns an error' do it 'returns an error' do
expect(ClusterProvisionWorker).not_to receive(:perform_async) expect(ClusterProvisionWorker).not_to receive(:perform_async)
expect { subject }.to change { Clusters::Cluster.count }.by(0) expect { subject }.to change { Clusters::Cluster.count }.by(0)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# Specifications for behavior common to all objects with executable attributes. # Specifications for behavior common to all objects with executable attributes.
# It can take a `default_params`. # It can take a `default_params`.
shared_examples 'new issuable record that supports quick actions' do RSpec.shared_examples 'new issuable record that supports quick actions' do
let!(:project) { create(:project, :repository) } let!(:project) { create(:project, :repository) }
let(:user) { create(:user).tap { |u| project.add_maintainer(u) } } let(:user) { create(:user).tap { |u| project.add_maintainer(u) } }
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'issuable update service' do RSpec.shared_examples 'issuable update service' do
def update_issuable(opts) def update_issuable(opts)
described_class.new(project, user, opts).execute(open_issuable) described_class.new(project, user, opts).execute(open_issuable)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require "spec_helper" RSpec.shared_examples "migrating a deleted user's associated records to the ghost user" do |record_class, fields|
shared_examples "migrating a deleted user's associated records to the ghost user" do |record_class, fields|
record_class_name = record_class.to_s.titleize.downcase record_class_name = record_class.to_s.titleize.downcase
let(:project) do let(:project) do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'change access checks context' do RSpec.shared_context 'change access checks context' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user_access) { Gitlab::UserAccess.new(user, project: project) } let(:user_access) { Gitlab::UserAccess.new(user, project: project) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'a GitHub-ish import controller' do RSpec.shared_context 'a GitHub-ish import controller' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:token) { "asdasd12345" } let(:token) { "asdasd12345" }
let(:access_params) { { github_access_token: token } } let(:access_params) { { github_access_token: token } }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_context 'Ldap::OmniauthCallbacksController' do
shared_context 'Ldap::OmniauthCallbacksController' do
include LoginHelpers include LoginHelpers
include LdapHelpers include LdapHelpers
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context :email_shared_context do RSpec.shared_context :email_shared_context do
let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" }
let(:receiver) { Gitlab::Email::Receiver.new(email_raw) } let(:receiver) { Gitlab::Email::Receiver.new(email_raw) }
let(:markdown) { "![image](uploads/image.png)" } let(:markdown) { "![image](uploads/image.png)" }
...@@ -18,7 +18,7 @@ shared_context :email_shared_context do ...@@ -18,7 +18,7 @@ shared_context :email_shared_context do
end end
end end
shared_examples :reply_processing_shared_examples do RSpec.shared_examples :reply_processing_shared_examples do
context "when the user could not be found" do context "when the user could not be found" do
before do before do
user.destroy user.destroy
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper'
RSpec.shared_context 'GroupProjectsFinder context' do RSpec.shared_context 'GroupProjectsFinder context' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:subgroup) { create(:group, parent: group) } let(:subgroup) { create(:group, parent: group) }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper'
RSpec.shared_context 'IssuesFinder context' do RSpec.shared_context 'IssuesFinder context' do
set(:user) { create(:user) } set(:user) { create(:user) }
set(:user2) { create(:user) } set(:user2) { create(:user) }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper'
RSpec.shared_context 'MergeRequestsFinder multiple projects with merge requests context' do RSpec.shared_context 'MergeRequestsFinder multiple projects with merge requests context' do
include ProjectForksHelper include ProjectForksHelper
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper'
RSpec.shared_context 'UsersFinder#execute filter by project context' do RSpec.shared_context 'UsersFinder#execute filter by project context' do
set(:normal_user) { create(:user, username: 'johndoe') } set(:normal_user) { create(:user, username: 'johndoe') }
set(:blocked_user) { create(:user, :blocked, username: 'notsorandom') } set(:blocked_user) { create(:user, :blocked, username: 'notsorandom') }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'JSON response' do RSpec.shared_context 'JSON response' do
let(:json_response) { JSON.parse(response.body) } let(:json_response) { JSON.parse(response.body) }
end end
# frozen_string_literal: true
RSpec.shared_context 'gitlab email notification' do
set(:group) { create(:group) }
set(:subgroup) { create(:group, parent: group) }
set(:project) { create(:project, :repository, name: 'a-known-name', group: group) }
set(:recipient) { create(:user, email: 'recipient@example.com') }
let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name }
let(:gitlab_sender) { Gitlab.config.gitlab.email_from }
let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to }
let(:new_user_address) { 'newguy@example.com' }
before do
email = recipient.emails.create(email: "notifications@example.com")
recipient.update_attribute(:notification_email, email.email)
stub_incoming_email_setting(enabled: true, address: "reply+%{key}@#{Gitlab.config.gitlab.host}")
end
end
RSpec.shared_context 'reply-by-email is enabled with incoming address without %{key}' do
before do
stub_incoming_email_setting(enabled: true, address: "reply@#{Gitlab.config.gitlab.host}")
end
end
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'merge request create context' do RSpec.shared_context 'merge request create context' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:target_project) { create(:project, :public, :repository) } let(:target_project) { create(:project, :public, :repository) }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_context 'merge request edit context' do
shared_context 'merge request edit context' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let!(:milestone) { create(:milestone, project: target_project) } let!(:milestone) { create(:milestone, project: target_project) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'merge request allowing collaboration' do RSpec.shared_context 'merge request allowing collaboration' do
include ProjectForksHelper include ProjectForksHelper
let(:canonical) { create(:project, :public, :repository) } let(:canonical) { create(:project, :public, :repository) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'rack attack cache store' do RSpec.shared_context 'rack attack cache store' do
around do |example| around do |example|
# Instead of test environment's :null_store so the throttles can increment # Instead of test environment's :null_store so the throttles can increment
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
......
# frozen_string_literal: true # frozen_string_literal: true
Service.available_services_names.each do |service| Service.available_services_names.each do |service|
shared_context service do RSpec.shared_context service do
let(:dashed_service) { service.dasherize } let(:dashed_service) { service.dasherize }
let(:service_method) { "#{service}_service".to_sym } let(:service_method) { "#{service}_service".to_sym }
let(:service_klass) { "#{service}_service".classify.constantize } let(:service_klass) { "#{service}_service".classify.constantize }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# let(:session) variable # let(:session) variable
# we do not use a parameter such as |session| because it does not play nice # we do not use a parameter such as |session| because it does not play nice
# with let variables # with let variables
shared_context 'custom session' do RSpec.shared_context 'custom session' do
let!(:session) { {} } let!(:session) { {} }
around do |example| around do |example|
......
# frozen_string_literal: true
RSpec.shared_context 'unique ips sign in limit' do
include StubENV
let(:request_context) { Gitlab::RequestContext.instance }
before do
Gitlab::Redis::Cache.with(&:flushall)
Gitlab::Redis::Queues.with(&:flushall)
Gitlab::Redis::SharedState.with(&:flushall)
end
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
Gitlab::CurrentSettings.update!(
unique_ips_limit_enabled: true,
unique_ips_limit_time_window: 10000
)
# Make sure we're working with the same reqeust context everywhere
allow(Gitlab::RequestContext).to receive(:instance).and_return(request_context)
end
def change_ip(ip)
allow(request_context).to receive(:client_ip).and_return(ip)
end
def request_from_ip(ip)
change_ip(ip)
request
response
end
def operation_from_ip(ip)
change_ip(ip)
operation
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Construct an `uploader` variable that is configured to `check_upload_type` # Construct an `uploader` variable that is configured to `check_upload_type`
# with `mime_types` and `extensions`. # with `mime_types` and `extensions`.
shared_context 'uploader with type check' do RSpec.shared_context 'uploader with type check' do
let(:uploader_class) do let(:uploader_class) do
Class.new(GitlabUploader) do Class.new(GitlabUploader) do
include UploadTypeCheck::Concern include UploadTypeCheck::Concern
...@@ -20,7 +20,7 @@ shared_context 'uploader with type check' do ...@@ -20,7 +20,7 @@ shared_context 'uploader with type check' do
end end
end end
shared_context 'stubbed MimeMagic mime type detection' do RSpec.shared_context 'stubbed MimeMagic mime type detection' do
let(:mime_type) { '' } let(:mime_type) { '' }
let(:magic_mime) { mime_type } let(:magic_mime) { mime_type }
let(:ext_mime) { mime_type } let(:ext_mime) { mime_type }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'invalid urls' do RSpec.shared_context 'invalid urls' do
let(:urls_with_CRLF) do let(:urls_with_CRLF) do
["http://127.0.0.1:333/pa\rth", ["http://127.0.0.1:333/pa\rth",
"http://127.0.0.1:333/pa\nth", "http://127.0.0.1:333/pa\nth",
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for 'multiple issue boards' do RSpec.shared_examples 'multiple issue boards' do
context 'authorized user' do context 'authorized user' do
before do before do
parent.add_maintainer(user) parent.add_maintainer(user)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'aborted merge requests for MWPS' do RSpec.shared_examples 'aborted merge requests for MWPS' do
let(:aborted_message) do let(:aborted_message) do
/aborted the automatic merge because target branch was updated/ /aborted the automatic merge because target branch was updated/
end end
...@@ -23,7 +23,7 @@ shared_examples 'aborted merge requests for MWPS' do ...@@ -23,7 +23,7 @@ shared_examples 'aborted merge requests for MWPS' do
end end
end end
shared_examples 'maintained merge requests for MWPS' do RSpec.shared_examples 'maintained merge requests for MWPS' do
it 'does not cancel auto merge' do it 'does not cancel auto merge' do
expect(merge_request.auto_merge_enabled?).to be_truthy expect(merge_request.auto_merge_enabled?).to be_truthy
expect(merge_request.notes).to be_empty expect(merge_request.notes).to be_empty
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for 'correct pipeline information for pipelines for merge requests' do RSpec.shared_examples 'correct pipeline information for pipelines for merge requests' do
context 'when pipeline for merge request' do context 'when pipeline for merge request' do
let(:pipeline) { merge_request.all_pipelines.first } let(:pipeline) { merge_request.all_pipelines.first }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'manual playable stage' do |stage_type| RSpec.shared_examples 'manual playable stage' do |stage_type|
let(:stage) { build(stage_type, status: status) } let(:stage) { build(stage_type, status: status) }
describe '#manual_playable?' do describe '#manual_playable?' do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'renders correct panels' do RSpec.shared_examples 'renders correct panels' do
it 'renders correct action on error' do it 'renders correct action on error' do
expect_next_instance_of(ApplicationSettings::UpdateService) do |service| expect_next_instance_of(ApplicationSettings::UpdateService) do |service|
allow(service).to receive(:execute).and_return(false) allow(service).to receive(:execute).and_return(false)
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_examples 'discussions provider' do
shared_examples 'discussions provider' do
it 'returns the expected discussions' do it 'returns the expected discussions' do
get :discussions, params: { namespace_id: project.namespace, project_id: project, id: requested_iid } get :discussions, params: { namespace_id: project.namespace, project_id: project, id: requested_iid }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for 'successful response for #cancel_auto_stop' do RSpec.shared_examples 'successful response for #cancel_auto_stop' do
include GitlabRoutingHelper include GitlabRoutingHelper
context 'when request is html' do context 'when request is html' do
...@@ -42,7 +42,7 @@ shared_examples_for 'successful response for #cancel_auto_stop' do ...@@ -42,7 +42,7 @@ shared_examples_for 'successful response for #cancel_auto_stop' do
end end
end end
shared_examples_for 'failed response for #cancel_auto_stop' do RSpec.shared_examples 'failed response for #cancel_auto_stop' do
context 'when request is html' do context 'when request is html' do
let(:params) { environment_params(format: :html) } let(:params) { environment_params(format: :html) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'sets the polling header' do RSpec.shared_examples 'sets the polling header' do
subject { response.headers[Gitlab::PollingInterval::HEADER_NAME] } subject { response.headers[Gitlab::PollingInterval::HEADER_NAME] }
it { is_expected.to eq '1000'} it { is_expected.to eq '1000'}
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_examples 'disabled when using an external authorization service' do
shared_examples 'disabled when using an external authorization service' do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
it 'works when the feature is not enabled' do it 'works when the feature is not enabled' do
...@@ -20,7 +18,7 @@ shared_examples 'disabled when using an external authorization service' do ...@@ -20,7 +18,7 @@ shared_examples 'disabled when using an external authorization service' do
end end
end end
shared_examples 'unauthorized when external service denies access' do RSpec.shared_examples 'unauthorized when external service denies access' do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
it 'allows access when the authorization service allows it' do it 'allows access when the authorization service allows it' do
......
...@@ -10,7 +10,7 @@ def assign_session_token(provider) ...@@ -10,7 +10,7 @@ def assign_session_token(provider)
session[:"#{provider}_access_token"] = 'asdasd12345' session[:"#{provider}_access_token"] = 'asdasd12345'
end end
shared_examples 'a GitHub-ish import controller: POST personal_access_token' do RSpec.shared_examples 'a GitHub-ish import controller: POST personal_access_token' do
let(:status_import_url) { public_send("status_import_#{provider}_url") } let(:status_import_url) { public_send("status_import_#{provider}_url") }
it "updates access token" do it "updates access token" do
...@@ -38,7 +38,7 @@ shared_examples 'a GitHub-ish import controller: POST personal_access_token' do ...@@ -38,7 +38,7 @@ shared_examples 'a GitHub-ish import controller: POST personal_access_token' do
end end
end end
shared_examples 'a GitHub-ish import controller: GET new' do RSpec.shared_examples 'a GitHub-ish import controller: GET new' do
let(:status_import_url) { public_send("status_import_#{provider}_url") } let(:status_import_url) { public_send("status_import_#{provider}_url") }
it "redirects to status if we already have a token" do it "redirects to status if we already have a token" do
...@@ -57,7 +57,7 @@ shared_examples 'a GitHub-ish import controller: GET new' do ...@@ -57,7 +57,7 @@ shared_examples 'a GitHub-ish import controller: GET new' do
end end
end end
shared_examples 'a GitHub-ish import controller: GET status' do RSpec.shared_examples 'a GitHub-ish import controller: GET status' do
let(:new_import_url) { public_send("new_import_#{provider}_url") } let(:new_import_url) { public_send("new_import_#{provider}_url") }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:repo) { OpenStruct.new(login: 'vim', full_name: 'asd/vim', name: 'vim', owner: { login: 'owner' }) } let(:repo) { OpenStruct.new(login: 'vim', full_name: 'asd/vim', name: 'vim', owner: { login: 'owner' }) }
...@@ -76,7 +76,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do ...@@ -76,7 +76,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do
get :status, format: :json get :status, format: :json
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.dig("imported_projects", 0, "id")).to eq(project.id) expect(json_response.dig("imported_projects", 0, "id")).to eq(project.id)
expect(json_response.dig("provider_repos", 0, "id")).to eq(repo.id) expect(json_response.dig("provider_repos", 0, "id")).to eq(repo.id)
expect(json_response.dig("provider_repos", 1, "id")).to eq(org_repo.id) expect(json_response.dig("provider_repos", 1, "id")).to eq(org_repo.id)
...@@ -107,7 +107,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do ...@@ -107,7 +107,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do
get :status get :status
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it "handles an invalid access token" do it "handles an invalid access token" do
...@@ -153,7 +153,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do ...@@ -153,7 +153,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do
it 'filters list of repositories by name' do it 'filters list of repositories by name' do
get :status, params: { filter: 'emacs' }, format: :json get :status, params: { filter: 'emacs' }, format: :json
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.dig("imported_projects").count).to eq(0) expect(json_response.dig("imported_projects").count).to eq(0)
expect(json_response.dig("provider_repos").count).to eq(1) expect(json_response.dig("provider_repos").count).to eq(1)
expect(json_response.dig("provider_repos", 0, "id")).to eq(repo_2.id) expect(json_response.dig("provider_repos", 0, "id")).to eq(repo_2.id)
...@@ -173,7 +173,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do ...@@ -173,7 +173,7 @@ shared_examples 'a GitHub-ish import controller: GET status' do
end end
end end
shared_examples 'a GitHub-ish import controller: POST create' do RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:provider_username) { user.username } let(:provider_username) { user.username }
let(:provider_user) { OpenStruct.new(login: provider_username) } let(:provider_user) { OpenStruct.new(login: provider_username) }
...@@ -198,7 +198,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do ...@@ -198,7 +198,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do
post :create, format: :json post :create, format: :json
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it 'returns 422 response with the base error when the project could not be imported' do it 'returns 422 response with the base error when the project could not be imported' do
...@@ -212,7 +212,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do ...@@ -212,7 +212,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do
post :create, format: :json post :create, format: :json
expect(response).to have_gitlab_http_status(422) expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response['errors']).to eq('Name is invalid, Path is old') expect(json_response['errors']).to eq('Name is invalid, Path is old')
end end
...@@ -484,13 +484,13 @@ shared_examples 'a GitHub-ish import controller: POST create' do ...@@ -484,13 +484,13 @@ shared_examples 'a GitHub-ish import controller: POST create' do
post :create, params: { target_namespace: other_namespace.name }, format: :json post :create, params: { target_namespace: other_namespace.name }, format: :json
expect(response).to have_gitlab_http_status(422) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
end end
end end
end end
shared_examples 'a GitHub-ish import controller: GET realtime_changes' do RSpec.shared_examples 'a GitHub-ish import controller: GET realtime_changes' do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'instance statistics availability' do RSpec.shared_examples 'instance statistics availability' do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'issuable notes filter' do RSpec.shared_examples 'issuable notes filter' do
let(:params) do let(:params) do
if issuable_parent.is_a?(Project) if issuable_parent.is_a?(Project)
{ namespace_id: issuable_parent.namespace, project_id: issuable_parent, id: issuable.iid } { namespace_id: issuable_parent.namespace, project_id: issuable_parent, id: issuable.iid }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'issuables list meta-data' do |issuable_type, action = nil| RSpec.shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
include ProjectForksHelper include ProjectForksHelper
def get_action(action, project, extra_params = {}) def get_action(action, project, extra_params = {})
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'issuables requiring filter' do |action| RSpec.shared_examples 'issuables requiring filter' do |action|
it "doesn't load any issuables if no filter is set" do it "doesn't load any issuables if no filter is set" do
expect_any_instance_of(described_class).not_to receive(:issuables_collection) expect_any_instance_of(described_class).not_to receive(:issuables_collection)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'milestone tabs' do RSpec.shared_examples 'milestone tabs' do
def go(path, extra_params = {}) def go(path, extra_params = {})
params = params =
case milestone case milestone
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_examples 'paginated collection' do
shared_examples 'paginated collection' do
let(:collection) { nil } let(:collection) { nil }
let(:last_page) { collection.page.total_pages } let(:last_page) { collection.page.total_pages }
let(:action) { :index } let(:action) { :index }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# it_behaves_like 'a controller that can serve LFS files', skip_lfs_disabled_tests: true do # it_behaves_like 'a controller that can serve LFS files', skip_lfs_disabled_tests: true do
# ... # ...
# end # end
shared_examples 'a controller that can serve LFS files' do |options = {}| RSpec.shared_examples 'a controller that can serve LFS files' do |options = {}|
let(:lfs_oid) { '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897' } let(:lfs_oid) { '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897' }
let(:lfs_size) { '1575078' } let(:lfs_size) { '1575078' }
let!(:lfs_object) { create(:lfs_object, oid: lfs_oid, size: lfs_size) } let!(:lfs_object) { create(:lfs_object, oid: lfs_oid, size: lfs_size) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'authenticates sessionless user' do |path, format, params| RSpec.shared_examples 'authenticates sessionless user' do |path, format, params|
params ||= {} params ||= {}
before do before do
...@@ -20,14 +20,14 @@ shared_examples 'authenticates sessionless user' do |path, format, params| ...@@ -20,14 +20,14 @@ shared_examples 'authenticates sessionless user' do |path, format, params|
get path, params: default_params.merge(private_token: personal_access_token.token) get path, params: default_params.merge(private_token: personal_access_token.token)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(controller.current_user).to eq(user) expect(controller.current_user).to eq(user)
end end
it 'does not log the user in if page is public', if: params[:public] do it 'does not log the user in if page is public', if: params[:public] do
get path, params: default_params get path, params: default_params
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(controller.current_user).to be_nil expect(controller.current_user).to be_nil
end end
end end
...@@ -48,7 +48,7 @@ shared_examples 'authenticates sessionless user' do |path, format, params| ...@@ -48,7 +48,7 @@ shared_examples 'authenticates sessionless user' do |path, format, params|
get path, params: default_params.merge(private_token: personal_access_token.token) get path, params: default_params.merge(private_token: personal_access_token.token)
expect(response).not_to have_gitlab_http_status(200) expect(response).not_to have_gitlab_http_status(:ok)
end end
end end
...@@ -62,7 +62,7 @@ shared_examples 'authenticates sessionless user' do |path, format, params| ...@@ -62,7 +62,7 @@ shared_examples 'authenticates sessionless user' do |path, format, params|
@request.headers['PRIVATE-TOKEN'] = personal_access_token.token @request.headers['PRIVATE-TOKEN'] = personal_access_token.token
get path, params: default_params get path, params: default_params
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -75,7 +75,7 @@ shared_examples 'authenticates sessionless user' do |path, format, params| ...@@ -75,7 +75,7 @@ shared_examples 'authenticates sessionless user' do |path, format, params|
get path, params: default_params.merge(feed_token: user.feed_token) get path, params: default_params.merge(feed_token: user.feed_token)
expect(response).to have_gitlab_http_status 200 expect(response).to have_gitlab_http_status(:ok)
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'set sort order from user preference' do RSpec.shared_examples 'set sort order from user preference' do
describe '#set_sort_order_from_user_preference' do describe '#set_sort_order_from_user_preference' do
# There is no sorting_field defined in any CE controllers yet, # There is no sorting_field defined in any CE controllers yet,
# however any other field present in user_preferences table can be used for testing. # however any other field present in user_preferences table can be used for testing.
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'todos actions' do RSpec.shared_examples 'todos actions' do
context 'when authorized' do context 'when authorized' do
before do before do
sign_in(user) sign_in(user)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'a Trackable Controller' do RSpec.shared_examples 'a Trackable Controller' do
describe '#track_event' do describe '#track_event' do
before do before do
sign_in user sign_in user
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'update invalid issuable' do |klass| RSpec.shared_examples 'update invalid issuable' do |klass|
let(:params) do let(:params) do
{ {
namespace_id: project.namespace.path, namespace_id: project.namespace.path,
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'handle uploads' do RSpec.shared_examples 'handle uploads' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:jpg) { fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') } let(:jpg) { fixture_file_upload('spec/fixtures/rails_sample.jpg', 'image/jpg') }
let(:txt) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') } let(:txt) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') }
...@@ -287,7 +287,7 @@ shared_examples 'handle uploads' do ...@@ -287,7 +287,7 @@ shared_examples 'handle uploads' do
end end
end end
shared_examples 'handle uploads authorize' do RSpec.shared_examples 'handle uploads authorize' do
describe "POST #authorize" do describe "POST #authorize" do
context 'when a user is not authorized to upload a file' do context 'when a user is not authorized to upload a file' do
it 'returns 404 status' do it 'returns 404 status' do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'GET #show lists all variables' do RSpec.shared_examples 'GET #show lists all variables' do
it 'renders the variables as json' do it 'renders the variables as json' do
subject subject
...@@ -14,7 +14,7 @@ shared_examples 'GET #show lists all variables' do ...@@ -14,7 +14,7 @@ shared_examples 'GET #show lists all variables' do
end end
end end
shared_examples 'PATCH #update updates variables' do RSpec.shared_examples 'PATCH #update updates variables' do
let(:variable_attributes) do let(:variable_attributes) do
{ id: variable.id, { id: variable.id,
key: variable.key, key: variable.key,
......
# frozen_string_literal: true
shared_examples_for 'correctly finds the mail key' do
specify do
expect(Gitlab::Email::Handler).to receive(:for).with(an_instance_of(Mail::Message), 'gitlabhq/gitlabhq+auth_token').and_return(handler)
receiver.execute
end
end
# frozen_string_literal: true
shared_examples 'updated exposed field' do
it 'creates another Evidence object' do
model.send("#{updated_field}=", updated_value)
expect(model.evidence_summary_keys).to include(updated_field)
expect { model.save! }.to change(Evidence, :count).by(1)
expect(updated_json_field).to eq(updated_value)
end
end
shared_examples 'updated non-exposed field' do
it 'does not create any Evidence object' do
model.send("#{updated_field}=", updated_value)
expect(model.evidence_summary_keys).not_to include(updated_field)
expect { model.save! }.not_to change(Evidence, :count)
end
end
shared_examples 'updated field on non-linked entity' do
it 'does not create any Evidence object' do
model.send("#{updated_field}=", updated_value)
expect(model.evidence_summary_keys).to be_empty
expect { model.save! }.not_to change(Evidence, :count)
end
end
# frozen_string_literal: true
shared_examples_for 'fast destroyable' do
describe 'Forbid #destroy and #destroy_all' do
it 'does not delete database rows and associted external data' do
expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0
expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`')
expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`') # rubocop: disable DestroyAll
expect(subjects.count).to be > 0
expect(external_data_counter).to be > 0
end
end
describe '.fast_destroy_all' do
it 'deletes database rows and associted external data' do
expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0
expect { subjects.fast_destroy_all }.not_to raise_error
expect(subjects.count).to eq(0)
expect(external_data_counter).to eq(0)
end
end
describe '.use_fast_destroy' do
it 'performs cascading delete with fast_destroy_all' do
expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0
expect { parent.destroy }.not_to raise_error
expect(subjects.count).to eq(0)
expect(external_data_counter).to eq(0)
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'archive download buttons' do RSpec.shared_examples 'archive download buttons' do
let(:path_to_visit) { project_path(project) } let(:path_to_visit) { project_path(project) }
let(:ref) { project.default_branch } let(:ref) { project.default_branch }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'comment on merge request file' do RSpec.shared_examples 'comment on merge request file' do
it 'adds a comment' do it 'adds a comment' do
click_diff_line(find("[id='#{sample_commit.line_code}']")) click_diff_line(find("[id='#{sample_commit.line_code}']"))
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'dirty submit form' do |selector_args| RSpec.shared_examples 'dirty submit form' do |selector_args|
selectors = selector_args.is_a?(Array) ? selector_args : [selector_args] selectors = selector_args.is_a?(Array) ? selector_args : [selector_args]
def expect_disabled_state(form, submit_selector, is_disabled = true) def expect_disabled_state(form, submit_selector, is_disabled = true)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'thread comments' do |resource_name| RSpec.shared_examples 'thread comments' do |resource_name|
let(:form_selector) { '.js-main-target-form' } let(:form_selector) { '.js-main-target-form' }
let(:dropdown_selector) { "#{form_selector} .comment-type-dropdown" } let(:dropdown_selector) { "#{form_selector} .comment-type-dropdown" }
let(:toggle_selector) { "#{dropdown_selector} .dropdown-toggle" } let(:toggle_selector) { "#{dropdown_selector} .dropdown-toggle" }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'issue sidebar stays collapsed on mobile' do RSpec.shared_examples 'issue sidebar stays collapsed on mobile' do
before do before do
resize_screen_xs resize_screen_xs
end end
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'issuable user dropdown behaviors' do RSpec.shared_examples 'issuable user dropdown behaviors' do
include FilteredSearchHelpers include FilteredSearchHelpers
before do before do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'multiple assignees merge request' do |action, save_button_title| RSpec.shared_examples 'multiple assignees merge request' do |action, save_button_title|
it "#{action} a MR with multiple assignees", :js do it "#{action} a MR with multiple assignees", :js do
find('.js-assignee-search').click find('.js-assignee-search').click
page.within '.dropdown-menu-user' do page.within '.dropdown-menu-user' do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'project features apply to issuables' do |klass| RSpec.shared_examples 'project features apply to issuables' do |klass|
let(:described_class) { klass } let(:described_class) { klass }
let(:group) { create(:group) } let(:group) { create(:group) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'shows public projects' do RSpec.shared_examples 'shows public projects' do
it 'shows projects' do it 'shows projects' do
expect(page).to have_content(public_project.title) expect(page).to have_content(public_project.title)
expect(page).not_to have_content(internal_project.title) expect(page).not_to have_content(internal_project.title)
...@@ -9,7 +9,7 @@ shared_examples 'shows public projects' do ...@@ -9,7 +9,7 @@ shared_examples 'shows public projects' do
end end
end end
shared_examples 'shows public and internal projects' do RSpec.shared_examples 'shows public and internal projects' do
it 'shows projects' do it 'shows projects' do
expect(page).to have_content(public_project.title) expect(page).to have_content(public_project.title)
expect(page).to have_content(internal_project.title) expect(page).to have_content(internal_project.title)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples "protected branches > access control > CE" do RSpec.shared_examples "protected branches > access control > CE" do
ProtectedRefAccess::HUMAN_ACCESS_LEVELS.each do |(access_type_id, access_type_name)| ProtectedRefAccess::HUMAN_ACCESS_LEVELS.each do |(access_type_id, access_type_name)|
it "allows creating protected branches that #{access_type_name} can push to" do it "allows creating protected branches that #{access_type_name} can push to" do
visit project_protected_branches_path(project) visit project_protected_branches_path(project)
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_examples 'reportable note' do |type|
shared_examples 'reportable note' do |type|
include MobileHelpers include MobileHelpers
include NotesHelper include NotesHelper
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'creating an issue for a thread' do RSpec.shared_examples 'creating an issue for a thread' do
it 'shows an issue with the title filled in' do it 'shows an issue with the title filled in' do
title_field = page.find_field('issue[title]') title_field = page.find_field('issue[title]')
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples "an autodiscoverable RSS feed with current_user's feed token" do RSpec.shared_examples "an autodiscoverable RSS feed with current_user's feed token" do
it "has an RSS autodiscovery link tag with current_user's feed token" do it "has an RSS autodiscovery link tag with current_user's feed token" do
expect(page).to have_css("link[type*='atom+xml'][href*='feed_token=#{user.feed_token}']", visible: false) expect(page).to have_css("link[type*='atom+xml'][href*='feed_token=#{user.feed_token}']", visible: false)
end end
end end
shared_examples "it has an RSS button with current_user's feed token" do RSpec.shared_examples "it has an RSS button with current_user's feed token" do
it "shows the RSS button with current_user's feed token" do it "shows the RSS button with current_user's feed token" do
expect(page) expect(page)
.to have_css("a:has(.fa-rss)[href*='feed_token=#{user.feed_token}']") .to have_css("a:has(.fa-rss)[href*='feed_token=#{user.feed_token}']")
...@@ -14,13 +14,13 @@ shared_examples "it has an RSS button with current_user's feed token" do ...@@ -14,13 +14,13 @@ shared_examples "it has an RSS button with current_user's feed token" do
end end
end end
shared_examples "an autodiscoverable RSS feed without a feed token" do RSpec.shared_examples "an autodiscoverable RSS feed without a feed token" do
it "has an RSS autodiscovery link tag without a feed token" do it "has an RSS autodiscovery link tag without a feed token" do
expect(page).to have_css("link[type*='atom+xml']:not([href*='feed_token'])", visible: false) expect(page).to have_css("link[type*='atom+xml']:not([href*='feed_token'])", visible: false)
end end
end end
shared_examples "it has an RSS button without a feed token" do RSpec.shared_examples "it has an RSS button without a feed token" do
it "shows the RSS button without a feed token" do it "shows the RSS button without a feed token" do
expect(page) expect(page)
.to have_css("a:has(.fa-rss):not([href*='feed_token'])") .to have_css("a:has(.fa-rss):not([href*='feed_token'])")
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'top right search form' do RSpec.shared_examples 'top right search form' do
it 'does not show top right search form' do it 'does not show top right search form' do
expect(page).not_to have_selector('.search') expect(page).not_to have_selector('.search')
end end
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'showing user status' do RSpec.shared_examples 'showing user status' do
let!(:status) { create(:user_status, user: user_with_status, emoji: 'smirk', message: 'Authoring this object') } let!(:status) { create(:user_status, user: user_with_status, emoji: 'smirk', message: 'Authoring this object') }
it 'shows the status' do it 'shows the status' do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'variable list' do RSpec.shared_examples 'variable list' do
it 'shows list of variables' do it 'shows list of variables' do
page.within('.js-ci-variable-list-section') do page.within('.js-ci-variable-list-section') do
expect(first('.js-ci-variable-input-key').value).to eq(variable.key) expect(first('.js-ci-variable-input-key').value).to eq(variable.key)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# Requires a context containing: # Requires a context containing:
# project # project
shared_examples 'wiki file attachments' do RSpec.shared_examples 'wiki file attachments' do
include DropzoneHelper include DropzoneHelper
context 'uploading attachments', :js do context 'uploading attachments', :js do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'assignee ID filter' do RSpec.shared_examples 'assignee ID filter' do
it 'returns issuables assigned to that user' do it 'returns issuables assigned to that user' do
expect(issuables).to contain_exactly(*expected_issuables) expect(issuables).to contain_exactly(*expected_issuables)
end end
end end
shared_examples 'assignee NOT ID filter' do RSpec.shared_examples 'assignee NOT ID filter' do
it 'returns issuables not assigned to that user' do it 'returns issuables not assigned to that user' do
expect(issuables).to contain_exactly(*expected_issuables) expect(issuables).to contain_exactly(*expected_issuables)
end end
end end
shared_examples 'assignee username filter' do RSpec.shared_examples 'assignee username filter' do
it 'returns issuables assigned to those users' do it 'returns issuables assigned to those users' do
expect(issuables).to contain_exactly(*expected_issuables) expect(issuables).to contain_exactly(*expected_issuables)
end end
end end
shared_examples 'assignee NOT username filter' do RSpec.shared_examples 'assignee NOT username filter' do
it 'returns issuables not assigned to those users' do it 'returns issuables not assigned to those users' do
expect(issuables).to contain_exactly(*expected_issuables) expect(issuables).to contain_exactly(*expected_issuables)
end end
end end
shared_examples 'no assignee filter' do RSpec.shared_examples 'no assignee filter' do
let(:params) { { assignee_id: 'None' } } let(:params) { { assignee_id: 'None' } }
it 'returns issuables not assigned to any assignee' do it 'returns issuables not assigned to any assignee' do
...@@ -38,7 +38,7 @@ shared_examples 'no assignee filter' do ...@@ -38,7 +38,7 @@ shared_examples 'no assignee filter' do
end end
end end
shared_examples 'any assignee filter' do RSpec.shared_examples 'any assignee filter' do
context '' do context '' do
let(:params) { { assignee_id: 'Any' } } let(:params) { { assignee_id: 'Any' } }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' RSpec.shared_examples 'a finder with external authorization service' do
shared_examples 'a finder with external authorization service' do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper'
# Shared example for legal queries that are expected to return nil. # Shared example for legal queries that are expected to return nil.
# Requires the following let bindings to be defined: # Requires the following let bindings to be defined:
# - post_query: action to send the query # - post_query: action to send the query
# - path: array of keys from query root to the result # - path: array of keys from query root to the result
shared_examples 'a failure to find anything' do RSpec.shared_examples 'a failure to find anything' do
it 'finds nothing' do it 'finds nothing' do
post_query post_query
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper'
shared_context 'exposing regular notes on a noteable in GraphQL' do RSpec.shared_context 'exposing regular notes on a noteable in GraphQL' do
include GraphqlHelpers include GraphqlHelpers
let(:note) do let(:note) do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'a request using Gitlab::UrlBlocker' do RSpec.shared_examples 'a request using Gitlab::UrlBlocker' do
# Written to test internal patches against 3rd party libraries # Written to test internal patches against 3rd party libraries
# #
# Expects the following to be available in the example contexts: # Expects the following to be available in the example contexts:
......
# frozen_string_literal: true
shared_examples 'redirecting a legacy path' do |source, target|
include RSpec::Rails::RequestExampleGroup
it "redirects #{source} to #{target} when the resource does not exist" do
expect(get(source)).to redirect_to(target)
end
it "does not redirect #{source} to #{target} when the resource exists" do
resource
expect(get(source)).not_to redirect_to(target)
end
end
shared_examples 'redirecting a legacy project path' do |source, target|
include RSpec::Rails::RequestExampleGroup
it "redirects #{source} to #{target}" do
expect(get(source)).to redirect_to(target)
end
end
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'backfill migration for project repositories' do |storage| RSpec.shared_examples 'backfill migration for project repositories' do |storage|
describe '#perform' do describe '#perform' do
let(:storage_versions) { storage == :legacy ? [nil, 0] : [1, 2] } let(:storage_versions) { storage == :legacy ? [nil, 0] : [1, 2] }
let(:storage_version) { storage_versions.first } let(:storage_version) { storage_versions.first }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for 'common trace features' do RSpec.shared_examples 'common trace features' do
describe '#html' do describe '#html' do
before do before do
trace.set("12\n34") trace.set("12\n34")
...@@ -284,7 +284,7 @@ shared_examples_for 'common trace features' do ...@@ -284,7 +284,7 @@ shared_examples_for 'common trace features' do
end end
end end
shared_examples_for 'trace with disabled live trace feature' do RSpec.shared_examples 'trace with disabled live trace feature' do
it_behaves_like 'common trace features' it_behaves_like 'common trace features'
describe '#read' do describe '#read' do
...@@ -618,7 +618,7 @@ shared_examples_for 'trace with disabled live trace feature' do ...@@ -618,7 +618,7 @@ shared_examples_for 'trace with disabled live trace feature' do
end end
end end
shared_examples_for 'trace with enabled live trace feature' do RSpec.shared_examples 'trace with enabled live trace feature' do
it_behaves_like 'common trace features' it_behaves_like 'common trace features'
describe '#read' do describe '#read' do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for 'cycle analytics event' do RSpec.shared_examples_for 'cycle analytics event' do
let(:params) { {} } let(:params) { {} }
let(:instance) { described_class.new(params) } let(:instance) { described_class.new(params) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'diff statistics' do |test_include_stats_flag: true| RSpec.shared_examples 'diff statistics' do |test_include_stats_flag: true|
subject { described_class.new(diffable, collection_default_args) } subject { described_class.new(diffable, collection_default_args) }
def stub_stats_find_by_path(path, stats_mock) def stub_stats_find_by_path(path, stats_mock)
...@@ -42,7 +42,7 @@ shared_examples 'diff statistics' do |test_include_stats_flag: true| ...@@ -42,7 +42,7 @@ shared_examples 'diff statistics' do |test_include_stats_flag: true|
end end
end end
shared_examples 'unfoldable diff' do RSpec.shared_examples 'unfoldable diff' do
let(:subject) { described_class.new(diffable, diff_options: nil) } let(:subject) { described_class.new(diffable, diff_options: nil) }
it 'calls Gitlab::Diff::File#unfold_diff_lines with correct position' do it 'calls Gitlab::Diff::File#unfold_diff_lines with correct position' do
...@@ -58,7 +58,7 @@ shared_examples 'unfoldable diff' do ...@@ -58,7 +58,7 @@ shared_examples 'unfoldable diff' do
end end
end end
shared_examples 'cacheable diff collection' do RSpec.shared_examples 'cacheable diff collection' do
let(:cache) { instance_double(Gitlab::Diff::HighlightCache) } let(:cache) { instance_double(Gitlab::Diff::HighlightCache) }
before do before do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'file finder' do RSpec.shared_examples 'file finder' do
let(:query) { 'files' } let(:query) { 'files' }
let(:search_results) { subject.find(query) } let(:search_results) { subject.find(query) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'helm commands' do RSpec.shared_examples 'helm commands' do
describe '#generate_script' do describe '#generate_script' do
let(:helm_setup) do let(:helm_setup) do
<<~EOS <<~EOS
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'log import failure' do |importable_column| RSpec.shared_examples 'log import failure' do |importable_column|
it 'tracks error' do it 'tracks error' do
extra = { extra = {
relation_key: relation_key, relation_key: relation_key,
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for 'normalizes a DN' do RSpec.shared_examples 'normalizes a DN' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:test_description, :given, :expected) do where(:test_description, :given, :expected) do
...@@ -40,7 +40,7 @@ shared_examples_for 'normalizes a DN' do ...@@ -40,7 +40,7 @@ shared_examples_for 'normalizes a DN' do
end end
end end
shared_examples_for 'normalizes a DN attribute value' do RSpec.shared_examples 'normalizes a DN attribute value' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:test_description, :given, :expected) do where(:test_description, :given, :expected) do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'timeout' require 'timeout'
shared_examples 'malicious regexp' do RSpec.shared_examples 'malicious regexp' do
let(:malicious_text) { 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!' } let(:malicious_text) { 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!' }
let(:malicious_regexp_re2) { '(?i)^(([a-z])+.)+[A-Z]([a-z])+$' } let(:malicious_regexp_re2) { '(?i)^(([a-z])+.)+[A-Z]([a-z])+$' }
let(:malicious_regexp_ruby) { '/^(([a-z])+.)+[A-Z]([a-z])+$/i' } let(:malicious_regexp_ruby) { '/^(([a-z])+.)+[A-Z]([a-z])+$/i' }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'skips validation' do |validation_option| RSpec.shared_examples 'skips validation' do |validation_option|
it 'skips validation' do it 'skips validation' do
expect(model).not_to receive(:disable_statement_timeout) expect(model).not_to receive(:disable_statement_timeout)
expect(model).to receive(:execute).with(/ADD CONSTRAINT/) expect(model).to receive(:execute).with(/ADD CONSTRAINT/)
...@@ -10,7 +10,7 @@ shared_examples 'skips validation' do |validation_option| ...@@ -10,7 +10,7 @@ shared_examples 'skips validation' do |validation_option|
end end
end end
shared_examples 'performs validation' do |validation_option| RSpec.shared_examples 'performs validation' do |validation_option|
it 'performs validation' do it 'performs validation' do
expect(model).to receive(:disable_statement_timeout).and_call_original expect(model).to receive(:disable_statement_timeout).and_call_original
expect(model).to receive(:execute).with(/statement_timeout/) expect(model).to receive(:execute).with(/statement_timeout/)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples_for "position formatter" do RSpec.shared_examples "position formatter" do
let(:formatter) { described_class.new(attrs) } let(:formatter) { described_class.new(attrs) }
describe '#key' do describe '#key' do
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'a repo type' do RSpec.shared_examples 'a repo type' do
describe "#identifier_for_repositorable" do describe "#identifier_for_repositorable" do
subject { described_class.identifier_for_repositorable(project) } subject { described_class.identifier_for_repositorable(project) }
......
# frozen_string_literal: true # frozen_string_literal: true
shared_context 'unique ips sign in limit' do RSpec.shared_examples 'user login operation with unique ip limit' do
include StubENV
let(:request_context) { Gitlab::RequestContext.instance }
before do
Gitlab::Redis::Cache.with(&:flushall)
Gitlab::Redis::Queues.with(&:flushall)
Gitlab::Redis::SharedState.with(&:flushall)
end
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
Gitlab::CurrentSettings.update!(
unique_ips_limit_enabled: true,
unique_ips_limit_time_window: 10000
)
# Make sure we're working with the same reqeust context everywhere
allow(Gitlab::RequestContext).to receive(:instance).and_return(request_context)
end
def change_ip(ip)
allow(request_context).to receive(:client_ip).and_return(ip)
end
def request_from_ip(ip)
change_ip(ip)
request
response
end
def operation_from_ip(ip)
change_ip(ip)
operation
end
end
shared_examples 'user login operation with unique ip limit' do
include_context 'unique ips sign in limit' do include_context 'unique ips sign in limit' do
before do before do
Gitlab::CurrentSettings.update!(unique_ips_limit_per_user: 1) Gitlab::CurrentSettings.update!(unique_ips_limit_per_user: 1)
...@@ -56,7 +18,7 @@ shared_examples 'user login operation with unique ip limit' do ...@@ -56,7 +18,7 @@ shared_examples 'user login operation with unique ip limit' do
end end
end end
shared_examples 'user login request with unique ip limit' do |success_status = 200| RSpec.shared_examples 'user login request with unique ip limit' do |success_status = 200|
include_context 'unique ips sign in limit' do include_context 'unique ips sign in limit' do
before do before do
Gitlab::CurrentSettings.update!(unique_ips_limit_per_user: 1) Gitlab::CurrentSettings.update!(unique_ips_limit_per_user: 1)
......
# frozen_string_literal: true # frozen_string_literal: true
shared_examples 'a redis usage counter' do |thing, event| RSpec.shared_examples 'a redis usage counter' do |thing, event|
describe ".count(#{event})", :clean_gitlab_redis_shared_state do describe ".count(#{event})", :clean_gitlab_redis_shared_state do
it "increments the #{thing} #{event} counter by 1" do it "increments the #{thing} #{event} counter by 1" do
expect do expect do
...@@ -22,7 +22,7 @@ shared_examples 'a redis usage counter' do |thing, event| ...@@ -22,7 +22,7 @@ shared_examples 'a redis usage counter' do |thing, event|
end end
end end
shared_examples 'a redis usage counter with totals' do |prefix, events| RSpec.shared_examples 'a redis usage counter with totals' do |prefix, events|
describe 'totals', :clean_gitlab_redis_shared_state do describe 'totals', :clean_gitlab_redis_shared_state do
before do before do
events.each do |k, n| events.each do |k, n|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment