rapns_rails_2 3.5.1 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -0
  3. data/lib/rapns/daemon/gcm/delivery.rb +4 -3
  4. data/lib/rapns/version.rb +1 -1
  5. metadata +46 -163
  6. data/config/database.yml +0 -44
  7. data/spec/support/cert_with_password.pem +0 -90
  8. data/spec/support/cert_without_password.pem +0 -59
  9. data/spec/support/simplecov_helper.rb +0 -13
  10. data/spec/support/simplecov_quality_formatter.rb +0 -8
  11. data/spec/tmp/.gitkeep +0 -0
  12. data/spec/unit/apns/app_spec.rb +0 -29
  13. data/spec/unit/apns/feedback_spec.rb +0 -9
  14. data/spec/unit/apns/notification_spec.rb +0 -215
  15. data/spec/unit/apns_feedback_spec.rb +0 -21
  16. data/spec/unit/app_spec.rb +0 -16
  17. data/spec/unit/configuration_spec.rb +0 -55
  18. data/spec/unit/daemon/apns/app_runner_spec.rb +0 -45
  19. data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +0 -11
  20. data/spec/unit/daemon/apns/connection_spec.rb +0 -287
  21. data/spec/unit/daemon/apns/delivery_handler_spec.rb +0 -59
  22. data/spec/unit/daemon/apns/delivery_spec.rb +0 -101
  23. data/spec/unit/daemon/apns/disconnection_error_spec.rb +0 -18
  24. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +0 -134
  25. data/spec/unit/daemon/app_runner_shared.rb +0 -83
  26. data/spec/unit/daemon/app_runner_spec.rb +0 -170
  27. data/spec/unit/daemon/batch_spec.rb +0 -219
  28. data/spec/unit/daemon/delivery_error_spec.rb +0 -13
  29. data/spec/unit/daemon/delivery_handler_collection_spec.rb +0 -37
  30. data/spec/unit/daemon/delivery_handler_shared.rb +0 -45
  31. data/spec/unit/daemon/feeder_spec.rb +0 -89
  32. data/spec/unit/daemon/gcm/app_runner_spec.rb +0 -19
  33. data/spec/unit/daemon/gcm/delivery_handler_spec.rb +0 -44
  34. data/spec/unit/daemon/gcm/delivery_spec.rb +0 -289
  35. data/spec/unit/daemon/interruptible_sleep_spec.rb +0 -68
  36. data/spec/unit/daemon/reflectable_spec.rb +0 -27
  37. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +0 -114
  38. data/spec/unit/daemon/store/active_record_spec.rb +0 -281
  39. data/spec/unit/daemon_spec.rb +0 -157
  40. data/spec/unit/deprecatable_spec.rb +0 -32
  41. data/spec/unit/deprecation_spec.rb +0 -15
  42. data/spec/unit/embed_spec.rb +0 -50
  43. data/spec/unit/gcm/app_spec.rb +0 -4
  44. data/spec/unit/gcm/notification_spec.rb +0 -52
  45. data/spec/unit/logger_spec.rb +0 -180
  46. data/spec/unit/notification_shared.rb +0 -45
  47. data/spec/unit/notification_spec.rb +0 -4
  48. data/spec/unit/notifier_spec.rb +0 -52
  49. data/spec/unit/push_spec.rb +0 -44
  50. data/spec/unit/rapns_spec.rb +0 -9
  51. data/spec/unit/reflection_spec.rb +0 -30
  52. data/spec/unit/upgraded_spec.rb +0 -40
  53. data/spec/unit_spec_helper.rb +0 -137
