From 2cb69ae0d7595463f92ec7f9646ac82f77315a60 Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Tue, 3 May 2011 11:03:24 -0600 Subject: [PATCH] use user host url for summary message links, fixes #4455 Change-Id: Iddfd3b9c72cd9367b5bcb22928de3adfe795c4e8 Reviewed-on: https://gerrit.instructure.com/3440 Reviewed-by: Zach Wily Tested-by: Hudson --- app/messages/summaries.email.erb | 4 ++-- spec/factories/notification_factory.rb | 3 +-- spec/models/delayed_message_spec.rb | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/messages/summaries.email.erb b/app/messages/summaries.email.erb index 9de4a93ed08..e558502fa35 100644 --- a/app/messages/summaries.email.erb +++ b/app/messages/summaries.email.erb @@ -1,5 +1,5 @@ <% define_content :link do %> - http://<%= HostUrl.default_host %> + http://<%= HostUrl.context_host(user.pseudonym.try(:account)) %> <% end %> <% define_content :subject do %> @@ -25,4 +25,4 @@ You can change your notification settings by visiting the following page: -http://<%= HostUrl.default_host %>/profile/communication \ No newline at end of file +http://<%= HostUrl.context_host(user.pseudonym.try(:account)) %>/profile/communication diff --git a/spec/factories/notification_factory.rb b/spec/factories/notification_factory.rb index 878f7fd294f..2809f02162f 100644 --- a/spec/factories/notification_factory.rb +++ b/spec/factories/notification_factory.rb @@ -17,7 +17,6 @@ # def notification_model(opts={}) - Notification.find(:all).each{|n| n.destroy } @notification = Notification.create!(notification_valid_attributes.merge(opts)) end @@ -28,4 +27,4 @@ def notification_valid_attributes :body => "value for body", :category => "TestImmediately" } -end \ No newline at end of file +end diff --git a/spec/models/delayed_message_spec.rb b/spec/models/delayed_message_spec.rb index 49f14fc40c6..adaec1f5c71 100644 --- a/spec/models/delayed_message_spec.rb +++ b/spec/models/delayed_message_spec.rb @@ -111,4 +111,19 @@ describe DelayedMessage do @delayed_message.state.should eql(:sent) end end + + it "should use the user's main account domain for links" do + Canvas::MessageHelper.create_notification('Summary', 'Summaries', 0, '', 'Summaries') + account = Account.create!(:name => 'new acct') + user = user_with_pseudonym(:account => account) + user.pseudonym.update_attribute(:account, account) + user.pseudonym.account.should == account + HostUrl.should_receive(:context_host).with(user.pseudonym.account).at_least(:once).and_return("dm.dummy.test.host") + HostUrl.should_receive(:default_host).any_number_of_times.and_return("test.host") + dm = DelayedMessage.create!(:summary => "This is a notification", :context => Account.default, :communication_channel => user.communication_channel, :notification => notification_model) + DelayedMessage.summarize([dm]) + message = Message.last + message.body.to_s.should_not match(%r{http://test.host/}) + message.body.to_s.should match(%r{http://dm.dummy.test.host/}) + end end