Commit fc57d360 authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Robert Speicher

Minor changes in note validation specs

parent 99ef3a84
...@@ -9,9 +9,9 @@ FactoryGirl.define do ...@@ -9,9 +9,9 @@ FactoryGirl.define do
author author
noteable { create(:issue, project: project) } 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, traits: [:on_commit]
factory :note_on_commit_diff, traits: [:on_commit, :on_diff], class: LegacyDiffNote 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, traits: [:on_merge_request]
factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff], class: LegacyDiffNote factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff], class: LegacyDiffNote
factory :note_on_project_snippet, traits: [:on_project_snippet] factory :note_on_project_snippet, traits: [:on_project_snippet]
...@@ -19,14 +19,20 @@ FactoryGirl.define do ...@@ -19,14 +19,20 @@ FactoryGirl.define do
factory :downvote_note, traits: [:award, :downvote] factory :downvote_note, traits: [:award, :downvote]
factory :upvote_note, traits: [:award, :upvote] factory :upvote_note, traits: [:award, :upvote]
trait :on_issue do
noteable_type 'Issue'
end
trait :on_commit do trait :on_commit do
noteable nil noteable nil
noteable_type 'Commit'
noteable_id nil
commit_id RepoHelpers.sample_commit.id 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 end
trait :on_merge_request do trait :on_merge_request do
...@@ -42,10 +48,6 @@ FactoryGirl.define do ...@@ -42,10 +48,6 @@ FactoryGirl.define do
noteable { create(:snippet, project: project) } noteable { create(:snippet, project: project) }
end end
trait :on_diff do
line_code "0_184_184"
end
trait :system do trait :system do
system true system true
end end
......
...@@ -228,9 +228,11 @@ describe Issue, "Issuable" do ...@@ -228,9 +228,11 @@ describe Issue, "Issuable" do
end end
describe "votes" do describe "votes" do
let(:project) { issue.project }
before do before do
issue.notes.awards.create!(note: "thumbsup", author: user, project: issue.project) issue.notes.awards.create!(note: "thumbsup", author: user, project: project)
issue.notes.awards.create!(note: "thumbsdown", author: user, project: issue.project) issue.notes.awards.create!(note: "thumbsdown", author: user, project: project)
end end
it "returns correct values" do it "returns correct values" do
......
...@@ -120,7 +120,6 @@ describe MergeRequest, models: true do ...@@ -120,7 +120,6 @@ describe MergeRequest, models: true do
before do before do
allow(merge_request).to receive(:commits) { [merge_request.source_project.repository.commit] } allow(merge_request).to receive(:commits) { [merge_request.source_project.repository.commit] }
create(:note_on_commit, commit_id: merge_request.commits.first.id, create(:note_on_commit, commit_id: merge_request.commits.first.id,
noteable_type: 'Commit',
project: merge_request.project) project: merge_request.project)
create(:note, noteable: merge_request, project: merge_request.project) create(:note, noteable: merge_request, project: merge_request.project)
end end
...@@ -132,7 +131,6 @@ describe MergeRequest, models: true do ...@@ -132,7 +131,6 @@ describe MergeRequest, models: true do
it "should include notes for commits from target project as well" do it "should include notes for commits from target project as well" do
create(:note_on_commit, commit_id: merge_request.commits.first.id, create(:note_on_commit, commit_id: merge_request.commits.first.id,
noteable_type: 'Commit',
project: merge_request.target_project) project: merge_request.target_project)
expect(merge_request.commits).not_to be_empty expect(merge_request.commits).not_to be_empty
......
...@@ -13,29 +13,30 @@ describe Note, models: true do ...@@ -13,29 +13,30 @@ describe Note, models: true do
it { is_expected.to validate_presence_of(:note) } it { is_expected.to validate_presence_of(:note) }
it { is_expected.to validate_presence_of(:project) } 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) } before { allow(subject).to receive(:for_commit?).and_return(true) }
it { is_expected.to validate_presence_of(:commit_id) } it { is_expected.to validate_presence_of(:commit_id) }
it { is_expected.to_not validate_presence_of(:noteable_id) } it { is_expected.to_not validate_presence_of(:noteable_id) }
end 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) } before { allow(subject).to receive(:for_commit?).and_return(false) }
it { is_expected.to_not validate_presence_of(:commit_id) } it { is_expected.to_not validate_presence_of(:commit_id) }
it { is_expected.to validate_presence_of(:noteable_id) } it { is_expected.to validate_presence_of(:noteable_id) }
end end
context 'when noteable and note project is different' do context 'when noteable and note project differ' do
subject do subject do
build(:note, noteable: create(:issue), project: create(:project)) build(:note, noteable: build_stubbed(:issue),
project: build_stubbed(:project))
end end
it { is_expected.to be_invalid } it { is_expected.to be_invalid }
end 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) } subject { create(:note) }
it { is_expected.to be_valid } it { is_expected.to be_valid }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment