diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-05-18 19:38:52 +0200 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-05-29 15:03:00 -0400 |
commit | dbba60029c84fa091350d3a7d8b2e73cfec25f7e (patch) | |
tree | 5024609041e64fe4e27899ea3f40214c4aba0b04 | |
parent | cc2efcf1a681223d5c74eef6fca73cde71dce7c2 (diff) | |
download | gitlab-ce-dbba60029c84fa091350d3a7d8b2e73cfec25f7e.tar.gz |
Improve note factory
-rw-r--r-- | features/steps/project/merge_requests.rb | 2 | ||||
-rw-r--r-- | spec/factories/notes.rb | 7 | ||||
-rw-r--r-- | spec/features/issues/note_polling_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/note_data_builder_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/legacy_diff_note_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/project_services/hipchat_service_spec.rb | 6 |
6 files changed, 19 insertions, 21 deletions
diff --git a/features/steps/project/merge_requests.rb b/features/steps/project/merge_requests.rb index cfa586f859f..b2fa8750234 100644 --- a/features/steps/project/merge_requests.rb +++ b/features/steps/project/merge_requests.rb @@ -273,7 +273,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps step 'user "John Doe" leaves a comment like "Line is wrong" on diff' do mr = MergeRequest.find_by(title: "Bug NS-05") create(:note_on_merge_request_diff, project: project, - noteable_id: mr.id, + noteable: mr, author: user_exists("John Doe"), line_code: sample_commit.line_code, note: 'Line is wrong') diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index 6f9b3568e70..c32e205ee69 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -7,7 +7,7 @@ FactoryGirl.define do project note "Note" author - noteable { create(:issue, project: project) } + on_issue factory :note_on_commit, traits: [:on_commit] factory :note_on_commit_diff, traits: [:on_commit, :on_diff], class: LegacyDiffNote @@ -21,8 +21,8 @@ FactoryGirl.define do trait :on_commit do noteable nil - noteable_type 'Commit' noteable_id nil + noteable_type 'Commit' commit_id RepoHelpers.sample_commit.id end @@ -31,17 +31,14 @@ FactoryGirl.define do end trait :on_issue do - noteable_type 'Issue' noteable { create(:issue, project: project) } end trait :on_merge_request do - noteable_type 'MergeRequest' noteable { create(:merge_request, source_project: project) } end trait :on_project_snippet do - noteable_type 'Snippet' noteable { create(:snippet, project: project) } end diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb index 9f521263e4c..f5cfe2d666e 100644 --- a/spec/features/issues/note_polling_spec.rb +++ b/spec/features/issues/note_polling_spec.rb @@ -9,9 +9,8 @@ feature 'Issue notes polling' do end scenario 'Another user adds a comment to an issue', js: true do - note = create(:note_on_issue, noteable: issue, - project: project, - note: 'Looks good!') + note = create(:note, noteable: issue, project: project, + note: 'Looks good!') page.execute_script('notes.refresh();') diff --git a/spec/lib/gitlab/note_data_builder_spec.rb b/spec/lib/gitlab/note_data_builder_spec.rb index 82823e7f790..e848d88182f 100644 --- a/spec/lib/gitlab/note_data_builder_spec.rb +++ b/spec/lib/gitlab/note_data_builder_spec.rb @@ -44,13 +44,13 @@ describe 'Gitlab::NoteDataBuilder', lib: true do end let(:note) do - create(:note_on_issue, noteable_id: issue.id, project: project) + create(:note_on_issue, noteable: issue, project: project) end it 'returns the note and issue-specific data' do expect(data).to have_key(:issue) expect(data[:issue].except('updated_at')) - .to eq(issue.hook_attrs.except('updated_at')) + .to eq(issue.reload.hook_attrs.except('updated_at')) expect(data[:issue]['updated_at']) .to be > issue.hook_attrs['updated_at'] end @@ -67,14 +67,14 @@ describe 'Gitlab::NoteDataBuilder', lib: true do end let(:note) do - create(:note_on_merge_request, noteable_id: merge_request.id, + create(:note_on_merge_request, noteable: merge_request, project: project) end it 'returns the note and merge request data' do expect(data).to have_key(:merge_request) expect(data[:merge_request].except('updated_at')) - .to eq(merge_request.hook_attrs.except('updated_at')) + .to eq(merge_request.reload.hook_attrs.except('updated_at')) expect(data[:merge_request]['updated_at']) .to be > merge_request.hook_attrs['updated_at'] end @@ -90,14 +90,14 @@ describe 'Gitlab::NoteDataBuilder', lib: true do end let(:note) do - create(:note_on_merge_request_diff, noteable_id: merge_request.id, + create(:note_on_merge_request_diff, noteable: merge_request, project: project) end it 'returns the note and merge request diff data' do expect(data).to have_key(:merge_request) expect(data[:merge_request].except('updated_at')) - .to eq(merge_request.hook_attrs.except('updated_at')) + .to eq(merge_request.reload.hook_attrs.except('updated_at')) expect(data[:merge_request]['updated_at']) .to be > merge_request.hook_attrs['updated_at'] end @@ -113,14 +113,14 @@ describe 'Gitlab::NoteDataBuilder', lib: true do end let!(:note) do - create(:note_on_project_snippet, noteable_id: snippet.id, + create(:note_on_project_snippet, noteable: snippet, project: project) end it 'returns the note and project snippet data' do expect(data).to have_key(:snippet) expect(data[:snippet].except('updated_at')) - .to eq(snippet.hook_attrs.except('updated_at')) + .to eq(snippet.reload.hook_attrs.except('updated_at')) expect(data[:snippet]['updated_at']) .to be > snippet.hook_attrs['updated_at'] end diff --git a/spec/models/legacy_diff_note_spec.rb b/spec/models/legacy_diff_note_spec.rb index 7c29bef54e4..b2d06853886 100644 --- a/spec/models/legacy_diff_note_spec.rb +++ b/spec/models/legacy_diff_note_spec.rb @@ -63,7 +63,9 @@ describe LegacyDiffNote, models: true do code = Gitlab::Diff::LineCode.generate(diff.new_path, line.new_pos, line.old_pos) # We're persisting in order to trigger the set_diff callback - note = create(:note_on_merge_request_diff, noteable: merge, line_code: code) + note = create(:note_on_merge_request_diff, noteable: merge, + line_code: code, + project: merge.source_project) # Make sure we don't get a false positive from a guard clause expect(note).to receive(:find_noteable_diff).and_call_original diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index 7013ffbf3e1..5f618322aab 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -211,7 +211,7 @@ describe HipchatService, models: true do end let(:merge_request_note) do - create(:note_on_merge_request, noteable_id: merge_request.id, + create(:note_on_merge_request, noteable: merge_request, project: project, note: "merge request note") end @@ -239,7 +239,7 @@ describe HipchatService, models: true do context 'when issue comment event triggered' do let(:issue) { create(:issue, project: project) } let(:issue_note) do - create(:note_on_issue, noteable_id: issue.id, project: project, + create(:note_on_issue, noteable: issue, project: project, note: "issue note") end @@ -264,7 +264,7 @@ describe HipchatService, models: true do context 'when snippet comment event triggered' do let(:snippet) { create(:project_snippet, project: project) } let(:snippet_note) do - create(:note_on_project_snippet, noteable_id: snippet.id, + create(:note_on_project_snippet, noteable: snippet, project: project, note: "snippet note") end |