diff options
author | ZJ van de Weg <zegerjan@gitlab.com> | 2016-05-30 14:46:23 +0200 |
---|---|---|
committer | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-05-30 18:54:08 +0200 |
commit | cbd7801b3d1d435a95ec70032c5acc9df33b0337 (patch) | |
tree | 7bd367bf31690e4a6b0115d238cf2c312c9fb2ab /spec/models/note_spec.rb | |
parent | f99b38c9d5dab11677b2680a671c1a66fb69283b (diff) | |
parent | 2485bd7bbf9686f993d2a417943feff5c7d5b6f3 (diff) | |
download | gitlab-ce-cbd7801b3d1d435a95ec70032c5acc9df33b0337.tar.gz |
Merge branch 'master' into awardables
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r-- | spec/models/note_spec.rb | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index a3ab1b796be..457bf337b52 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -12,6 +12,34 @@ 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 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.not_to validate_presence_of(:noteable_id) } + end + + context 'when note is not on commit' do + before { allow(subject).to receive(:for_commit?).and_return(false) } + + it { is_expected.not_to validate_presence_of(:commit_id) } + it { is_expected.to validate_presence_of(:noteable_id) } + end + + context 'when noteable and note project differ' do + subject do + build(:note, noteable: build_stubbed(:issue), + project: build_stubbed(:project)) + end + + it { is_expected.to be_invalid } + end + + context 'when noteable and note project are the same' do + subject { create(:note) } + it { is_expected.to be_valid } + end end describe "Commit notes" do @@ -89,8 +117,8 @@ describe Note, models: true do end describe "#all_references" do - let!(:note1) { create(:note) } - let!(:note2) { create(:note) } + let!(:note1) { create(:note_on_issue) } + let!(:note2) { create(:note_on_issue) } it "reads the rendered note body from the cache" do expect(Banzai::Renderer).to receive(:render).with(note1.note, pipeline: :note, cache_key: [note1, "note"], project: note1.project) @@ -102,7 +130,7 @@ describe Note, models: true do end describe '.search' do - let(:note) { create(:note, note: 'WoW') } + let(:note) { create(:note_on_issue, note: 'WoW') } it 'returns notes with matching content' do expect(described_class.search(note.note)).to eq([note]) |