2019-07-25 05:27:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-21 04:23:27 +00:00
|
|
|
# This is a helper class used by the GitLab Markdown feature spec
|
|
|
|
#
|
|
|
|
# Because the feature spec only cares about the output of the Markdown, and the
|
|
|
|
# test setup and teardown and parsing is fairly expensive, we only want to do it
|
|
|
|
# once. Unfortunately RSpec will not let you access `let`s in a `before(:all)`
|
|
|
|
# block, so we fake it by encapsulating all the shared setup in this class.
|
|
|
|
#
|
|
|
|
# The class renders `spec/fixtures/markdown.md.erb` using ERB, allowing for
|
|
|
|
# reference to the factory-created objects.
|
|
|
|
class MarkdownFeature
|
2017-12-14 00:13:44 +00:00
|
|
|
include FactoryBot::Syntax::Methods
|
2015-07-21 04:23:27 +00:00
|
|
|
|
2018-09-14 18:50:37 +00:00
|
|
|
attr_reader :fixture_path
|
|
|
|
|
|
|
|
def initialize(fixture_path = Rails.root.join('spec/fixtures/markdown.md.erb'))
|
|
|
|
@fixture_path = fixture_path
|
|
|
|
end
|
|
|
|
|
2015-07-21 04:23:27 +00:00
|
|
|
def user
|
|
|
|
@user ||= create(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group
|
2015-09-01 22:09:52 +00:00
|
|
|
@group ||= create(:group).tap do |group|
|
|
|
|
group.add_developer(user)
|
2015-07-21 04:23:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Direct references ----------------------------------------------------------
|
|
|
|
|
|
|
|
def project
|
2017-08-03 11:50:06 +00:00
|
|
|
@project ||= create(:project, :repository, group: group).tap do |project|
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2015-09-01 22:09:52 +00:00
|
|
|
end
|
2015-07-21 04:23:27 +00:00
|
|
|
end
|
|
|
|
|
2020-05-25 21:08:00 +00:00
|
|
|
def wiki
|
|
|
|
@wiki ||= ProjectWiki.new(project, user)
|
2016-01-12 21:00:35 +00:00
|
|
|
end
|
|
|
|
|
2020-05-25 21:08:00 +00:00
|
|
|
def wiki_page
|
|
|
|
@wiki_page ||= build(:wiki_page, wiki: wiki)
|
2016-06-08 05:02:50 +00:00
|
|
|
end
|
|
|
|
|
2015-07-21 04:23:27 +00:00
|
|
|
def issue
|
|
|
|
@issue ||= create(:issue, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
@merge_request ||= create(:merge_request, :simple, source_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def snippet
|
|
|
|
@snippet ||= create(:project_snippet, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit
|
|
|
|
@commit ||= project.commit
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_range
|
2015-09-01 22:09:52 +00:00
|
|
|
@commit_range ||= begin
|
2015-07-21 04:23:27 +00:00
|
|
|
commit2 = project.commit('HEAD~3')
|
2015-09-01 22:09:52 +00:00
|
|
|
CommitRange.new("#{commit.id}...#{commit2.id}", project)
|
2015-07-21 04:23:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def simple_label
|
|
|
|
@simple_label ||= create(:label, name: 'gfm', project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def label
|
|
|
|
@label ||= create(:label, name: 'awaiting feedback', project: project)
|
|
|
|
end
|
|
|
|
|
2016-03-31 02:12:34 +00:00
|
|
|
def simple_milestone
|
|
|
|
@simple_milestone ||= create(:milestone, name: 'gfm-milestone', project: project)
|
|
|
|
end
|
|
|
|
|
2015-12-24 13:43:07 +00:00
|
|
|
def milestone
|
2016-03-31 02:12:34 +00:00
|
|
|
@milestone ||= create(:milestone, name: 'next goal', project: project)
|
2015-12-24 13:43:07 +00:00
|
|
|
end
|
|
|
|
|
2017-08-03 11:50:06 +00:00
|
|
|
def group_milestone
|
|
|
|
@group_milestone ||= create(:milestone, name: 'group-milestone', group: group)
|
|
|
|
end
|
|
|
|
|
2015-07-21 04:23:27 +00:00
|
|
|
# Cross-references -----------------------------------------------------------
|
|
|
|
|
|
|
|
def xproject
|
2015-09-01 22:09:52 +00:00
|
|
|
@xproject ||= begin
|
2017-02-24 14:13:57 +00:00
|
|
|
group = create(:group, :nested)
|
2017-03-28 21:13:16 +00:00
|
|
|
create(:project, :repository, namespace: group) do |project|
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_developer(user)
|
2015-09-01 22:09:52 +00:00
|
|
|
end
|
2015-07-21 04:23:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def xissue
|
|
|
|
@xissue ||= create(:issue, project: xproject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def xmerge_request
|
|
|
|
@xmerge_request ||= create(:merge_request, :simple, source_project: xproject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def xsnippet
|
|
|
|
@xsnippet ||= create(:project_snippet, project: xproject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def xcommit
|
|
|
|
@xcommit ||= xproject.commit
|
|
|
|
end
|
|
|
|
|
|
|
|
def xcommit_range
|
2015-09-01 22:09:52 +00:00
|
|
|
@xcommit_range ||= begin
|
2015-07-21 04:23:27 +00:00
|
|
|
xcommit2 = xproject.commit('HEAD~2')
|
2015-09-01 22:09:52 +00:00
|
|
|
CommitRange.new("#{xcommit.id}...#{xcommit2.id}", xproject)
|
2015-07-21 04:23:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-24 13:43:07 +00:00
|
|
|
def xmilestone
|
|
|
|
@xmilestone ||= create(:milestone, project: xproject)
|
|
|
|
end
|
|
|
|
|
2015-12-03 13:00:00 +00:00
|
|
|
def urls
|
2016-03-24 16:00:26 +00:00
|
|
|
Gitlab::Routing.url_helpers
|
2015-12-03 13:00:00 +00:00
|
|
|
end
|
|
|
|
|
2015-07-21 04:23:27 +00:00
|
|
|
def raw_markdown
|
2018-09-14 18:50:37 +00:00
|
|
|
markdown = File.read(fixture_path)
|
2015-08-20 19:41:47 +00:00
|
|
|
ERB.new(markdown).result(binding)
|
2015-07-21 04:23:27 +00:00
|
|
|
end
|
|
|
|
end
|