Skip to content

Commit b2a4883

Browse files
rashidspmikeproeng37
authored andcommitted
Renames notification-center methods (#117)
1 parent ea0d318 commit b2a4883

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

lib/optimizely/notification_center.rb

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2017, Optimizely and contributors
4+
# Copyright 2017-2018, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -86,20 +86,31 @@ def remove_notification_listener(notification_id)
8686
false
8787
end
8888

89+
# @deprecated Use {#clear_notification_listeners} instead.
8990
def clear_notifications(notification_type)
90-
# Removes notifications for a certain notification type
91-
#
92-
# Args:
93-
# notification_type: one of the constants in NOTIFICATION_TYPES
91+
@logger.log Logger::WARN, "'clear_notifications' is deprecated. Call 'clear_notification_listeners' instead."
92+
clear_notification_listeners(notification_type)
93+
end
9494

95+
# Removes notifications for a certain notification type
96+
#
97+
# @param notification_type - one of the constants in NOTIFICATION_TYPES
98+
99+
def clear_notification_listeners(notification_type)
95100
return nil unless notification_type_valid?(notification_type)
96101

97102
@notifications[notification_type] = []
98103
@logger.log Logger::INFO, "All callbacks for notification type #{notification_type} have been removed."
99104
end
100105

106+
# @deprecated Use {#clear_all_notification_listeners} instead.
101107
def clean_all_notifications
102-
# Removes all notifications
108+
@logger.log Logger::WARN, "'clean_all_notifications' is deprecated. Call 'clear_all_notification_listeners' instead."
109+
clear_all_notification_listeners
110+
end
111+
112+
# Removes all notifications
113+
def clear_all_notification_listeners
103114
@notifications.each_key { |key| @notifications[key] = [] }
104115
end
105116

spec/notification_center_spec.rb

+25-8
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def call; end
255255

256256
it 'should not remove notifications for an invalid notification type' do
257257
invalid_type = 'Invalid notification'
258-
expect { @inner_notification_center.clear_notifications(invalid_type) }
258+
expect { @inner_notification_center.clear_notification_listeners(invalid_type) }
259259
.to raise_error(Optimizely::InvalidNotificationType)
260260
expect(spy_logger).to have_received(:log).once
261261
.with(Logger::ERROR, 'Invalid notification type.')
@@ -273,7 +273,7 @@ def call; end
273273

274274
it 'should remove all notifications for a valid notification type' do
275275
notification_type = Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]
276-
@inner_notification_center.clear_notifications(notification_type)
276+
@inner_notification_center.clear_notification_listeners(notification_type)
277277
expect(spy_logger).to have_received(:log).once
278278
.with(Logger::INFO, "All callbacks for notification type #{notification_type} have been removed.")
279279
expect(
@@ -288,10 +288,19 @@ def call; end
288288
).to eq(1)
289289
end
290290

291-
it 'should not throw an error when clear_notifications is called again for the same notification type' do
291+
it 'should call clear_notification_listeners and log depreciation message' do
292292
notification_type = Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]
293+
expect(@inner_notification_center).to receive(:clear_notification_listeners).once.with(notification_type)
293294
@inner_notification_center.clear_notifications(notification_type)
294-
expect { @inner_notification_center.clear_notifications(notification_type) }
295+
expect(spy_logger).to have_received(:log).once.with(
296+
Logger::WARN, "'clear_notifications' is deprecated. Call 'clear_notification_listeners' instead."
297+
)
298+
end
299+
300+
it 'should not throw an error when clear_notification_listeners is called again for the same notification type' do
301+
notification_type = Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]
302+
@inner_notification_center.clear_notification_listeners(notification_type)
303+
expect { @inner_notification_center.clear_notification_listeners(notification_type) }
295304
.to_not raise_error(Optimizely::InvalidNotificationType)
296305
expect(
297306
@inner_notification_center.notifications[
@@ -361,17 +370,25 @@ def call; end
361370
end
362371

363372
it 'should remove all notifications for each notification type' do
364-
@inner_notification_center.clean_all_notifications
373+
@inner_notification_center.clear_all_notification_listeners
365374
@inner_notification_center.notifications.each_key do |key|
366375
expect(@inner_notification_center.notifications[key]).to be_empty
367376
end
368377
end
369378

370-
it 'clean_all_notifications does not throw an error when called again' do
371-
@inner_notification_center.clean_all_notifications
372-
expect { @inner_notification_center.clean_all_notifications }
379+
it 'clear_all_notification_listeners does not throw an error when called again' do
380+
@inner_notification_center.clear_all_notification_listeners
381+
expect { @inner_notification_center.clear_all_notification_listeners }
373382
.to_not raise_error
374383
end
384+
385+
it 'should call clear_all_notification_listeners and log depreciation message' do
386+
expect(@inner_notification_center).to receive(:clear_all_notification_listeners).once
387+
@inner_notification_center.clean_all_notifications
388+
expect(spy_logger).to have_received(:log).once.with(
389+
Logger::WARN, "'clean_all_notifications' is deprecated. Call 'clear_all_notification_listeners' instead."
390+
)
391+
end
375392
end
376393

377394
describe '.send_notifications' do

0 commit comments

Comments
 (0)