Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ Layout/SpaceInsideHashLiteralBraces:
Naming/VariableNumber:
Enabled: false

Lint/RescueWithoutErrorClass:
Style/RescueStandardError:
Enabled: false
1 change: 0 additions & 1 deletion lib/optimizely/notification_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def initialize(logger, error_handler)

def add_notification_listener(notification_type, notification_callback)
return nil unless notification_type_valid?(notification_type)

unless notification_callback
@logger.log Logger::ERROR, 'Callback can not be empty.'
return nil
Expand Down
6 changes: 3 additions & 3 deletions optimizely-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.4.0'
spec.add_development_dependency 'rubocop', '~> 0.51.0'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rspec', '~> 3.7.0'
spec.add_development_dependency 'rubocop', '~> 0.56.0'

spec.add_runtime_dependency 'httparty', '~> 0.11'
spec.add_runtime_dependency 'json-schema', '~> 2.6'
Expand Down
2 changes: 1 addition & 1 deletion spec/bucketing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_bucketing_key(bucketing_id, entity_id = nil)
expect(bucketer.send(:generate_bucket_value, get_bucketing_key(
'a very very very very very very very very very very very very '\
'very very very long ppd string'
))).to eq(6128)
))).to eq(6128)
end

it 'should return the proper variation for a user in a mutually exclusive grouped experiment' do
Expand Down
37 changes: 18 additions & 19 deletions spec/notification_center_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ def call; end
describe 'test add notification with invalid params' do
it 'should log and return nil if notification type is empty' do
expect(notification_center.add_notification_listener(
nil,
@callback_reference
)).to eq(nil)
nil, @callback_reference
)).to eq(nil)
expect(spy_logger).to have_received(:log).once
.with(Logger::ERROR, 'Notification type can not be empty.')
end
Expand All @@ -52,7 +51,7 @@ def call; end
expect(notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
nil
)).to eq(nil)
)).to eq(nil)
expect(spy_logger).to have_received(:log).once
.with(Logger::ERROR, 'Callback can not be empty.')
end
Expand All @@ -61,7 +60,7 @@ def call; end
expect(notification_center.add_notification_listener(
'Test notification type',
@callback_reference
)).to eq(nil)
)).to eq(nil)
expect(spy_logger).to have_received(:log).once
.with(Logger::ERROR, 'Invalid notification type.')
end
Expand All @@ -70,7 +69,7 @@ def call; end
expect(notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
'Invalid callback!'
)).to eq(nil)
)).to eq(nil)
expect(spy_logger).to have_received(:log).once
.with(Logger::ERROR, 'Invalid notification callback given.')
end
Expand All @@ -81,7 +80,7 @@ def call; end
expect(notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference
)).to eq(1)
)).to eq(1)
# verifies that one notification is added
expect(notification_center.notifications[Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]].length)
.to eq(1)
Expand All @@ -95,7 +94,7 @@ def call; end
expect(notification_center.add_notification_listener(
value,
@callback_reference
)).to eq(notification_id)
)).to eq(notification_id)
end
notification_center.notifications.each_key do |key|
expect(notification_center.notifications[key].length)
Expand Down Expand Up @@ -141,19 +140,19 @@ def call; end
expect(notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference
)).to eq(-1)
)).to eq(-1)
end

it 'should add same callback for a different notification type' do
expect(notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference
)).to eq(1)
)).to eq(1)

expect(notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK],
@callback_reference
)).to eq(2)
)).to eq(2)
end
end

Expand All @@ -169,18 +168,18 @@ def call; end
expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference
)).to eq(1)
)).to eq(1)

expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK],
@callback_reference
)).to eq(2)
)).to eq(2)

# add another callback for NOTIFICATION_TYPES::ACTIVATE
expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference_second
)).to eq(3)
)).to eq(3)
# Verify that notifications length for NOTIFICATION_TYPES::ACTIVATE is 2
expect(@inner_notification_center.notifications[
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]].length).to eq(2)
Expand Down Expand Up @@ -338,27 +337,27 @@ def call; end
expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference
)).to eq(1)
)).to eq(1)

expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference_second
)).to eq(2)
)).to eq(2)

expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE],
@callback_reference_third
)).to eq(3)
)).to eq(3)

expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK],
@callback_reference
)).to eq(4)
)).to eq(4)

expect(@inner_notification_center.add_notification_listener(
Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK],
@callback_reference_second
)).to eq(5)
)).to eq(5)

# verify that notifications length for each type reflects the just added callbacks

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
require 'coveralls'
Coveralls.wear!
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'optimizely'
require 'spec_params'

Expand Down