create summary messages on the user's shard
Change-Id: I35324dac349907031c0737a8eb9f4d2f9444255f Reviewed-on: https://gerrit.instructure.com/30090 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
ee625244ef
commit
fc60771d78
|
@ -27,6 +27,7 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
has_many :pseudonyms
|
||||
belongs_to :user
|
||||
has_many :notification_policies, :dependent => :destroy
|
||||
has_many :delayed_messages
|
||||
has_many :messages
|
||||
belongs_to :access_token
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ class NotificationPolicy < ActiveRecord::Base
|
|||
|
||||
belongs_to :notification
|
||||
belongs_to :communication_channel
|
||||
has_many :delayed_messages
|
||||
|
||||
attr_accessible :notification, :communication_channel, :frequency, :notification_id, :communication_channel_id
|
||||
|
||||
|
|
|
@ -112,8 +112,7 @@ class NotificationMessageCreator
|
|||
def build_fallback_for(user)
|
||||
fallback_channel = immediate_channels_for(user).sort_by(&:path_type).first
|
||||
fallback_policy = fallback_channel.notification_policies.by('daily').where(:notification_id => nil).first
|
||||
fallback_policy ||= NotificationPolicy.new(:communication_channel => fallback_channel,
|
||||
:frequency => 'daily')
|
||||
fallback_policy ||= fallback_channel.notification_policies.create!(frequency: 'daily')
|
||||
|
||||
build_summary_for(user, fallback_policy)
|
||||
end
|
||||
|
@ -125,15 +124,14 @@ class NotificationMessageCreator
|
|||
def build_summary_for(user, policy)
|
||||
message = user.messages.build(message_options_for(user))
|
||||
message.parse!('summary')
|
||||
delayed_message = DelayedMessage.new(:notification => @notification,
|
||||
:notification_policy => policy,
|
||||
:frequency => policy.frequency,
|
||||
:communication_channel_id => policy.communication_channel_id,
|
||||
:root_account_id => message.context_root_account.try(:id),
|
||||
:linked_name => 'work on this link!!!',
|
||||
:name_of_topic => message.subject,
|
||||
:link => message.url,
|
||||
:summary => message.body)
|
||||
delayed_message = policy.delayed_messages.build(:notification => @notification,
|
||||
:frequency => policy.frequency,
|
||||
:communication_channel_id => policy.communication_channel_id,
|
||||
:root_account_id => message.context_root_account.try(:id),
|
||||
:linked_name => 'work on this link!!!',
|
||||
:name_of_topic => message.subject,
|
||||
:link => message.url,
|
||||
:summary => message.body)
|
||||
delayed_message.context = @asset
|
||||
delayed_message.save! if Rails.env.test?
|
||||
delayed_message
|
||||
|
|
|
@ -388,15 +388,19 @@ describe NotificationMessageCreator do
|
|||
end
|
||||
end
|
||||
|
||||
it "should create policies on the user's shard" do
|
||||
it "should create policies and summary messages on the user's shard" do
|
||||
@shard1.activate do
|
||||
@user = User.create!
|
||||
@user.communication_channels.create!(path: "user@example.com").confirm!
|
||||
@cc = @user.communication_channels.create!(path: "user@example.com")
|
||||
@cc.confirm!
|
||||
end
|
||||
notification_model(category: 'TestWeekly')
|
||||
creator = NotificationMessageCreator.new(@notification, nil)
|
||||
creator.expects(:too_many_messages_for?).returns(false)
|
||||
creator.send(:delayed_policies_for, @user).first.shard.should == @shard1
|
||||
Message.any_instance.stubs(:get_template).returns('template')
|
||||
@cc.notification_policies.should be_empty
|
||||
@cc.delayed_messages.should be_empty
|
||||
NotificationMessageCreator.new(@notification, @user, :to_list => @user).create_message
|
||||
@cc.notification_policies.should_not be_empty
|
||||
@cc.delayed_messages.reload.should_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue