debian-mirror-gitlab/spec/models/concerns/mentionable_spec.rb

99 lines
2.8 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Mentionable do
include Mentionable
def author
nil
end
2015-12-23 02:04:40 +05:30
describe :references do
let(:project) { create(:project) }
it 'excludes JIRA references' do
allow(project).to receive_messages(jira_tracker?: true)
expect(referenced_mentionables(project, 'JIRA-123')).to be_empty
end
end
end
2015-04-26 12:48:37 +05:30
describe Issue, "Mentionable" do
2015-09-11 14:41:01 +05:30
describe '#mentioned_users' do
2015-04-26 12:48:37 +05:30
let!(:user) { create(:user, username: 'stranger') }
let!(:user2) { create(:user, username: 'john') }
2015-09-11 14:41:01 +05:30
let!(:issue) { create(:issue, description: "#{user.to_reference} mentioned") }
2015-04-26 12:48:37 +05:30
subject { issue.mentioned_users }
it { is_expected.to include(user) }
it { is_expected.not_to include(user2) }
end
2015-09-11 14:41:01 +05:30
describe '#create_cross_references!' do
let(:project) { create(:project) }
let(:author) { double('author') }
let(:commit) { project.commit }
let(:commit2) { project.commit }
let!(:issue) do
create(:issue, project: project, description: commit.to_reference)
end
it 'correctly removes already-mentioned Commits' do
expect(SystemNoteService).not_to receive(:cross_reference)
2015-10-24 18:46:33 +05:30
issue.create_cross_references!(author, [commit2])
2015-09-11 14:41:01 +05:30
end
end
describe '#create_new_cross_references!' do
let(:project) { create(:project) }
2016-06-02 11:05:42 +05:30
let(:author) { create(:author) }
let(:issues) { create_list(:issue, 2, project: project, author: author) }
2015-09-11 14:41:01 +05:30
context 'before changes are persisted' do
it 'ignores pre-existing references' do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).not_to receive(:cross_reference)
issue.description = 'New description'
issue.create_new_cross_references!
end
it 'notifies new references' do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)
issue.description = issues[1].to_reference
issue.create_new_cross_references!
end
end
context 'after changes are persisted' do
it 'ignores pre-existing references' do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).not_to receive(:cross_reference)
issue.update_attributes(description: 'New description')
issue.create_new_cross_references!
end
it 'notifies new references' do
issue = create_issue(description: issues[0].to_reference)
expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)
issue.update_attributes(description: issues[1].to_reference)
issue.create_new_cross_references!
end
end
def create_issue(description:)
2016-06-02 11:05:42 +05:30
create(:issue, project: project, description: description, author: author)
2015-09-11 14:41:01 +05:30
end
end
2015-04-26 12:48:37 +05:30
end