rapns 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/README.md +26 -20
  3. data/config/database.yml +9 -0
  4. data/lib/generators/templates/add_gcm.rb +12 -12
  5. data/lib/rapns/apns/app.rb +2 -2
  6. data/lib/rapns/apns_feedback.rb +12 -0
  7. data/lib/rapns/daemon/apns/app_runner.rb +6 -17
  8. data/lib/rapns/daemon/apns/connection.rb +3 -3
  9. data/lib/rapns/daemon/apns/delivery.rb +2 -2
  10. data/lib/rapns/daemon/apns/delivery_handler.rb +19 -5
  11. data/lib/rapns/daemon/apns/feedback_receiver.rb +10 -6
  12. data/lib/rapns/daemon/app_runner.rb +14 -8
  13. data/lib/rapns/daemon/database_reconnectable.rb +6 -6
  14. data/lib/rapns/daemon/delivery_handler.rb +1 -1
  15. data/lib/rapns/daemon/feeder.rb +1 -1
  16. data/lib/rapns/daemon/gcm/delivery.rb +4 -4
  17. data/lib/rapns/daemon/interruptible_sleep.rb +2 -2
  18. data/lib/rapns/daemon/reflectable.rb +1 -1
  19. data/lib/rapns/daemon.rb +4 -40
  20. data/lib/rapns/logger.rb +66 -0
  21. data/lib/rapns/push.rb +6 -2
  22. data/lib/rapns/upgraded.rb +31 -0
  23. data/lib/rapns/version.rb +1 -1
  24. data/lib/rapns.rb +12 -0
  25. data/spec/acceptance_spec_helper.rb +2 -2
  26. data/spec/unit/apns/feedback_spec.rb +0 -3
  27. data/spec/unit/apns/notification_spec.rb +0 -3
  28. data/spec/unit/apns_feedback_spec.rb +16 -0
  29. data/spec/unit/app_spec.rb +1 -3
  30. data/spec/unit/daemon/apns/app_runner_spec.rb +9 -5
  31. data/spec/unit/daemon/apns/connection_spec.rb +2 -2
  32. data/spec/unit/daemon/apns/delivery_handler_spec.rb +14 -9
  33. data/spec/unit/daemon/apns/delivery_spec.rb +2 -3
  34. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +6 -6
  35. data/spec/unit/daemon/app_runner_spec.rb +26 -6
  36. data/spec/unit/daemon/database_reconnectable_spec.rb +9 -7
  37. data/spec/unit/daemon/delivery_handler_shared.rb +3 -3
  38. data/spec/unit/daemon/feeder_spec.rb +2 -1
  39. data/spec/unit/daemon/gcm/app_runner_spec.rb +1 -1
  40. data/spec/unit/daemon/gcm/delivery_spec.rb +7 -7
  41. data/spec/unit/daemon/reflectable_spec.rb +2 -2
  42. data/spec/unit/daemon_spec.rb +25 -75
  43. data/spec/unit/embed_spec.rb +6 -0
  44. data/spec/unit/gcm/app_spec.rb +1 -2
  45. data/spec/unit/gcm/notification_spec.rb +0 -2
  46. data/spec/unit/{daemon/logger_spec.rb → logger_spec.rb} +19 -20
  47. data/spec/unit/notification_spec.rb +1 -3
  48. data/spec/unit/push_spec.rb +20 -9
  49. data/spec/unit/rapns_spec.rb +9 -0
  50. data/spec/unit/upgraded_spec.rb +46 -0
  51. data/spec/unit_spec_helper.rb +5 -2
  52. metadata +20 -6
  53. data/lib/rapns/daemon/logger.rb +0 -68
@@ -1,4 +1,4 @@
1
- require "unit_spec_helper"
1
+ require 'unit_spec_helper'
2
2
 
3
3
  describe Rapns::Daemon, "when starting" do
4
4
  module Rails; end
@@ -7,41 +7,43 @@ describe Rapns::Daemon, "when starting" do
7
7
  let(:password) { stub }
8
8
  let(:config) { stub(:pid_file => nil, :airbrake_notify => false,
9
9
  :foreground => true, :embedded => false, :push => false) }
10
- let(:logger) { stub(:info => nil, :error => nil, :warn => nil) }
10
+ let(:logger) { stub(:logger, :info => nil, :error => nil, :warn => nil) }
11
11
 
12
12
  before do
13
13
  Rapns.stub(:config => config)
14
+ Rapns::Logger.stub(:new => logger)
14
15
  Rapns::Daemon::Feeder.stub(:start)
15
- Rapns::Daemon::Logger.stub(:new).and_return(logger)
16
16
  Rapns::Daemon::AppRunner.stub(:sync => nil, :stop => nil)
17
17
  Rapns::Daemon.stub(:daemonize => nil, :reconnect_database => nil, :exit => nil, :puts => nil)
18
18
  File.stub(:open)
19
19
  Rails.stub(:root).and_return("/rails_root")
20
20
  end
21
21
 
22
- it "forks into a daemon if the foreground option is false" do
23
- config.stub(:foreground => false)
24
- ActiveRecord::Base.stub(:establish_connection)
25
- Rapns::Daemon.should_receive(:daemonize)
26
- Rapns::Daemon.start
27
- end
22
+ unless defined?(JRUBY_VERSION)
23
+ it "forks into a daemon if the foreground option is false" do
24
+ config.stub(:foreground => false)
25
+ ActiveRecord::Base.stub(:establish_connection)
26
+ Rapns::Daemon.should_receive(:daemonize)
27
+ Rapns::Daemon.start
28
+ end
28
29
 
29
- it "does not fork into a daemon if the foreground option is true" do
30
- config.stub(:foreground => true)
31
- Rapns::Daemon.should_not_receive(:daemonize)
32
- Rapns::Daemon.start
33
- end
30
+ it "does not fork into a daemon if the foreground option is true" do
31
+ config.stub(:foreground => true)
32
+ Rapns::Daemon.should_not_receive(:daemonize)
33
+ Rapns::Daemon.start
34
+ end
34
35
 
35
- it "does not fork into a daemon if the push option is true" do
36
- config.stub(:push => true)
37
- Rapns::Daemon.should_not_receive(:daemonize)
38
- Rapns::Daemon.start
39
- end
36
+ it "does not fork into a daemon if the push option is true" do
37
+ config.stub(:push => true)
38
+ Rapns::Daemon.should_not_receive(:daemonize)
39
+ Rapns::Daemon.start
40
+ end
40
41
 
41
- it "does not fork into a daemon if the embedded option is true" do
42
- config.stub(:embedded => true)
43
- Rapns::Daemon.should_not_receive(:daemonize)
44
- Rapns::Daemon.start
42
+ it "does not fork into a daemon if the embedded option is true" do
43
+ config.stub(:embedded => true)
44
+ Rapns::Daemon.should_not_receive(:daemonize)
45
+ Rapns::Daemon.start
46
+ end
45
47
  end
46
48
 
47
49
  it 'sets up setup signal traps' do
@@ -55,12 +57,6 @@ describe Rapns::Daemon, "when starting" do
55
57
  Rapns::Daemon.start
56
58
  end
57
59
 
58
- it 'does not setup signal traps when in push mode' do
59
- config.stub(:push => true)
60
- Rapns::Daemon.should_not_receive(:setup_signal_traps)
61
- Rapns::Daemon.start
62
- end
63
-
64
60
  it "writes the process ID to the PID file" do
65
61
  Rapns::Daemon.should_receive(:write_pid_file)
66
62
  Rapns::Daemon.start
@@ -82,52 +78,6 @@ describe Rapns::Daemon, "when starting" do
82
78
  Rapns::Daemon::AppRunner.should_receive(:sync)
83
79
  Rapns::Daemon.start
84
80
  end
