Minor changes in note validation specs
This commit is contained in:
parent
99ef3a84b5
commit
fc57d36018
4 changed files with 22 additions and 19 deletions
|
@ -9,9 +9,9 @@ FactoryGirl.define do
|
|||
author
|
||||
noteable { create(:issue, project: project) }
|
||||
|
||||
factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
|
||||
factory :note_on_commit, traits: [:on_commit]
|
||||
factory :note_on_commit_diff, traits: [:on_commit, :on_diff], class: LegacyDiffNote
|
||||
factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
|
||||
factory :note_on_merge_request, traits: [:on_merge_request]
|
||||
factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff], class: LegacyDiffNote
|
||||
factory :note_on_project_snippet, traits: [:on_project_snippet]
|
||||
|
@ -19,14 +19,20 @@ FactoryGirl.define do
|
|||
factory :downvote_note, traits: [:award, :downvote]
|
||||
factory :upvote_note, traits: [:award, :upvote]
|
||||
|
||||
trait :on_issue do
|
||||
noteable_type 'Issue'
|
||||
end
|
||||
|
||||
trait :on_commit do
|
||||
noteable nil
|
||||
noteable_type 'Commit'
|
||||
noteable_id nil
|
||||
commit_id RepoHelpers.sample_commit.id
|
||||
noteable_type "Commit"
|
||||
end
|
||||
|
||||
trait :on_diff do
|
||||
line_code "0_184_184"
|
||||
end
|
||||
|
||||
trait :on_issue do
|
||||
noteable_type 'Issue'
|
||||
noteable { create(:issue, project: project) }
|
||||
end
|
||||
|
||||
trait :on_merge_request do
|
||||
|
@ -42,10 +48,6 @@ FactoryGirl.define do
|
|||
noteable { create(:snippet, project: project) }
|
||||
end
|
||||
|
||||
trait :on_diff do
|
||||
line_code "0_184_184"
|
||||
end
|
||||
|
||||
trait :system do
|
||||
system true
|
||||
end
|
||||
|
|
|
@ -228,9 +228,11 @@ describe Issue, "Issuable" do
|
|||
end
|
||||
|
||||
describe "votes" do
|
||||
let(:project) { issue.project }
|
||||
|
||||
before do
|
||||
issue.notes.awards.create!(note: "thumbsup", author: user, project: issue.project)
|
||||
issue.notes.awards.create!(note: "thumbsdown", author: user, project: issue.project)
|
||||
issue.notes.awards.create!(note: "thumbsup", author: user, project: project)
|
||||
issue.notes.awards.create!(note: "thumbsdown", author: user, project: project)
|
||||
end
|
||||
|
||||
it "returns correct values" do
|
||||
|
|
|
@ -120,7 +120,6 @@ describe MergeRequest, models: true do
|
|||
before do
|
||||
allow(merge_request).to receive(:commits) { [merge_request.source_project.repository.commit] }
|
||||
create(:note_on_commit, commit_id: merge_request.commits.first.id,
|
||||
noteable_type: 'Commit',
|
||||
project: merge_request.project)
|
||||
create(:note, noteable: merge_request, project: merge_request.project)
|
||||
end
|
||||
|
@ -132,7 +131,6 @@ describe MergeRequest, models: true do
|
|||
|
||||
it "should include notes for commits from target project as well" do
|
||||
create(:note_on_commit, commit_id: merge_request.commits.first.id,
|
||||
noteable_type: 'Commit',
|
||||
project: merge_request.target_project)
|
||||
|
||||
expect(merge_request.commits).not_to be_empty
|
||||
|
|
|
@ -13,29 +13,30 @@ describe Note, models: true 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
|
||||
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.to_not validate_presence_of(:noteable_id) }
|
||||
end
|
||||
|
||||
context 'when note is not comment on commit' do
|
||||
context 'when note is not 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
|
||||
context 'when noteable and note project differ' do
|
||||
subject do
|
||||
build(:note, noteable: create(:issue), project: create(:project))
|
||||
build(:note, noteable: build_stubbed(:issue),
|
||||
project: build_stubbed(:project))
|
||||
end
|
||||
|
||||
it { is_expected.to be_invalid }
|
||||
end
|
||||
|
||||
context 'when noteable and note project is the same one' do
|
||||
context 'when noteable and note project are the same' do
|
||||
subject { create(:note) }
|
||||
it { is_expected.to be_valid }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue