Skip to content

Commit cd59cb6

Browse files
lukfuglsimonista
authored andcommitted
don't perform mute/unmute side effects w/o change
fixes CNVS-21979 particularly, if an assignment is already unmuted, don't trigger "just unmuted" broadcast events when "unmute!" is called test-plan: - have your account configured to receive unmute notification - edit an unmuted assignment in a published course you're enrolled in - save it with the "Mute" checkbox still off - don't receive an unmute notification Change-Id: I948b5f1b2176e574ecf43fcde187019d7eadb50d Reviewed-on: https://gerrit.instructure.com/58788 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins QA-Review: Ben Bolton <bbolton@instructure.com> Product-Review: Matt Fairbourn <mfairbourn@instructure.com>
1 parent 4fb8066 commit cd59cb6

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

lib/mutable.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ def declare_mutable_broadcast_policy(options)
2020
end
2121

2222
def mute!
23+
return if muted?
2324
self.update_attribute(:muted, true)
2425
clear_sent_messages
2526
hide_stream_items
2627
end
2728

2829
def unmute!
30+
return unless muted?
2931
self.update_attribute(:muted, false)
3032
broadcast_unmute_event
3133
show_stream_items

spec/lib/mutable_spec.rb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# Copyright (C) 2015 Instructure, Inc.
3+
#
4+
# This file is part of Canvas.
5+
#
6+
# Canvas is free software: you can redistribute it and/or modify it under
7+
# the terms of the GNU Affero General Public License as published by the Free
8+
# Software Foundation, version 3 of the License.
9+
#
10+
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
11+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12+
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13+
# details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License along
16+
# with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
20+
21+
describe Mutable do
22+
before do
23+
@klass = Class.new do
24+
# the signature that Mutable requires. if we care about side
25+
# effects/return values from these methods for specific tests, we'll mock
26+
# them
27+
def muted?; end
28+
def update_attribute(*args); end
29+
def save!; end
30+
31+
include Mutable
32+
end
33+
34+
@mutable = @klass.new
35+
end
36+
37+
describe "mute!" do
38+
it "updates if not yet muted" do
39+
@mutable.expects(:muted?).returns(false)
40+
@mutable.expects(:update_attribute).once.with(:muted, true)
41+
@mutable.mute!
42+
end
43+
44+
it "skips update if already muted" do
45+
@mutable.expects(:muted?).returns(true)
46+
@mutable.expects(:update_attribute).never
47+
@mutable.mute!
48+
end
49+
end
50+
51+
describe "unmute!" do
52+
it "updates if currently muted" do
53+
@mutable.expects(:muted?).returns(true)
54+
@mutable.expects(:update_attribute).once.with(:muted, false)
55+
@mutable.unmute!
56+
end
57+
58+
it "skips update if not muted" do
59+
@mutable.expects(:muted?).returns(false)
60+
@mutable.expects(:update_attribute).never
61+
@mutable.unmute!
62+
end
63+
64+
it "broadcasts unmute event if currently muted" do
65+
@mutable.expects(:muted?).returns(true)
66+
@mutable.expects(:broadcast_unmute_event).once
67+
@mutable.unmute!
68+
end
69+
70+
it "skips unmute event if not muted" do
71+
@mutable.expects(:muted?).returns(false)
72+
@mutable.expects(:broadcast_unmute_event).never
73+
@mutable.unmute!
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)