85
-
86
- it "sets up the logger" do
87
- config.stub(:airbrake_notify => true)
88
- Rapns::Daemon::Logger.should_receive(:new).with(:foreground => true, :airbrake_notify => true)
89
- Rapns::Daemon.start
90
- end
91
-
92
- it "makes the logger accessible" do
93
- Rapns::Daemon.start
94
- Rapns::Daemon.logger.should == logger
95
- end
96
-
97
- it 'prints a warning if there are no apps' do
98
- Rapns::App.stub(:count => 0)
99
- logger.should_receive(:warn).any_number_of_times
100
- Rapns::Daemon.start
101
- end
102
-
103
- it 'prints a warning exists if rapns has not been upgraded' do
104
- Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
105
- Rapns::Daemon.should_receive(:puts).any_number_of_times
106
- Rapns::Daemon.should_receive(:exit).with(1)
107
- Rapns::Daemon.start
108
- end
109
-
110
- it 'does not exit if Rapns has not been upgraded and is embedded' do
111
- config.stub(:embedded => true)
112
- Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
113
- Rapns::Daemon.should_receive(:puts).any_number_of_times
114
- Rapns::Daemon.should_not_receive(:exit)
115
- Rapns::Daemon.start
116
- end
117
-
118
- it 'does not exit if Rapns has not been upgraded and is in push mode' do
119
- config.stub(:push => true)
120
- Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
121
- Rapns::Daemon.should_receive(:puts).any_number_of_times
122
- Rapns::Daemon.should_not_receive(:exit)
123
- Rapns::Daemon.start
124
- end
125
-
126
- it 'warns if rapns.yml still exists' do
127
- File.should_receive(:exists?).with('/rails_root/config/rapns/rapns.yml').and_return(true)
128
- logger.should_receive(:warn).with("Since 2.0.0 rapns uses command-line options and a Ruby based configuration file.\nPlease run 'rails g rapns' to generate a new configuration file into config/initializers.\nRemove config/rapns/rapns.yml to avoid this warning.\n")
129
- Rapns::Daemon.start
130
- end
131
81
  end
132
82
 
133
83
  describe Rapns::Daemon, "when being shutdown" do
@@ -23,6 +23,8 @@ describe Rapns, 'embed' do
23
23
  end
24
24
 
25
25
  describe Rapns, 'shutdown' do
26
+ before { Rapns.config.embedded = true }
27
+
26
28
  it 'shuts down the daemon' do
27
29
  Rapns::Daemon.should_receive(:shutdown)
28
30
  Rapns.shutdown
@@ -30,6 +32,8 @@ describe Rapns, 'shutdown' do
30
32
  end
31
33
 
32
34
  describe Rapns, 'sync' do
35
+ before { Rapns.config.embedded = true }
36
+
33
37
  it 'syncs the AppRunner' do
34
38
  Rapns::Daemon::AppRunner.should_receive(:sync)
35
39
  Rapns.sync
@@ -37,6 +41,8 @@ describe Rapns, 'sync' do
37
41
  end
38
42
 
39
43
  describe Rapns, 'debug' do
44
+ before { Rapns.config.embedded = true }
45
+
40
46
  it 'debugs the AppRunner' do
41
47
  Rapns::Daemon::AppRunner.should_receive(:debug)
42
48
  Rapns.debug
@@ -1,5 +1,4 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rapns::Gcm::App do
4
- it { should validate_presence_of(:auth_key) }
5
- end
4
+ end
@@ -10,8 +10,6 @@ describe Rapns::Gcm::Notification do
10
10
  let(:data_setter) { 'data=' }
11
11
  let(:data_getter) { 'data' }
12
12
 
13
- it { should validate_presence_of :registration_ids }
14
-
15
13
  it "has a 'data' payload limit of 4096 bytes" do
16
14
  notification.data = { :key => "a" * 4096 }
17
15
  notification.valid?.should be_false
@@ -16,11 +16,11 @@ module HoptoadNotifier
16
16
  end
17
17
 
18
18
  module Airbrake
19
- def self.notify(e)
19
+ def self.notify_or_ignore(e)
20
20
  end
21
21
  end
22
22
 
23
- describe Rapns::Daemon::Logger do
23
+ describe Rapns::Logger do
24
24
  let(:log) { stub(:sync= => true) }
25
25
  let(:config) { stub(:airbrake_notify => true) }
26
26
 
@@ -29,7 +29,6 @@ describe Rapns::Daemon::Logger do
29
29
  @buffered_logger = mock("BufferedLogger", :info => nil, :error => nil, :level => 0, :auto_flushing => 1, :auto_flushing= => nil)
30
30
  Rails.logger = @buffered_logger
31
31
  ActiveSupport::BufferedLogger.stub(:new).and_return(@buffered_logger)
