create messages from DelayedMessage.summarize on the user's shard

fixes CNVS-1714

test plan:
 * do an action that goes through DelayedMessage.summarize
   (I think just means setting some notifications to every 5 minutes
    or something)
 * wait the five minutes
 * the message(s) should show up in /users/x/messages

Change-Id: Ibcc646f9ec869543b8ba84c1d7c7f8171ce55d78
Reviewed-on: https://gerrit.instructure.com/17166
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jacob Fugal <jacob@instructure.com>
QA-Review: Clare Hetherington <clare@instructure.com>
This commit is contained in:
Cody Cutrer 2013-01-25 16:36:23 -07:00
parent cd0f84a0ba
commit 16a53809c8
2 changed files with 22 additions and 4 deletions

View File

@ -114,14 +114,13 @@ class DelayedMessage < ActiveRecord::Base
return nil unless context # the context for this message has already been deleted
notification = Notification.by_name('Summaries')
path = HostUrl.outgoing_email_address
message = notification.messages.build(
message = to.messages.build(
:subject => notification.subject,
:to => to.path,
:body => notification.body,
:notification_name => notification.name,
:notification => notification,
:from => path,
:communication_channel => to,
:user => user
)
message.delayed_messages = delayed_messages

View File

@ -16,7 +16,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
require File.expand_path(File.dirname(__FILE__) + '/../sharding_spec_helper.rb')
describe DelayedMessage do
it "should create a new instance given valid attributes" do
@ -123,7 +123,6 @@ describe DelayedMessage 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.expects(:context_host).with(user.pseudonym.account).at_least(1).returns("dm.dummy.test.host")
HostUrl.stubs(:default_host).returns("test.host")
@ -134,6 +133,26 @@ describe DelayedMessage do
message.body.to_s.should match(%r{http://dm.dummy.test.host/})
end
context "sharding" do
it_should_behave_like "sharding"
it "should create messages on the user's shard" do
Canvas::MessageHelper.create_notification('Summary', 'Summaries', 0, '', 'Summaries')
@shard1.activate do
account = Account.create!(:name => 'new acct')
user = user_with_pseudonym(:account => account)
user.pseudonym.account.should == account
HostUrl.expects(:context_host).with(user.pseudonym.account).at_least(1).returns("dm.dummy.test.host")
HostUrl.stubs(:default_host).returns("test.host")
dm = DelayedMessage.create!(:summary => "This is a notification", :context => Account.default, :communication_channel => user.communication_channel, :notification => notification_model)
DelayedMessage.summarize([dm])
end
@cc.messages.last.should_not be_nil
@cc.messages.last.shard.should == @shard1
end
end
describe "set_send_at" do
def force_now(time)
[@mountain, @central, @eastern].each do |time_zone|