From a61c19778180a8316321ac9ca6f84de76a6c23b3 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 8 Dec 2016 14:45:34 +1100 Subject: Don't disable capybara-screenshot in CI environment --- spec/support/capybara.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'spec/support') diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 16d5f2bf0b8..ebb1f30f090 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,6 +1,7 @@ require 'capybara/rails' require 'capybara/rspec' require 'capybara/poltergeist' +require 'capybara-screenshot/rspec' # Give CI some extra time timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 10 @@ -21,12 +22,8 @@ end Capybara.default_max_wait_time = timeout Capybara.ignore_hidden_elements = true -unless ENV['CI'] || ENV['CI_SERVER'] - require 'capybara-screenshot/rspec' - - # Keep only the screenshots generated from the last failing test suite - Capybara::Screenshot.prune_strategy = :keep_last_run -end +# Keep only the screenshots generated from the last failing test suite +Capybara::Screenshot.prune_strategy = :keep_last_run RSpec.configure do |config| config.before(:suite) do -- cgit v1.2.1 From 0267b83898d604181e70c5ea8ac4a84108d2e6d6 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 22 Dec 2016 13:31:12 +0100 Subject: Delegate a single discussion to a new issue Delegate a discussion in a merge request into a new issue. The discussion wil be marked as resolved and a system note will be added linking to the newly created issue. --- ...issues_resolving_discussions_shared_examples.rb | 15 +++++++++++++ ...olving_discussions_in_issues_shared_examples.rb | 25 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 spec/support/api/issues_resolving_discussions_shared_examples.rb create mode 100644 spec/support/features/resolving_discussions_in_issues_shared_examples.rb (limited to 'spec/support') diff --git a/spec/support/api/issues_resolving_discussions_shared_examples.rb b/spec/support/api/issues_resolving_discussions_shared_examples.rb new file mode 100644 index 00000000000..d26d279363c --- /dev/null +++ b/spec/support/api/issues_resolving_discussions_shared_examples.rb @@ -0,0 +1,15 @@ +shared_examples 'creating an issue resolving discussions through the API' do + it 'creates a new project issue' do + expect(response).to have_http_status(:created) + end + + it 'resolves the discussions in a merge request' do + discussion.first_note.reload + + expect(discussion.resolved?).to be(true) + end + + it 'assigns a description to the issue mentioning the merge request' do + expect(json_response['description']).to include(merge_request.to_reference) + end +end diff --git a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb new file mode 100644 index 00000000000..8712e688d33 --- /dev/null +++ b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb @@ -0,0 +1,25 @@ +shared_examples 'creating an issue for a discussion' do + it 'shows an issue with the title filled in' do + title_field = page.find_field('issue[title]') + + expect(title_field.value).to include(merge_request.title) + end + + it 'has a mention of the discussion in the description' do + description_field = page.find_field('issue[description]') + + expect(description_field.value).to include(discussion.first_note.note) + end + + it 'can create a new issue for the project' do + expect { click_button 'Submit issue' }.to change { project.issues.reload.size }.by(1) + end + + it 'resolves the discussion in the merge request' do + click_button 'Submit issue' + + discussion.first_note.reload + + expect(discussion.resolved?).to eq(true) + end +end -- cgit v1.2.1 From f86928953d2d79f40f10813a6e244c1da0779d16 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 27 Feb 2017 10:23:36 +0100 Subject: Always require MR-iid for resolving discussions And deduplicate the finding of MR's & discussions. Now the searching is done in the service, istead of the controller & the API. --- .../features/resolving_discussions_in_issues_shared_examples.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/support') diff --git a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb index 8712e688d33..669b306d94e 100644 --- a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb +++ b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb @@ -22,4 +22,10 @@ shared_examples 'creating an issue for a discussion' do expect(discussion.resolved?).to eq(true) end + + it 'has a hidden field for the merge request' do + merge_request_field = find('#merge_request_for_resolving_discussions', visible: false) + + expect(merge_request_field.value).to eq(merge_request.iid.to_s) + end end -- cgit v1.2.1 From 6f9304e03078acfa9c7afdceb1ed02e4c87265ca Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 8 Mar 2017 20:16:17 +0100 Subject: Add a flash messages when an issue resolving discussions is created --- .../resolving_discussions_in_issues_shared_examples.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/support') diff --git a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb index 669b306d94e..c8e5021d9a6 100644 --- a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb +++ b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb @@ -23,6 +23,16 @@ shared_examples 'creating an issue for a discussion' do expect(discussion.resolved?).to eq(true) end + it 'shows a flash messaage after resolving a discussion' do + click_button 'Submit issue' + + page.within '.flash-notice' do + # Only check for the word 'Resolved' since the spec might have resolved + # multiple discussions + expect(page).to have_content('Resolved') + end + end + it 'has a hidden field for the merge request' do merge_request_field = find('#merge_request_for_resolving_discussions', visible: false) -- cgit v1.2.1 From ea70a0d674539d53e40c63a0a3cebef33d7e13b7 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 10 Mar 2017 09:19:12 +0100 Subject: Rename variable merge_request_for_resolving_discussions -> merge_request_to_resolve_discussions_of --- .../support/features/resolving_discussions_in_issues_shared_examples.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/support') diff --git a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb index c8e5021d9a6..4a946995f84 100644 --- a/spec/support/features/resolving_discussions_in_issues_shared_examples.rb +++ b/spec/support/features/resolving_discussions_in_issues_shared_examples.rb @@ -34,7 +34,7 @@ shared_examples 'creating an issue for a discussion' do end it 'has a hidden field for the merge request' do - merge_request_field = find('#merge_request_for_resolving_discussions', visible: false) + merge_request_field = find('#merge_request_to_resolve_discussions_of', visible: false) expect(merge_request_field.value).to eq(merge_request.iid.to_s) end -- cgit v1.2.1 From 5f7592d53805b18fbbc2a117ab8b4d953b13dbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 9 Mar 2017 00:41:02 +0100 Subject: Implement `json_response` as a `let` variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not a good idea to memoize `json_response` using an instance variable because `rspec-retry` doesn't clear instance variables on retries, only `let` variables. This will avoid issues where retries would fail on a different line that the original failure, blurrying what's the real failure. Also, automatically add api: true to specs under /spec/requests/(ci/)?api/, and include JsonHelpers in controller, request and API specs. Signed-off-by: Rémy Coutable --- spec/support/api_helpers.rb | 4 ---- spec/support/json_response_helpers.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 spec/support/json_response_helpers.rb (limited to 'spec/support') diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb index ae6e708cf87..35d1e1cfc7d 100644 --- a/spec/support/api_helpers.rb +++ b/spec/support/api_helpers.rb @@ -49,8 +49,4 @@ module ApiHelpers '' end end - - def json_response - @_json_response ||= JSON.parse(response.body) - end end diff --git a/spec/support/json_response_helpers.rb b/spec/support/json_response_helpers.rb new file mode 100644 index 00000000000..e8d2ef2d7f0 --- /dev/null +++ b/spec/support/json_response_helpers.rb @@ -0,0 +1,9 @@ +shared_context 'JSON response' do + let(:json_response) { JSON.parse(response.body) } +end + +RSpec.configure do |config| + config.include_context 'JSON response', type: :controller + config.include_context 'JSON response', type: :request + config.include_context 'JSON response', :api +end -- cgit v1.2.1 From 464ca33747ec3f2a4063795e18ab5888e429b334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 14 Mar 2017 18:30:53 +0100 Subject: Allow to override GITLAB_GIT_TEST_REPO_URL to specify a different gitlab-git-test repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will set this to the dev mirror in GitLab CE and EE on dev. Signed-off-by: Rémy Coutable --- spec/support/seed_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/support') diff --git a/spec/support/seed_helper.rb b/spec/support/seed_helper.rb index 07f81e9c4f3..f55fee28ff9 100644 --- a/spec/support/seed_helper.rb +++ b/spec/support/seed_helper.rb @@ -7,7 +7,7 @@ TEST_MUTABLE_REPO_PATH = File.join(SEED_REPOSITORY_PATH, "mutable-repo.git") TEST_BROKEN_REPO_PATH = File.join(SEED_REPOSITORY_PATH, "broken-repo.git") module SeedHelper - GITLAB_URL = "https://gitlab.com/gitlab-org/gitlab-git-test.git".freeze + GITLAB_GIT_TEST_REPO_URL = ENV.fetch('GITLAB_GIT_TEST_REPO_URL', 'https://gitlab.com/gitlab-org/gitlab-git-test.git').freeze def ensure_seeds if File.exist?(SEED_REPOSITORY_PATH) @@ -25,7 +25,7 @@ module SeedHelper end def create_bare_seeds - system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{GITLAB_URL}), + system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{GITLAB_GIT_TEST_REPO_URL}), chdir: SEED_REPOSITORY_PATH, out: '/dev/null', err: '/dev/null') @@ -45,7 +45,7 @@ module SeedHelper system(git_env, *%w(git branch -t feature origin/feature), chdir: TEST_MUTABLE_REPO_PATH, out: '/dev/null', err: '/dev/null') - system(git_env, *%W(#{Gitlab.config.git.bin_path} remote add expendable #{GITLAB_URL}), + system(git_env, *%W(#{Gitlab.config.git.bin_path} remote add expendable #{GITLAB_GIT_TEST_REPO_URL}), chdir: TEST_MUTABLE_REPO_PATH, out: '/dev/null', err: '/dev/null') end -- cgit v1.2.1 From 517598ba10793efa02cb90379f78ab97c9c5b25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 16 Mar 2017 10:56:39 +0100 Subject: Add a new have_html_escaped_body_text that match an HTML-escaped text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This solves transient failures when a text contains HTML-escapable characters such as `'`. Signed-off-by: Rémy Coutable --- spec/support/matchers/email_matchers.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 spec/support/matchers/email_matchers.rb (limited to 'spec/support') diff --git a/spec/support/matchers/email_matchers.rb b/spec/support/matchers/email_matchers.rb new file mode 100644 index 00000000000..d9d59ec12ec --- /dev/null +++ b/spec/support/matchers/email_matchers.rb @@ -0,0 +1,5 @@ +RSpec::Matchers.define :have_html_escaped_body_text do |expected| + match do |actual| + expect(actual).to have_body_text(ERB::Util.html_escape(expected)) + end +end -- cgit v1.2.1