diff options
Diffstat (limited to 'spec')
68 files changed, 773 insertions, 202 deletions
diff --git a/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb b/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb index 34cd9f7e4eb..3855763b200 100644 --- a/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb +++ b/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ReferenceFilter, benchmark: true do +describe Banzai::Filter::ReferenceFilter, benchmark: true do let(:input) do html = <<-EOF <p>Hello @alice and @bob, how are you doing today?</p> diff --git a/spec/factories.rb b/spec/factories.rb index 4bf93adabe2..d6b4efa9a03 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -43,7 +43,8 @@ FactoryGirl.define do end after(:create) do |user, evaluator| - user.identities << create(:identity, + user.identities << create( + :identity, provider: evaluator.provider, extern_uid: evaluator.extern_uid ) diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb index 66a2cc0c157..26d03944b8a 100644 --- a/spec/features/admin/admin_runners_spec.rb +++ b/spec/features/admin/admin_runners_spec.rb @@ -63,7 +63,7 @@ describe "Admin Runners" do end describe 'runners registration token' do - let!(:token) { current_application_settings.ensure_runners_registration_token } + let!(:token) { current_application_settings.runners_registration_token } before { visit admin_runners_path } it 'has a registration token' do diff --git a/spec/features/ci_lint_spec.rb b/spec/features/ci_lint_spec.rb new file mode 100644 index 00000000000..e6e73e5e67c --- /dev/null +++ b/spec/features/ci_lint_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'CI Lint' do + before do + login_as :user + end + + describe 'YAML parsing' do + before do + visit ci_lint_path + fill_in 'content', with: yaml_content + click_on 'Validate' + end + + context 'YAML is correct' do + let(:yaml_content) do + File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) + end + + it 'Yaml parsing' do + within "table" do + expect(page).to have_content('Job - rspec') + expect(page).to have_content('Job - spinach') + expect(page).to have_content('Deploy Job - staging') + expect(page).to have_content('Deploy Job - production') + end + end + end + + context 'YAML is incorrect' do + let(:yaml_content) { '' } + + it 'displays information about an error' do + expect(page).to have_content('Status: syntax is incorrect') + expect(page).to have_content('Error: Please provide content of .gitlab-ci.yml') + end + end + end +end diff --git a/spec/features/commits_spec.rb b/spec/features/commits_spec.rb index ecc85376ffc..fe7f07f5b75 100644 --- a/spec/features/commits_spec.rb +++ b/spec/features/commits_spec.rb @@ -19,30 +19,13 @@ describe 'Commits' do let!(:build) { FactoryGirl.create :ci_build, commit: commit } describe 'Project commits' do - context 'builds enabled' do - context '.gitlab-ci.yml found' do - before do - visit namespace_project_commits_path(project.namespace, project, :master) - end - - it 'should show build status' do - page.within("//li[@id='commit-#{commit.short_sha}']") do - expect(page).to have_css(".ci-status-link") - end - end - end + before do + visit namespace_project_commits_path(project.namespace, project, :master) + end - context 'no .gitlab-ci.yml found' do - before do - stub_ci_commit_yaml_file(nil) - visit namespace_project_commits_path(project.namespace, project, :master) - end - - it 'should not show build status' do - page.within("//li[@id='commit-#{commit.short_sha}']") do - expect(page).to have_no_css(".ci-status-link") - end - end + it 'should show build status' do + page.within("//li[@id='commit-#{commit.short_sha}']") do + expect(page).to have_css(".ci-status-link") end end end diff --git a/spec/features/issues/filter_by_milestone_spec.rb b/spec/features/issues/filter_by_milestone_spec.rb index f600f8684ac..38c8d343ce3 100644 --- a/spec/features/issues/filter_by_milestone_spec.rb +++ b/spec/features/issues/filter_by_milestone_spec.rb @@ -13,7 +13,7 @@ feature 'Issue filtering by Milestone', feature: true do visit_issues(project) filter_by_milestone(Milestone::None.title) - expect(page).to have_css('.issue-title', count: 1) + expect(page).to have_css('.title', count: 1) end scenario 'filters by a specific Milestone', js: true do @@ -23,7 +23,7 @@ feature 'Issue filtering by Milestone', feature: true do visit_issues(project) filter_by_milestone(milestone.title) - expect(page).to have_css('.issue-title', count: 1) + expect(page).to have_css('.title', count: 1) end def visit_issues(project) diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb new file mode 100644 index 00000000000..e4efdbe2421 --- /dev/null +++ b/spec/features/issues/note_polling_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +feature 'Issue notes polling' do + let!(:project) { create(:project, :public) } + let!(:issue) { create(:issue, project: project) } + + background do + visit namespace_project_issue_path(project.namespace, project, issue) + end + + scenario 'Another user adds a comment to an issue', js: true do + note = create(:note_on_issue, noteable: issue, note: 'Looks good!') + page.execute_script('notes.refresh();') + expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!') + end +end diff --git a/spec/features/lint_spec.rb b/spec/features/lint_spec.rb deleted file mode 100644 index 5d8f56e2cfb..00000000000 --- a/spec/features/lint_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -describe "Lint" do - before do - login_as :user - end - - it "Yaml parsing", js: true do - content = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) - visit ci_lint_path - fill_in "content", with: content - click_on "Validate" - within "table" do - expect(page).to have_content("Job - rspec") - expect(page).to have_content("Job - spinach") - expect(page).to have_content("Deploy Job - staging") - expect(page).to have_content("Deploy Job - production") - end - end - - it "Yaml parsing with error", js: true do - visit ci_lint_path - fill_in "content", with: "" - click_on "Validate" - expect(page).to have_content("Status: syntax is incorrect") - expect(page).to have_content("Error: Please provide content of .gitlab-ci.yml") - end -end diff --git a/spec/features/merge_requests/merge_when_build_succeeds_spec.rb b/spec/features/merge_requests/merge_when_build_succeeds_spec.rb index 28a46a0725d..7aa7eb965e9 100644 --- a/spec/features/merge_requests/merge_when_build_succeeds_spec.rb +++ b/spec/features/merge_requests/merge_when_build_succeeds_spec.rb @@ -21,12 +21,12 @@ feature 'Merge When Build Succeeds', feature: true, js: true do end it 'displays the Merge When Build Succeeds button' do - expect(page).to have_link "Merge When Build Succeeds" + expect(page).to have_button "Merge When Build Succeeds" end context "Merge When Build succeeds enabled" do before do - click_link "Merge When Build Succeeds" + click_button "Merge When Build Succeeds" end it 'activates Merge When Build Succeeds feature' do @@ -58,7 +58,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do it 'cancels the automatic merge' do click_link "Cancel Automatic Merge" - expect(page).to have_link "Merge When Build Succeeds" + expect(page).to have_button "Merge When Build Succeeds" visit_merge_request(merge_request) # Needed to refresh the page expect(page).to have_content "Canceled the automatic merge" diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb index 09fcff2444a..74b148f5d17 100644 --- a/spec/features/projects_spec.rb +++ b/spec/features/projects_spec.rb @@ -70,6 +70,20 @@ feature 'Project', feature: true do end end + describe 'leave project link' do + let(:user) { create(:user) } + let(:project) { create(:project, namespace: user.namespace) } + + before do + login_with(user) + project.team.add_user(user, Gitlab::Access::MASTER) + visit namespace_project_path(project.namespace, project) + end + + it { expect(page).to have_content('You have Master access to this project.') } + it { expect(page).to have_link('Leave this project') } + end + def remove_with_confirm(button_text, confirm_with) click_button button_text fill_in 'confirm_name_input', with: confirm_with diff --git a/spec/features/security/group_access_spec.rb b/spec/features/security/group_access_spec.rb index 4b78e3a61f0..65f8073c693 100644 --- a/spec/features/security/group_access_spec.rb +++ b/spec/features/security/group_access_spec.rb @@ -16,11 +16,11 @@ describe 'Group access', feature: true do end end - def group_member(access_level, group = group) + def group_member(access_level, grp = group()) level = Object.const_get("Gitlab::Access::#{access_level.upcase}") create(:user).tap do |user| - group.add_user(user, level) + grp.add_user(user, level) end end diff --git a/spec/features/task_lists_spec.rb b/spec/features/task_lists_spec.rb index fca3c77fc64..b7368cca29d 100644 --- a/spec/features/task_lists_spec.rb +++ b/spec/features/task_lists_spec.rb @@ -47,7 +47,7 @@ feature 'Task Lists', feature: true do it 'contains the required selectors' do visit_issue(project, issue) - container = '.issue-details .description.js-task-list-container' + container = '.detail-page-description .description.js-task-list-container' expect(page).to have_selector(container) expect(page).to have_selector("#{container} .wiki .task-list .task-list-item .task-list-item-checkbox") @@ -123,7 +123,7 @@ feature 'Task Lists', feature: true do it 'contains the required selectors' do visit_merge_request(project, merge) - container = '.merge-request-details .description.js-task-list-container' + container = '.detail-page-description .description.js-task-list-container' expect(page).to have_selector(container) expect(page).to have_selector("#{container} .wiki .task-list .task-list-item .task-list-item-checkbox") diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 5568f06639c..68527c3a4f8 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -263,11 +263,12 @@ describe ApplicationHelper do end it 'includes a default js-timeago class' do - expect(element.attr('class')).to eq 'time_ago js-timeago' + expect(element.attr('class')).to eq 'time_ago js-timeago js-timeago-pending' end it 'accepts a custom html_class' do - expect(element(html_class: 'custom_class').attr('class')).to eq 'custom_class js-timeago' + expect(element(html_class: 'custom_class').attr('class')). + to eq 'custom_class js-timeago js-timeago-pending' end it 'accepts a custom tooltip placement' do @@ -278,7 +279,7 @@ describe ApplicationHelper do el = element.next_element expect(el.name).to eq 'script' - expect(el.text).to include "$('.js-timeago').last().timeago()" + expect(el.text).to include "$('.js-timeago-pending').removeClass('js-timeago-pending').timeago()" end it 'allows the script tag to be excluded' do diff --git a/spec/helpers/ci_status_helper_spec.rb b/spec/helpers/ci_status_helper_spec.rb index 7fc53eb1472..4f8d9c67262 100644 --- a/spec/helpers/ci_status_helper_spec.rb +++ b/spec/helpers/ci_status_helper_spec.rb @@ -6,13 +6,8 @@ describe CiStatusHelper do let(:success_commit) { double("Ci::Commit", status: 'success') } let(:failed_commit) { double("Ci::Commit", status: 'failed') } - describe 'ci_status_color' do - it { expect(ci_status_icon(success_commit)).to include('fa-check') } - it { expect(ci_status_icon(failed_commit)).to include('fa-close') } - end - - describe 'ci_status_color' do - it { expect(ci_status_color(success_commit)).to eq('green') } - it { expect(ci_status_color(failed_commit)).to eq('red') } + describe 'ci_status_icon' do + it { expect(helper.ci_status_icon(success_commit)).to include('fa-check') } + it { expect(helper.ci_status_icon(failed_commit)).to include('fa-close') } end end diff --git a/spec/helpers/groups_helper.rb b/spec/helpers/groups_helper.rb index 5d174460681..4ea90a80a92 100644 --- a/spec/helpers/groups_helper.rb +++ b/spec/helpers/groups_helper.rb @@ -9,7 +9,7 @@ describe GroupsHelper do group.avatar = File.open(avatar_file_path) group.save! expect(group_icon(group.path).to_s). - to match("/uploads/group/avatar/#{ group.id }/banana_sample.gif") + to match("/uploads/group/avatar/#{group.id}/banana_sample.gif") end it 'should give default avatar_icon when no avatar is present' do diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb index 0ef1efb8bce..600e1c4e9ec 100644 --- a/spec/helpers/merge_requests_helper_spec.rb +++ b/spec/helpers/merge_requests_helper_spec.rb @@ -1,24 +1,57 @@ require 'spec_helper' describe MergeRequestsHelper do - describe "#issues_sentence" do + describe 'ci_build_details_path' do + let(:project) { create :project } + let(:merge_request) { MergeRequest.new } + let(:ci_service) { CiService.new } + let(:last_commit) { Ci::Commit.new({}) } + + before do + allow(merge_request).to receive(:source_project).and_return(project) + allow(merge_request).to receive(:last_commit).and_return(last_commit) + allow(project).to receive(:ci_service).and_return(ci_service) + allow(last_commit).to receive(:sha).and_return('12d65c') + end + + it 'does not include api credentials in a link' do + allow(ci_service). + to receive(:build_page).and_return("http://secretuser:secretpass@jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c") + expect(helper.ci_build_details_path(merge_request)).to_not match("secret") + end + end + + describe '#issues_sentence' do subject { issues_sentence(issues) } let(:issues) do [build(:issue, iid: 1), build(:issue, iid: 2), build(:issue, iid: 3)] end it { is_expected.to eq('#1, #2, and #3') } + + context 'for JIRA issues' do + let(:project) { create(:project) } + let(:issues) do + [ + JiraIssue.new('JIRA-123', project), + JiraIssue.new('JIRA-456', project), + JiraIssue.new('FOOBAR-7890', project) + ] + end + + it { is_expected.to eq('FOOBAR-7890, JIRA-123, and JIRA-456') } + end end - describe "#format_mr_branch_names" do - describe "within the same project" do + describe '#format_mr_branch_names' do + describe 'within the same project' do let(:merge_request) { create(:merge_request) } subject { format_mr_branch_names(merge_request) } it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) } end - describe "within different projects" do + describe 'within different projects' do let(:project) { create(:project) } let(:fork_project) { create(:project, forked_from_project: project) } let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: project) } diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index f2efb528aeb..53207767581 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -53,6 +53,16 @@ describe ProjectsHelper do end end + describe 'user_max_access_in_project' do + let(:project) { create(:project) } + let(:user) { create(:user) } + before do + project.team.add_user(user, Gitlab::Access::MASTER) + end + + it { expect(helper.user_max_access_in_project(user.id, project)).to eq('Master') } + end + describe "readme_cache_key" do let(:project) { create(:project) } diff --git a/spec/javascripts/fixtures/issues_show.html.haml b/spec/javascripts/fixtures/issues_show.html.haml index 7e8b2a64351..8447dfdda32 100644 --- a/spec/javascripts/fixtures/issues_show.html.haml +++ b/spec/javascripts/fixtures/issues_show.html.haml @@ -1,6 +1,6 @@ %a.btn-close -.issue-details +.detail-page-description .description.js-task-list-container .wiki %ul.task-list diff --git a/spec/javascripts/fixtures/merge_requests_show.html.haml b/spec/javascripts/fixtures/merge_requests_show.html.haml index f0c622935f8..8447dfdda32 100644 --- a/spec/javascripts/fixtures/merge_requests_show.html.haml +++ b/spec/javascripts/fixtures/merge_requests_show.html.haml @@ -1,6 +1,6 @@ %a.btn-close -.merge-request-details +.detail-page-description .description.js-task-list-container .wiki %ul.task-list diff --git a/spec/lib/gitlab/markdown/cross_project_reference_spec.rb b/spec/lib/banzai/cross_project_reference_spec.rb index f594fe4ccf6..81b9a513ce3 100644 --- a/spec/lib/gitlab/markdown/cross_project_reference_spec.rb +++ b/spec/lib/banzai/cross_project_reference_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::CrossProjectReference, lib: true do +describe Banzai::CrossProjectReference, lib: true do include described_class describe '#project_from_ref' do diff --git a/spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb b/spec/lib/banzai/filter/autolink_filter_spec.rb index a0844aee559..84c2ddf444e 100644 --- a/spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb +++ b/spec/lib/banzai/filter/autolink_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::AutolinkFilter, lib: true do +describe Banzai::Filter::AutolinkFilter, lib: true do include FilterSpecHelper let(:link) { 'http://about.gitlab.com/' } diff --git a/spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb index 570c9767628..c2a8ad36c30 100644 --- a/spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::CommitRangeReferenceFilter, lib: true do +describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_reference_filter_spec.rb index 76e7957bbb9..473534ba68a 100644 --- a/spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::CommitReferenceFilter, lib: true do +describe Banzai::Filter::CommitReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb b/spec/lib/banzai/filter/emoji_filter_spec.rb index ea9b81862cf..cf314058158 100644 --- a/spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb +++ b/spec/lib/banzai/filter/emoji_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::EmojiFilter, lib: true do +describe Banzai::Filter::EmojiFilter, lib: true do include FilterSpecHelper before do diff --git a/spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb index d8420102648..953466679e4 100644 --- a/spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ExternalIssueReferenceFilter, lib: true do +describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do include FilterSpecHelper def helper diff --git a/spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb b/spec/lib/banzai/filter/external_link_filter_spec.rb index e559f5741cc..e3a8e15330e 100644 --- a/spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb +++ b/spec/lib/banzai/filter/external_link_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ExternalLinkFilter, lib: true do +describe Banzai::Filter::ExternalLinkFilter, lib: true do include FilterSpecHelper it 'ignores elements without an href attribute' do diff --git a/spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb index 1aa5d44568e..5a0d3d577a8 100644 --- a/spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::IssueReferenceFilter, lib: true do +describe Banzai::Filter::IssueReferenceFilter, lib: true do include FilterSpecHelper def helper diff --git a/spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb b/spec/lib/banzai/filter/label_reference_filter_spec.rb index 4fcbb329fe4..b46ccc47605 100644 --- a/spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'html/pipeline' -describe Gitlab::Markdown::LabelReferenceFilter, lib: true do +describe Banzai::Filter::LabelReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:empty_project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb index 589550e15c4..352710df307 100644 --- a/spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::MergeRequestReferenceFilter, lib: true do +describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb index 9e6ee9f0d61..e9bb388e361 100644 --- a/spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb +++ b/spec/lib/banzai/filter/redactor_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::RedactorFilter, lib: true do +describe Banzai::Filter::RedactorFilter, lib: true do include ActionView::Helpers::UrlHelper include FilterSpecHelper diff --git a/spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb b/spec/lib/banzai/filter/reference_gatherer_filter_spec.rb index abfb5ad5e49..c8b1dfdf944 100644 --- a/spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb +++ b/spec/lib/banzai/filter/reference_gatherer_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ReferenceGathererFilter, lib: true do +describe Banzai::Filter::ReferenceGathererFilter, lib: true do include ActionView::Helpers::UrlHelper include FilterSpecHelper diff --git a/spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index e0f53e2a533..0b3e5ecbc9f 100644 --- a/spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Markdown::RelativeLinkFilter, lib: true do +describe Banzai::Filter::RelativeLinkFilter, lib: true do def filter(doc, contexts = {}) contexts.reverse_merge!({ commit: project.commit, diff --git a/spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb index a5e5ee0e08a..760d60a4190 100644 --- a/spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb +++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::SanitizationFilter, lib: true do +describe Banzai::Filter::SanitizationFilter, lib: true do include FilterSpecHelper describe 'default whitelist' do diff --git a/spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb index 51526b58597..26466fbb180 100644 --- a/spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::SnippetReferenceFilter, lib: true do +describe Banzai::Filter::SnippetReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:empty_project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index 8b76048f3e3..407617f3307 100644 --- a/spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::SyntaxHighlightFilter, lib: true do +describe Banzai::Filter::SyntaxHighlightFilter, lib: true do include FilterSpecHelper it 'highlights valid code blocks' do diff --git a/spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb index c8c79c41847..6a5d003e87f 100644 --- a/spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Markdown::TableOfContentsFilter, lib: true do +describe Banzai::Filter::TableOfContentsFilter, lib: true do include FilterSpecHelper def header(level, text) diff --git a/spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb b/spec/lib/banzai/filter/task_list_filter_spec.rb index 1b1714ef882..f2e3a44478d 100644 --- a/spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb +++ b/spec/lib/banzai/filter/task_list_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::TaskListFilter, lib: true do +describe Banzai::Filter::TaskListFilter, lib: true do include FilterSpecHelper it 'does not apply `task-list` class to non-task lists' do diff --git a/spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb b/spec/lib/banzai/filter/upload_link_filter_spec.rb index 38a007b5bee..3b073a90a95 100644 --- a/spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb +++ b/spec/lib/banzai/filter/upload_link_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Markdown::UploadLinkFilter, lib: true do +describe Banzai::Filter::UploadLinkFilter, lib: true do def filter(doc, contexts = {}) contexts.reverse_merge!({ project: project diff --git a/spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb index 277037cf68a..3534bf97784 100644 --- a/spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::UserReferenceFilter, lib: true do +describe Banzai::Filter::UserReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:empty_project, :public) } diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb index 3a860899e18..6beb21c6d2b 100644 --- a/spec/lib/gitlab/asciidoc_spec.rb +++ b/spec/lib/gitlab/asciidoc_spec.rb @@ -50,7 +50,7 @@ module Gitlab filtered_html = '<b>ASCII</b>' allow(Asciidoctor).to receive(:convert).and_return(html) - expect(Gitlab::Markdown).to receive(:render) + expect(Banzai).to receive(:render) .with(html, context.merge(pipeline: :asciidoc)) .and_return(filtered_html) diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb index 66dc5d4911d..7d963795e17 100644 --- a/spec/lib/gitlab/reference_extractor_spec.rb +++ b/spec/lib/gitlab/reference_extractor_spec.rb @@ -97,6 +97,16 @@ describe Gitlab::ReferenceExtractor, lib: true do expect(extracted.first.commit_to).to eq commit end + context 'with an external issue tracker' do + let(:project) { create(:jira_project) } + subject { described_class.new(project, project.creator) } + + it 'returns JIRA issues for a JIRA-integrated project' do + subject.analyze('JIRA-123 and FOOBAR-4567') + expect(subject.issues).to eq [JiraIssue.new('JIRA-123', project), JiraIssue.new('FOOBAR-4567', project)] + end + end + context 'with a project with an underscore' do let(:other_project) { create(:project, path: 'test_project') } let(:issue) { create(:issue, project: other_project) } diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 96b6f1dbca6..1c22e3cb7c4 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -189,6 +189,12 @@ describe Ci::Build, models: true do it { is_expected.to eq(98.29) } end + + context 'using a regex capture' do + subject { build.extract_coverage('TOTAL 9926 3489 65%', 'TOTAL\s+\d+\s+\d+\s+(\d{1,3}\%)') } + + it { is_expected.to eq(65) } + end end describe :variables do @@ -390,4 +396,68 @@ describe Ci::Build, models: true do it { is_expected.to include('gitlab-ci-token') } it { is_expected.to include(project.web_url[7..-1]) } end + + def create_mr(build, commit, factory: :merge_request, created_at: Time.now) + FactoryGirl.create(factory, + source_project_id: commit.gl_project_id, + target_project_id: commit.gl_project_id, + source_branch: build.ref, + created_at: created_at) + end + + describe :merge_request do + context 'when a MR has a reference to the commit' do + before do + @merge_request = create_mr(build, commit, factory: :merge_request) + + commits = [double(id: commit.sha)] + allow(@merge_request).to receive(:commits).and_return(commits) + allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request]) + end + + it 'returns the single associated MR' do + expect(build.merge_request.id).to eq(@merge_request.id) + end + end + + context 'when there is not a MR referencing the commit' do + it 'returns nil' do + expect(build.merge_request).to be_nil + end + end + + context 'when more than one MR have a reference to the commit' do + before do + @merge_request = create_mr(build, commit, factory: :merge_request) + @merge_request.close! + @merge_request2 = create_mr(build, commit, factory: :merge_request) + + commits = [double(id: commit.sha)] + allow(@merge_request).to receive(:commits).and_return(commits) + allow(@merge_request2).to receive(:commits).and_return(commits) + allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request, @merge_request2]) + end + + it 'returns the first MR' do + expect(build.merge_request.id).to eq(@merge_request.id) + end + end + + context 'when a Build is created after the MR' do + before do + @merge_request = create_mr(build, commit, factory: :merge_request_with_diffs) + commit2 = FactoryGirl.create :ci_commit, project: project + @build2 = FactoryGirl.create :ci_build, commit: commit2 + + commits = [double(id: commit.sha), double(id: commit2.sha)] + allow(@merge_request).to receive(:commits).and_return(commits) + allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request]) + end + + it 'returns the current MR' do + expect(@build2.merge_request.id).to eq(@merge_request.id) + end + end + + end end diff --git a/spec/models/ci/commit_spec.rb b/spec/models/ci/commit_spec.rb index ac61c8fb525..b193e16e7f8 100644 --- a/spec/models/ci/commit_spec.rb +++ b/spec/models/ci/commit_spec.rb @@ -37,14 +37,14 @@ describe Ci::Commit, models: true do it 'returns ordered list of commits' do commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project - commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project + commit2 = FactoryGirl.create :ci_commit, committed_at: 2.hours.ago, project: project expect(project.ci_commits.ordered).to eq([commit2, commit1]) end it 'returns commits ordered by committed_at and id, with nulls last' do commit1 = FactoryGirl.create :ci_commit, committed_at: 1.hour.ago, project: project commit2 = FactoryGirl.create :ci_commit, committed_at: nil, project: project - commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hour.ago, project: project + commit3 = FactoryGirl.create :ci_commit, committed_at: 2.hours.ago, project: project commit4 = FactoryGirl.create :ci_commit, committed_at: nil, project: project expect(project.ci_commits.ordered).to eq([commit2, commit4, commit3, commit1]) end diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb index 6179882e935..6653621a83e 100644 --- a/spec/models/concerns/mentionable_spec.rb +++ b/spec/models/concerns/mentionable_spec.rb @@ -1,5 +1,18 @@ require 'spec_helper' +describe Mentionable do + include Mentionable + + describe :references do + let(:project) { create(:project) } + + it 'excludes JIRA references' do + allow(project).to receive_messages(jira_tracker?: true) + expect(referenced_mentionables(project, 'JIRA-123')).to be_empty + end + end +end + describe Issue, "Mentionable" do describe '#mentioned_users' do let!(:user) { create(:user, username: 'stranger') } diff --git a/spec/models/concerns/token_authenticatable_spec.rb b/spec/models/concerns/token_authenticatable_spec.rb index a9b0b64e5de..30c0a04b840 100644 --- a/spec/models/concerns/token_authenticatable_spec.rb +++ b/spec/models/concerns/token_authenticatable_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' shared_examples 'TokenAuthenticatable' do describe 'dynamically defined methods' do - it { expect(described_class).to be_private_method_defined(:generate_token_for) } + it { expect(described_class).to be_private_method_defined(:generate_token) } + it { expect(described_class).to be_private_method_defined(:write_new_token) } it { expect(described_class).to respond_to("find_by_#{token_field}") } it { is_expected.to respond_to("ensure_#{token_field}") } it { is_expected.to respond_to("reset_#{token_field}!") } @@ -24,11 +25,11 @@ describe ApplicationSetting, 'TokenAuthenticatable' do it_behaves_like 'TokenAuthenticatable' describe 'generating new token' do - subject { described_class.new } - let(:token) { subject.send(token_field) } - context 'token is not generated yet' do - it { expect(token).to be nil } + describe 'token field accessor' do + subject { described_class.new.send(token_field) } + it { is_expected.to_not be_blank } + end describe 'ensured token' do subject { described_class.new.send("ensure_#{token_field}") } @@ -36,11 +37,21 @@ describe ApplicationSetting, 'TokenAuthenticatable' do it { is_expected.to be_a String } it { is_expected.to_not be_blank } end + + describe 'ensured! token' do + subject { described_class.new.send("ensure_#{token_field}!") } + + it 'should persist new token' do + expect(subject).to eq described_class.current[token_field] + end + end end context 'token is generated' do before { subject.send("reset_#{token_field}!") } - it { expect(token).to be_a String } + it 'persists a new token 'do + expect(subject.send(:read_attribute, token_field)).to be_a String + end end end diff --git a/spec/models/jira_issue_spec.rb b/spec/models/jira_issue_spec.rb new file mode 100644 index 00000000000..1634265b439 --- /dev/null +++ b/spec/models/jira_issue_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe JiraIssue do + let(:project) { create(:project) } + subject { JiraIssue.new('JIRA-123', project) } + + describe 'id' do + subject { super().id } + it { is_expected.to eq('JIRA-123') } + end + + describe 'iid' do + subject { super().iid } + it { is_expected.to eq('JIRA-123') } + end + + describe 'to_s' do + subject { super().to_s } + it { is_expected.to eq('JIRA-123') } + end + + describe :== do + specify { expect(subject).to eq(JiraIssue.new('JIRA-123', project)) } + specify { expect(subject).not_to eq(JiraIssue.new('JIRA-124', project)) } + + it 'only compares with JiraIssues' do + expect(subject).not_to eq('JIRA-123') + end + end +end diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index d7fe01976d8..c962b83644a 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -81,7 +81,7 @@ describe Key, models: true do it 'rejects the multiple line key' do key = build(:key) - key.key.gsub!(' ', "\n") + key.key.tr!(' ', "\n") expect(key).not_to be_valid end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 1aeba9b2b3b..e0653a8327d 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -164,6 +164,17 @@ describe MergeRequest, models: true do expect(subject.closes_issues).to include(issue2) end + + context 'for a project with JIRA integration' do + let(:issue0) { JiraIssue.new('JIRA-123', subject.project) } + let(:issue1) { JiraIssue.new('FOOBAR-4567', subject.project) } + + it 'returns sorted JiraIssues' do + allow(subject.project).to receive_messages(default_branch: subject.target_branch) + + expect(subject.closes_issues).to eq([issue0, issue1]) + end + end end describe "#work_in_progress?" do diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 216c7dabae0..b7006fa5e68 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -164,8 +164,8 @@ describe Note, models: true do let(:issue) { create :issue } it "converts aliases to actual name" do - note = create :note, note: ":thumbsup:", noteable: issue - expect(note.reload.note).to eq("+1") + note = create :note, note: ":+1:", noteable: issue + expect(note.reload.note).to eq("thumbsup") end end end diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index a5662b08bda..91dd92b7c67 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -57,23 +57,21 @@ describe HipchatService, models: true do it 'should use v1 if version is provided' do allow(hipchat).to receive(:api_version).and_return('v1') - expect(HipChat::Client).to receive(:new). - with(token, - api_version: 'v1', - server_url: server_url). - and_return( - double(:hipchat_service).as_null_object) + expect(HipChat::Client).to receive(:new).with( + token, + api_version: 'v1', + server_url: server_url + ).and_return(double(:hipchat_service).as_null_object) hipchat.execute(push_sample_data) end it 'should use v2 as the version when nothing is provided' do allow(hipchat).to receive(:api_version).and_return('') - expect(HipChat::Client).to receive(:new). - with(token, - api_version: 'v2', - server_url: server_url). - and_return( - double(:hipchat_service).as_null_object) + expect(HipChat::Client).to receive(:new).with( + token, + api_version: 'v2', + server_url: server_url + ).and_return(double(:hipchat_service).as_null_object) hipchat.execute(push_sample_data) end diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 7d91ebe9ce6..2f8193170ae 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -26,6 +26,113 @@ describe JiraService, models: true do it { is_expected.to have_one :service_hook } end + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:merge_request) { create(:merge_request) } + + before do + @jira_service = JiraService.new + allow(@jira_service).to receive_messages( + project_id: project.id, + project: project, + service_hook: true, + project_url: 'http://jira.example.com', + username: 'gitlab_jira_username', + password: 'gitlab_jira_password' + ) + @jira_service.save # will build API URL, as api_url was not specified above + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + # https://github.com/bblimke/webmock#request-with-basic-authentication + @api_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions' + @comment_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment' + + WebMock.stub_request(:post, @api_url) + WebMock.stub_request(:post, @comment_url) + end + + it "should call JIRA API" do + @jira_service.execute(merge_request, JiraIssue.new("JIRA-123", project)) + expect(WebMock).to have_requested(:post, @comment_url).with( + body: /Issue solved with/ + ).once + end + + it "calls the api with jira_issue_transition_id" do + @jira_service.jira_issue_transition_id = 'this-is-a-custom-id' + @jira_service.execute(merge_request, JiraIssue.new("JIRA-123", project)) + expect(WebMock).to have_requested(:post, @api_url).with( + body: /this-is-a-custom-id/ + ).once + end + end + + describe "Stored password invalidation" do + let(:project) { create(:project) } + + context "when a password was previously set" do + before do + @jira_service = JiraService.create( + project: create(:project), + properties: { + api_url: 'http://jira.example.com/rest/api/2', + username: 'mic', + password: "password" + } + ) + end + + it "reset password if url changed" do + @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2' + @jira_service.save + expect(@jira_service.password).to be_nil + end + + it "does not reset password if username changed" do + @jira_service.username = "some_name" + @jira_service.save + expect(@jira_service.password).to eq("password") + end + + it "does not reset password if new url is set together with password, even if it's the same password" do + @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2' + @jira_service.password = 'password' + @jira_service.save + expect(@jira_service.password).to eq("password") + expect(@jira_service.api_url).to eq("http://jira_edited.example.com/rest/api/2") + end + + it "should reset password if url changed, even if setter called multiple times" do + @jira_service.api_url = 'http://jira1.example.com/rest/api/2' + @jira_service.api_url = 'http://jira1.example.com/rest/api/2' + @jira_service.save + expect(@jira_service.password).to be_nil + end + end + + context "when no password was previously set" do + before do + @jira_service = JiraService.create( + project: create(:project), + properties: { + api_url: 'http://jira.example.com/rest/api/2', + username: 'mic' + } + ) + end + + it "saves password if new url is set together with password" do + @jira_service.api_url = 'http://jira_edited.example.com/rest/api/2' + @jira_service.password = 'password' + @jira_service.save + expect(@jira_service.password).to eq("password") + expect(@jira_service.api_url).to eq("http://jira_edited.example.com/rest/api/2") + end + + end + end + + describe "Validations" do context "active" do before do @@ -78,11 +185,12 @@ describe JiraService, models: true do context 'when gitlab.yml was initialized' do before do - settings = { "jira" => { - "title" => "Jira", - "project_url" => "http://jira.sample/projects/project_a", - "issues_url" => "http://jira.sample/issues/:id", - "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" + settings = { + "jira" => { + "title" => "Jira", + "project_url" => "http://jira.sample/projects/project_a", + "issues_url" => "http://jira.sample/issues/:id", + "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" } } allow(Gitlab.config).to receive(:issues_tracker).and_return(settings) diff --git a/spec/models/project_services/slack_service/note_message_spec.rb b/spec/models/project_services/slack_service/note_message_spec.rb index ebf8837570e..06006b9a4f5 100644 --- a/spec/models/project_services/slack_service/note_message_spec.rb +++ b/spec/models/project_services/slack_service/note_message_spec.rb @@ -89,10 +89,10 @@ describe SlackService::NoteMessage, models: true do it 'returns a message regarding notes on an issue' do message = SlackService::NoteMessage.new(@args) expect(message.pretext).to eq( - "Test User commented on " \ - "<url|issue #20> in <somewhere.com|project_name>: " \ - "*issue title*") - expected_attachments = [ + "Test User commented on " \ + "<url|issue #20> in <somewhere.com|project_name>: " \ + "*issue title*") + expected_attachments = [ { text: "comment on an issue", color: color, diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 87582e07494..c4d3813e9c9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -172,13 +172,17 @@ describe Project, models: true do describe '#get_issue' do let(:project) { create(:empty_project) } - let(:issue) { create(:issue, project: project) } + let!(:issue) { create(:issue, project: project) } context 'with default issues tracker' do it 'returns an issue' do expect(project.get_issue(issue.iid)).to eq issue end + it 'returns count of open issues' do + expect(project.open_issues_count).to eq(1) + end + it 'returns nil when no issue found' do expect(project.get_issue(999)).to be_nil end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index daa9d1087bf..2f184bbaf92 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -26,6 +26,7 @@ # bio :string(255) # failed_attempts :integer default(0) # locked_at :datetime +# unlock_token :string(255) # username :string(255) # can_create_group :boolean default(TRUE), not null # can_create_team :boolean default(TRUE), not null @@ -462,8 +463,8 @@ describe User, models: true do expect(User.search(user1.username.downcase).to_a).to eq([user1]) expect(User.search(user2.username.upcase).to_a).to eq([user2]) expect(User.search(user2.username.downcase).to_a).to eq([user2]) - expect(User.search(user1.username.downcase).to_a.count).to eq(2) - expect(User.search(user2.username.downcase).to_a.count).to eq(1) + expect(User.search(user1.username.downcase).to_a.size).to eq(2) + expect(User.search(user2.username.downcase).to_a.size).to eq(1) end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index a91fa735321..e194eb93cf4 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -6,7 +6,7 @@ describe API::API, api: true do let(:user) { create(:user) } let!(:project) {create(:project, creator_id: user.id, namespace: user.namespace) } let!(:merge_request) { create(:merge_request, :simple, author: user, assignee: user, source_project: project, target_project: project, title: "Test", created_at: base_time) } - let!(:merge_request_closed) { create(:merge_request, state: "closed", author: user, assignee: user, source_project: project, target_project: project, title: "Closed test", created_at: base_time + 1.seconds) } + let!(:merge_request_closed) { create(:merge_request, state: "closed", author: user, assignee: user, source_project: project, target_project: project, title: "Closed test", created_at: base_time + 1.second) } let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds) } let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") } let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") } diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index e784b7d1f2d..7f0f9454b10 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -65,6 +65,22 @@ describe API::API, api: true do expect(json_response.first.keys).to include('tag_list') end + it 'should include open_issues_count' do + get api('/projects', user) + expect(response.status).to eq 200 + expect(json_response).to be_an Array + expect(json_response.first.keys).to include('open_issues_count') + end + + it 'should not include open_issues_count' do + project.update_attributes( { issues_enabled: false } ) + + get api('/projects', user) + expect(response.status).to eq 200 + expect(json_response).to be_an Array + expect(json_response.first.keys).not_to include('open_issues_count') + end + context 'and using search' do it 'should return searched project' do get api('/projects', user), { search: project.name } @@ -115,6 +131,7 @@ describe API::API, api: true do expect(json_response).to satisfy do |response| response.one? do |entry| + entry.has_key?('permissions') && entry['name'] == project.name && entry['owner']['username'] == user.username end @@ -123,6 +140,25 @@ describe API::API, api: true do end end + describe 'GET /projects/starred' do + before do + admin.starred_projects << project + admin.save! + end + + it 'should return the starred projects' do + get api('/projects/all', admin) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + + expect(json_response).to satisfy do |response| + response.one? do |entry| + entry['name'] == project.name + end + end + end + end + describe 'POST /projects' do context 'maximum number of projects reached' do it 'should not create new project and respond with 403' do @@ -347,6 +383,18 @@ describe API::API, api: true do end describe 'permissions' do + context 'all projects' do + it 'Contains permission information' do + project.team << [user, :master] + get api("/projects", user) + + expect(response.status).to eq(200) + expect(json_response.first['permissions']['project_access']['access_level']). + to eq(Gitlab::Access::MASTER) + expect(json_response.first['permissions']['group_access']).to be_nil + end + end + context 'personal project' do it 'Sets project access and returns 200' do project.team << [user, :master] @@ -455,7 +503,7 @@ describe API::API, api: true do end end - describe 'PUT /projects/:id/snippets/:shippet_id' do + describe 'PUT /projects/:id/snippets/:snippet_id' do it 'should update an existing project snippet' do put api("/projects/#{project.id}/snippets/#{snippet.id}", user), code: 'updated code' diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index b180d2fec77..fed9ae1949b 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -29,7 +29,7 @@ describe API::API, api: true do if required_attributes.empty? expected_code = 200 else - attrs.delete(required_attributes.shuffle.first) + attrs.delete(required_attributes.sample) expected_code = 400 end diff --git a/spec/requests/ci/api/runners_spec.rb b/spec/requests/ci/api/runners_spec.rb index 567da013e6f..5942aa7a1b5 100644 --- a/spec/requests/ci/api/runners_spec.rb +++ b/spec/requests/ci/api/runners_spec.rb @@ -8,7 +8,6 @@ describe Ci::API::API do before do stub_gitlab_calls - stub_application_setting(ensure_runners_registration_token: registration_token) stub_application_setting(runners_registration_token: registration_token) end diff --git a/spec/services/create_commit_builds_service_spec.rb b/spec/services/create_commit_builds_service_spec.rb index 798c480b81a..ea5dcfa068a 100644 --- a/spec/services/create_commit_builds_service_spec.rb +++ b/spec/services/create_commit_builds_service_spec.rb @@ -17,7 +17,7 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: [{ message: "Message" }] - ) + ) end it { expect(commit).to be_kind_of(Ci::Commit) } @@ -34,7 +34,7 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: [{ message: "Message" }] - ) + ) expect(result).to be_persisted end @@ -47,26 +47,24 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: [{ message: "Message" }] - ) + ) expect(result).to be_persisted end end - it 'skips commits without .gitlab-ci.yml' do + it 'skips creating ci_commit for refs without .gitlab-ci.yml' do stub_ci_commit_yaml_file(nil) result = service.execute(project, user, ref: 'refs/heads/0_1', before: '00000000', after: '31das312', commits: [{ message: 'Message' }] - ) - expect(result).to be_persisted - expect(result.builds.any?).to be_falsey - expect(result.status).to eq('skipped') - expect(result.yaml_errors).to be_nil + ) + expect(result).to be_falsey + expect(Ci::Commit.count).to eq(0) end - it 'skips commits if yaml is invalid' do + it 'fails commits if yaml is invalid' do message = 'message' allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message } stub_ci_commit_yaml_file('invalid: file: file') @@ -76,7 +74,8 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.builds.any?).to be false expect(commit.status).to eq('failed') expect(commit.yaml_errors).to_not be_nil @@ -96,7 +95,8 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.builds.any?).to be false expect(commit.status).to eq("skipped") end @@ -110,8 +110,9 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.builds.first.name).to eq("staging") end @@ -123,7 +124,8 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.builds.any?).to be false expect(commit.status).to eq("skipped") expect(commit.yaml_errors).to be_nil @@ -139,7 +141,8 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.builds.count(:all)).to eq(2) commit = service.execute(project, user, @@ -147,7 +150,8 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.builds.count(:all)).to eq(2) end @@ -161,8 +165,9 @@ describe CreateCommitBuildsService, services: true do before: '00000000', after: '31das312', commits: commits - ) + ) + expect(commit).to be_persisted expect(commit.status).to eq("failed") expect(commit.builds.any?).to be false end diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb index a04c242cf0e..c1080ef190a 100644 --- a/spec/services/git_push_service_spec.rb +++ b/spec/services/git_push_service_spec.rb @@ -265,6 +265,75 @@ describe GitPushService, services: true do expect(Issue.find(issue.id)).to be_opened end end + + # EE-only tests + context "for jira issue tracker" do + include JiraServiceHelper + + let(:jira_tracker) { project.create_jira_service if project.jira_service.nil? } + + before do + jira_service_settings + + WebMock.stub_request(:post, jira_api_transition_url) + WebMock.stub_request(:post, jira_api_comment_url) + WebMock.stub_request(:get, jira_api_comment_url).to_return(body: jira_issue_comments) + WebMock.stub_request(:get, jira_api_test_url) + + allow(closing_commit).to receive_messages({ + issue_closing_regex: Regexp.new(Gitlab.config.gitlab.issue_closing_pattern), + safe_message: message, + author_name: commit_author.name, + author_email: commit_author.email + }) + + allow(project.repository).to receive_messages(commits_between: [closing_commit]) + end + + after do + jira_tracker.destroy! + end + + context "mentioning an issue" do + let(:message) { "this is some work.\n\nrelated to JIRA-1" } + + it "should initiate one api call to jira server to mention the issue" do + service.execute(project, user, @oldrev, @newrev, @ref) + + expect(WebMock).to have_requested(:post, jira_api_comment_url).with( + body: /mentioned this issue in/ + ).once + end + end + + context "closing an issue" do + let(:message) { "this is some work.\n\ncloses JIRA-1" } + + it "should initiate one api call to jira server to close the issue" do + transition_body = { + transition: { + id: '2' + } + }.to_json + + service.execute(project, user, @oldrev, @newrev, @ref) + expect(WebMock).to have_requested(:post, jira_api_transition_url).with( + body: transition_body + ).once + end + + it "should initiate one api call to jira server to comment on the issue" do + comment_body = { + body: "Issue solved with [#{closing_commit.id}|http://localhost/#{project.path_with_namespace}/commit/#{closing_commit.id}]." + }.to_json + + service.execute(project, user, @oldrev, @newrev, @ref) + expect(WebMock).to have_requested(:post, jira_api_comment_url).with( + body: comment_body + ).once + end + end + end end describe "empty project" do diff --git a/spec/services/git_tag_push_service_spec.rb b/spec/services/git_tag_push_service_spec.rb index e2d15f1a83d..b982274c529 100644 --- a/spec/services/git_tag_push_service_spec.rb +++ b/spec/services/git_tag_push_service_spec.rb @@ -58,14 +58,14 @@ describe GitTagPushService, services: true do it { is_expected.to include(timestamp: @commit.date.xmlschema) } it do is_expected.to include( - url: [ - Gitlab.config.gitlab.url, - project.namespace.to_param, - project.to_param, - 'commit', - @commit.id - ].join('/') - ) + url: [ + Gitlab.config.gitlab.url, + project.namespace.to_param, + project.to_param, + 'commit', + @commit.id + ].join('/') + ) end context "with a author" do diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 0a4f9b230e8..c9f828ae2f7 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -425,4 +425,65 @@ describe SystemNoteService, services: true do end end end + + include JiraServiceHelper + + describe 'JIRA integration' do + let(:project) { create(:project) } + let(:author) { create(:user) } + let(:issue) { create(:issue, project: project) } + let(:mergereq) { create(:merge_request, :simple, target_project: project, source_project: project) } + let(:jira_issue) { JiraIssue.new("JIRA-1", project)} + let(:jira_tracker) { project.create_jira_service if project.jira_service.nil? } + let(:commit) { project.commit } + + context 'in JIRA issue tracker' do + before do + jira_service_settings + WebMock.stub_request(:post, jira_api_comment_url) + end + + after do + jira_tracker.destroy! + end + + describe "new reference" do + before do + WebMock.stub_request(:get, jira_api_comment_url).to_return(body: jira_issue_comments) + end + + subject { described_class.cross_reference(jira_issue, commit, author) } + + it { is_expected.to eq(jira_status_message) } + end + + describe "existing reference" do + before do + message = "[#{author.name}|http://localhost/u/#{author.username}] mentioned this issue in [a commit of #{project.path_with_namespace}|http://localhost/#{project.path_with_namespace}/commit/#{commit.id}]." + WebMock.stub_request(:get, jira_api_comment_url).to_return(body: "{\"comments\":[{\"body\":\"#{message}\"}]}") + end + + subject { described_class.cross_reference(jira_issue, commit, author) } + it { is_expected.not_to eq(jira_status_message) } + end + end + + context 'issue from an issue' do + context 'in JIRA issue tracker' do + before do + jira_service_settings + WebMock.stub_request(:post, jira_api_comment_url) + WebMock.stub_request(:get, jira_api_comment_url).to_return(body: jira_issue_comments) + end + + after do + jira_tracker.destroy! + end + + subject { described_class.cross_reference(jira_issue, issue, author) } + + it { is_expected.to eq(jira_status_message) } + end + end + end end diff --git a/spec/services/update_snippet_service_spec.rb b/spec/services/update_snippet_service_spec.rb index 124bb76e678..48d114896d0 100644 --- a/spec/services/update_snippet_service_spec.rb +++ b/spec/services/update_snippet_service_spec.rb @@ -42,7 +42,7 @@ describe UpdateSnippetService, services: true do CreateSnippetService.new(project, user, opts).execute end - def update_snippet(project = nil, user, snippet, opts) + def update_snippet(project, user, snippet, opts) UpdateSnippetService.new(project, user, snippet, opts).execute end end diff --git a/spec/support/filter_spec_helper.rb b/spec/support/filter_spec_helper.rb index 91e3bee13c1..d6e03cbef3d 100644 --- a/spec/support/filter_spec_helper.rb +++ b/spec/support/filter_spec_helper.rb @@ -1,4 +1,4 @@ -# Helper methods for Gitlab::Markdown filter specs +# Helper methods for Banzai filter specs # # Must be included into specs manually module FilterSpecHelper @@ -10,49 +10,49 @@ module FilterSpecHelper # if none is provided. # # html - HTML String to pass to the filter's `call` method. - # contexts - Hash context for the filter. (default: {project: project}) + # context - Hash context for the filter. (default: {project: project}) # # Returns a Nokogiri::XML::DocumentFragment - def filter(html, contexts = {}) + def filter(html, context = {}) if defined?(project) - contexts.reverse_merge!(project: project) + context.reverse_merge!(project: project) end - described_class.call(html, contexts) + described_class.call(html, context) end # Run text through HTML::Pipeline with the current filter and return the # result Hash # # body - String text to run through the pipeline - # contexts - Hash context for the filter. (default: {project: project}) + # context - Hash context for the filter. (default: {project: project}) # # Returns the Hash - def pipeline_result(body, contexts = {}) - contexts.reverse_merge!(project: project) if defined?(project) + def pipeline_result(body, context = {}) + context.reverse_merge!(project: project) if defined?(project) - pipeline = HTML::Pipeline.new([described_class], contexts) + pipeline = HTML::Pipeline.new([described_class], context) pipeline.call(body) end - def reference_pipeline(contexts = {}) - contexts.reverse_merge!(project: project) if defined?(project) + def reference_pipeline(context = {}) + context.reverse_merge!(project: project) if defined?(project) filters = [ - Gitlab::Markdown::AutolinkFilter, + Banzai::Filter::AutolinkFilter, described_class, - Gitlab::Markdown::ReferenceGathererFilter + Banzai::Filter::ReferenceGathererFilter ] - HTML::Pipeline.new(filters, contexts) + HTML::Pipeline.new(filters, context) end - def reference_pipeline_result(body, contexts = {}) - reference_pipeline(contexts).call(body) + def reference_pipeline_result(body, context = {}) + reference_pipeline(context).call(body) end - def reference_filter(html, contexts = {}) - reference_pipeline(contexts).to_document(html) + def reference_filter(html, context = {}) + reference_pipeline(context).to_document(html) end # Modify a String reference to make it invalid diff --git a/spec/support/jira_service_helper.rb b/spec/support/jira_service_helper.rb new file mode 100644 index 00000000000..a3f496359b1 --- /dev/null +++ b/spec/support/jira_service_helper.rb @@ -0,0 +1,67 @@ +module JiraServiceHelper + + def jira_service_settings + properties = { + "title"=>"JIRA tracker", + "project_url"=>"http://jira.example/issues/?jql=project=A", + "issues_url"=>"http://jira.example/browse/JIRA-1", + "new_issue_url"=>"http://jira.example/secure/CreateIssue.jspa", + "api_url"=>"http://jira.example/rest/api/2" + } + + jira_tracker.update_attributes(properties: properties, active: true) + end + + def jira_status_message + "JiraService SUCCESS 200: Successfully posted to #{jira_api_comment_url}." + end + + def jira_issue_comments + "{\"startAt\":0,\"maxResults\":11,\"total\":11, + \"comments\":[{\"self\":\"http://0.0.0.0:4567/rest/api/2/issue/10002/comment/10609\", + \"id\":\"10609\",\"author\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\", + \"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\", + \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\", + \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\", + \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\", + \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"}, + \"displayName\":\"GitLab\",\"active\":true}, + \"body\":\"[Administrator|http://localhost:3000/u/root] mentioned JIRA-1 in Merge request of [gitlab-org/gitlab-test|http://localhost:3000/gitlab-org/gitlab-test/merge_requests/2].\", + \"updateAuthor\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\",\"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\", + \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\", + \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\", + \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\", + \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},\"displayName\":\"GitLab\",\"active\":true}, + \"created\":\"2015-02-12T22:47:07.826+0100\", + \"updated\":\"2015-02-12T22:47:07.826+0100\"}, + {\"self\":\"http://0.0.0.0:4567/rest/api/2/issue/10002/comment/10700\", + \"id\":\"10700\",\"author\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\", + \"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\", + \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\", + \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\", + \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\", + \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},\"displayName\":\"GitLab\",\"active\":true}, + \"body\":\"[Administrator|http://localhost:3000/u/root] mentioned this issue in [a commit of h5bp/html5-boilerplate|http://localhost:3000/h5bp/html5-boilerplate/commit/2439f77897122fbeee3bfd9bb692d3608848433e].\", + \"updateAuthor\":{\"self\":\"http://0.0.0.0:4567/rest/api/2/user?username=gitlab\",\"name\":\"gitlab\",\"emailAddress\":\"gitlab@example.com\", + \"avatarUrls\":{\"16x16\":\"http://0.0.0.0:4567/secure/useravatar?size=xsmall&avatarId=10122\", + \"24x24\":\"http://0.0.0.0:4567/secure/useravatar?size=small&avatarId=10122\", + \"32x32\":\"http://0.0.0.0:4567/secure/useravatar?size=medium&avatarId=10122\", + \"48x48\":\"http://0.0.0.0:4567/secure/useravatar?avatarId=10122\"},\"displayName\":\"GitLab\",\"active\":true}, + \"created\":\"2015-04-01T03:45:55.667+0200\", + \"updated\":\"2015-04-01T03:45:55.667+0200\" + } + ]}" + end + + def jira_api_comment_url + 'http://jira.example/rest/api/2/issue/JIRA-1/comment' + end + + def jira_api_transition_url + 'http://jira.example/rest/api/2/issue/JIRA-1/transitions' + end + + def jira_api_test_url + 'http://jira.example/rest/api/2/myself' + end +end diff --git a/spec/support/repo_helpers.rb b/spec/support/repo_helpers.rb index aadf791bf3f..aa8258d6dad 100644 --- a/spec/support/repo_helpers.rb +++ b/spec/support/repo_helpers.rb @@ -45,12 +45,12 @@ eos def another_sample_commit OpenStruct.new( - id: "e56497bb5f03a90a51293fc6d516788730953899", - parent_id: '4cd80ccab63c82b4bad16faa5193fbd2aa06df40', - author_full_name: "Sytse Sijbrandij", - author_email: "sytse@gitlab.com", - files_changed_count: 1, - message: <<eos + id: "e56497bb5f03a90a51293fc6d516788730953899", + parent_id: '4cd80ccab63c82b4bad16faa5193fbd2aa06df40', + author_full_name: "Sytse Sijbrandij", + author_email: "sytse@gitlab.com", + files_changed_count: 1, + message: <<eos Add directory structure for tree_helper spec This directory structure is needed for a testing the method flatten_tree(tree) in the TreeHelper module diff --git a/spec/workers/repository_fork_worker_spec.rb b/spec/workers/repository_fork_worker_spec.rb index 245f066df1f..dae31992620 100644 --- a/spec/workers/repository_fork_worker_spec.rb +++ b/spec/workers/repository_fork_worker_spec.rb @@ -9,20 +9,22 @@ describe RepositoryForkWorker do describe "#perform" do it "creates a new repository from a fork" do expect_any_instance_of(Gitlab::Shell).to receive(:fork_repository).with( - project.path_with_namespace, - fork_project.namespace.path). - and_return(true) + project.path_with_namespace, + fork_project.namespace.path + ).and_return(true) - subject.perform(project.id, - project.path_with_namespace, - fork_project.namespace.path) + subject.perform( + project.id, + project.path_with_namespace, + fork_project.namespace.path) end it "handles bad fork" do expect_any_instance_of(Gitlab::Shell).to receive(:fork_repository).and_return(false) - subject.perform(project.id, - project.path_with_namespace, - fork_project.namespace.path) + subject.perform( + project.id, + project.path_with_namespace, + fork_project.namespace.path) end end end diff --git a/spec/workers/stuck_ci_builds_worker_spec.rb b/spec/workers/stuck_ci_builds_worker_spec.rb index f9d87d97014..665ec20f224 100644 --- a/spec/workers/stuck_ci_builds_worker_spec.rb +++ b/spec/workers/stuck_ci_builds_worker_spec.rb @@ -15,7 +15,7 @@ describe StuckCiBuildsWorker do end it 'gets dropped if it was updated over 2 days ago' do - build.update!(updated_at: 2.day.ago) + build.update!(updated_at: 2.days.ago) StuckCiBuildsWorker.new.perform is_expected.to eq('failed') end @@ -35,7 +35,7 @@ describe StuckCiBuildsWorker do end it "is still #{status}" do - build.update!(updated_at: 2.day.ago) + build.update!(updated_at: 2.days.ago) StuckCiBuildsWorker.new.perform is_expected.to eq(status) end |