32
- Rapns::Daemon.stub(:config => config)
33
32
  File.stub(:open => log)
34
33
  STDERR.stub(:puts)
35
34
  end
@@ -38,32 +37,32 @@ describe Rapns::Daemon::Logger do
38
37
  File.stub(:open).and_raise(Errno::ENOENT)
39
38
  STDERR.should_receive(:puts).with(/No such file or directory/)
40
39
  STDERR.should_receive(:puts).with(/Logging disabled/)
41
- Rapns::Daemon::Logger.new(:foreground => true)
40
+ Rapns::Logger.new(:foreground => true)
42
41
  end
43
42
 
44
43
  it "should open the a log file in the Rails log directory" do
45
44
  File.should_receive(:open).with('/rails_root/log/rapns.log', 'a')
46
- Rapns::Daemon::Logger.new(:foreground => true)
45
+ Rapns::Logger.new(:foreground => true)
47
46
  end
48
47
 
49
48
  it 'sets sync mode on the log descriptor' do
50
49
  log.should_receive(:sync=).with(true)
51
- Rapns::Daemon::Logger.new(:foreground => true)
50
+ Rapns::Logger.new(:foreground => true)
52
51
  end
53
52
 
54
53
  it 'instantiates the BufferedLogger' do
55
54
  ActiveSupport::BufferedLogger.should_receive(:new).with(log, Rails.logger.level)
56
- Rapns::Daemon::Logger.new(:foreground => true)
55
+ Rapns::Logger.new(:foreground => true)
57
56
  end
58
57
 
59
58
  it "should print out the msg if running in the foreground" do
60
- logger = Rapns::Daemon::Logger.new(:foreground => true)
59
+ logger = Rapns::Logger.new(:foreground => true)
61
60
  STDOUT.should_receive(:puts).with(/hi mom/)
62
61
  logger.info("hi mom")
63
62
  end
64
63
 
65
64
  it "should not print out the msg if not running in the foreground" do
66
- logger = Rapns::Daemon::Logger.new(:foreground => false)
65
+ logger = Rapns::Logger.new(:foreground => false)
67
66
  STDOUT.should_not_receive(:puts).with(/hi mom/)
68
67
  logger.info("hi mom")
69
68
  end
@@ -71,19 +70,19 @@ describe Rapns::Daemon::Logger do
71
70
  it "should prefix log lines with the current time" do
72
71
  now = Time.now
73
72
  Time.stub(:now).and_return(now)
74
- logger = Rapns::Daemon::Logger.new(:foreground => false)
73
+ logger = Rapns::Logger.new(:foreground => false)
75
74
  @buffered_logger.should_receive(:info).with(/#{Regexp.escape("[#{now.to_s(:db)}]")}/)
76
75
  logger.info("blah")
77
76
  end
78
77
 
79
78
  it "should prefix error logs with the ERROR label" do
80
- logger = Rapns::Daemon::Logger.new(:foreground => false)
79
+ logger = Rapns::Logger.new(:foreground => false)
81
80
  @buffered_logger.should_receive(:error).with(/#{Regexp.escape("[ERROR]")}/)
82
81
  logger.error("eeek")
83
82
  end
84
83
 
85
84
  it "should prefix warn logs with the WARNING label" do
86
- logger = Rapns::Daemon::Logger.new(:foreground => false)
85
+ logger = Rapns::Logger.new(:foreground => false)
87
86
  @buffered_logger.should_receive(:warn).with(/#{Regexp.escape("[WARNING]")}/)
88
87
  logger.warn("eeek")
89
88
  end
@@ -91,7 +90,7 @@ describe Rapns::Daemon::Logger do
91
90
  it "should handle an Exception instance" do
92
91
  e = RuntimeError.new("hi mom")
93
92
  e.stub(:backtrace => [])
94
- logger = Rapns::Daemon::Logger.new(:foreground => false)
93
+ logger = Rapns::Logger.new(:foreground => false)
95
94
  @buffered_logger.should_receive(:error).with(/RuntimeError, hi mom/)
96
95
  logger.error(e)
97
96
  end
@@ -99,7 +98,7 @@ describe Rapns::Daemon::Logger do
99
98
  it "should notify Airbrake of the exception" do
100
99
  e = RuntimeError.new("hi mom")
101
100
  e.stub(:backtrace => [])
102
- logger = Rapns::Daemon::Logger.new(:foreground => false, :airbrake_notify => true)
101
+ logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => true)
103
102
  Airbrake.should_receive(:notify_or_ignore).with(e)
104
103
  logger.error(e)
105
104
  end
@@ -111,7 +110,7 @@ describe Rapns::Daemon::Logger do
111
110
 
112
111
  after do
113
112
  module Airbrake
114
- def self.notify(e)
113
+ def self.notify_or_ignore(e)
115
114
  end
116
115
  end
117
116
  end
@@ -119,7 +118,7 @@ describe Rapns::Daemon::Logger do
119
118
  it "should notify using HoptoadNotifier" do
120
119
  e = RuntimeError.new("hi mom")
121
120
  e.stub(:backtrace => [])
122
- logger = Rapns::Daemon::Logger.new(:foreground => false, :airbrake_notify => true)
121
+ logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => true)
123
122
  HoptoadNotifier.should_receive(:notify_or_ignore).with(e)
124
123
  logger.error(e)
125
124
  end
@@ -128,7 +127,7 @@ describe Rapns::Daemon::Logger do
128
127
  it "should not notify Airbrake of the exception if the airbrake_notify option is false" do
129
128
  e = RuntimeError.new("hi mom")
130
129
  e.stub(:backtrace => [])
131
- logger = Rapns::Daemon::Logger.new(:foreground => false, :airbrake_notify => false)
130
+ logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => false)
132
131
  Airbrake.should_not_receive(:notify_or_ignore).with(e)
