From 874413cf701870a0fc1051f7c0a5fc4b4f884657 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Mar 2017 09:28:47 -0600 Subject: [PATCH] Fix specs --- app/mailers/emails/notes.rb | 1 + app/mailers/notify.rb | 4 ++-- app/services/notes/build_service.rb | 4 +++- app/views/discussions/_notes.html.haml | 2 +- app/views/layouts/notify.html.haml | 4 ++-- app/views/notify/new_mention_in_issue_email.html.haml | 2 +- app/views/notify/new_mention_in_merge_request_email.html.haml | 2 +- spec/factories/sent_notifications.rb | 2 +- spec/models/discussion_note_spec.rb | 1 - spec/models/individual_note_discussion_spec.rb | 1 - spec/models/out_of_context_discussion_spec.rb | 1 - spec/models/sent_notification_spec.rb | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/mailers/emails/notes.rb b/app/mailers/emails/notes.rb index de58314fef2..a42745acd71 100644 --- a/app/mailers/emails/notes.rb +++ b/app/mailers/emails/notes.rb @@ -66,6 +66,7 @@ module Emails def setup_note_mail(note_id, recipient_id) @note = Note.find(note_id) @project = @note.project + return unless @project @sent_notification = SentNotification.record_note(@note, recipient_id, reply_key) end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 14df6f8f0a3..f315e38bcaa 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -111,7 +111,7 @@ class Notify < BaseMailer headers["X-GitLab-#{model.class.name}-ID"] = model.id headers['X-GitLab-Reply-Key'] = reply_key - if Gitlab::IncomingEmail.enabled? + if Gitlab::IncomingEmail.enabled? && @sent_notification address = Mail::Address.new(Gitlab::IncomingEmail.reply_address(reply_key)) address.display_name = @project.name_with_namespace @@ -176,6 +176,6 @@ class Notify < BaseMailer end headers['List-Unsubscribe'] = list_unsubscribe_methods.map { |e| "<#{e}>" }.join(',') - @sent_notification_url = unsubscribe_sent_notification_url(@sent_notification) + @unsubscribe_url = unsubscribe_sent_notification_url(@sent_notification) end end diff --git a/app/services/notes/build_service.rb b/app/services/notes/build_service.rb index 8d5a022d319..eddfcf5f391 100644 --- a/app/services/notes/build_service.rb +++ b/app/services/notes/build_service.rb @@ -2,6 +2,8 @@ module Notes class BuildService < BaseService def execute in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id) + new_discussion = params.delete(:new_discussion) + if project && in_reply_to_discussion_id.present? discussion = project.notes.find_original_discussion(in_reply_to_discussion_id) || @@ -14,7 +16,7 @@ module Notes end params.merge!(discussion.reply_attributes) - elsif params.delete(:new_discussion) + elsif new_discussion # TODO: Remove when we use a selectbox instead of a submit button params[:type] = DiscussionNote.name end diff --git a/app/views/discussions/_notes.html.haml b/app/views/discussions/_notes.html.haml index c8fcc37d1ab..d7b2abf1269 100644 --- a/app/views/discussions/_notes.html.haml +++ b/app/views/discussions/_notes.html.haml @@ -11,7 +11,7 @@ = link_to_reply_discussion(discussion, line_type) = render "discussions/resolve_all", discussion: discussion - + .btn-group.discussion-actions = render "discussions/new_issue_for_discussion", discussion: discussion, merge_request: discussion.noteable = render "discussions/jump_to_next", discussion: discussion diff --git a/app/views/layouts/notify.html.haml b/app/views/layouts/notify.html.haml index 76268c1b705..40bf45cece7 100644 --- a/app/views/layouts/notify.html.haml +++ b/app/views/layouts/notify.html.haml @@ -25,8 +25,8 @@ - if @labels_url adjust your #{link_to 'label subscriptions', @labels_url}. - else - - if @sent_notification_url - = link_to "unsubscribe", @sent_notification_url + - if @unsubscribe_url + = link_to "unsubscribe", @unsubscribe_url from this thread or adjust your notification settings. diff --git a/app/views/notify/new_mention_in_issue_email.html.haml b/app/views/notify/new_mention_in_issue_email.html.haml index d7c22219285..6b45ac265f7 100644 --- a/app/views/notify/new_mention_in_issue_email.html.haml +++ b/app/views/notify/new_mention_in_issue_email.html.haml @@ -1,4 +1,4 @@ %p You have been mentioned in an issue. -= render template: 'new_issue_email' += render template: 'notify/new_issue_email' diff --git a/app/views/notify/new_mention_in_merge_request_email.html.haml b/app/views/notify/new_mention_in_merge_request_email.html.haml index 07d8c301988..b061f9c106e 100644 --- a/app/views/notify/new_mention_in_merge_request_email.html.haml +++ b/app/views/notify/new_mention_in_merge_request_email.html.haml @@ -1,4 +1,4 @@ %p You have been mentioned in Merge Request #{@merge_request.to_reference} -= render template: 'new_merge_request_email' += render template: 'notify/new_merge_request_email' diff --git a/spec/factories/sent_notifications.rb b/spec/factories/sent_notifications.rb index 0590bf999c0..99253be5a22 100644 --- a/spec/factories/sent_notifications.rb +++ b/spec/factories/sent_notifications.rb @@ -2,7 +2,7 @@ FactoryGirl.define do factory :sent_notification do project factory: :empty_project recipient factory: :user - noteable factory: :issue + noteable { create(:issue, project: project) } reply_key { SentNotification.reply_key } end end diff --git a/spec/models/discussion_note_spec.rb b/spec/models/discussion_note_spec.rb index 49084c854d8..c9dd3d45270 100644 --- a/spec/models/discussion_note_spec.rb +++ b/spec/models/discussion_note_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' describe DiscussionNote, models: true do - end diff --git a/spec/models/individual_note_discussion_spec.rb b/spec/models/individual_note_discussion_spec.rb index 3938dfc4bb1..1f7c2c820e0 100644 --- a/spec/models/individual_note_discussion_spec.rb +++ b/spec/models/individual_note_discussion_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' describe IndividualNoteDiscussion, models: true do - end diff --git a/spec/models/out_of_context_discussion_spec.rb b/spec/models/out_of_context_discussion_spec.rb index d765e7052d1..1bcd118855e 100644 --- a/spec/models/out_of_context_discussion_spec.rb +++ b/spec/models/out_of_context_discussion_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' describe OutOfContextDiscussion, model: true do - end diff --git a/spec/models/sent_notification_spec.rb b/spec/models/sent_notification_spec.rb index 7a7ece24fc9..e482cafa831 100644 --- a/spec/models/sent_notification_spec.rb +++ b/spec/models/sent_notification_spec.rb @@ -4,7 +4,7 @@ describe SentNotification, model: true do describe 'validation' do describe 'note validity' do context "when the project doesn't match the noteable's project" do - subject { build(:sent_notification, project: create(:project)) } + subject { build(:sent_notification, noteable: create(:issue)) } it "is invalid" do expect(subject).not_to be_valid