summaryrefslogtreecommitdiff
path: root/spec/models/note_spec.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-04-26 11:59:41 +0200
committerRobert Speicher <rspeicher@gmail.com>2016-05-29 15:03:00 -0400
commit0e613db76d8d6e8521a3b4d546f552c8d184ffa1 (patch)
treeebbab63ab2b72c69018ed973ff891ab20ce51667 /spec/models/note_spec.rb
parent57b551a19f18d8da78175b4de6098d5517cde49f (diff)
downloadgitlab-ce-0e613db76d8d6e8521a3b4d546f552c8d184ffa1.tar.gz
Add more validation tests for note model
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r--spec/models/note_spec.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index fe13c06b1e0..d90b54464cd 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -12,6 +12,33 @@ describe Note, models: true do
describe 'validation' do
it { is_expected.to validate_presence_of(:note) }
it { is_expected.to validate_presence_of(:project) }
+
+ context 'when note is comment on commit' do
+ before { allow(subject).to receive(:for_commit?).and_return(true) }
+
+ it { is_expected.to validate_presence_of(:commit_id) }
+ it { is_expected.to_not validate_presence_of(:noteable_id) }
+ end
+
+ context 'when note is not comment on commit' do
+ before { allow(subject).to receive(:for_commit?).and_return(false) }
+
+ it { is_expected.to_not validate_presence_of(:commit_id) }
+ it { is_expected.to validate_presence_of(:noteable_id) }
+ end
+
+ context 'when noteable and note project is different' do
+ subject do
+ build(:note, noteable: create(:issue), project: create(:project))
+ end
+
+ it { is_expected.to be_invalid }
+ end
+
+ context 'when noteable and note project is the same one' do
+ subject { create(:note) }
+ it { is_expected.to be_valid }
+ end
end
describe "Commit notes" do