133
132
  logger.error(e)
134
133
  end
@@ -136,13 +135,13 @@ describe Rapns::Daemon::Logger do
136
135
  it "should not notify Airbrake if explicitly disabled in the call to error" do
137
136
  e = RuntimeError.new("hi mom")
138
137
  e.stub(:backtrace => [])
139
- logger = Rapns::Daemon::Logger.new(:foreground => false, :airbrake_notify => true)
138
+ logger = Rapns::Logger.new(:foreground => false, :airbrake_notify => true)
140
139
  Airbrake.should_not_receive(:notify_or_ignore).with(e)
141
140
  logger.error(e, :airbrake_notify => false)
142
141
  end
143
142
 
144
143
  it "should not attempt to notify Airbrake of the error is not an Exception" do
145
- logger = Rapns::Daemon::Logger.new(:foreground => false)
144
+ logger = Rapns::Logger.new(:foreground => false)
146
145
  Airbrake.should_not_receive(:notify_or_ignore)
147
146
  logger.error("string error message")
148
147
  end
@@ -150,7 +149,7 @@ describe Rapns::Daemon::Logger do
150
149
  it 'defaults auto_flushing to true if the Rails logger does not respond to auto_flushing' do
151
150
  rails_logger = mock(:info => nil, :error => nil, :level => 0)
152
151
  Rails.logger = rails_logger
153
- logger = Rapns::Daemon::Logger.new({})
152
+ logger = Rapns::Logger.new({})
154
153
  @buffered_logger.auto_flushing.should be_true
155
154
  end
156
155
  end
@@ -1,6 +1,4 @@
1
1
  require "unit_spec_helper"
2
2
 
3
3
  describe Rapns::Notification do
4
- it { should validate_numericality_of(:expiry) }
5
- it { should validate_presence_of(:app) }
6
- end
4
+ end
@@ -1,9 +1,10 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rapns, 'push' do
4
- before do
5
- Rapns::Daemon.stub(:start)
6
- Rapns::Daemon.stub(:shutdown)
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)
7
8
  end
8
9
 
9
10
  it 'sets the push config option to true' do
@@ -11,18 +12,28 @@ describe Rapns, 'push' do
11
12
  Rapns.config.push.should be_true
12
13
  end
13
14
 
14
- it 'starts the daemon' do
15
- Rapns::Daemon.should_receive(:start)
15
+ it 'syncs the app runner' do
16
+ Rapns::Daemon::AppRunner.should_receive(:sync)
16
17
  Rapns.push
17
18
  end
18
19
 
