rpush_extended 3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +365 -0
- data/LICENSE +7 -0
- data/README.md +393 -0
- data/bin/rpush +4 -0
- data/lib/generators/rpush_config_generator.rb +7 -0
- data/lib/generators/rpush_migration_generator.rb +66 -0
- data/lib/generators/templates/add_adm.rb +23 -0
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +9 -0
- data/lib/generators/templates/add_app_to_rapns.rb +11 -0
- data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +9 -0
- data/lib/generators/templates/add_gcm.rb +117 -0
- data/lib/generators/templates/add_rpush.rb +402 -0
- data/lib/generators/templates/add_wpns.rb +16 -0
- data/lib/generators/templates/create_rapns_apps.rb +16 -0
- data/lib/generators/templates/create_rapns_feedback.rb +25 -0
- data/lib/generators/templates/create_rapns_notifications.rb +36 -0
- data/lib/generators/templates/rename_rapns_to_rpush.rb +87 -0
- data/lib/generators/templates/rpush.rb +135 -0
- data/lib/generators/templates/rpush_2_0_0_updates.rb +79 -0
- data/lib/generators/templates/rpush_2_1_0_updates.rb +11 -0
- data/lib/generators/templates/rpush_2_6_0_updates.rb +10 -0
- data/lib/generators/templates/rpush_2_7_0_updates.rb +12 -0
- data/lib/generators/templates/rpush_3_0_0_updates.rb +11 -0
- data/lib/generators/templates/rpush_3_0_1_updates.rb +13 -0
- data/lib/generators/templates/rpush_3_1_0_add_pushy.rb +9 -0
- data/lib/generators/templates/rpush_3_1_1_updates.rb +15 -0
- data/lib/generators/templates/rpush_3_2_0_add_apns_p8.rb +15 -0
- data/lib/generators/templates/rpush_3_2_4_updates.rb +9 -0
- data/lib/generators/templates/rpush_3_3_0_updates.rb +9 -0
- data/lib/generators/templates/rpush_3_3_1_updates.rb +11 -0
- data/lib/rpush/apns_feedback.rb +17 -0
- data/lib/rpush/cli.rb +213 -0
- data/lib/rpush/client/active_model/adm/app.rb +23 -0
- data/lib/rpush/client/active_model/adm/data_validator.rb +14 -0
- data/lib/rpush/client/active_model/adm/notification.rb +28 -0
- data/lib/rpush/client/active_model/apns/app.rb +37 -0
- data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +16 -0
- data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +14 -0
- data/lib/rpush/client/active_model/apns/notification.rb +104 -0
- data/lib/rpush/client/active_model/apns2/app.rb +15 -0
- data/lib/rpush/client/active_model/apns2/notification.rb +9 -0
- data/lib/rpush/client/active_model/apnsp8/app.rb +23 -0
- data/lib/rpush/client/active_model/apnsp8/notification.rb +9 -0
- data/lib/rpush/client/active_model/gcm/app.rb +19 -0
- data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +14 -0
- data/lib/rpush/client/active_model/gcm/notification.rb +59 -0
- data/lib/rpush/client/active_model/notification.rb +22 -0
- data/lib/rpush/client/active_model/payload_data_size_validator.rb +13 -0
- data/lib/rpush/client/active_model/pushy/app.rb +20 -0
- data/lib/rpush/client/active_model/pushy/notification.rb +31 -0
- data/lib/rpush/client/active_model/pushy/time_to_live_validator.rb +14 -0
- data/lib/rpush/client/active_model/registration_ids_count_validator.rb +13 -0
- data/lib/rpush/client/active_model/wns/app.rb +23 -0
- data/lib/rpush/client/active_model/wns/notification.rb +32 -0
- data/lib/rpush/client/active_model/wpns/app.rb +13 -0
- data/lib/rpush/client/active_model/wpns/notification.rb +28 -0
- data/lib/rpush/client/active_model.rb +34 -0
- data/lib/rpush/client/active_record/adm/app.rb +11 -0
- data/lib/rpush/client/active_record/adm/notification.rb +11 -0
- data/lib/rpush/client/active_record/apns/app.rb +11 -0
- data/lib/rpush/client/active_record/apns/feedback.rb +18 -0
- data/lib/rpush/client/active_record/apns/notification.rb +40 -0
- data/lib/rpush/client/active_record/apns2/app.rb +11 -0
- data/lib/rpush/client/active_record/apns2/notification.rb +10 -0
- data/lib/rpush/client/active_record/apnsp8/app.rb +11 -0
- data/lib/rpush/client/active_record/apnsp8/notification.rb +10 -0
- data/lib/rpush/client/active_record/app.rb +13 -0
- data/lib/rpush/client/active_record/gcm/app.rb +11 -0
- data/lib/rpush/client/active_record/gcm/notification.rb +11 -0
- data/lib/rpush/client/active_record/notification.rb +42 -0
- data/lib/rpush/client/active_record/pushy/app.rb +11 -0
- data/lib/rpush/client/active_record/pushy/notification.rb +11 -0
- data/lib/rpush/client/active_record/wns/app.rb +11 -0
- data/lib/rpush/client/active_record/wns/badge_notification.rb +15 -0
- data/lib/rpush/client/active_record/wns/notification.rb +11 -0
- data/lib/rpush/client/active_record/wns/raw_notification.rb +13 -0
- data/lib/rpush/client/active_record/wpns/app.rb +11 -0
- data/lib/rpush/client/active_record/wpns/notification.rb +11 -0
- data/lib/rpush/client/active_record.rb +33 -0
- data/lib/rpush/client/redis/adm/app.rb +14 -0
- data/lib/rpush/client/redis/adm/notification.rb +11 -0
- data/lib/rpush/client/redis/apns/app.rb +11 -0
- data/lib/rpush/client/redis/apns/feedback.rb +20 -0
- data/lib/rpush/client/redis/apns/notification.rb +11 -0
- data/lib/rpush/client/redis/apns2/app.rb +11 -0
- data/lib/rpush/client/redis/apns2/notification.rb +11 -0
- data/lib/rpush/client/redis/apnsp8/app.rb +11 -0
- data/lib/rpush/client/redis/apnsp8/notification.rb +11 -0
- data/lib/rpush/client/redis/app.rb +29 -0
- data/lib/rpush/client/redis/gcm/app.rb +11 -0
- data/lib/rpush/client/redis/gcm/notification.rb +11 -0
- data/lib/rpush/client/redis/notification.rb +74 -0
- data/lib/rpush/client/redis/pushy/app.rb +16 -0
- data/lib/rpush/client/redis/pushy/notification.rb +18 -0
- data/lib/rpush/client/redis/wns/app.rb +14 -0
- data/lib/rpush/client/redis/wns/badge_notification.rb +15 -0
- data/lib/rpush/client/redis/wns/notification.rb +11 -0
- data/lib/rpush/client/redis/wns/raw_notification.rb +11 -0
- data/lib/rpush/client/redis/wpns/app.rb +11 -0
- data/lib/rpush/client/redis/wpns/notification.rb +11 -0
- data/lib/rpush/client/redis.rb +56 -0
- data/lib/rpush/configuration.rb +115 -0
- data/lib/rpush/daemon/adm/delivery.rb +226 -0
- data/lib/rpush/daemon/adm.rb +9 -0
- data/lib/rpush/daemon/apns/delivery.rb +43 -0
- data/lib/rpush/daemon/apns/feedback_receiver.rb +90 -0
- data/lib/rpush/daemon/apns.rb +17 -0
- data/lib/rpush/daemon/apns2/delivery.rb +127 -0
- data/lib/rpush/daemon/apns2.rb +10 -0
- data/lib/rpush/daemon/apnsp8/delivery.rb +166 -0
- data/lib/rpush/daemon/apnsp8/token.rb +43 -0
- data/lib/rpush/daemon/apnsp8.rb +10 -0
- data/lib/rpush/daemon/app_runner.rb +190 -0
- data/lib/rpush/daemon/batch.rb +138 -0
- data/lib/rpush/daemon/constants.rb +59 -0
- data/lib/rpush/daemon/delivery.rb +46 -0
- data/lib/rpush/daemon/delivery_error.rb +27 -0
- data/lib/rpush/daemon/dispatcher/apns_http2.rb +51 -0
- data/lib/rpush/daemon/dispatcher/apns_tcp.rb +152 -0
- data/lib/rpush/daemon/dispatcher/apnsp8_http2.rb +33 -0
- data/lib/rpush/daemon/dispatcher/http.rb +21 -0
- data/lib/rpush/daemon/dispatcher/tcp.rb +22 -0
- data/lib/rpush/daemon/dispatcher_loop.rb +73 -0
- data/lib/rpush/daemon/errors.rb +18 -0
- data/lib/rpush/daemon/feeder.rb +69 -0
- data/lib/rpush/daemon/gcm/delivery.rb +241 -0
- data/lib/rpush/daemon/gcm.rb +9 -0
- data/lib/rpush/daemon/interruptible_sleep.rb +24 -0
- data/lib/rpush/daemon/loggable.rb +33 -0
- data/lib/rpush/daemon/proc_title.rb +17 -0
- data/lib/rpush/daemon/pushy/delivery.rb +90 -0
- data/lib/rpush/daemon/pushy.rb +9 -0
- data/lib/rpush/daemon/queue_payload.rb +12 -0
- data/lib/rpush/daemon/retry_header_parser.rb +23 -0
- data/lib/rpush/daemon/retryable_error.rb +22 -0
- data/lib/rpush/daemon/ring_buffer.rb +16 -0
- data/lib/rpush/daemon/rpc/client.rb +27 -0
- data/lib/rpush/daemon/rpc/server.rb +82 -0
- data/lib/rpush/daemon/rpc.rb +9 -0
- data/lib/rpush/daemon/service_config_methods.rb +51 -0
- data/lib/rpush/daemon/signal_handler.rb +75 -0
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +80 -0
- data/lib/rpush/daemon/store/active_record.rb +214 -0
- data/lib/rpush/daemon/store/interface.rb +20 -0
- data/lib/rpush/daemon/store/redis.rb +166 -0
- data/lib/rpush/daemon/string_helpers.rb +15 -0
- data/lib/rpush/daemon/synchronizer.rb +62 -0
- data/lib/rpush/daemon/tcp_connection.rb +190 -0
- data/lib/rpush/daemon/wns/badge_request.rb +32 -0
- data/lib/rpush/daemon/wns/delivery.rb +178 -0
- data/lib/rpush/daemon/wns/post_request.rb +33 -0
- data/lib/rpush/daemon/wns/raw_request.rb +22 -0
- data/lib/rpush/daemon/wns/toast_request.rb +54 -0
- data/lib/rpush/daemon/wns.rb +9 -0
- data/lib/rpush/daemon/wpns/delivery.rb +132 -0
- data/lib/rpush/daemon/wpns.rb +9 -0
- data/lib/rpush/daemon.rb +179 -0
- data/lib/rpush/deprecatable.rb +24 -0
- data/lib/rpush/deprecation.rb +26 -0
- data/lib/rpush/embed.rb +41 -0
- data/lib/rpush/logger.rb +92 -0
- data/lib/rpush/multi_json_helper.rb +16 -0
- data/lib/rpush/plugin.rb +44 -0
- data/lib/rpush/push.rb +11 -0
- data/lib/rpush/reflectable.rb +13 -0
- data/lib/rpush/reflection_collection.rb +44 -0
- data/lib/rpush/reflection_public_methods.rb +11 -0
- data/lib/rpush/version.rb +14 -0
- data/lib/rpush.rb +43 -0
- data/lib/tasks/quality.rake +35 -0
- data/lib/tasks/test.rake +69 -0
- data/spec/.rubocop.yml +4 -0
- data/spec/functional/adm_spec.rb +50 -0
- data/spec/functional/apns2_spec.rb +232 -0
- data/spec/functional/apns_spec.rb +162 -0
- data/spec/functional/cli_spec.rb +36 -0
- data/spec/functional/embed_spec.rb +49 -0
- data/spec/functional/gcm_spec.rb +46 -0
- data/spec/functional/new_app_spec.rb +44 -0
- data/spec/functional/pushy_spec.rb +22 -0
- data/spec/functional/retry_spec.rb +42 -0
- data/spec/functional/synchronization_spec.rb +97 -0
- data/spec/functional/wpns_spec.rb +71 -0
- data/spec/functional_spec_helper.rb +32 -0
- data/spec/spec_helper.rb +69 -0
- data/spec/support/active_record_setup.rb +73 -0
- data/spec/support/cert_with_password.pem +90 -0
- data/spec/support/cert_without_password.pem +59 -0
- data/spec/support/config/database.yml +44 -0
- data/spec/support/simplecov_helper.rb +24 -0
- data/spec/support/simplecov_quality_formatter.rb +12 -0
- data/spec/tmp/.gitkeep +0 -0
- data/spec/unit/apns_feedback_spec.rb +28 -0
- data/spec/unit/client/active_record/adm/app_spec.rb +58 -0
- data/spec/unit/client/active_record/adm/notification_spec.rb +43 -0
- data/spec/unit/client/active_record/apns/app_spec.rb +29 -0
- data/spec/unit/client/active_record/apns/feedback_spec.rb +9 -0
- data/spec/unit/client/active_record/apns/notification_spec.rb +324 -0
- data/spec/unit/client/active_record/app_spec.rb +30 -0
- data/spec/unit/client/active_record/gcm/app_spec.rb +4 -0
- data/spec/unit/client/active_record/gcm/notification_spec.rb +67 -0
- data/spec/unit/client/active_record/notification_spec.rb +21 -0
- data/spec/unit/client/active_record/pushy/app_spec.rb +17 -0
- data/spec/unit/client/active_record/pushy/notification_spec.rb +65 -0
- data/spec/unit/client/active_record/wns/badge_notification_spec.rb +15 -0
- data/spec/unit/client/active_record/wns/raw_notification_spec.rb +26 -0
- data/spec/unit/client/active_record/wpns/app_spec.rb +4 -0
- data/spec/unit/client/active_record/wpns/notification_spec.rb +21 -0
- data/spec/unit/configuration_spec.rb +46 -0
- data/spec/unit/daemon/adm/delivery_spec.rb +253 -0
- data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +11 -0
- data/spec/unit/daemon/apns/delivery_spec.rb +108 -0
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +119 -0
- data/spec/unit/daemon/app_runner_spec.rb +188 -0
- data/spec/unit/daemon/batch_spec.rb +169 -0
- data/spec/unit/daemon/delivery_error_spec.rb +13 -0
- data/spec/unit/daemon/delivery_spec.rb +51 -0
- data/spec/unit/daemon/dispatcher/http_spec.rb +34 -0
- data/spec/unit/daemon/dispatcher/tcp_spec.rb +32 -0
- data/spec/unit/daemon/dispatcher_loop_spec.rb +53 -0
- data/spec/unit/daemon/feeder_spec.rb +96 -0
- data/spec/unit/daemon/gcm/delivery_spec.rb +387 -0
- data/spec/unit/daemon/proc_title_spec.rb +11 -0
- data/spec/unit/daemon/pushy/delivery_spec.rb +159 -0
- data/spec/unit/daemon/retryable_error_spec.rb +14 -0
- data/spec/unit/daemon/service_config_methods_spec.rb +36 -0
- data/spec/unit/daemon/signal_handler_spec.rb +99 -0
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +165 -0
- data/spec/unit/daemon/store/active_record_spec.rb +357 -0
- data/spec/unit/daemon/store/redis_spec.rb +365 -0
- data/spec/unit/daemon/tcp_connection_spec.rb +292 -0
- data/spec/unit/daemon/wns/delivery_spec.rb +176 -0
- data/spec/unit/daemon/wns/post_request_spec.rb +117 -0
- data/spec/unit/daemon/wpns/delivery_spec.rb +167 -0
- data/spec/unit/daemon_spec.rb +138 -0
- data/spec/unit/deprecatable_spec.rb +32 -0
- data/spec/unit/deprecation_spec.rb +15 -0
- data/spec/unit/embed_spec.rb +47 -0
- data/spec/unit/logger_spec.rb +127 -0
- data/spec/unit/notification_shared.rb +53 -0
- data/spec/unit/plugin_spec.rb +36 -0
- data/spec/unit/push_spec.rb +34 -0
- data/spec/unit/reflectable_spec.rb +27 -0
- data/spec/unit/reflection_collection_spec.rb +26 -0
- data/spec/unit/rpush_spec.rb +8 -0
- data/spec/unit_spec_helper.rb +26 -0
- metadata +709 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
require "unit_spec_helper"
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
attr_accessor :logger
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Rpush::Logger do
|
8
|
+
let(:log) { double(:sync= => true, :level= => nil) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
@logger_class = defined?(ActiveSupport::BufferedLogger) ? ActiveSupport::BufferedLogger : ActiveSupport::Logger
|
12
|
+
@logger = double(@logger_class.name, info: nil, error: nil, level: 0, :level= => nil, auto_flushing: true, :auto_flushing= => nil)
|
13
|
+
allow(@logger_class).to receive(:new).and_return(@logger)
|
14
|
+
allow(Rails).to receive_messages(logger: @logger)
|
15
|
+
allow(File).to receive_messages(open: log)
|
16
|
+
allow(FileUtils).to receive_messages(mkdir_p: nil)
|
17
|
+
allow(STDERR).to receive(:puts)
|
18
|
+
Rpush.config.foreground = true
|
19
|
+
Rpush.config.log_file = 'log/rpush.log'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "disables logging if the log file cannot be opened" do
|
23
|
+
allow(File).to receive(:open).and_raise(Errno::ENOENT)
|
24
|
+
expect(STDERR).to receive(:puts).with(/Logging disabled/)
|
25
|
+
Rpush::Logger.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates the log directory' do
|
29
|
+
expect(FileUtils).to receive(:mkdir_p).with('/tmp/rails_root/log')
|
30
|
+
Rpush::Logger.new
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should open the a log file in the Rails log directory" do
|
34
|
+
expect(File).to receive(:open).with('/tmp/rails_root/log/rpush.log', 'a')
|
35
|
+
Rpush::Logger.new
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'sets sync mode on the log descriptor' do
|
39
|
+
expect(log).to receive(:sync=).with(true)
|
40
|
+
Rpush::Logger.new
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'uses the user-defined logger' do
|
44
|
+
my_logger = double(:level= => nil)
|
45
|
+
Rpush.config.logger = my_logger
|
46
|
+
logger = Rpush::Logger.new
|
47
|
+
expect(my_logger).to receive(:info)
|
48
|
+
Rpush.config.foreground = false
|
49
|
+
logger.info('test')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'uses ActiveSupport::BufferedLogger if a user-defined logger is not set' do
|
53
|
+
if ActiveSupport.const_defined?('BufferedLogger')
|
54
|
+
expect(ActiveSupport::BufferedLogger).to receive(:new).with(log)
|
55
|
+
Rpush::Logger.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'uses ActiveSupport::Logger if BufferedLogger does not exist' do
|
60
|
+
stub_const('ActiveSupport::Logger', double)
|
61
|
+
allow(ActiveSupport).to receive_messages(const_defined?: false)
|
62
|
+
expect(ActiveSupport::Logger).to receive(:new).with(log).and_return(log)
|
63
|
+
Rpush::Logger.new
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'sets the log level on the logger' do
|
67
|
+
stub_const('ActiveSupport::Logger', double)
|
68
|
+
allow(ActiveSupport).to receive_messages(const_defined?: false)
|
69
|
+
expect(ActiveSupport::Logger).to receive(:new).with(log).and_return(log)
|
70
|
+
Rpush.config.log_level = ::Logger::Severity::ERROR
|
71
|
+
expect(log).to receive(:level=).with(::Logger::Severity::ERROR)
|
72
|
+
Rpush::Logger.new
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should print out the msg if running in the foreground" do
|
76
|
+
logger = Rpush::Logger.new
|
77
|
+
expect(STDOUT).to receive(:puts).with(/hi mom/)
|
78
|
+
logger.info("hi mom")
|
79
|
+
end
|
80
|
+
|
81
|
+
unless Rpush.jruby? # These tests do not work on JRuby.
|
82
|
+
it "should not print out the msg if not running in the foreground" do
|
83
|
+
Rpush.config.foreground = false
|
84
|
+
logger = Rpush::Logger.new
|
85
|
+
expect(STDOUT).not_to receive(:puts).with(/hi mom/)
|
86
|
+
logger.info("hi mom")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should prefix log lines with the current time" do
|
91
|
+
Rpush.config.foreground = false
|
92
|
+
now = Time.now
|
93
|
+
allow(Time).to receive(:now).and_return(now)
|
94
|
+
logger = Rpush::Logger.new
|
95
|
+
expect(@logger).to receive(:info).with(/#{Regexp.escape("[#{now.to_s(:db)}]")}/)
|
96
|
+
logger.info("blah")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should prefix error logs with the ERROR label" do
|
100
|
+
Rpush.config.foreground = false
|
101
|
+
logger = Rpush::Logger.new
|
102
|
+
expect(@logger).to receive(:error).with(/#{Regexp.escape("[ERROR]")}/)
|
103
|
+
logger.error("eeek")
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should prefix warn logs with the WARNING label" do
|
107
|
+
Rpush.config.foreground = false
|
108
|
+
logger = Rpush::Logger.new
|
109
|
+
expect(@logger).to receive(:warn).with(/#{Regexp.escape("[WARNING]")}/)
|
110
|
+
logger.warn("eeek")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should handle an Exception instance" do
|
114
|
+
Rpush.config.foreground = false
|
115
|
+
e = RuntimeError.new("hi mom")
|
116
|
+
allow(e).to receive_messages(backtrace: [])
|
117
|
+
logger = Rpush::Logger.new
|
118
|
+
expect(@logger).to receive(:error).with(/RuntimeError, hi mom/)
|
119
|
+
logger.error(e)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'defaults auto_flushing to true if the Rails logger does not respond to auto_flushing' do
|
123
|
+
allow(Rails).to receive_messages(logger: double(info: nil, error: nil, level: 0))
|
124
|
+
Rpush::Logger.new
|
125
|
+
expect(@logger.auto_flushing).to eq(true)
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
shared_examples_for 'an Notification subclass' do
|
2
|
+
describe 'when assigning data for the device' do
|
3
|
+
before { allow(Rpush::Deprecation).to receive(:warn) }
|
4
|
+
|
5
|
+
it 'calls MultiJson.dump when multi_json responds to :dump' do
|
6
|
+
notification = notification_class.new
|
7
|
+
allow(MultiJson).to receive(:respond_to?).with(:dump).and_return(true)
|
8
|
+
expect(MultiJson).to receive(:dump).with(any_args)
|
9
|
+
notification.data = { pirates: 1 }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'calls MultiJson.encode when multi_json does not respond to :dump' do
|
13
|
+
notification = notification_class.new
|
14
|
+
allow(MultiJson).to receive(:respond_to?).with(:dump).and_return(false)
|
15
|
+
expect(MultiJson).to receive(:encode).with(any_args)
|
16
|
+
notification.data = { ninjas: 1 }
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raises an ArgumentError if something other than a Hash is assigned' do
|
20
|
+
expect do
|
21
|
+
notification.data = []
|
22
|
+
end.to raise_error(ArgumentError, 'must be a Hash')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'encodes the given Hash as JSON' do
|
26
|
+
notification.data = { hi: 'mom'}
|
27
|
+
expect(notification.read_attribute(:data)).to eq('{"hi":"mom"}')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'decodes the JSON when using the reader method' do
|
31
|
+
notification.data = { hi: 'mom'}
|
32
|
+
expect(notification.data).to eq('hi' => 'mom')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'when assigning the notification payload for the device' do
|
37
|
+
it 'raises an ArgumentError if something other than a Hash is assigned' do
|
38
|
+
expect do
|
39
|
+
notification.notification = []
|
40
|
+
end.to raise_error(ArgumentError, 'must be a Hash')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'encodes the given Hash as JSON' do
|
44
|
+
notification.notification = { hi: 'dad'}
|
45
|
+
expect(notification.read_attribute(:notification)).to eq('{"hi":"dad"}')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'decodes the JSON when using the reader method' do
|
49
|
+
notification.notification = { hi: 'dad'}
|
50
|
+
expect(notification.notification).to eq('hi' => 'dad')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush::Plugin do
|
4
|
+
include Rpush::Reflectable
|
5
|
+
|
6
|
+
it 'can only be initialized once' do
|
7
|
+
plugin = double(Rpush::Plugin, unload: nil)
|
8
|
+
expect(Rpush::Plugin).to receive(:new).once.and_return(plugin)
|
9
|
+
Rpush.plugin(:test)
|
10
|
+
Rpush.plugin(:test)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can be referenced' do
|
14
|
+
plugin = Rpush.plugin(:test)
|
15
|
+
expect(Rpush.plugins[:test]).to eq(plugin)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can be configured' do
|
19
|
+
plugin = Rpush.plugin(:test)
|
20
|
+
plugin.configure do |config|
|
21
|
+
config.is_configured = true
|
22
|
+
end
|
23
|
+
expect(Rpush.config.plugin.test.is_configured).to eq(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can hook up reflections' do
|
27
|
+
plugin = Rpush.plugin(:test)
|
28
|
+
reflected_error = nil
|
29
|
+
plugin.reflect do |on|
|
30
|
+
on.error { |error| reflected_error = error }
|
31
|
+
end
|
32
|
+
error = double
|
33
|
+
reflect(:error, error)
|
34
|
+
expect(reflected_error).to eq(error)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush, 'push' do
|
4
|
+
before do
|
5
|
+
allow(Rpush::Daemon::Synchronizer).to receive_messages(sync: nil)
|
6
|
+
allow(Rpush::Daemon::AppRunner).to receive_messages(wait: nil)
|
7
|
+
allow(Rpush::Daemon::Feeder).to receive_messages(start: nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'sets the push config option to true' do
|
11
|
+
Rpush.push
|
12
|
+
expect(Rpush.config.push).to eq(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'initializes the daemon' do
|
16
|
+
expect(Rpush::Daemon).to receive(:common_init)
|
17
|
+
Rpush.push
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'syncs' do
|
21
|
+
expect(Rpush::Daemon::Synchronizer).to receive(:sync)
|
22
|
+
Rpush.push
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'starts the feeder' do
|
26
|
+
expect(Rpush::Daemon::Feeder).to receive(:start)
|
27
|
+
Rpush.push
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'stops on the app runner' do
|
31
|
+
expect(Rpush::Daemon::AppRunner).to receive(:stop)
|
32
|
+
Rpush.push
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush::Reflectable do
|
4
|
+
class TestReflectable
|
5
|
+
include Rpush::Reflectable
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:logger) { double(error: nil) }
|
9
|
+
let(:test_reflectable) { TestReflectable.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(Rpush.reflection_stack[0]).to receive(:__dispatch)
|
13
|
+
allow(Rpush).to receive_messages(logger: logger)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'dispatches the given reflection' do
|
17
|
+
expect(Rpush.reflection_stack[0]).to receive(:__dispatch).with(:error)
|
18
|
+
test_reflectable.reflect(:error)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'logs errors raised by the reflection' do
|
22
|
+
error = StandardError.new
|
23
|
+
allow(Rpush.reflection_stack[0]).to receive(:__dispatch).and_raise(error)
|
24
|
+
expect(Rpush.logger).to receive(:error).with(error)
|
25
|
+
test_reflectable.reflect(:error)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rpush do
|
4
|
+
it 'yields reflections for configuration' do
|
5
|
+
did_yield = false
|
6
|
+
Rpush.reflect { did_yield = true }
|
7
|
+
expect(did_yield).to eq(true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Rpush::ReflectionCollection do
|
12
|
+
it 'dispatches the given reflection' do
|
13
|
+
did_yield = false
|
14
|
+
Rpush.reflect do |on|
|
15
|
+
on.error { did_yield = true }
|
16
|
+
end
|
17
|
+
Rpush.reflection_stack[0].__dispatch(:error)
|
18
|
+
expect(did_yield).to eq(true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'raises an error when trying to dispatch and unknown reflection' do
|
22
|
+
expect do
|
23
|
+
Rpush.reflection_stack[0].__dispatch(:unknown)
|
24
|
+
end.to raise_error(Rpush::ReflectionCollection::NoSuchReflectionError)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
def unit_example?(metadata)
|
5
|
+
metadata[:file_path] =~ %r{spec/unit}
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.before(:each) do
|
10
|
+
Modis.with_connection do |redis|
|
11
|
+
redis.keys('rpush:*').each { |key| redis.del(key) }
|
12
|
+
end if redis?
|
13
|
+
|
14
|
+
if active_record? && unit_example?(self.class.metadata)
|
15
|
+
connection = ActiveRecord::Base.connection
|
16
|
+
connection.begin_transaction joinable: false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after(:each) do
|
21
|
+
if active_record? && unit_example?(self.class.metadata)
|
22
|
+
connection = ActiveRecord::Base.connection
|
23
|
+
connection.rollback_transaction if connection.transaction_open?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|