@@ -1,15 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
-
3
- describe Rapns::Deprecation do
4
- it 'prints a warning' do
5
- STDERR.should_receive(:puts).with("DEPRECATION WARNING: msg")
6
- Rapns::Deprecation.warn("msg")
7
- end
8
-
9
- it 'does not print a warning when muted' do
10
- STDERR.should_not_receive(:puts)
11
- Rapns::Deprecation.muted do
12
- Rapns::Deprecation.warn("msg")
13
- end
14
- end
15
- end
@@ -1,50 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
-
3
- describe Rapns, 'embed' do
4
- before do
5
- Rapns::Daemon.stub(:start)
6
- Kernel.stub(:at_exit)
7
- end
8
-
9
- it 'sets the embedded config option to true' do
10
- Rapns.embed
11
- Rapns.config.embedded.should be_true
12
- end
13
-
14
- it 'starts the daemon' do
15
- Rapns::Daemon.should_receive(:start)
16
- Rapns.embed
17
- end
18
-
19
- it 'overrides the default config options with those given as a hash' do
20
- Rapns.config.push_poll = 4
21
- expect { Rapns.embed(:push_poll => 2) }.to change(Rapns.config, :push_poll).to(2)
22
- end
23
- end
24
-
25
- describe Rapns, 'shutdown' do
26
- before { Rapns.config.embedded = true }
27
-
28
- it 'shuts down the daemon' do
29
- Rapns::Daemon.should_receive(:shutdown)
30
- Rapns.shutdown
31
- end
32
- end
33
-
34
- describe Rapns, 'sync' do
35
- before { Rapns.config.embedded = true }
36
-
37
- it 'syncs the AppRunner' do
38
- Rapns::Daemon::AppRunner.should_receive(:sync)
39
- Rapns.sync
40
- end
41
- end
42
-
43
- describe Rapns, 'debug' do
44
- before { Rapns.config.embedded = true }
45
-
46
- it 'debugs the AppRunner' do
47
- Rapns::Daemon::AppRunner.should_receive(:debug)
48
- Rapns.debug
49
- end
50
- end
@@ -1,4 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
-
3
- describe Rapns::Gcm::App do
4
- end
@@ -1,52 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
- require 'spec/unit/notification_shared.rb'
3
-
4
- describe Rapns::Gcm::Notification do
5
- it_should_behave_like 'an Notification subclass'
6
-
7
- let(:app) { Rapns::Gcm::App.create!(:name => 'test', :auth_key => 'abc') }
8
- let(:notification_class) { Rapns::Gcm::Notification }
9
- let(:notification) { notification_class.new }
10
- let(:data_setter) { 'data=' }
11
- let(:data_getter) { 'data' }
12
-
13
- it "has a 'data' payload limit of 4096 bytes" do
14
- notification.data = { :key => "a" * 4096 }
15
- notification.valid?.should be_false
16
- notification.errors[:base].should == "GCM notification payload data cannot be larger than 4096 bytes."
17
- end
18
-
19
- it 'allows assignment of many registration IDs' do
20
- notification.app = app
21
- notification.registration_ids = ['a', 'b']
22
- notification.save!
23
- reloaded_notification = notification_class.find(notification.id)
24
- reloaded_notification.registration_ids.should == ['a', 'b']
25
- end
26
-
27
- it 'num of registration Ids limit of 1000' do
28
- notification.registration_ids = ['a']*(1000+1)
29
- notification.valid?.should be_false
30
- notification.errors[:base].should == "GCM notification number of registration_ids cannot be larger than 1000"
31
- end
32
-
33
- it 'allows assignment of a single registration ID' do
34
- notification.app = app
35
- notification.registration_ids = 'a'
36
- notification.save!
37
- reloaded_notification = notification_class.find(notification.id)
38
- reloaded_notification.registration_ids.should == ['a']
39
- end
40
-
41
- it 'validates expiry is present if collapse_key is set' do
42
- notification.collapse_key = 'test'
43
- notification.expiry = nil
44
- notification.valid?.should be_false
45
- notification.errors[:expiry].should == 'must be set when using a collapse_key'
46
- end
47
-
48
- it 'includes time_to_live in the payload' do
49
- notification.expiry = 100
50
- notification.as_json['time_to_live'].should == 100
51
- end
52
- end
@@ -1,180 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
-
3
- module Rails
4
- def self.logger
5
- @logger
6
- end
7
-
8
- def self.logger=(logger)
9
- @logger = logger
10
- end
11
- end
12
-
13
- module HoptoadNotifier
14
- def self.notify(e)
15
- end
16
- end
17
-
18
- module Airbrake
19
- def self.notify_or_ignore(e)
20
- end
21
- end
22
-
23
- describe Rapns::Logger do
24
- let(:log) { double(:sync= => true) }
25
- let(:config) { double(:airbrake_notify => true) }
26
-
27
- before do
28
- Rails.stub(:root).and_return("/rails_root")
29
-
30
- @logger_class = if defined?(ActiveSupport::BufferedLogger)
31
- ActiveSupport::BufferedLogger
32
- else
33
- ActiveSupport::Logger
34
- end
35
-
36
- @logger = double(@logger_class.name, :info => nil, :error => nil, :level => 0, :auto_flushing => 1, :auto_flushing= => nil)
37
- @logger_class.stub(:new).and_return(@logger)
38
- Rails.logger = @logger
39
- File.stub(:open => log)
40
- STDERR.stub(:puts)
41
- end
42
-
43
- it "disables logging if the log file cannot be opened" do
44
- File.stub(:open).and_raise(Errno::ENOENT)
45
- STDERR.should_receive(:puts).with(/No such file or directory/)
46
- STDERR.should_receive(:puts).with(/Logging disabled/)
47
- Rapns::Logger.new(:foreground => true)
48
- end
49
-
50
- it "should open the a log file in the Rails log directory" do
51
- File.should_receive(:open).with('/rails_root/log/rapns.log', 'a')
52
- Rapns::Logger.new(:foreground => true)
53
- end
54
-
55
- it 'sets sync mode on the log descriptor' do
56
- log.should_receive(:sync=).with(true)
57
- Rapns::Logger.new(:foreground => true)
58
- end
59
-
60
- it 'uses the user-defined logger' do
61
- my_logger = double
62
- Rapns.config.logger = my_logger
63
- logger = Rapns::Logger.new({})
64
- my_logger.should_receive(:info)
65
- logger.info('test')
66
- end
67
-
68
- it 'uses ActiveSupport::BufferedLogger if a user-defined logger is not set' do
69
- if ActiveSupport.const_defined?('BufferedLogger')
70
- ActiveSupport::BufferedLogger.should_receive(:new).with(log, Rails.logger.level)
71
- Rapns::Logger.new(:foreground => true)
72
- end
73
- end
74
-
75
- it 'uses ActiveSupport::Logger if BufferedLogger does not exist' do
76
- ActiveSupport.stub_constants(:Logger => double) do
77
- ActiveSupport.stub(:const_defined? => false)
78
- ActiveSupport::Logger.should_receive(:new).with(log, Rails.logger.level)
79
- Rapns::Logger.new(:foreground => true)
80
- end
81
- end
82
-
83
- it "should print out the msg if running in the foreground" do
84
- logger = Rapns::Logger.new(:foreground => true)
85
- STDOUT.should_receive(:puts).with(/hi mom/)
86
- logger.info("hi mom")
87
- end
88
-
89
- it "should not print out the msg if not running in the foreground" do
90
- logger = Rapns::Logger.new(:foreground => false)
91
- STDOUT.should_not_receive(:puts).with(/hi mom/)
92
- logger.info("hi mom")
93
- end
94
-
95
- it "should prefix log lines with the current time" do
96
- now = Time.now
97
- Time.stub(:now).and_return(now)
98
- logger = Rapns::Logger.new(:foreground => false)
99
- @logger.should_receive(:info).with(/#{Regexp.escape("[#{now.to_s(:db)}]")}/)
100
- logger.info("blah")
101
- end
102
-
103
- it "should prefix error logs with the ERROR label" do
104
- logger = Rapns::Logger.new(:foreground => false)
105
- @logger.should_receive(:error).with(/#{Regexp.escape("[ERROR]")}/)
106
- logger.error("eeek")
107
- end
108
-
109
- it "should prefix warn logs with the WARNING label" do
110
- logger = Rapns::Logger.new(:foreground => false)
111
- @logger.should_receive(:warn).with(/#{Regexp.escape("[WARNING]")}/)
112
- logger.warn("eeek")
113
- end
114
-
115
- it "should handle an Exception instance" do
116
- e = RuntimeError.new("hi mom")
117
- e.stub(:backtrace => [])
118
- logger = Rapns::Logger.new(:foreground => false)
119
- @logger.should_receive(:error).with(/RuntimeError, hi mom/)
120
- logger.error(e)
121
- end
122
-
123
- it "should notify Airbrake of the exception" do
124
- e = RuntimeError.new("hi mom")
125
- e.stub(:backtrace => [])
126
- logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => true)
127
- Airbrake.should_receive(:notify_or_ignore).with(e)
128
- logger.error(e)
129
- end
130
-
131
- context "without Airbrake defined" do
132
- before do
133
- Object.send(:remove_const, :Airbrake)
134
- end
135
-
136
- after do
137
- module Airbrake
138
- def self.notify_or_ignore(e)
139
- end
140
- end
141
- end
142
-
143
- it "should notify using HoptoadNotifier" do
144
- e = RuntimeError.new("hi mom")
145
- e.stub(:backtrace => [])
146
- logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => true)
147
- HoptoadNotifier.should_receive(:notify_or_ignore).with(e)
148
- logger.error(e)
149
- end
150
- end
151
-
152
- it "should not notify Airbrake of the exception if the airbrake_notify option is false" do
153
- e = RuntimeError.new("hi mom")
154
- e.stub(:backtrace => [])
155
- logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => false)
156
- Airbrake.should_not_receive(:notify_or_ignore).with(e)
157
- logger.error(e)
158
- end
159
-
160
- it "should not notify Airbrake if explicitly disabled in the call to error" do
161
- e = RuntimeError.new("hi mom")
162
- e.stub(:backtrace => [])
163
- logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => true)
164
- Airbrake.should_not_receive(:notify_or_ignore).with(e)
165
- logger.error(e, :airbrake_notify => false)
166
- end
167
-
168
- it "should not attempt to notify Airbrake of the error is not an Exception" do
169
- logger = Rapns::Logger.new(:foreground => false)
170
- Airbrake.should_not_receive(:notify_or_ignore)
171
- logger.error("string error message")
172
- end
173
-
174
- it 'defaults auto_flushing to true if the Rails logger does not respond to auto_flushing' do
175
- rails_logger = double(:info => nil, :error => nil, :level => 0)
176
- Rails.logger = rails_logger
177
- logger = Rapns::Logger.new({})
178
- @logger.auto_flushing.should be_true
179
- end
180
- end
@@ -1,45 +0,0 @@
1
- shared_examples_for "an Notification subclass" do
2
- describe "when assigning data for the device" do
3
- before { Rapns::Deprecation.stub(:warn) }
4
-
5
- it "calls MultiJson.dump when multi_json responds to :dump" do
6
- Object.stub_constants(:MultiJson => mock) do
7
- MultiJson.should_receive(:dump).with(any_args())
8
- notification = notification_class.new
9
- notification.send(data_setter, { :pirates => 1 })
10
- end
11
- end
12
-
13
- it "calls MultiJson.encode when multi_json does not respond to :dump" do
14
- Object.stub_constants(:MultiJson => mock) do
15
- notification = notification_class.new
16
- MultiJson.should_receive(:encode).with(any_args())
17
- notification.send(data_setter, { :ninjas => 1 })
18
- end
19
- end
20
-
21
- it "raises an ArgumentError if something other than a Hash is assigned" do
22
- expect do
23
- notification.send(data_setter, Array.new)
24
- end.to raise_error(ArgumentError, "must be a Hash")
25
- end
26
-
27
- it "encodes the given Hash as JSON" do
28
- notification.send(data_setter, { :hi => "mom" })
29
- notification.read_attribute(:data).should == "{\"hi\":\"mom\"}"
30
- end
31
-
32
- it "decodes the JSON when using the reader method" do
33
- notification.send(data_setter, { :hi => "mom" })
34
- notification.send(data_getter).should == {"hi" => "mom"}
35
- end
36
-
37
- if Rapns.is_rails2_or_3?
38
- it 'warns if attributes_for_device is assigned via mass-assignment' do
39
- RAILS_DEFAULT_LOGGER.stub!(:debug)
40
- Rapns::Deprecation.should_receive(:warn).with(':attributes_for_device via mass-assignment is deprecated. Use :data or the attributes_for_device= instance method.')
41
- notification_class.new(:attributes_for_device => {:hi => 'mom'})
42
- end
43
- end
44
- end
45
- end
@@ -1,4 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
-
3
- describe Rapns::Notification do
4
- end
@@ -1,52 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
- require 'rapns/notifier'
3
-
4
- describe Rapns::Notifier do
5
-
6
- before(:each) { @port = 5000 }
7
- subject { Rapns::Notifier.new('127.0.0.1', @port) }
8
- its(:socket) { should_not be_nil }
9
-
10
- context "when connected" do
11
- before :each do
12
- @reader = UDPSocket.new
13
- @reader.bind('127.0.0.1', 0)
14
- @port = @reader.addr[1]
15
- end
16
-
17
- describe "notify" do
18
- it "calls write on the socket" do
19
- sock = UDPSocket.new
20
- UDPSocket.should_receive(:new).and_return(sock)
21
- sock.should_receive(:write)
22
-
23
- subject.notify
24
- end
25
-
26
- it "writes data that can be read from socket" do
27
- subject.notify
28
- @reader.recvfrom(4096).should be_an(Array)
29
- end
30
- end
31
- end
32
-
33
- describe "default notifier" do
34
- it "creates using :connect first" do
35
- Rapns.config.stub :wakeup => { :connect => '127.0.0.1', :port => 1234 }
36
- Rapns::Notifier.should_receive(:new).with('127.0.0.1', 1234)
37
- Rapns.notifier
38
- end
39
-
40
- it "creates using :host next" do
41
- Rapns.config.stub :wakeup => { :host => '127.0.0.1', :port => 1234 }
42
- Rapns::Notifier.should_receive(:new).with('127.0.0.1', 1234)
43
- Rapns.notifier
44
- end
45
-
46
- it "returns nil when wakeup is not specified" do
47
- Rapns.config.stub :wakeup => nil
48
- Rapns::Notifier.should_not_receive(:new)
49
- Rapns.notifier.should be_nil
50
- end
51
- end
52
- end
@@ -1,44 +0,0 @@
1
- require File.expand_path("spec/unit_spec_helper")
2
-
3
- describe Rapns, 'push' do
4
- before do
5
- Rapns::Upgraded.stub(:check => nil)
6
- Rapns::Daemon::AppRunner.stub(:sync => nil, :wait => nil)
7
- Rapns::Daemon::Feeder.stub(:start => nil)
8
- end
9
-
10
- it 'sets the push config option to true' do
11
- Rapns.push
12
- Rapns.config.push.should be_true
13
- end
14
-
15
- it 'initializes the store' do
16
- Rapns::Daemon.should_receive(:initialize_store)
17
- Rapns.push
18
- end
19
-
20
- it 'syncs the app runner' do
21
- Rapns::Daemon::AppRunner.should_receive(:sync)
22
- Rapns.push
23
- end
24
-
25
- it 'starts the feeder' do
26
- Rapns::Daemon::Feeder.should_receive(:start)
27
- Rapns.push
28
- end
29
-
30
- it 'waits on the app runner' do
31
- Rapns::Daemon::AppRunner.should_receive(:wait)
32
- Rapns.push
33
- end
34
-
35
- it 'stops on the app runner' do
36
- Rapns::Daemon::AppRunner.should_receive(:stop)
37
- Rapns.push
38
- end
39
-
40
- it 'overrides the default config options with those given as a hash' do
41
- Rapns.config.batch_size = 20
42
- expect { Rapns.push(:batch_size => 10) }.to change(Rapns.config, :batch_size).to(10)
43
- end
44
- end