From b4e1529e57e28dade05e307c7a3ff508c2d54f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Mon, 19 Jun 2017 17:06:17 -0400 Subject: Reinstall shell on the test env if it's outdated --- spec/support/test_env.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'spec/support') diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 3f472e59c49..6d71dd476c3 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -120,18 +120,21 @@ module TestEnv end def setup_gitlab_shell - unless File.directory?(Gitlab.config.gitlab_shell.path) - unless system('rake', 'gitlab:shell:install') - raise 'Can`t clone gitlab-shell' - end + shell_needs_update = component_needs_update?(Gitlab.config.gitlab_shell.path, + Gitlab::Shell.version_required) + + unless !shell_needs_update || system('rake', 'gitlab:shell:install') + raise 'Can`t clone gitlab-shell' end end def setup_gitaly socket_path = Gitlab::GitalyClient.address('default').sub(/\Aunix:/, '') gitaly_dir = File.dirname(socket_path) + gitaly_needs_update = component_needs_update?(gitaly_dir, + Gitlab::GitalyClient.expected_server_version) - unless !gitaly_needs_update?(gitaly_dir) || system('rake', "gitlab:gitaly:install[#{gitaly_dir}]") + unless !gitaly_needs_update || system('rake', "gitlab:gitaly:install[#{gitaly_dir}]") raise "Can't clone gitaly" end @@ -261,13 +264,13 @@ module TestEnv end end - def gitaly_needs_update?(gitaly_dir) - gitaly_version = File.read(File.join(gitaly_dir, 'VERSION')).strip + def component_needs_update?(component_folder, expected_version) + version = File.read(File.join(component_folder, 'VERSION')).strip # Notice that this will always yield true when using branch versions # (`=branch_name`), but that actually makes sure the server is always based # on the latest branch revision. - gitaly_version != Gitlab::GitalyClient.expected_server_version + version != expected_version rescue Errno::ENOENT true end -- cgit v1.2.1 From 3e84b6336f3d61ff56e3e8ef5cc5d8ca08ef0432 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 6 Jun 2017 12:28:28 +0200 Subject: Track all renames in redis --- spec/support/fake_migration_classes.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/support') diff --git a/spec/support/fake_migration_classes.rb b/spec/support/fake_migration_classes.rb index 3de0460c3ca..33cd1043132 100644 --- a/spec/support/fake_migration_classes.rb +++ b/spec/support/fake_migration_classes.rb @@ -1,3 +1,7 @@ class FakeRenameReservedPathMigrationV1 < ActiveRecord::Migration include Gitlab::Database::RenameReservedPathsMigration::V1 + + def version + '20170316163845' + end end -- cgit v1.2.1 From d6a0c288c89765fa8f0e96aedefc608dd7025491 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 12 Jun 2017 19:19:00 +0200 Subject: Use the migration name as a key in redis --- spec/support/fake_migration_classes.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/support') diff --git a/spec/support/fake_migration_classes.rb b/spec/support/fake_migration_classes.rb index 33cd1043132..b0fc8422857 100644 --- a/spec/support/fake_migration_classes.rb +++ b/spec/support/fake_migration_classes.rb @@ -4,4 +4,8 @@ class FakeRenameReservedPathMigrationV1 < ActiveRecord::Migration def version '20170316163845' end + + def name + "FakeRenameReservedPathMigrationV1" + end end -- cgit v1.2.1 From 5545d4dc8761d393f39acfd8c22966f2fe394d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 27 Jun 2017 18:34:34 +0200 Subject: Move share examples to their correct location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- .../access_control_ce_shared_examples.rb | 91 ---------------------- .../protected_branches_access_control_ce.rb | 91 ++++++++++++++++++++++ 2 files changed, 91 insertions(+), 91 deletions(-) delete mode 100644 spec/support/protected_branches/access_control_ce_shared_examples.rb create mode 100644 spec/support/shared_examples/features/protected_branches_access_control_ce.rb (limited to 'spec/support') diff --git a/spec/support/protected_branches/access_control_ce_shared_examples.rb b/spec/support/protected_branches/access_control_ce_shared_examples.rb deleted file mode 100644 index 287d6bb13c3..00000000000 --- a/spec/support/protected_branches/access_control_ce_shared_examples.rb +++ /dev/null @@ -1,91 +0,0 @@ -RSpec.shared_examples "protected branches > access control > CE" do - ProtectedBranch::PushAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)| - it "allows creating protected branches that #{access_type_name} can push to" do - visit namespace_project_protected_branches_path(project.namespace, project) - - set_protected_branch_name('master') - - within('.new_protected_branch') do - allowed_to_push_button = find(".js-allowed-to-push") - - unless allowed_to_push_button.text == access_type_name - allowed_to_push_button.trigger('click') - within(".dropdown.open .dropdown-menu") { click_on access_type_name } - end - end - - click_on "Protect" - - expect(ProtectedBranch.count).to eq(1) - expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to eq([access_type_id]) - end - - it "allows updating protected branches so that #{access_type_name} can push to them" do - visit namespace_project_protected_branches_path(project.namespace, project) - - set_protected_branch_name('master') - - click_on "Protect" - - expect(ProtectedBranch.count).to eq(1) - - within(".protected-branches-list") do - find(".js-allowed-to-push").click - - within('.js-allowed-to-push-container') do - expect(first("li")).to have_content("Roles") - click_on access_type_name - end - end - - wait_for_requests - - expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to include(access_type_id) - end - end - - ProtectedBranch::MergeAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)| - it "allows creating protected branches that #{access_type_name} can merge to" do - visit namespace_project_protected_branches_path(project.namespace, project) - - set_protected_branch_name('master') - - within('.new_protected_branch') do - allowed_to_merge_button = find(".js-allowed-to-merge") - - unless allowed_to_merge_button.text == access_type_name - allowed_to_merge_button.click - within(".dropdown.open .dropdown-menu") { click_on access_type_name } - end - end - - click_on "Protect" - - expect(ProtectedBranch.count).to eq(1) - expect(ProtectedBranch.last.merge_access_levels.map(&:access_level)).to eq([access_type_id]) - end - - it "allows updating protected branches so that #{access_type_name} can merge to them" do - visit namespace_project_protected_branches_path(project.namespace, project) - - set_protected_branch_name('master') - - click_on "Protect" - - expect(ProtectedBranch.count).to eq(1) - - within(".protected-branches-list") do - find(".js-allowed-to-merge").click - - within('.js-allowed-to-merge-container') do - expect(first("li")).to have_content("Roles") - click_on access_type_name - end - end - - wait_for_requests - - expect(ProtectedBranch.last.merge_access_levels.map(&:access_level)).to include(access_type_id) - end - end -end diff --git a/spec/support/shared_examples/features/protected_branches_access_control_ce.rb b/spec/support/shared_examples/features/protected_branches_access_control_ce.rb new file mode 100644 index 00000000000..b6341127a76 --- /dev/null +++ b/spec/support/shared_examples/features/protected_branches_access_control_ce.rb @@ -0,0 +1,91 @@ +shared_examples "protected branches > access control > CE" do + ProtectedBranch::PushAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)| + it "allows creating protected branches that #{access_type_name} can push to" do + visit namespace_project_protected_branches_path(project.namespace, project) + + set_protected_branch_name('master') + + within('.new_protected_branch') do + allowed_to_push_button = find(".js-allowed-to-push") + + unless allowed_to_push_button.text == access_type_name + allowed_to_push_button.trigger('click') + within(".dropdown.open .dropdown-menu") { click_on access_type_name } + end + end + + click_on "Protect" + + expect(ProtectedBranch.count).to eq(1) + expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to eq([access_type_id]) + end + + it "allows updating protected branches so that #{access_type_name} can push to them" do + visit namespace_project_protected_branches_path(project.namespace, project) + + set_protected_branch_name('master') + + click_on "Protect" + + expect(ProtectedBranch.count).to eq(1) + + within(".protected-branches-list") do + find(".js-allowed-to-push").click + + within('.js-allowed-to-push-container') do + expect(first("li")).to have_content("Roles") + click_on access_type_name + end + end + + wait_for_requests + + expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to include(access_type_id) + end + end + + ProtectedBranch::MergeAccessLevel.human_access_levels.each do |(access_type_id, access_type_name)| + it "allows creating protected branches that #{access_type_name} can merge to" do + visit namespace_project_protected_branches_path(project.namespace, project) + + set_protected_branch_name('master') + + within('.new_protected_branch') do + allowed_to_merge_button = find(".js-allowed-to-merge") + + unless allowed_to_merge_button.text == access_type_name + allowed_to_merge_button.click + within(".dropdown.open .dropdown-menu") { click_on access_type_name } + end + end + + click_on "Protect" + + expect(ProtectedBranch.count).to eq(1) + expect(ProtectedBranch.last.merge_access_levels.map(&:access_level)).to eq([access_type_id]) + end + + it "allows updating protected branches so that #{access_type_name} can merge to them" do + visit namespace_project_protected_branches_path(project.namespace, project) + + set_protected_branch_name('master') + + click_on "Protect" + + expect(ProtectedBranch.count).to eq(1) + + within(".protected-branches-list") do + find(".js-allowed-to-merge").click + + within('.js-allowed-to-merge-container') do + expect(first("li")).to have_content("Roles") + click_on access_type_name + end + end + + wait_for_requests + + expect(ProtectedBranch.last.merge_access_levels.map(&:access_level)).to include(access_type_id) + end + end +end -- cgit v1.2.1 From 8f13c1ebd9671058a878b21ce3f40d255e8591df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 27 Jun 2017 15:00:10 +0200 Subject: Use a slightly cleaner approach to stub ENV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/support/stub_env.rb | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'spec/support') diff --git a/spec/support/stub_env.rb b/spec/support/stub_env.rb index 2999bcd9fb1..b8928867174 100644 --- a/spec/support/stub_env.rb +++ b/spec/support/stub_env.rb @@ -1,15 +1,33 @@ +# Inspired by https://github.com/ljkbennett/stub_env/blob/master/lib/stub_env/helpers.rb module StubENV - def stub_env(key, value) - allow(ENV).to receive(:[]).and_call_original unless @env_already_stubbed - @env_already_stubbed ||= true + def stub_env(key_or_hash, value = nil) + init_stub unless env_stubbed? + if key_or_hash.is_a? Hash + key_or_hash.each { |k, v| add_stubbed_value(k, v) } + else + add_stubbed_value key_or_hash, value + end + end + + private + + STUBBED_KEY = '__STUBBED__'.freeze + + def add_stubbed_value(key, value) allow(ENV).to receive(:[]).with(key).and_return(value) + allow(ENV).to receive(:fetch).with(key).and_return(value) + allow(ENV).to receive(:fetch).with(key, anything()) do |_, default_val| + value || default_val + end + end + + def env_stubbed? + ENV[STUBBED_KEY] end -end -# It's possible that the state of the class variables are not reset across -# test runs. -RSpec.configure do |config| - config.after(:each) do - @env_already_stubbed = nil + def init_stub + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:fetch).and_call_original + add_stubbed_value(STUBBED_KEY, true) end end -- cgit v1.2.1 From 489d8e11b39f7eae6b36d2bdcf3098548ed62e53 Mon Sep 17 00:00:00 2001 From: "Jacob Vosmaer (GitLab)" Date: Wed, 28 Jun 2017 09:30:02 +0000 Subject: Vendor the gitlab-git-test repo --- spec/support/generate-seed-repo-rb | 2 +- spec/support/gitlab-git-test.git/HEAD | 1 + spec/support/gitlab-git-test.git/README.md | 16 +++++++++ spec/support/gitlab-git-test.git/config | 7 ++++ ...ck-691247af2a6acb0b63b73ac0cb90540e93614043.idx | Bin 0 -> 5496 bytes ...k-691247af2a6acb0b63b73ac0cb90540e93614043.pack | Bin 0 -> 381502 bytes spec/support/gitlab-git-test.git/packed-refs | 18 ++++++++++ .../gitlab-git-test.git/refs/heads/.gitkeep | 0 .../support/gitlab-git-test.git/refs/tags/.gitkeep | 0 spec/support/prepare-gitlab-git-test-for-commit | 17 +++++++++ spec/support/seed_helper.rb | 2 +- spec/support/unpack-gitlab-git-test | 38 +++++++++++++++++++++ 12 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 spec/support/gitlab-git-test.git/HEAD create mode 100644 spec/support/gitlab-git-test.git/README.md create mode 100644 spec/support/gitlab-git-test.git/config create mode 100644 spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.idx create mode 100644 spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.pack create mode 100644 spec/support/gitlab-git-test.git/packed-refs create mode 100644 spec/support/gitlab-git-test.git/refs/heads/.gitkeep create mode 100644 spec/support/gitlab-git-test.git/refs/tags/.gitkeep create mode 100755 spec/support/prepare-gitlab-git-test-for-commit create mode 100755 spec/support/unpack-gitlab-git-test (limited to 'spec/support') diff --git a/spec/support/generate-seed-repo-rb b/spec/support/generate-seed-repo-rb index 7335f74c0e9..c89389b90ca 100755 --- a/spec/support/generate-seed-repo-rb +++ b/spec/support/generate-seed-repo-rb @@ -15,7 +15,7 @@ require 'erb' require 'tempfile' -SOURCE = 'https://gitlab.com/gitlab-org/gitlab-git-test.git'.freeze +SOURCE = File.expand_path('../gitlab-git-test.git', __FILE__).freeze SCRIPT_NAME = 'generate-seed-repo-rb'.freeze REPO_NAME = 'gitlab-git-test.git'.freeze diff --git a/spec/support/gitlab-git-test.git/HEAD b/spec/support/gitlab-git-test.git/HEAD new file mode 100644 index 00000000000..cb089cd89a7 --- /dev/null +++ b/spec/support/gitlab-git-test.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/spec/support/gitlab-git-test.git/README.md b/spec/support/gitlab-git-test.git/README.md new file mode 100644 index 00000000000..f072cd421be --- /dev/null +++ b/spec/support/gitlab-git-test.git/README.md @@ -0,0 +1,16 @@ +# Gitlab::Git test repository + +This repository is used by (some of) the tests in spec/lib/gitlab/git. + +Do not add new large files to this repository. Otherwise we needlessly +inflate the size of the gitlab-ce repository. + +## How to make changes to this repository + +- (if needed) clone `https://gitlab.com/gitlab-org/gitlab-ce.git` to your local machine +- clone `gitlab-ce/spec/support/gitlab-git-test.git` locally (i.e. clone from your hard drive, not from the internet) +- make changes in your local clone of gitlab-git-test +- run `git push` which will push to your local source `gitlab-ce/spec/support/gitlab-git-test.git` +- in gitlab-ce: run `spec/support/prepare-gitlab-git-test-for-commit` +- in gitlab-ce: `git add spec/support/seed_repo.rb spec/support/gitlab-git-test.git` +- commit your changes in gitlab-ce diff --git a/spec/support/gitlab-git-test.git/config b/spec/support/gitlab-git-test.git/config new file mode 100644 index 00000000000..03e2d1b1e0f --- /dev/null +++ b/spec/support/gitlab-git-test.git/config @@ -0,0 +1,7 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true + precomposeunicode = true +[remote "origin"] + url = https://gitlab.com/gitlab-org/gitlab-git-test.git diff --git a/spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.idx b/spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.idx new file mode 100644 index 00000000000..2253da798c4 Binary files /dev/null and b/spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.idx differ diff --git a/spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.pack b/spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.pack new file mode 100644 index 00000000000..3a61107c5b1 Binary files /dev/null and b/spec/support/gitlab-git-test.git/objects/pack/pack-691247af2a6acb0b63b73ac0cb90540e93614043.pack differ diff --git a/spec/support/gitlab-git-test.git/packed-refs b/spec/support/gitlab-git-test.git/packed-refs new file mode 100644 index 00000000000..ce5ab1f705b --- /dev/null +++ b/spec/support/gitlab-git-test.git/packed-refs @@ -0,0 +1,18 @@ +# pack-refs with: peeled fully-peeled +0b4bc9a49b562e85de7cc9e834518ea6828729b9 refs/heads/feature +12d65c8dd2b2676fa3ac47d955accc085a37a9c1 refs/heads/fix +6473c90867124755509e100d0d35ebdc85a0b6ae refs/heads/fix-blob-path +58fa1a3af4de73ea83fe25a1ef1db8e0c56f67e5 refs/heads/fix-existing-submodule-dir +40f4a7a617393735a95a0bb67b08385bc1e7c66d refs/heads/fix-mode +9abd6a8c113a2dd76df3fdb3d58a8cec6db75f8d refs/heads/gitattributes +46e1395e609395de004cacd4b142865ab0e52a29 refs/heads/gitattributes-updated +4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6 refs/heads/master +5937ac0a7beb003549fc5fd26fc247adbce4a52e refs/heads/merge-test +f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8 refs/tags/v1.0.0 +^6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 +8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b refs/tags/v1.1.0 +^5937ac0a7beb003549fc5fd26fc247adbce4a52e +10d64eed7760f2811ee2d64b44f1f7d3b364f17b refs/tags/v1.2.0 +^eb49186cfa5c4338011f5f590fac11bd66c5c631 +2ac1f24e253e08135507d0830508febaaccf02ee refs/tags/v1.2.1 +^fa1b1e6c004a68b7d8763b86455da9e6b23e36d6 diff --git a/spec/support/gitlab-git-test.git/refs/heads/.gitkeep b/spec/support/gitlab-git-test.git/refs/heads/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spec/support/gitlab-git-test.git/refs/tags/.gitkeep b/spec/support/gitlab-git-test.git/refs/tags/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/spec/support/prepare-gitlab-git-test-for-commit b/spec/support/prepare-gitlab-git-test-for-commit new file mode 100755 index 00000000000..3047786a599 --- /dev/null +++ b/spec/support/prepare-gitlab-git-test-for-commit @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +abort unless [ + system('spec/support/generate-seed-repo-rb', out: 'spec/support/seed_repo.rb'), + system('spec/support/unpack-gitlab-git-test') +].all? + +exit if ARGV.first != '--check-for-changes' + +git_status = IO.popen(%w[git status --porcelain], &:read) +abort unless $?.success? + +puts git_status + +if git_status.lines.grep(%r{^.. spec/support/gitlab-git-test.git}).any? + abort "error: detected changes in gitlab-git-test.git" +end diff --git a/spec/support/seed_helper.rb b/spec/support/seed_helper.rb index 47b5f556e66..8731847592b 100644 --- a/spec/support/seed_helper.rb +++ b/spec/support/seed_helper.rb @@ -9,7 +9,7 @@ TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'.freeze TEST_BROKEN_REPO_PATH = 'broken-repo.git'.freeze module SeedHelper - GITLAB_GIT_TEST_REPO_URL = ENV.fetch('GITLAB_GIT_TEST_REPO_URL', 'https://gitlab.com/gitlab-org/gitlab-git-test.git').freeze + GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __FILE__).freeze def ensure_seeds if File.exist?(SEED_STORAGE_PATH) diff --git a/spec/support/unpack-gitlab-git-test b/spec/support/unpack-gitlab-git-test new file mode 100755 index 00000000000..d5b4912457d --- /dev/null +++ b/spec/support/unpack-gitlab-git-test @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +require 'fileutils' + +REPO = 'spec/support/gitlab-git-test.git'.freeze +PACK_DIR = REPO + '/objects/pack' +GIT = %W[git --git-dir=#{REPO}].freeze +BASE_PACK = 'pack-691247af2a6acb0b63b73ac0cb90540e93614043'.freeze + +def main + unpack + # We want to store the refs in a packed-refs file because if we don't + # they can get mangled by filesystems. + abort unless system(*GIT, *%w[pack-refs --all]) + abort unless system(*GIT, 'fsck') +end + +# We don't want contributors to commit new pack files because those +# create unnecessary churn. +def unpack + pack_files = Dir[File.join(PACK_DIR, '*')].reject do |pack| + pack.start_with?(File.join(PACK_DIR, BASE_PACK)) + end + return if pack_files.empty? + + pack_files.each do |pack| + unless pack.end_with?('.pack') + FileUtils.rm(pack) + next + end + + File.open(pack, 'rb') do |open_pack| + File.unlink(pack) + abort unless system(*GIT, 'unpack-objects', in: open_pack) + end + end +end + +main -- cgit v1.2.1 From 8026f47d67546d48139cb35a0dc16bbac47b1bb7 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 5 Jun 2017 22:19:23 +0900 Subject: Add changelog. Add AccessMatchersForController --- .../matchers/access_matchers_for_controller.rb | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 spec/support/matchers/access_matchers_for_controller.rb (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb new file mode 100644 index 00000000000..4da10247801 --- /dev/null +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -0,0 +1,88 @@ +# AccessMatchersForController +# +# For testing authorize_xxx in controller. +module AccessMatchersForController + extend RSpec::Matchers::DSL + include Warden::Test::Helpers + + EXPECTED_STATUS_CODE_ALLOWED = [200, 302] + EXPECTED_STATUS_CODE_DENIED = [404] + + def emulate_user(role, membership = nil) + case role + when :admin + user = create(:admin) + sign_in(user) + when *Gitlab::Access.sym_options_with_owner.keys # owner, master, developer, reporter, guest + raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership + + if role == :owner && membership.owner + user = membership.owner + else + user = create(:user) + membership.public_send(:"add_#{role}", user) + end + + sign_in(user) + when :user + user = create(:user) + sign_in(user) + when :external + user = create(:user, external: true) + sign_in(user) + when :visitor + # no-op + else + raise ArgumentError, "cannot emulate user #{role}" + end + + user + end + + def description_for(role, type, expected, result) + "be #{type} for #{role}." \ + " Expected: #{expected.join(',')} Result: #{result}" + end + + matcher :be_allowed_for do |role| + match do |action| + user = emulate_user(role, @membership) + begin + action.call(user) + rescue Exception => e + # Ignore internal exceptions which will be caused in the controller + # In such cases, response.status will be 200. + end + + EXPECTED_STATUS_CODE_ALLOWED.include?(response.status) + end + + chain :of do |membership| + @membership = membership + end + + description { description_for(role, 'allowed', EXPECTED_STATUS_CODE_ALLOWED, response.status) } + supports_block_expectations + end + + matcher :be_denied_for do |role| + match do |action| + user = emulate_user(role, @membership) + begin + action.call(user) + rescue Exception => e + # Ignore internal exceptions which will be caused in the controller + # In such cases, response.status will be 200. + end + + EXPECTED_STATUS_CODE_DENIED.include?(response.status) + end + + chain :of do |membership| + @membership = membership + end + + description { description_for(role, 'denied', EXPECTED_STATUS_CODE_DENIED, response.status) } + supports_block_expectations + end +end -- cgit v1.2.1 From e9734c6df33dba7ab89d4c575ace3a508c5da64b Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 6 Jun 2017 00:13:17 +0900 Subject: Resolve static analysis --- spec/support/matchers/access_matchers_for_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 4da10247801..14500201a59 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -49,7 +49,7 @@ module AccessMatchersForController user = emulate_user(role, @membership) begin action.call(user) - rescue Exception => e + rescue # Ignore internal exceptions which will be caused in the controller # In such cases, response.status will be 200. end @@ -70,7 +70,7 @@ module AccessMatchersForController user = emulate_user(role, @membership) begin action.call(user) - rescue Exception => e + rescue # Ignore internal exceptions which will be caused in the controller # In such cases, response.status will be 200. end -- cgit v1.2.1 From 359d72ba3ec931205a58b4a992cc9b6e93fd0ca2 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 6 Jun 2017 02:29:34 +0900 Subject: Fix static analysys --- .../matchers/access_matchers_for_controller.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 14500201a59..12f4b57e43d 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -5,14 +5,22 @@ module AccessMatchersForController extend RSpec::Matchers::DSL include Warden::Test::Helpers - EXPECTED_STATUS_CODE_ALLOWED = [200, 302] - EXPECTED_STATUS_CODE_DENIED = [404] + EXPECTED_STATUS_CODE_ALLOWED = [200, 302].freeze + EXPECTED_STATUS_CODE_DENIED = [404].freeze def emulate_user(role, membership = nil) case role when :admin user = create(:admin) sign_in(user) + when :user + user = create(:user) + sign_in(user) + when :external + user = create(:user, external: true) + sign_in(user) + when :visitor # rubocop:disable Lint/EmptyWhen + # no-op when *Gitlab::Access.sym_options_with_owner.keys # owner, master, developer, reporter, guest raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership @@ -24,14 +32,6 @@ module AccessMatchersForController end sign_in(user) - when :user - user = create(:user) - sign_in(user) - when :external - user = create(:user, external: true) - sign_in(user) - when :visitor - # no-op else raise ArgumentError, "cannot emulate user #{role}" end -- cgit v1.2.1 From 043f1b8232a0d5a5f0b1427c3ed8038dcf029f53 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 26 Jun 2017 14:59:25 +0900 Subject: Remove author. Replace Result to Got. --- spec/support/matchers/access_matchers_for_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 12f4b57e43d..844464233b8 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -41,7 +41,7 @@ module AccessMatchersForController def description_for(role, type, expected, result) "be #{type} for #{role}." \ - " Expected: #{expected.join(',')} Result: #{result}" + " Expected: #{expected.join(',')} Got: #{result}" end matcher :be_allowed_for do |role| -- cgit v1.2.1 From ac7ad422812cb3224afb6e1943f9ee22e2488912 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 26 Jun 2017 23:42:01 +0900 Subject: IMprove access_matchers --- .../matchers/access_matchers_for_controller.rb | 47 ++++++++++------------ 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 844464233b8..59c6f528e74 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -5,8 +5,8 @@ module AccessMatchersForController extend RSpec::Matchers::DSL include Warden::Test::Helpers - EXPECTED_STATUS_CODE_ALLOWED = [200, 302].freeze - EXPECTED_STATUS_CODE_DENIED = [404].freeze + EXPECTED_STATUS_CODE_ALLOWED = [200, 201, 302].freeze + EXPECTED_STATUS_CODE_DENIED = [401, 404].freeze def emulate_user(role, membership = nil) case role @@ -19,18 +19,13 @@ module AccessMatchersForController when :external user = create(:user, external: true) sign_in(user) - when :visitor # rubocop:disable Lint/EmptyWhen - # no-op + when :visitor + user = nil + when User + user = role + sign_in(user) when *Gitlab::Access.sym_options_with_owner.keys # owner, master, developer, reporter, guest - raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership - - if role == :owner && membership.owner - user = membership.owner - else - user = create(:user) - membership.public_send(:"add_#{role}", user) - end - + user = cerate_user_by_membership(role, membership) sign_in(user) else raise ArgumentError, "cannot emulate user #{role}" @@ -39,6 +34,18 @@ module AccessMatchersForController user end + def cerate_user_by_membership(role, membership = nil) + raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership + + if role == :owner && membership.owner + user = membership.owner + else + user = create(:user) + membership.public_send(:"add_#{role}", user) + end + user + end + def description_for(role, type, expected, result) "be #{type} for #{role}." \ " Expected: #{expected.join(',')} Got: #{result}" @@ -47,12 +54,7 @@ module AccessMatchersForController matcher :be_allowed_for do |role| match do |action| user = emulate_user(role, @membership) - begin - action.call(user) - rescue - # Ignore internal exceptions which will be caused in the controller - # In such cases, response.status will be 200. - end + action.call(user) EXPECTED_STATUS_CODE_ALLOWED.include?(response.status) end @@ -68,12 +70,7 @@ module AccessMatchersForController matcher :be_denied_for do |role| match do |action| user = emulate_user(role, @membership) - begin - action.call(user) - rescue - # Ignore internal exceptions which will be caused in the controller - # In such cases, response.status will be 200. - end + action.call(user) EXPECTED_STATUS_CODE_DENIED.include?(response.status) end -- cgit v1.2.1 From d1fae597431c8005067a11d0030a0d690231685a Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 00:55:20 +0900 Subject: Improve description_for --- spec/support/matchers/access_matchers_for_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 59c6f528e74..78a0cc0a45d 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -47,8 +47,7 @@ module AccessMatchersForController end def description_for(role, type, expected, result) - "be #{type} for #{role}." \ - " Expected: #{expected.join(',')} Got: #{result}" + "be #{type} for #{role}. Expected: #{expected.join(',')} Got: #{result}" end matcher :be_allowed_for do |role| -- cgit v1.2.1 From 07b0615e2b59cbd3f277e17d7d0e1bf7f11f9fee Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 22:43:43 +0900 Subject: Fixed typo and hash alighment --- spec/support/matchers/access_matchers_for_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index 78a0cc0a45d..d9980ff2f98 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -25,7 +25,7 @@ module AccessMatchersForController user = role sign_in(user) when *Gitlab::Access.sym_options_with_owner.keys # owner, master, developer, reporter, guest - user = cerate_user_by_membership(role, membership) + user = create_user_by_membership(role, membership) sign_in(user) else raise ArgumentError, "cannot emulate user #{role}" @@ -34,7 +34,7 @@ module AccessMatchersForController user end - def cerate_user_by_membership(role, membership = nil) + def create_user_by_membership(role, membership = nil) raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership if role == :owner && membership.owner -- cgit v1.2.1 From a513ae4ae58cf1f55872cc07c734866167eae45f Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 28 Jun 2017 00:31:26 +0900 Subject: use go instead of let proc --- spec/support/matchers/access_matchers_for_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index d9980ff2f98..c951c6b754d 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -52,8 +52,8 @@ module AccessMatchersForController matcher :be_allowed_for do |role| match do |action| - user = emulate_user(role, @membership) - action.call(user) + emulate_user(role, @membership) + action.call EXPECTED_STATUS_CODE_ALLOWED.include?(response.status) end @@ -68,8 +68,8 @@ module AccessMatchersForController matcher :be_denied_for do |role| match do |action| - user = emulate_user(role, @membership) - action.call(user) + emulate_user(role, @membership) + action.call EXPECTED_STATUS_CODE_DENIED.include?(response.status) end -- cgit v1.2.1 From d9d5600711426d280cc1768820e809357293f14d Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 28 Jun 2017 22:04:49 +0900 Subject: Make membership required for create_user_by_membership --- spec/support/matchers/access_matchers_for_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers/access_matchers_for_controller.rb b/spec/support/matchers/access_matchers_for_controller.rb index c951c6b754d..fb43f51c70c 100644 --- a/spec/support/matchers/access_matchers_for_controller.rb +++ b/spec/support/matchers/access_matchers_for_controller.rb @@ -25,6 +25,8 @@ module AccessMatchersForController user = role sign_in(user) when *Gitlab::Access.sym_options_with_owner.keys # owner, master, developer, reporter, guest + raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership + user = create_user_by_membership(role, membership) sign_in(user) else @@ -34,9 +36,7 @@ module AccessMatchersForController user end - def create_user_by_membership(role, membership = nil) - raise ArgumentError, "cannot emulate #{role} without membership parent" unless membership - + def create_user_by_membership(role, membership) if role == :owner && membership.owner user = membership.owner else -- cgit v1.2.1 From 70b05a83772abc59b3c914c84bc4d2c07749884d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 13 Jun 2017 17:12:31 -0500 Subject: Split up MergeRequestsController --- spec/support/features/issuable_slash_commands_shared_examples.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'spec/support') diff --git a/spec/support/features/issuable_slash_commands_shared_examples.rb b/spec/support/features/issuable_slash_commands_shared_examples.rb index 50869099bb7..98b014df6cd 100644 --- a/spec/support/features/issuable_slash_commands_shared_examples.rb +++ b/spec/support/features/issuable_slash_commands_shared_examples.rb @@ -28,7 +28,12 @@ shared_examples 'issuable record that supports quick actions in its description describe "new #{issuable_type}", js: true do context 'with commands in the description' do it "creates the #{issuable_type} and interpret commands accordingly" do - visit public_send("new_namespace_project_#{issuable_type}_path", project.namespace, project, new_url_opts) + case issuable_type + when :merge_request + visit public_send("namespace_project_new_merge_request_path", project.namespace, project, new_url_opts) + when :issue + visit public_send("new_namespace_project_issue_path", project.namespace, project, new_url_opts) + end fill_in "#{issuable_type}_title", with: 'bug 345' fill_in "#{issuable_type}_description", with: "bug description\n/label ~bug\n/milestone %\"ASAP\"" click_button "Submit #{issuable_type}".humanize -- cgit v1.2.1 From a7335c1188d32edd58aebdb818dbf4c49899149b Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Wed, 28 Jun 2017 13:16:40 -0500 Subject: Refactored tests and added a breakpoint to the merge_request_tabs --- .../shared_examples/features/issuable_sidebar_shared_examples.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/support/shared_examples/features/issuable_sidebar_shared_examples.rb (limited to 'spec/support') diff --git a/spec/support/shared_examples/features/issuable_sidebar_shared_examples.rb b/spec/support/shared_examples/features/issuable_sidebar_shared_examples.rb new file mode 100644 index 00000000000..96c821b26f7 --- /dev/null +++ b/spec/support/shared_examples/features/issuable_sidebar_shared_examples.rb @@ -0,0 +1,9 @@ +shared_examples 'issue sidebar stays collapsed on mobile' do + before do + resize_screen_xs + end + + it 'keeps the sidebar collapsed' do + expect(page).not_to have_css('.right-sidebar.right-sidebar-collapsed') + end +end -- cgit v1.2.1