spec/support/mentionable_shared_examples.rb
def common_mentionable_setup
  # Avoid name collisions with let(:project) or let(:author) in the surrounding scope.
  let(:mproject) { create :project }
  let(:mauthor) { subject.author }

  let(:mentioned_issue) { create :issue, project: mproject }
  let(:other_issue) { create :issue, project: mproject }
  let(:mentioned_mr) { create :merge_request, source_project: mproject, source_branch: 'different' }
  let(:mentioned_commit) { double('commit', sha: '1234567890abcdef').as_null_object }

  # Override to add known commits to the repository stub.
  let(:extra_commits) { [] }

  # A string that mentions each of the +mentioned_.*+ objects above. Mentionables should add a self-reference
  # to this string and place it in their +mentionable_text+.
  let(:ref_string) do
    "mentions ##{mentioned_issue.iid} twice ##{mentioned_issue.iid}, !#{mentioned_mr.iid}, " +
    "#{mentioned_commit.sha[0..5]} and itself as #{backref_text}"
  end

  before do
    # Wire the project's repository to return the mentioned commit, and +nil+ for any
    # unrecognized commits.
    commitmap = { '123456' => mentioned_commit }
    extra_commits.each { |c| commitmap[c.sha[0..5]] = c }

    repo = double('repository')
    repo.stub(:commit) { |sha| commitmap[sha] }
    mproject.stub(repository: repo)

    set_mentionable_text.call(ref_string)
  end
end
# Specifications for behavior common to all Mentionable implementations.
# Requires a shared context containing:
# - let(:subject) { "the mentionable implementation" }
# - let(:backref_text) { "the way that +subject+ should refer to itself in backreferences " }
# - let(:set_mentionable_text) { lambda { |txt| "block that assigns txt to the subject's mentionable_text" } }
Specifications for behavior common to all Mentionable implementations.
Specifications for behavior common to all Mentionable implementations .
def common_mentionable_setup
  let(:mproject) { create :project }
  let(:mauthor) { subject.author }
  let(:mentioned_issue) { create :issue, project: mproject }
  let(:other_issue) { create :issue, project: mproject }
  let(:mentioned_mr) { create :merge_request, source_project: mproject, source_branch: 'different' }
  let(:mentioned_commit) { double('commit', sha: '1234567890abcdef').as_null_object }
  let(:extra_commits) { [] }
  let(:ref_string) do
    "mentions ##{mentioned_issue.iid} twice ##{mentioned_issue.iid}, !#{mentioned_mr.iid}, " +
    "#{mentioned_commit.sha[0..5]} and itself as #{backref_text}"
  end
  before do
    commitmap = { '123456' => mentioned_commit }
    extra_commits.each { |c| commitmap[c.sha[0..5]] = c }
    repo = double('repository')
    repo.stub(:commit) { |sha| commitmap[sha] }
    mproject.stub(repository: repo)
    set_mentionable_text.call(ref_string)
  end
end
def common_mentionable_setup let ( :mproject ) { create :project } let ( :mauthor ) { subject . author } let ( :mentioned_issue ) { create :issue , project : mproject } let ( :other_issue ) { create :issue , project : mproject } let ( :mentioned_mr ) { create :merge_request , source_project : mproject , source_branch : 'different' } let ( :mentioned_commit ) { double ( 'commit' , sha : '1234567890abcdef' ) . as_null_object } let ( :extra_commits ) { [ ] } let ( :ref_string ) do "mentions ##{mentioned_issue.iid} twice ##{mentioned_issue.iid}, !#{mentioned_mr.iid}, " + "#{mentioned_commit.sha[0..5]} and itself as #{backref_text}" end before do commitmap = { '123456' => mentioned_commit } extra_commits . each { | c | commitmap [ c . sha [ 0 .. 5 ] ] = c } repo = double ( 'repository' ) repo . stub ( :commit ) { | sha | commitmap [ sha ] } mproject . stub ( repository : repo ) set_mentionable_text . call ( ref_string ) end end
Specifications for behavior common to all Mentionable implementations.
Specifications for behavior common to all Mentionable implementations .
# Avoid name collisions with let(:project) or let(:author) in the surrounding scope. # Override to add known commits to the repository stub. # A string that mentions each of the +mentioned_.*+ objects above. Mentionables should add a self-reference # to this string and place it in their +mentionable_text+. # Wire the project's repository to return the mentioned commit, and +nil+ for any # unrecognized commits.