summaryrefslogtreecommitdiff
path: root/spec/models/note_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r--spec/models/note_spec.rb108
1 files changed, 105 insertions, 3 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 646255543a0..ef143debcc1 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -72,7 +72,6 @@ describe Note do
end
let(:project) { create(:project) }
- let(:commit) { project.repository.commit }
describe "Commit notes" do
let!(:note) { create(:note_on_commit, note: "+1 from me") }
@@ -131,7 +130,7 @@ describe Note do
describe "Merge request notes" do
let!(:note) { create(:note_on_merge_request, note: "+1 from me") }
- it "should not be votable" do
+ it "should be votable" do
note.should be_votable
end
end
@@ -150,7 +149,7 @@ describe Note do
let(:author) { create(:user) }
let(:status) { 'new_status' }
- subject { Note.create_status_change_note(thing, project, author, status) }
+ subject { Note.create_status_change_note(thing, project, author, status, nil) }
it 'creates and saves a Note' do
should be_a Note
@@ -161,6 +160,102 @@ describe Note do
its(:project) { should == thing.project }
its(:author) { should == author }
its(:note) { should =~ /Status changed to #{status}/ }
+
+ it 'appends a back-reference if a closing mentionable is supplied' do
+ commit = double('commit', gfm_reference: 'commit 123456')
+ n = Note.create_status_change_note(thing, project, author, status, commit)
+
+ n.note.should =~ /Status changed to #{status} by commit 123456/
+ end
+ end
+
+ describe '#create_cross_reference_note' do
+ let(:project) { create(:project_with_code) }
+ let(:author) { create(:user) }
+ let(:issue) { create(:issue, project: project) }
+ let(:mergereq) { create(:merge_request, target_project: project) }
+ let(:commit) { project.repository.commit }
+
+ # Test all of {issue, merge request, commit} in both the referenced and referencing
+ # roles, to ensure that the correct information can be inferred from any argument.
+
+ context 'issue from a merge request' do
+ subject { Note.create_cross_reference_note(issue, mergereq, author, project) }
+
+ it { should be_valid }
+ its(:noteable) { should == issue }
+ its(:project) { should == issue.project }
+ its(:author) { should == author }
+ its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
+ end
+
+ context 'issue from a commit' do
+ subject { Note.create_cross_reference_note(issue, commit, author, project) }
+
+ it { should be_valid }
+ its(:noteable) { should == issue }
+ its(:note) { should == "_mentioned in commit #{commit.sha[0..5]}_" }
+ end
+
+ context 'merge request from an issue' do
+ subject { Note.create_cross_reference_note(mergereq, issue, author, project) }
+
+ it { should be_valid }
+ its(:noteable) { should == mergereq }
+ its(:project) { should == mergereq.project }
+ its(:note) { should == "_mentioned in issue ##{issue.iid}_" }
+ end
+
+ context 'commit from a merge request' do
+ subject { Note.create_cross_reference_note(commit, mergereq, author, project) }
+
+ it { should be_valid }
+ its(:noteable) { should == commit }
+ its(:project) { should == project }
+ its(:note) { should == "_mentioned in merge request !#{mergereq.iid}_" }
+ end
+ end
+
+ describe '#cross_reference_exists?' do
+ let(:project) { create :project }
+ let(:author) { create :user }
+ let(:issue) { create :issue }
+ let(:commit0) { double 'commit0', gfm_reference: 'commit 123456' }
+ let(:commit1) { double 'commit1', gfm_reference: 'commit 654321' }
+
+ before do
+ Note.create_cross_reference_note(issue, commit0, author, project)
+ end
+
+ it 'detects if a mentionable has already been mentioned' do
+ Note.cross_reference_exists?(issue, commit0).should be_true
+ end
+
+ it 'detects if a mentionable has not already been mentioned' do
+ Note.cross_reference_exists?(issue, commit1).should be_false
+ end
+ end
+
+ describe '#system?' do
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue, project: project) }
+ let(:other) { create(:issue, project: project) }
+ let(:author) { create(:user) }
+
+ it 'should recognize user-supplied notes as non-system' do
+ @note = create(:note_on_issue)
+ @note.should_not be_system
+ end
+
+ it 'should identify status-change notes as system notes' do
+ @note = Note.create_status_change_note(issue, project, author, 'closed', nil)
+ @note.should be_system
+ end
+
+ it 'should identify cross-reference notes as system notes' do
+ @note = Note.create_cross_reference_note(issue, other, author, project)
+ @note.should be_system
+ end
end
describe :authorization do
@@ -208,4 +303,11 @@ describe Note do
it { @abilities.allowed?(@u3, :admin_note, @p1).should be_false }
end
end
+
+ it_behaves_like 'an editable mentionable' do
+ let(:issue) { create :issue, project: project }
+ let(:subject) { create :note, noteable: issue, project: project }
+ let(:backref_text) { issue.gfm_reference }
+ let(:set_mentionable_text) { ->(txt) { subject.note = txt } }
+ end
end