determine recipients and queue notifications _after_ transaction commit
fixes CNVS-22546 test plan: * regression test notifications Change-Id: I7896f03b18b19003cff6228aefa72029a8c08a29 Reviewed-on: https://gerrit.instructure.com/61249 Reviewed-by: Joel Hough <joel@instructure.com> Tested-by: Jenkins QA-Review: Adrian Russell <arussell@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
dd43ace886
commit
7a261cbeef
|
@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|||
s.test_files = Dir["spec_canvas/**/*"]
|
||||
|
||||
s.add_dependency "activesupport"
|
||||
s.add_dependency "after_transaction_commit"
|
||||
s.add_development_dependency "rspec"
|
||||
s.add_development_dependency "pry"
|
||||
end
|
||||
|
|
|
@ -40,21 +40,23 @@ module BroadcastPolicy
|
|||
notification = BroadcastPolicy.notification_finder.by_name(self.dispatch)
|
||||
return if notification.nil?
|
||||
|
||||
to_list = record.instance_eval(&self.to)
|
||||
to_list = Array(to_list).flatten
|
||||
return if to_list.empty?
|
||||
record.connection.after_transaction_commit do
|
||||
to_list = record.instance_eval(&self.to)
|
||||
to_list = Array(to_list).flatten
|
||||
next if to_list.empty?
|
||||
|
||||
asset_context = record.instance_eval(&self.context) if self.context
|
||||
data = record.instance_eval(&self.data) if self.data
|
||||
asset_context = record.instance_eval(&self.context) if self.context
|
||||
data = record.instance_eval(&self.data) if self.data
|
||||
|
||||
BroadcastPolicy.notifier.send_notification(
|
||||
record,
|
||||
self.dispatch,
|
||||
notification,
|
||||
to_list,
|
||||
asset_context,
|
||||
data
|
||||
)
|
||||
BroadcastPolicy.notifier.send_notification(
|
||||
record,
|
||||
self.dispatch,
|
||||
notification,
|
||||
to_list,
|
||||
asset_context,
|
||||
data
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -10,6 +10,7 @@ describe BroadcastPolicy::NotificationPolicy do
|
|||
end
|
||||
|
||||
let(:test_notification) { double(:test_notification) }
|
||||
let(:test_connection_class) { Class.new { def after_transaction_commit; yield; end } }
|
||||
|
||||
before(:each) do
|
||||
BroadcastPolicy.notifier = MockNotifier.new
|
||||
|
@ -17,7 +18,7 @@ describe BroadcastPolicy::NotificationPolicy do
|
|||
end
|
||||
|
||||
it "should call the notifier" do
|
||||
record = double('test record', skip_broadcasts: false)
|
||||
record = double('test record', skip_broadcasts: false, connection: test_connection_class.new)
|
||||
subject.broadcast(record)
|
||||
expect(BroadcastPolicy.notifier.messages.count).to eq(1)
|
||||
end
|
||||
|
@ -36,21 +37,21 @@ describe BroadcastPolicy::NotificationPolicy do
|
|||
end
|
||||
|
||||
it "should not send if there is not a recipient list" do
|
||||
record = double('test object', skip_broadcasts: false)
|
||||
record = double('test object', skip_broadcasts: false, connection: test_connection_class.new)
|
||||
subject.to = ->(_) { nil }
|
||||
subject.broadcast(record)
|
||||
expect(BroadcastPolicy.notifier.messages).to be_empty
|
||||
end
|
||||
|
||||
it "should send even if there isn't a context" do
|
||||
record = double('test object', skip_broadcasts: false)
|
||||
record = double('test object', skip_broadcasts: false, connection: test_connection_class.new)
|
||||
subject.context = ->(_) { nil }
|
||||
subject.broadcast(record)
|
||||
expect(BroadcastPolicy.notifier.messages).to_not be_empty
|
||||
end
|
||||
|
||||
it "should send even if there isn't data" do
|
||||
record = double('test object', skip_broadcasts: false)
|
||||
record = double('test object', skip_broadcasts: false, connection: test_connection_class.new)
|
||||
subject.data = ->(_) { nil }
|
||||
subject.broadcast(record)
|
||||
expect(BroadcastPolicy.notifier.messages).to_not be_empty
|
||||
|
|
Loading…
Reference in New Issue