backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
data/spec/notifier/prowl_spec.rb
CHANGED
@@ -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
|
15
|
-
notifier.application
|
16
|
-
notifier.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
|
-
|
24
|
-
Backup::Configuration::Notifier::Prowl.
|
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
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
36
|
+
notifier = Backup::Notifier::Prowl.new(model)
|
37
|
+
notifier.application.should == 'default_app'
|
38
|
+
notifier.api_key.should == 'default_api_key'
|
70
39
|
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
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
|
-
|
84
|
-
|
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
|
-
|
54
|
+
notifier = Backup::Notifier::Prowl.new(model) do |prowl|
|
55
|
+
prowl.application = 'new_app'
|
56
|
+
prowl.api_key = 'new_api_key'
|
97
57
|
|
98
|
-
|
99
|
-
|
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
|
-
|
111
|
-
|
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
|
-
|
117
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
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
|
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
|
-
|
28
|
-
Backup::Configuration::Notifier::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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
60
|
+
twitter.on_success = true
|
61
|
+
twitter.on_warning = false
|
62
|
+
twitter.on_failure = false
|
83
63
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
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
|
-
|
110
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
135
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
126
|
+
::Twitter::Client.expects(:new).returns(client)
|
127
|
+
client.expects(:update).with('a message')
|
149
128
|
|
150
|
-
|
129
|
+
notifier.send(:send_message, 'a message')
|
130
|
+
end
|
131
|
+
end
|
151
132
|
end
|