backup 3.0.20 → 3.0.21

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 (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -3,147 +3,115 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Notifier::Prowl do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
6
7
  let(:notifier) do
7
- Backup::Notifier::Prowl.new do |prowl|
8
+ Backup::Notifier::Prowl.new(model) do |prowl|
8
9
  prowl.application = 'application'
9
10
  prowl.api_key = 'api_key'
10
11
  end
11
12
  end
12
13
 
13
14
  describe '#initialize' do
14
- it 'sets the correct defaults' do
15
- notifier.application = 'application'
16
- notifier.api_key = 'api_key'
15
+ it 'should sets the correct values' do
16
+ notifier.application.should == 'application'
17
+ notifier.api_key.should == 'api_key'
17
18
 
18
19
  notifier.on_success.should == true
19
20
  notifier.on_warning.should == true
20
21
  notifier.on_failure.should == true
21
22
  end
22
23
 
23
- it 'uses and overrides configuration defaults' do
24
- Backup::Configuration::Notifier::Prowl.defaults do |notifier|
25
- notifier.application = 'my_default_application'
26
- notifier.on_success = false
27
- end
28
- prowl = Backup::Notifier::Prowl.new do |notifier|
29
- notifier.api_key = 'my_own_api_key'
30
- end
31
-
32
- prowl.application.should == 'my_default_application'
33
- prowl.api_key.should == 'my_own_api_key'
34
- prowl.on_success.should == false
35
- prowl.on_warning.should == true
36
- prowl.on_failure.should == true
37
- end
38
-
39
- it 'creates a new Prowler::Application' do
40
- notifier.prowl_client.should be_an_instance_of Prowler::Application
41
- notifier.prowl_client.application.should == notifier.application
42
- notifier.prowl_client.api_key.should == notifier.api_key
43
- end
44
- end
45
-
46
- describe '#perform!' do
47
- let(:model) { Backup::Model.new('trigger', 'label') {} }
48
- let(:message_a) { '[Backup::%s]' }
49
- let(:message_b) { 'label (trigger)' }
50
-
51
- before do
52
- notifier.on_success = false
53
- notifier.on_warning = false
54
- notifier.on_failure = false
55
- end
24
+ context 'when using configuration defaults' do
25
+ after { Backup::Configuration::Notifier::Prowl.clear_defaults! }
56
26
 
57
- context 'success' do
27
+ it 'should use the configuration defaults' do
28
+ Backup::Configuration::Notifier::Prowl.defaults do |prowl|
29
+ prowl.application = 'default_app'
30
+ prowl.api_key = 'default_api_key'
58
31
 
59
- context 'when on_success is true' do
60
- before { notifier.on_success = true }
61
-
62
- it 'sends success message' do
63
- notifier.expects(:log!)
64
- notifier.prowl_client.expects(:notify).
65
- with(message_a % 'Success', message_b)
66
-
67
- notifier.perform!(model)
32
+ prowl.on_success = false
33
+ prowl.on_warning = false
34
+ prowl.on_failure = false
68
35
  end
69
- end
36
+ notifier = Backup::Notifier::Prowl.new(model)
37
+ notifier.application.should == 'default_app'
38
+ notifier.api_key.should == 'default_api_key'
70
39
 
71
- context 'when on_success is false' do
72
- it 'sends no message' do
73
- notifier.expects(:log!).never
74
- notifier.expects(:notify!).never
75
- notifier.prowl_client.expects(:notify).never
76
-
77
- notifier.perform!(model)
78
- end
40
+ notifier.on_success.should == false
41
+ notifier.on_warning.should == false
42
+ notifier.on_failure.should == false
79
43
  end
80
44
 
81
- end # context 'success'
45
+ it 'should override the configuration defaults' do
46
+ Backup::Configuration::Notifier::Prowl.defaults do |prowl|
47
+ prowl.application = 'old_app'
48
+ prowl.api_key = 'old_api_key'
82
49
 
83
- context 'warning' do
84
- before { Backup::Logger.stubs(:has_warnings?).returns(true) }
85
-
86
- context 'when on_success is true' do
87
- before { notifier.on_success = true }
88
-
89
- it 'sends warning message' do
90
- notifier.expects(:log!)
91
- notifier.prowl_client.expects(:notify).
92
- with(message_a % 'Warning', message_b)
93
-
94
- notifier.perform!(model)
50
+ prowl.on_success = true
51
+ prowl.on_warning = false
52
+ prowl.on_failure = false
95
53
  end
96
- end
54
+ notifier = Backup::Notifier::Prowl.new(model) do |prowl|
55
+ prowl.application = 'new_app'
56
+ prowl.api_key = 'new_api_key'
97
57
 
98
- context 'when on_warning is true' do
99
- before { notifier.on_warning = true }
100
-
101
- it 'sends warning message' do
102
- notifier.expects(:log!)
103
- notifier.prowl_client.expects(:notify).
104
- with(message_a % 'Warning', message_b)
105
-
106
- notifier.perform!(model)
58
+ prowl.on_success = false
59
+ prowl.on_warning = true
60
+ prowl.on_failure = true
107
61
  end
108
- end
109
62
 
110
- context 'when on_success and on_warning are false' do
111
- it 'sends no message' do
112
- notifier.expects(:log!).never
113
- notifier.expects(:notify!).never
114
- notifier.prowl_client.expects(:notify).never
63
+ notifier.application.should == 'new_app'
64
+ notifier.api_key.should == 'new_api_key'
115
65
 
116
- notifier.perform!(model)
117
- end
66
+ notifier.on_success.should == false
67
+ notifier.on_warning.should == true
68
+ notifier.on_failure.should == true
118
69
  end
70
+ end # context 'when using configuration defaults'
71
+ end
119
72
 
120
- end # context 'warning'
121
-
122
- context 'failure' do
123
-
124
- context 'when on_failure is true' do
125
- before { notifier.on_failure = true }
126
-
127
- it 'sends failure message' do
128
- notifier.expects(:log!)
129
- notifier.prowl_client.expects(:notify).
130
- with(message_a % 'Failure', message_b)
131
-
132
- notifier.perform!(model, Exception.new)
133
- end
73
+ describe '#notify!' do
74
+ context 'when status is :success' do
75
+ it 'should send Success message' do
76
+ notifier.expects(:send_message).with(
77
+ '[Backup::Success]'
78
+ )
79
+ notifier.send(:notify!, :success)
134
80
  end
81
+ end
135
82
 
136
- context 'when on_failure is false' do
137
- it 'sends no message' do
138
- notifier.expects(:log!).never
139
- notifier.expects(:notify!).never
140
- notifier.prowl_client.expects(:notify).never
141
-
142
- notifier.perform!(model, Exception.new)
143
- end
83
+ context 'when status is :warning' do
84
+ it 'should send Warning message' do
85
+ notifier.expects(:send_message).with(
86
+ '[Backup::Warning]'
87
+ )
88
+ notifier.send(:notify!, :warning)
144
89
  end
90
+ end
145
91
 
146
- end # context 'failure'
92
+ context 'when status is :failure' do
93
+ it 'should send Failure message' do
94
+ notifier.expects(:send_message).with(
95
+ '[Backup::Failure]'
96
+ )
97
+ notifier.send(:notify!, :failure)
98
+ end
99
+ end
100
+ end # describe '#notify!'
101
+
102
+ describe '#send_message' do
103
+ it 'should send the given message' do
104
+ client = mock
105
+ Prowler.expects(:new).with(
106
+ :application => 'application', :api_key => 'api_key'
107
+ ).returns(client)
108
+ client.expects(:notify).with(
109
+ 'a message',
110
+ 'test label (test_trigger)'
111
+ )
112
+
113
+ notifier.send(:send_message, 'a message')
114
+ end
115
+ end
147
116
 
148
- end # describe '#perform!'
149
117
  end
@@ -3,8 +3,9 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Notifier::Twitter do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
6
7
  let(:notifier) do
7
- Backup::Notifier::Twitter.new do |twitter|
8
+ Backup::Notifier::Twitter.new(model) do |twitter|
8
9
  twitter.consumer_key = 'consumer_key'
9
10
  twitter.consumer_secret = 'consumer_secret'
10
11
  twitter.oauth_token = 'oauth_token'
@@ -13,7 +14,7 @@ describe Backup::Notifier::Twitter do
13
14
  end
14
15
 
15
16
  describe '#initialize' do
16
- it 'sets the correct defaults' do
17
+ it 'should sets the correct values' do
17
18
  notifier.consumer_key.should == 'consumer_key'
18
19
  notifier.consumer_secret.should == 'consumer_secret'
19
20
  notifier.oauth_token.should == 'oauth_token'
@@ -24,128 +25,108 @@ describe Backup::Notifier::Twitter do
24
25
  notifier.on_failure.should == true
25
26
  end
26
27
 
27
- it 'uses and overrides configuration defaults' do
28
- Backup::Configuration::Notifier::Twitter.defaults do |twitter|
29
- twitter.consumer_key = 'new_consumer_key'
30
- twitter.on_success = false
31
- end
32
- notifier = Backup::Notifier::Twitter.new do |twitter|
33
- twitter.consumer_key = 'my_own_consumer_key'
34
- end
35
-
36
- notifier.consumer_key.should == 'my_own_consumer_key'
37
- notifier.on_success.should == false
38
- notifier.on_warning.should == true
39
- notifier.on_failure.should == true
40
- end
28
+ context 'when using configuration defaults' do
29
+ after { Backup::Configuration::Notifier::Twitter.clear_defaults! }
41
30
 
42
- it 'create a new Twitter::Client' do
43
- notifier.twitter_client.should be_an_instance_of ::Twitter::Client
44
- #notifier.twitter_client.credentials?.should be_true
45
- options = ::Twitter.options # v1.7.1 API
46
- options[:consumer_key].should == notifier.consumer_key
47
- options[:consumer_secret].should == notifier.consumer_secret
48
- options[:oauth_token].should == notifier.oauth_token
49
- options[:oauth_token_secret].should == notifier.oauth_token_secret
50
- end
51
- end
31
+ it 'should use the configuration defaults' do
32
+ Backup::Configuration::Notifier::Twitter.defaults do |twitter|
33
+ twitter.consumer_key = 'some_consumer_key'
34
+ twitter.consumer_secret = 'some_consumer_secret'
35
+ twitter.oauth_token = 'some_oauth_token'
36
+ twitter.oauth_token_secret = 'some_oauth_token_secret'
52
37
 
53
- describe '#perform!' do
54
- let(:model) { Backup::Model.new('trigger', 'label') {} }
55
- let(:message) { '[Backup::%s] label (trigger)' }
56
-
57
- before do
58
- notifier.on_success = false
59
- notifier.on_warning = false
60
- notifier.on_failure = false
61
- end
62
-
63
- context 'success' do
64
-
65
- context 'when on_success is true' do
66
- before { notifier.on_success = true }
67
-
68
- it 'sends success message' do
69
- notifier.expects(:log!)
70
- notifier.twitter_client.expects(:update).with(message % 'Success')
71
-
72
- notifier.perform!(model)
38
+ twitter.on_success = false
39
+ twitter.on_warning = false
40
+ twitter.on_failure = false
73
41
  end
42
+ notifier = Backup::Notifier::Twitter.new(model)
43
+ notifier.consumer_key.should == 'some_consumer_key'
44
+ notifier.consumer_secret.should == 'some_consumer_secret'
45
+ notifier.oauth_token.should == 'some_oauth_token'
46
+ notifier.oauth_token_secret.should == 'some_oauth_token_secret'
47
+
48
+ notifier.on_success.should == false
49
+ notifier.on_warning.should == false
50
+ notifier.on_failure.should == false
74
51
  end
75
52
 
76
- context 'when on_success is false' do
77
- it 'sends no message' do
78
- notifier.expects(:log!).never
79
- notifier.expects(:notify!).never
80
- notifier.twitter_client.expects(:update).never
53
+ it 'should override the configuration defaults' do
54
+ Backup::Configuration::Notifier::Twitter.defaults do |twitter|
55
+ twitter.consumer_key = 'old_consumer_key'
56
+ twitter.consumer_secret = 'old_consumer_secret'
57
+ twitter.oauth_token = 'old_oauth_token'
58
+ twitter.oauth_token_secret = 'old_oauth_token_secret'
81
59
 
82
- notifier.perform!(model)
60
+ twitter.on_success = true
61
+ twitter.on_warning = false
62
+ twitter.on_failure = false
83
63
  end
84
- end
85
-
86
- end # context 'success'
87
-
88
- context 'warning' do
89
- before { Backup::Logger.stubs(:has_warnings?).returns(true) }
90
-
91
- context 'when on_success is true' do
92
- before { notifier.on_success = true }
93
-
94
- it 'sends warning message' do
95
- notifier.expects(:log!)
96
- notifier.twitter_client.expects(:update).with(message % 'Warning')
97
-
98
- notifier.perform!(model)
64
+ notifier = Backup::Notifier::Twitter.new(model) do |twitter|
65
+ twitter.consumer_key = 'new_consumer_key'
66
+ twitter.consumer_secret = 'new_consumer_secret'
67
+ twitter.oauth_token = 'new_oauth_token'
68
+ twitter.oauth_token_secret = 'new_oauth_token_secret'
69
+
70
+ twitter.on_success = false
71
+ twitter.on_warning = true
72
+ twitter.on_failure = true
99
73
  end
100
- end
101
-
102
- context 'when on_warning is true' do
103
- before { notifier.on_warning = true }
104
74
 
105
- it 'sends warning message' do
106
- notifier.expects(:log!)
107
- notifier.twitter_client.expects(:update).with(message % 'Warning')
75
+ notifier.consumer_key.should == 'new_consumer_key'
76
+ notifier.consumer_secret.should == 'new_consumer_secret'
77
+ notifier.oauth_token.should == 'new_oauth_token'
78
+ notifier.oauth_token_secret.should == 'new_oauth_token_secret'
108
79
 
109
- notifier.perform!(model)
110
- end
80
+ notifier.on_success.should == false
81
+ notifier.on_warning.should == true
82
+ notifier.on_failure.should == true
111
83
  end
84
+ end # context 'when using configuration defaults'
85
+ end
112
86
 
113
- context 'when on_success and on_warning are false' do
114
- it 'sends no message' do
115
- notifier.expects(:log!).never
116
- notifier.expects(:notify!).never
117
- notifier.twitter_client.expects(:update).never
118
-
119
- notifier.perform!(model)
120
- end
87
+ describe '#notify!' do
88
+ context 'when status is :success' do
89
+ it 'should send Success message' do
90
+ notifier.expects(:send_message).with(
91
+ '[Backup::Success] test label (test_trigger)'
92
+ )
93
+ notifier.send(:notify!, :success)
121
94
  end
95
+ end
122
96
 
123
- end # context 'warning'
124
-
125
- context 'failure' do
126
-
127
- context 'when on_failure is true' do
128
- before { notifier.on_failure = true }
129
-
130
- it 'sends failure message' do
131
- notifier.expects(:log!)
132
- notifier.twitter_client.expects(:update).with(message % 'Failure')
97
+ context 'when status is :warning' do
98
+ it 'should send Warning message' do
99
+ notifier.expects(:send_message).with(
100
+ '[Backup::Warning] test label (test_trigger)'
101
+ )
102
+ notifier.send(:notify!, :warning)
103
+ end
104
+ end
133
105
 
134
- notifier.perform!(model, Exception.new)
135
- end
106
+ context 'when status is :failure' do
107
+ it 'should send Failure message' do
108
+ notifier.expects(:send_message).with(
109
+ '[Backup::Failure] test label (test_trigger)'
110
+ )
111
+ notifier.send(:notify!, :failure)
136
112
  end
113
+ end
114
+ end # describe '#notify!'
137
115
 
138
- context 'when on_failure is false' do
139
- it 'sends no message' do
140
- notifier.expects(:log!).never
141
- notifier.expects(:notify!).never
142
- notifier.twitter_client.expects(:update).never
116
+ describe '#send_message' do
117
+ it 'should send a message' do
118
+ client, config = mock, mock
143
119
 
144
- notifier.perform!(model, Exception.new)
145
- end
146
- end
120
+ ::Twitter.expects(:configure).yields(config)
121
+ config.expects(:consumer_key=).with('consumer_key')
122
+ config.expects(:consumer_secret=).with('consumer_secret')
123
+ config.expects(:oauth_token=).with('oauth_token')
124
+ config.expects(:oauth_token_secret=).with('oauth_token_secret')
147
125
 
148
- end # context 'failure'
126
+ ::Twitter::Client.expects(:new).returns(client)
127
+ client.expects(:update).with('a message')
149
128
 
150
- end # describe '#perform!'
129
+ notifier.send(:send_message, 'a message')
130
+ end
131
+ end
151
132
  end