19
- it 'shuts down the daemon' do
20
- Rapns::Daemon.should_receive(:shutdown).with(true)
20
+ it 'starts the feeder' do
21
+ Rapns::Daemon::Feeder.should_receive(:start)
22
+ Rapns.push
23
+ end
24
+
25
+ it 'waits on the app runner' do
26
+ Rapns::Daemon::AppRunner.should_receive(:wait)
27
+ Rapns.push
28
+ end
29
+
30
+ it 'stops on the app runner' do
31
+ Rapns::Daemon::AppRunner.should_receive(:stop)
21
32
  Rapns.push
22
33
  end
23
34
 
24
35
  it 'overrides the default config options with those given as a hash' do
25
- Rapns.config.push_poll = 4
26
- expect { Rapns.push(:push_poll => 2) }.to change(Rapns.config, :push_poll).to(2)
36
+ Rapns.config.batch_size = 20
37
+ expect { Rapns.push(:batch_size => 10) }.to change(Rapns.config, :batch_size).to(10)
27
38
  end
28
39
  end
@@ -0,0 +1,9 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rapns do
4
+ it "lazy initializes the logger" do
5
+ Rapns.config.stub(:airbrake_notify => true, :foreground => true)
6
+ Rapns::Logger.should_receive(:new).with(:foreground => true, :airbrake_notify => true)
7
+ Rapns.logger
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rapns::Upgraded do
4
+ let(:logger) { stub(:logger, :warn => nil) }
5
+ let(:config) { stub(:config) }
6
+
7
+ before do
8
+ Rails.stub(:root).and_return('/rails_root')
9
+ Rapns.stub(:logger => logger, :config => config)
10
+ end
11
+
12
+ it 'prints a warning if there are no apps' do
13
+ Rapns::App.stub(:count => 0)
14
+ Rapns.logger.should_receive(:warn).any_number_of_times
15
+ Rapns::Upgraded.check(:exit => false)
16
+ end
17
+
18
+ it 'prints a warning and exists if rapns has not been upgraded' do
19
+ Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
20
+ Rapns::Upgraded.should_receive(:puts).any_number_of_times
21
+ Rapns::Upgraded.should_receive(:exit).with(1)
22
+ Rapns::Upgraded.check(:exit => true)
23
+ end
24
+
25
+ it 'does not exit if Rapns has not been upgraded and :exit is false' do
26
+ Rapns.config.stub(:embedded => true)
27
+ Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
28
+ Rapns::Upgraded.should_receive(:puts).any_number_of_times
29
+ Rapns::Upgraded.should_not_receive(:exit)
30
+ Rapns::Upgraded.check(:exit => false)
31
+ end
32
+
33
+ it 'does not exit if Rapns has not been upgraded and is in push mode' do
34
+ Rapns.config.stub(:push => true)
35
+ Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
36
+ Rapns::Upgraded.should_receive(:puts).any_number_of_times
37
+ Rapns::Upgraded.should_not_receive(:exit)
38
+ Rapns::Upgraded.check(:exit => false)
39
+ end
40
+
41
+ it 'warns if rapns.yml still exists' do
42
+ File.should_receive(:exists?).with('/rails_root/config/rapns/rapns.yml').and_return(true)
43
+ Rapns.logger.should_receive(:warn).with("Since 2.0.0 rapns uses command-line options and a Ruby based configuration file.\nPlease run 'rails g rapns' to generate a new configuration file into config/initializers.\nRemove config/rapns/rapns.yml to avoid this warning.\n")
44
+ Rapns::Upgraded.check(:exit => false)
45
+ end
46
+ end
@@ -49,7 +49,6 @@ end
49
49
  require 'bundler'
50
50
  Bundler.require(:default)
51
51
 
52
- require 'shoulda'
53
52
  require 'database_cleaner'
54
53
 
55
54
  DatabaseCleaner.strategy = :truncation
@@ -69,7 +68,11 @@ RSpec.configure do |config|
69
68
  # PerfTools::CpuProfiler.stop
70
69
  # end
71
70
 
72
- config.before(:each) { DatabaseCleaner.clean }
71
+ config.before(:each) do
72
+ DatabaseCleaner.clean
73
+ end
74
+
75
+ config.after(:each) { Rapns.logger = nil }
73
76
  end
74
77
 
