Commit 5e452d37 authored by Rémy Coutable's avatar Rémy Coutable

Improve & adds specs for Issue/MR references

- Improve specs for private Issue/MR referenced in public Issue
- Add specs for private Issue/MR referenced in public MR
parent 5efbfa14
No related merge requests found
...@@ -2,30 +2,32 @@ ...@@ -2,30 +2,32 @@
Feature: Project Issues References Feature: Project Issues References
Background: Background:
Given I sign in as "John Doe" Given I sign in as "John Doe"
And public project "Community"
And "John Doe" owns public project "Community" And "John Doe" owns public project "Community"
And project "Community" has "Public Issue 01" open issue And project "Community" has "Community issue" open issue
And I logout And I logout
And I sign in as "Mary Jane" And I sign in as "Mary Jane"
And "Mary Jane" owns private project "Private Library" And private project "Enterprise"
And project "Private Library" has "Fix NS-01" open merge request And "Mary Jane" owns private project "Enterprise"
And project "Private Library" has "Private Issue 01" open issue And project "Enterprise" has "Enterprise issue" open issue
And I visit merge request page "Fix NS-01" And project "Enterprise" has "Enterprise fix" open merge request
And I leave a comment referencing issue "Public Issue 01" from "Fix NS-01" merge request And I visit issue page "Enterprise issue"
And I visit issue page "Private Issue 01" And I leave a comment referencing issue "Community issue"
And I leave a comment referencing issue "Public Issue 01" from "Private Issue 01" issue And I visit merge request page "Enterprise fix"
And I leave a comment referencing issue "Community issue"
And I logout And I logout
@javascript @javascript
Scenario: Viewing the public issue as a "John Doe" Scenario: Viewing the public issue as a "John Doe"
Given I sign in as "John Doe" Given I sign in as "John Doe"
When I visit issue page "Public Issue 01" When I visit issue page "Community issue"
Then I should not see any related merge requests Then I should not see any related merge requests
And I should see no notes at all And I should see no notes at all
@javascript @javascript
Scenario: Viewing the public issue as "Mary Jane" Scenario: Viewing the public issue as "Mary Jane"
Given I sign in as "Mary Jane" Given I sign in as "Mary Jane"
When I visit issue page "Public Issue 01" When I visit issue page "Community issue"
Then I should see the "Fix NS-01" related merge request Then I should see the "Enterprise fix" related merge request
And I should see a note linking to "Fix NS-01" merge request And I should see a note linking to "Enterprise fix" merge request
And I should see a note linking to "Private Issue 01" issue And I should see a note linking to "Enterprise issue" issue
@project_merge_requests
Feature: Project Merge Requests References
Background:
Given I sign in as "John Doe"
And public project "Community"
And "John Doe" owns public project "Community"
And project "Community" has "Community fix" open merge request
And I logout
And I sign in as "Mary Jane"
And private project "Enterprise"
And "Mary Jane" owns private project "Enterprise"
And project "Enterprise" has "Enterprise issue" open issue
And project "Enterprise" has "Enterprise fix" open merge request
And I visit issue page "Enterprise issue"
And I leave a comment referencing issue "Community fix"
And I visit merge request page "Enterprise fix"
And I leave a comment referencing issue "Community fix"
And I logout
@javascript
Scenario: Viewing the public issue as a "John Doe"
Given I sign in as "John Doe"
When I visit issue page "Community fix"
Then I should see no notes at all
@javascript
Scenario: Viewing the public issue as "Mary Jane"
Given I sign in as "Mary Jane"
When I visit issue page "Community fix"
And I should see a note linking to "Enterprise fix" merge request
And I should see a note linking to "Enterprise issue" issue
class Spinach::Features::ProjectIssuesReferences < Spinach::FeatureSteps class Spinach::Features::ProjectIssuesReferences < Spinach::FeatureSteps
include SharedAuthentication include SharedAuthentication
include SharedIssuable
include SharedNote include SharedNote
include SharedProject include SharedProject
include SharedUser include SharedUser
step 'project "Community" has "Public Issue 01" open issue' do
project = Project.find_by(name: 'Community')
create(:issue,
title: 'Public Issue 01',
project: project,
author: project.users.first,
description: '# Description header'
)
end
step 'project "Private Library" has "Fix NS-01" open merge request' do
project = Project.find_by(name: 'Private Library')
create(:merge_request,
title: 'Fix NS-01',
source_project: project,
target_project: project,
source_branch: 'fix',
target_branch: 'master',
author: project.users.first,
description: '# Description header'
)
end
step 'project "Private Library" has "Private Issue 01" open issue' do
project = Project.find_by(name: 'Private Library')
create(:issue,
title: 'Private Issue 01',
project: project,
author: project.users.first,
description: '# Description header'
)
end
step 'I leave a comment referencing issue "Public Issue 01" from "Fix NS-01" merge request' do
project = Project.find_by(name: 'Private Library')
issue = Issue.find_by!(title: 'Public Issue 01')
page.within(".js-main-target-form") do
fill_in "note[note]", with: "##{issue.to_reference(project)}"
click_button "Add Comment"
end
end
step 'I leave a comment referencing issue "Public Issue 01" from "Private Issue 01" issue' do
project = Project.find_by(name: 'Private Library')
issue = Issue.find_by!(title: 'Public Issue 01')
page.within(".js-main-target-form") do
fill_in "note[note]", with: "##{issue.to_reference(project)}"
click_button "Add Comment"
end
end
step 'I visit merge request page "Fix NS-01"' do
mr = MergeRequest.find_by(title: "Fix NS-01")
visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
end
step 'I visit issue page "Private Issue 01"' do
issue = Issue.find_by(title: "Private Issue 01")
visit namespace_project_issue_path(issue.project.namespace, issue.project, issue)
end
step 'I visit issue page "Public Issue 01"' do
issue = Issue.find_by(title: "Public Issue 01")
visit namespace_project_issue_path(issue.project.namespace, issue.project, issue)
end
step 'I should not see any related merge requests' do
page.within '.issue-details' do
expect(page).not_to have_content('.merge-requests')
end
end
step 'I should see the "Fix NS-01" related merge request' do
page.within '.merge-requests' do
expect(page).to have_content("1 Related Merge Request")
expect(page).to have_content('Fix NS-01')
end
end
step 'I should see a note linking to "Fix NS-01" merge request' do
project = Project.find_by(name: 'Community')
mr = MergeRequest.find_by(title: 'Fix NS-01')
page.within('.notes') do
expect(page).to have_content('Mary Jane')
expect(page).to have_content("mentioned in merge request #{mr.to_reference(project)}")
end
end
step 'I should see a note linking to "Private Issue 01" issue' do
project = Project.find_by(name: 'Community')
issue = Issue.find_by(title: 'Private Issue 01')
page.within('.notes') do
expect(page).to have_content('Mary Jane')
expect(page).to have_content("mentioned in issue #{issue.to_reference(project)}")
end
end
end end
class Spinach::Features::ProjectMergeRequestsReferences < Spinach::FeatureSteps
include SharedAuthentication
include SharedIssuable
include SharedNote
include SharedProject
include SharedUser
end
...@@ -5,6 +5,99 @@ module SharedIssuable ...@@ -5,6 +5,99 @@ module SharedIssuable
find(:css, '.issuable-edit').click find(:css, '.issuable-edit').click
end end
step 'project "Community" has "Community issue" open issue' do
create_issuable_for_project(
project_name: 'Community',
title: 'Community issue'
)
end
step 'project "Community" has "Community fix" open merge request' do
create_issuable_for_project(
project_name: 'Community',
type: :merge_request,
title: 'Community fix'
)
end
step 'project "Enterprise" has "Enterprise issue" open issue' do
create_issuable_for_project(
project_name: 'Enterprise',
title: 'Enterprise issue'
)
end
step 'project "Enterprise" has "Enterprise fix" open merge request' do
create_issuable_for_project(
project_name: 'Enterprise',
type: :merge_request,
title: 'Enterprise fix'
)
end
step 'I leave a comment referencing issue "Community issue"' do
leave_reference_comment(
issuable: Issue.find_by(title: 'Community issue'),
from_project_name: 'Enterprise'
)
end
step 'I leave a comment referencing issue "Community fix"' do
leave_reference_comment(
issuable: MergeRequest.find_by(title: 'Community fix'),
from_project_name: 'Enterprise'
)
end
step 'I visit issue page "Enterprise issue"' do
issue = Issue.find_by(title: 'Enterprise issue')
visit namespace_project_issue_path(issue.project.namespace, issue.project, issue)
end
step 'I visit merge request page "Enterprise fix"' do
mr = MergeRequest.find_by(title: 'Enterprise fix')
visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
end
step 'I visit issue page "Community issue"' do
issue = Issue.find_by(title: 'Community issue')
visit namespace_project_issue_path(issue.project.namespace, issue.project, issue)
end
step 'I visit issue page "Community fix"' do
mr = MergeRequest.find_by(title: 'Community fix')
visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
end
step 'I should not see any related merge requests' do
page.within '.issue-details' do
expect(page).not_to have_content('.merge-requests')
end
end
step 'I should see the "Enterprise fix" related merge request' do
page.within '.merge-requests' do
expect(page).to have_content('1 Related Merge Request')
expect(page).to have_content('Enterprise fix')
end
end
step 'I should see a note linking to "Enterprise fix" merge request' do
visible_note(
issuable: MergeRequest.find_by(title: 'Enterprise fix'),
from_project_name: 'Community',
user_name: 'Mary Jane'
)
end
step 'I should see a note linking to "Enterprise issue" issue' do
visible_note(
issuable: Issue.find_by(title: 'Enterprise issue'),
from_project_name: 'Community',
user_name: 'Mary Jane'
)
end
step 'I click link "Edit" for the merge request' do step 'I click link "Edit" for the merge request' do
edit_issuable edit_issuable
end end
...@@ -12,4 +105,45 @@ module SharedIssuable ...@@ -12,4 +105,45 @@ module SharedIssuable
step 'I click link "Edit" for the issue' do step 'I click link "Edit" for the issue' do
edit_issuable edit_issuable
end end
def create_issuable_for_project(project_name:, title:, type: :issue)
project = Project.find_by(name: project_name)
attrs = {
title: title,
author: project.users.first,
description: '# Description header'
}
case type
when :issue
attrs.merge!(project: project)
when :merge_request
attrs.merge!(
source_project: project,
target_project: project,
source_branch: 'fix',
target_branch: 'master'
)
end
create(type, attrs)
end
def leave_reference_comment(issuable:, from_project_name:)
project = Project.find_by(name: from_project_name)
page.within('.js-main-target-form') do
fill_in 'note[note]', with: "##{issuable.to_reference(project)}"
click_button 'Add Comment'
end
end
def visible_note(issuable:, from_project_name:, user_name:)
project = Project.find_by(name: from_project_name)
expect(page).to have_content(user_name)
expect(page).to have_content("mentioned in #{issuable.class.to_s.titleize.downcase} #{issuable.to_reference(project)}")
end
end end
...@@ -107,9 +107,7 @@ module SharedNote ...@@ -107,9 +107,7 @@ module SharedNote
end end
step 'I should see no notes at all' do step 'I should see no notes at all' do
page.within('.notes') do expect(page).to_not have_css('.note')
expect(page).to_not have_css('.note')
end
end end
# Markdown # Markdown
......
...@@ -161,31 +161,33 @@ module SharedProject ...@@ -161,31 +161,33 @@ module SharedProject
end end
step '"John Doe" owns private project "Enterprise"' do step '"John Doe" owns private project "Enterprise"' do
user = user_exists("John Doe", username: "john_doe") user_owns_project(
project = Project.find_by(name: "Enterprise") user_name: 'John Doe',
project ||= create(:empty_project, name: "Enterprise", namespace: user.namespace) project_name: 'Enterprise'
project.team << [user, :master] )
end end
step '"John Doe" owns internal project "Internal"' do step '"Mary Jane" owns private project "Enterprise"' do
user = user_exists("John Doe", username: "john_doe") user_owns_project(
project = Project.find_by(name: "Internal") user_name: 'Mary Jane',
project ||= create :empty_project, :internal, name: 'Internal', namespace: user.namespace project_name: 'Enterprise'
project.team << [user, :master] )
end end
step '"John Doe" owns public project "Community"' do step '"John Doe" owns internal project "Internal"' do
user = user_exists("John Doe", username: "john_doe") user_owns_project(
project = Project.find_by(name: "Community") user_name: 'John Doe',
project ||= create :empty_project, :public, name: 'Community', namespace: user.namespace project_name: 'Internal',
project.team << [user, :master] visibility: :internal
)
end end
step '"Mary Jane" owns private project "Private Library"' do step '"John Doe" owns public project "Community"' do
user = user_exists('Mary Jane', username: 'mary_jane') user_owns_project(
project = Project.find_by(name: 'Private Library') user_name: 'John Doe',
project ||= create(:project, name: 'Private Library', namespace: user.namespace) project_name: 'Community',
project.team << [user, :master] visibility: :public
)
end end
step 'public empty project "Empty Public Project"' do step 'public empty project "Empty Public Project"' do
...@@ -220,4 +222,12 @@ module SharedProject ...@@ -220,4 +222,12 @@ module SharedProject
expect(page).to have_content("skipped") expect(page).to have_content("skipped")
end end
end end
def user_owns_project(user_name:, project_name:, visibility: :private)
user = user_exists(user_name, username: user_name.underscore)
project = Project.find_by(name: project_name)
project ||= create(:empty_project, visibility, name: project_name, namespace: user.namespace)
project.team << [user, :master]
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment