debian-mirror-gitlab/spec/support/markdown_feature.rb

101 lines
2.5 KiB
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
# 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
include FactoryGirl::Syntax::Methods
def user
@user ||= create(:user)
end
def group
2015-10-24 18:46:33 +05:30
@group ||= create(:group).tap do |group|
group.add_developer(user)
2015-09-11 14:41:01 +05:30
end
end
# Direct references ----------------------------------------------------------
def project
2015-10-24 18:46:33 +05:30
@project ||= create(:project).tap do |project|
project.team << [user, :master]
end
2015-09-11 14:41:01 +05:30
end
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-10-24 18:46:33 +05:30
@commit_range ||= begin
2015-09-11 14:41:01 +05:30
commit2 = project.commit('HEAD~3')
2015-10-24 18:46:33 +05:30
CommitRange.new("#{commit.id}...#{commit2.id}", project)
2015-09-11 14:41:01 +05:30
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
# Cross-references -----------------------------------------------------------
def xproject
2015-10-24 18:46:33 +05:30
@xproject ||= begin
2015-09-11 14:41:01 +05:30
namespace = create(:namespace, name: 'cross-reference')
2015-10-24 18:46:33 +05:30
create(:project, namespace: namespace) do |project|
project.team << [user, :developer]
end
2015-09-11 14:41:01 +05:30
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-10-24 18:46:33 +05:30
@xcommit_range ||= begin
2015-09-11 14:41:01 +05:30
xcommit2 = xproject.commit('HEAD~2')
2015-10-24 18:46:33 +05:30
CommitRange.new("#{xcommit.id}...#{xcommit2.id}", xproject)
2015-09-11 14:41:01 +05:30
end
end
def raw_markdown
2015-09-25 12:07:36 +05:30
markdown = File.read(Rails.root.join('spec/fixtures/markdown.md.erb'))
ERB.new(markdown).result(binding)
2015-09-11 14:41:01 +05:30
end
end