BigW Consortium Gitlab

markdown_feature.rb 2.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 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
18 19
    @group ||= create(:group).tap do |group|
      group.add_developer(user)
20 21 22 23 24 25
    end
  end

  # Direct references ----------------------------------------------------------

  def project
26
    @project ||= create(:project, :repository).tap do |project|
27 28
      project.team << [user, :master]
    end
29 30
  end

31 32 33 34
  def project_wiki
    @project_wiki ||= ProjectWiki.new(project, user)
  end

35 36 37 38
  def project_wiki_page
    @project_wiki_page ||= build(:wiki_page, wiki: project_wiki)
  end

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  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
56
    @commit_range ||= begin
57
      commit2 = project.commit('HEAD~3')
58
      CommitRange.new("#{commit.id}...#{commit2.id}", project)
59 60 61 62 63 64 65 66 67 68 69
    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

70 71 72 73
  def simple_milestone
    @simple_milestone ||= create(:milestone, name: 'gfm-milestone', project: project)
  end

74
  def milestone
75
    @milestone ||= create(:milestone, name: 'next goal', project: project)
76 77
  end

78 79 80
  # Cross-references -----------------------------------------------------------

  def xproject
81
    @xproject ||= begin
Douwe Maan committed
82
      group = create(:group, :nested)
83
      create(:project, :repository, namespace: group) do |project|
84 85
        project.team << [user, :developer]
      end
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    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
106
    @xcommit_range ||= begin
107
      xcommit2 = xproject.commit('HEAD~2')
108
      CommitRange.new("#{xcommit.id}...#{xcommit2.id}", xproject)
109 110 111
    end
  end

112 113 114 115
  def xmilestone
    @xmilestone ||= create(:milestone, project: xproject)
  end

Douwe Maan committed
116
  def urls
117
    Gitlab::Routing.url_helpers
Douwe Maan committed
118 119
  end

120
  def raw_markdown
121
    markdown = File.read(Rails.root.join('spec/fixtures/markdown.md.erb'))
Douwe Maan committed
122
    ERB.new(markdown).result(binding)
123 124
  end
end