75
78
  # a test certificate that contains both an X509 certificate and
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapns
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-26 00:00:00.000000000 Z
12
+ date: 2013-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -69,6 +69,7 @@ files:
69
69
  - lib/rapns/apns/feedback.rb
70
70
  - lib/rapns/apns/notification.rb
71
71
  - lib/rapns/apns/required_fields_validator.rb
72
+ - lib/rapns/apns_feedback.rb
72
73
  - lib/rapns/app.rb
73
74
  - lib/rapns/configuration.rb
74
75
  - lib/rapns/daemon.rb
@@ -91,7 +92,6 @@ files:
91
92
  - lib/rapns/daemon/gcm/delivery.rb
92
93
  - lib/rapns/daemon/gcm/delivery_handler.rb
93
94
  - lib/rapns/daemon/interruptible_sleep.rb
94
- - lib/rapns/daemon/logger.rb
95
95
  - lib/rapns/daemon/reflectable.rb
96
96
  - lib/rapns/deprecatable.rb
97
97
  - lib/rapns/deprecation.rb
@@ -101,6 +101,7 @@ files:
101
101
  - lib/rapns/gcm/notification.rb
102
102
  - lib/rapns/gcm/payload_data_size_validator.rb
103
103
  - lib/rapns/gcm/registration_ids_count_validator.rb
104
+ - lib/rapns/logger.rb
104
105
  - lib/rapns/multi_json_helper.rb
105
106
  - lib/rapns/notification.rb
106
107
  - lib/rapns/patches.rb
@@ -108,6 +109,7 @@ files:
108
109
  - lib/rapns/patches/rails/3.1.1/postgresql_adapter.rb
109
110
  - lib/rapns/push.rb
110
111
  - lib/rapns/reflection.rb
112
+ - lib/rapns/upgraded.rb
111
113
  - lib/rapns/version.rb
112
114
  - lib/tasks/cane.rake
113
115
  - lib/tasks/test.rake
@@ -121,6 +123,7 @@ files:
121
123
  - spec/unit/apns/app_spec.rb
122
124
  - spec/unit/apns/feedback_spec.rb
123
125
  - spec/unit/apns/notification_spec.rb
126
+ - spec/unit/apns_feedback_spec.rb
124
127
  - spec/unit/app_spec.rb
125
128
  - spec/unit/configuration_spec.rb
126
129
  - spec/unit/daemon/apns/app_runner_spec.rb
@@ -140,7 +143,6 @@ files:
140
143
  - spec/unit/daemon/gcm/delivery_handler_spec.rb
141
144
  - spec/unit/daemon/gcm/delivery_spec.rb
142
145
  - spec/unit/daemon/interruptible_sleep_spec.rb
143
- - spec/unit/daemon/logger_spec.rb
144
146
  - spec/unit/daemon/reflectable_spec.rb
145
147
  - spec/unit/daemon_spec.rb
146
148
  - spec/unit/deprecatable_spec.rb
@@ -148,10 +150,13 @@ files:
148
150
  - spec/unit/embed_spec.rb
149
151
  - spec/unit/gcm/app_spec.rb
150
152
  - spec/unit/gcm/notification_spec.rb
153
+ - spec/unit/logger_spec.rb
151
154
  - spec/unit/notification_shared.rb
152
155
  - spec/unit/notification_spec.rb
153
156
  - spec/unit/push_spec.rb
157
+ - spec/unit/rapns_spec.rb
154
158
  - spec/unit/reflection_spec.rb
159
+ - spec/unit/upgraded_spec.rb
155
160
  - spec/unit_spec_helper.rb
156
161
  - bin/rapns
157
162
  homepage: https://github.com/ileitch/rapns
@@ -166,15 +171,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
171
  - - ! '>='
167
172
  - !ruby/object:Gem::Version
168
173
  version: '0'
174
+ segments:
175
+ - 0
176
+ hash: -3688702007568166292
169
177
  required_rubygems_version: !ruby/object:Gem::Requirement
170
178
  none: false
171
179
  requirements:
172
180
  - - ! '>='
173
181
  - !ruby/object:Gem::Version
174
182
  version: '0'
183
+ segments:
184
+ - 0
185
+ hash: -3688702007568166292
175
186
  requirements: []
176
187
  rubyforge_project:
