diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-04-26 14:23:36 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-04-26 14:23:36 +0900 |
commit | 4eb67ccff350d181e60e4666e459a364cd36b064 (patch) | |
tree | c2c3e606b364dc5f1eee3320cba9f8312be7e634 /spec/support | |
parent | 0262ed904d293fba9ceb0e3d79f62ffe8e8a239f (diff) | |
parent | 55f07cc32e7684b21e0c1662c70128df14c6abf7 (diff) | |
download | gitlab-ce-4eb67ccff350d181e60e4666e459a364cd36b064.tar.gz |
Merge branch 'master' into live-trace-v2
Diffstat (limited to 'spec/support')
6 files changed, 76 insertions, 22 deletions
diff --git a/spec/support/controllers/ldap_omniauth_callbacks_controller_shared_context.rb b/spec/support/controllers/ldap_omniauth_callbacks_controller_shared_context.rb new file mode 100644 index 00000000000..72912ffb89d --- /dev/null +++ b/spec/support/controllers/ldap_omniauth_callbacks_controller_shared_context.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +shared_context 'Ldap::OmniauthCallbacksController' do + include LoginHelpers + include LdapHelpers + + let(:uid) { 'my-uid' } + let(:provider) { 'ldapmain' } + let(:valid_login?) { true } + let(:user) { create(:omniauth_user, extern_uid: uid, provider: provider) } + let(:ldap_server_config) do + { main: ldap_config_defaults(:main) } + end + + def ldap_config_defaults(key, hash = {}) + { + provider_name: "ldap#{key}", + attributes: {}, + encryption: 'plain' + }.merge(hash) + end + + before do + stub_ldap_setting(enabled: true, servers: ldap_server_config) + described_class.define_providers! + Rails.application.reload_routes! + + mock_auth_hash(provider.to_s, uid, user.email) + stub_omniauth_provider(provider, context: request) + + allow(Gitlab::Auth::LDAP::Access).to receive(:allowed?).and_return(valid_login?) + end +end diff --git a/spec/support/helpers/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb index 2197bc9d853..086a345dca8 100644 --- a/spec/support/helpers/javascript_fixtures_helpers.rb +++ b/spec/support/helpers/javascript_fixtures_helpers.rb @@ -31,7 +31,7 @@ module JavaScriptFixturesHelpers end def remove_repository(project) - Gitlab::Shell.new.remove_repository(project.repository_storage_path, project.disk_path) + Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path) end private diff --git a/spec/support/helpers/ldap_helpers.rb b/spec/support/helpers/ldap_helpers.rb index 0e87b3d359d..b90bbc4b106 100644 --- a/spec/support/helpers/ldap_helpers.rb +++ b/spec/support/helpers/ldap_helpers.rb @@ -18,6 +18,10 @@ module LdapHelpers allow_any_instance_of(::Gitlab::Auth::LDAP::Config).to receive_messages(messages) end + def stub_ldap_setting(messages) + allow(Gitlab.config.ldap).to receive_messages(to_settings(messages)) + end + # Stub an LDAP person search and provide the return entry. Specify `nil` for # `entry` to simulate when an LDAP person is not found # diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index db34090e971..72e5c2d66dd 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -112,7 +112,7 @@ module LoginHelpers } } }) - Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:saml] + Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[provider.to_sym] end def mock_saml_config @@ -129,7 +129,7 @@ module LoginHelpers env = env_from_context(context) set_devise_mapping(context: context) - env['omniauth.auth'] = OmniAuth.config.mock_auth[provider] + env['omniauth.auth'] = OmniAuth.config.mock_auth[provider.to_sym] end def stub_omniauth_saml_config(messages) diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index d87f265cdf0..1dad39fdab3 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -218,7 +218,8 @@ module TestEnv end def copy_repo(project, bare_repo:, refs:) - target_repo_path = File.expand_path(project.repository_storage_path + "/#{project.disk_path}.git") + target_repo_path = File.expand_path(repos_path + "/#{project.disk_path}.git") + FileUtils.mkdir_p(target_repo_path) FileUtils.cp_r("#{File.expand_path(bare_repo)}/.", target_repo_path) FileUtils.chmod_R 0755, target_repo_path @@ -226,7 +227,7 @@ module TestEnv end def repos_path - Gitlab.config.repositories.storages[REPOS_STORAGE].legacy_disk_path + @repos_path ||= Gitlab.config.repositories.storages[REPOS_STORAGE].legacy_disk_path end def backup_path diff --git a/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb b/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb index e61983c60b4..f4bc6f8efa5 100644 --- a/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb +++ b/spec/support/shared_examples/issuables_list_metadata_shared_examples.rb @@ -1,25 +1,30 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil| - before do - @issuable_ids = [] - - %w[fix improve/awesome].each do |source_branch| - issuable = - if issuable_type == :issue - create(issuable_type, project: project, author: project.creator) - else - create(issuable_type, source_project: project, source_branch: source_branch, author: project.creator) - end - - @issuable_ids << issuable.id - end - end + include ProjectForksHelper - it "creates indexed meta-data object for issuable notes and votes count" do + def get_action(action, project) if action get action, author_id: project.creator.id else get :index, namespace_id: project.namespace, project_id: project end + end + + def create_issuable(issuable_type, project, source_branch:) + if issuable_type == :issue + create(issuable_type, project: project, author: project.creator) + else + create(issuable_type, source_project: project, source_branch: source_branch, author: project.creator) + end + end + + before do + @issuable_ids = %w[fix improve/awesome].map do |source_branch| + create_issuable(issuable_type, project, source_branch: source_branch).id + end + end + + it "creates indexed meta-data object for issuable notes and votes count" do + get_action(action, project) meta_data = assigns(:issuable_meta_data) @@ -29,18 +34,29 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil| end end + it "avoids N+1 queries" do + control = ActiveRecord::QueryRecorder.new { get_action(action, project) } + issuable = create_issuable(issuable_type, project, source_branch: 'csv') + + if issuable_type == :merge_request + issuable.update!(source_project: fork_project(project)) + end + + expect { get_action(action, project) }.not_to exceed_query_limit(control.count) + end + describe "when given empty collection" do let(:project2) { create(:project, :public) } it "doesn't execute any queries with false conditions" do - get_action = + get_empty = if action proc { get action, author_id: project.creator.id } else proc { get :index, namespace_id: project2.namespace, project_id: project2 } end - expect(&get_action).not_to make_queries_matching(/WHERE (?:1=0|0=1)/) + expect(&get_empty).not_to make_queries_matching(/WHERE (?:1=0|0=1)/) end end end |