177
- rubygems_version: 1.8.23
188
+ rubygems_version: 1.8.25
178
189
  signing_key:
179
190
  specification_version: 3
180
191
  summary: Professional grade APNs and GCM for Ruby
@@ -189,6 +200,7 @@ test_files:
189
200
  - spec/unit/apns/app_spec.rb
190
201
  - spec/unit/apns/feedback_spec.rb
191
202
  - spec/unit/apns/notification_spec.rb
203
+ - spec/unit/apns_feedback_spec.rb
192
204
  - spec/unit/app_spec.rb
193
205
  - spec/unit/configuration_spec.rb
194
206
  - spec/unit/daemon/apns/app_runner_spec.rb
@@ -208,7 +220,6 @@ test_files:
208
220
  - spec/unit/daemon/gcm/delivery_handler_spec.rb
209
221
  - spec/unit/daemon/gcm/delivery_spec.rb
210
222
  - spec/unit/daemon/interruptible_sleep_spec.rb
211
- - spec/unit/daemon/logger_spec.rb
212
223
  - spec/unit/daemon/reflectable_spec.rb
213
224
  - spec/unit/daemon_spec.rb
214
225
  - spec/unit/deprecatable_spec.rb
@@ -216,8 +227,11 @@ test_files:
216
227
  - spec/unit/embed_spec.rb
217
228
  - spec/unit/gcm/app_spec.rb
218
229
  - spec/unit/gcm/notification_spec.rb
230
+ - spec/unit/logger_spec.rb
219
231
  - spec/unit/notification_shared.rb
220
232
  - spec/unit/notification_spec.rb
221
233
  - spec/unit/push_spec.rb
234
+ - spec/unit/rapns_spec.rb
222
235
  - spec/unit/reflection_spec.rb
236
+ - spec/unit/upgraded_spec.rb
223
237
  - spec/unit_spec_helper.rb
@@ -1,68 +0,0 @@
1
- module Rapns
2
- module Daemon
3
- class Logger
4
- def initialize(options)
5
- @options = options
6
-
7
- begin
8
- log = File.open(File.join(Rails.root, 'log', 'rapns.log'), 'a')
9
- log.sync = true
10
- @logger = ActiveSupport::BufferedLogger.new(log, Rails.logger.level)
11
- @logger.auto_flushing = Rails.logger.respond_to?(:auto_flushing) ? Rails.logger.auto_flushing : true
12
- rescue Errno::ENOENT, Errno::EPERM => e
13
- @logger = nil
14
- error(e)
15
- error('Logging disabled.')
16
- end
17
- end
18
-
19
- def info(msg)
20
- log(:info, msg)
21
- end
22
-
23
- def error(msg, options = {})
24
- airbrake_notify(msg) if notify_via_airbrake?(msg, options)
25
- log(:error, msg, 'ERROR', STDERR)
26
- end
27
-
28
- def warn(msg)
29
- log(:warn, msg, 'WARNING', STDERR)
30
- end
31
-
32
- private
33
-
34
- def log(where, msg, prefix = nil, io = STDOUT)
35
- if msg.is_a?(Exception)
36
- formatted_backtrace = msg.backtrace.join("\n")
37
- msg = "#{msg.class.name}, #{msg.message}\n#{formatted_backtrace}"
38
- end
39
-
40
- formatted_msg = "[#{Time.now.to_s(:db)}] "
41
- formatted_msg << "[#{prefix}] " if prefix
42
- formatted_msg << msg
43
-
44
- if io == STDERR
45
- io.puts formatted_msg
46
- elsif @options[:foreground]
47
- io.puts formatted_msg
48
- end
49
-
50
- @logger.send(where, formatted_msg) if @logger
51
- end
52
-
53
- def airbrake_notify(e)
54
- return unless @options[:airbrake_notify] == true
55
-
56
- if defined?(Airbrake)
57
- Airbrake.notify_or_ignore(e)
58
- elsif defined?(HoptoadNotifier)
59
- HoptoadNotifier.notify_or_ignore(e)
60
- end
61
- end
62
-
63
- def notify_via_airbrake?(msg, options)
64
- msg.is_a?(Exception) && options[:airbrake_notify] != false
65
- end
66
- end
67
- end
68
- end