backup 3.0.27 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +1 -1
- data/README.md +139 -386
- data/bin/backup +1 -7
- data/lib/backup.rb +3 -9
- data/lib/backup/archive.rb +26 -20
- data/lib/backup/cleaner.rb +2 -2
- data/lib/backup/cli.rb +366 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/gzip.rb +35 -1
- data/lib/backup/config.rb +1 -2
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +3 -3
- data/lib/backup/database/mysql.rb +3 -2
- data/lib/backup/database/postgresql.rb +3 -2
- data/lib/backup/database/riak.rb +18 -5
- data/lib/backup/dependency.rb +144 -93
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/logger.rb +108 -110
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/logfile.rb +113 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +67 -65
- data/lib/backup/notifier/base.rb +1 -1
- data/lib/backup/notifier/hipchat.rb +1 -1
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/notifier/pushover.rb +6 -3
- data/lib/backup/packager.rb +4 -4
- data/lib/backup/pipeline.rb +17 -3
- data/lib/backup/splitter.rb +2 -2
- data/lib/backup/storage/base.rb +2 -2
- data/lib/backup/storage/cloudfiles.rb +2 -2
- data/lib/backup/storage/dropbox.rb +4 -4
- data/lib/backup/storage/ftp.rb +2 -2
- data/lib/backup/storage/local.rb +2 -2
- data/lib/backup/storage/ninefold.rb +2 -2
- data/lib/backup/storage/rsync.rb +3 -3
- data/lib/backup/storage/s3.rb +2 -2
- data/lib/backup/storage/scp.rb +2 -6
- data/lib/backup/storage/sftp.rb +2 -5
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/cloud/base.rb +15 -8
- data/lib/backup/syncer/rsync/local.rb +1 -1
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +1 -1
- data/lib/backup/utilities.rb +211 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/{utility/archive → archive} +4 -8
- data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
- data/templates/cli/{utility/compressor → compressor}/custom +0 -0
- data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
- data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
- data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
- data/templates/cli/config +68 -0
- data/templates/cli/{utility/database → database}/mongodb +1 -1
- data/templates/cli/{utility/database → database}/mysql +1 -1
- data/templates/cli/{utility/database → database}/postgresql +1 -1
- data/templates/cli/{utility/database → database}/redis +0 -0
- data/templates/cli/database/riak +20 -0
- data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
- data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
- data/templates/cli/{utility/model.erb → model.erb} +4 -4
- data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
- data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
- data/templates/cli/{utility/notifier → notifier}/mail +0 -0
- data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
- data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
- data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
- data/templates/cli/{utility/splitter → splitter} +0 -0
- data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
- data/templates/cli/{utility/storage → storage}/dropbox +0 -0
- data/templates/cli/{utility/storage → storage}/ftp +0 -0
- data/templates/cli/{utility/storage → storage}/local +0 -0
- data/templates/cli/{utility/storage → storage}/ninefold +0 -0
- data/templates/cli/{utility/storage → storage}/rsync +0 -0
- data/templates/cli/{utility/storage → storage}/s3 +0 -0
- data/templates/cli/{utility/storage → storage}/scp +0 -0
- data/templates/cli/{utility/storage → storage}/sftp +0 -0
- data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
- data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
- metadata +55 -131
- data/.gitignore +0 -8
- data/.travis.yml +0 -10
- data/Gemfile +0 -28
- data/Guardfile +0 -23
- data/backup.gemspec +0 -32
- data/lib/backup/cli/helpers.rb +0 -93
- data/lib/backup/cli/utility.rb +0 -255
- data/spec-live/.gitignore +0 -6
- data/spec-live/README +0 -7
- data/spec-live/backups/config.rb +0 -83
- data/spec-live/backups/config.yml.template +0 -46
- data/spec-live/backups/models.rb +0 -184
- data/spec-live/compressor/custom_spec.rb +0 -30
- data/spec-live/compressor/gzip_spec.rb +0 -30
- data/spec-live/encryptor/gpg_keys.rb +0 -239
- data/spec-live/encryptor/gpg_spec.rb +0 -287
- data/spec-live/notifier/mail_spec.rb +0 -121
- data/spec-live/spec_helper.rb +0 -151
- data/spec-live/storage/dropbox_spec.rb +0 -151
- data/spec-live/storage/local_spec.rb +0 -83
- data/spec-live/storage/scp_spec.rb +0 -193
- data/spec-live/syncer/cloud/s3_spec.rb +0 -124
- data/spec/archive_spec.rb +0 -335
- data/spec/cleaner_spec.rb +0 -312
- data/spec/cli/helpers_spec.rb +0 -301
- data/spec/cli/utility_spec.rb +0 -411
- data/spec/compressor/base_spec.rb +0 -52
- data/spec/compressor/bzip2_spec.rb +0 -217
- data/spec/compressor/custom_spec.rb +0 -106
- data/spec/compressor/gzip_spec.rb +0 -217
- data/spec/compressor/lzma_spec.rb +0 -123
- data/spec/compressor/pbzip2_spec.rb +0 -165
- data/spec/config_spec.rb +0 -321
- data/spec/configuration/helpers_spec.rb +0 -247
- data/spec/configuration/store_spec.rb +0 -39
- data/spec/configuration_spec.rb +0 -62
- data/spec/database/base_spec.rb +0 -63
- data/spec/database/mongodb_spec.rb +0 -510
- data/spec/database/mysql_spec.rb +0 -411
- data/spec/database/postgresql_spec.rb +0 -353
- data/spec/database/redis_spec.rb +0 -334
- data/spec/database/riak_spec.rb +0 -176
- data/spec/dependency_spec.rb +0 -51
- data/spec/encryptor/base_spec.rb +0 -40
- data/spec/encryptor/gpg_spec.rb +0 -909
- data/spec/encryptor/open_ssl_spec.rb +0 -148
- data/spec/errors_spec.rb +0 -306
- data/spec/logger_spec.rb +0 -367
- data/spec/model_spec.rb +0 -666
- data/spec/notifier/base_spec.rb +0 -104
- data/spec/notifier/campfire_spec.rb +0 -217
- data/spec/notifier/hipchat_spec.rb +0 -211
- data/spec/notifier/mail_spec.rb +0 -316
- data/spec/notifier/prowl_spec.rb +0 -138
- data/spec/notifier/pushover_spec.rb +0 -123
- data/spec/notifier/twitter_spec.rb +0 -153
- data/spec/package_spec.rb +0 -61
- data/spec/packager_spec.rb +0 -213
- data/spec/pipeline_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -60
- data/spec/splitter_spec.rb +0 -120
- data/spec/storage/base_spec.rb +0 -166
- data/spec/storage/cloudfiles_spec.rb +0 -254
- data/spec/storage/cycler_spec.rb +0 -247
- data/spec/storage/dropbox_spec.rb +0 -480
- data/spec/storage/ftp_spec.rb +0 -271
- data/spec/storage/local_spec.rb +0 -259
- data/spec/storage/ninefold_spec.rb +0 -343
- data/spec/storage/rsync_spec.rb +0 -362
- data/spec/storage/s3_spec.rb +0 -245
- data/spec/storage/scp_spec.rb +0 -233
- data/spec/storage/sftp_spec.rb +0 -244
- data/spec/syncer/base_spec.rb +0 -109
- data/spec/syncer/cloud/base_spec.rb +0 -515
- data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
- data/spec/syncer/cloud/s3_spec.rb +0 -174
- data/spec/syncer/rsync/base_spec.rb +0 -98
- data/spec/syncer/rsync/local_spec.rb +0 -149
- data/spec/syncer/rsync/pull_spec.rb +0 -98
- data/spec/syncer/rsync/push_spec.rb +0 -333
- data/spec/version_spec.rb +0 -21
- data/templates/cli/utility/config +0 -32
- data/templates/cli/utility/database/riak +0 -11
data/spec/notifier/base_spec.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe 'Backup::Notifier::Base' do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:notifier) { Backup::Notifier::Base.new(model) }
|
8
|
-
|
9
|
-
it 'should include Configuration::Helpers' do
|
10
|
-
Backup::Notifier::Base.
|
11
|
-
include?(Backup::Configuration::Helpers).should be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#initialize' do
|
15
|
-
after { Backup::Notifier::Base.clear_defaults! }
|
16
|
-
|
17
|
-
it 'should load pre-configured defaults' do
|
18
|
-
Backup::Notifier::Base.any_instance.expects(:load_defaults!)
|
19
|
-
notifier
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should set a reference to the model' do
|
23
|
-
notifier.instance_variable_get(:@model).should == model
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when no pre-configured defaults have been set' do
|
27
|
-
it 'should set default values' do
|
28
|
-
notifier.on_success.should == true
|
29
|
-
notifier.on_warning.should == true
|
30
|
-
notifier.on_failure.should == true
|
31
|
-
end
|
32
|
-
end # context 'when no pre-configured defaults have been set'
|
33
|
-
|
34
|
-
context 'when pre-configured defaults have been set' do
|
35
|
-
before do
|
36
|
-
Backup::Notifier::Base.defaults do |n|
|
37
|
-
n.on_success = false
|
38
|
-
n.on_warning = false
|
39
|
-
n.on_failure = false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should use pre-configured defaults' do
|
44
|
-
notifier.on_success.should be_false
|
45
|
-
notifier.on_warning.should be_false
|
46
|
-
notifier.on_failure.should be_false
|
47
|
-
end
|
48
|
-
end # context 'when pre-configured defaults have been set'
|
49
|
-
end # describe '#initialize'
|
50
|
-
|
51
|
-
describe '#perform!' do
|
52
|
-
before do
|
53
|
-
notifier.expects(:log!)
|
54
|
-
Backup::Template.expects(:new).with({:model => model})
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when failure is false' do
|
58
|
-
context 'when no warnings were issued' do
|
59
|
-
before do
|
60
|
-
Backup::Logger.expects(:has_warnings?).returns(false)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should call #notify! with :success' do
|
64
|
-
notifier.expects(:notify!).with(:success)
|
65
|
-
notifier.perform!
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'when warnings were issued' do
|
70
|
-
before do
|
71
|
-
Backup::Logger.expects(:has_warnings?).returns(true)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should call #notify! with :warning' do
|
75
|
-
notifier.expects(:notify!).with(:warning)
|
76
|
-
notifier.perform!
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end # context 'when failure is false'
|
80
|
-
|
81
|
-
context 'when failure is true' do
|
82
|
-
it 'should call #notify with :failure' do
|
83
|
-
notifier.expects(:notify!).with(:failure)
|
84
|
-
notifier.perform!(true)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end # describe '#perform!'
|
88
|
-
|
89
|
-
describe '#notifier_name' do
|
90
|
-
it 'should return class name without Backup:: namespace' do
|
91
|
-
notifier.send(:notifier_name).should == 'Notifier::Base'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#log!' do
|
96
|
-
it 'should log a message' do
|
97
|
-
Backup::Logger.expects(:message).with(
|
98
|
-
"Notifier::Base started notifying about the process."
|
99
|
-
)
|
100
|
-
notifier.send(:log!)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
@@ -1,217 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Notifier::Campfire do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:notifier) do
|
8
|
-
Backup::Notifier::Campfire.new(model) do |campfire|
|
9
|
-
campfire.api_token = 'token'
|
10
|
-
campfire.subdomain = 'subdomain'
|
11
|
-
campfire.room_id = 'room_id'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be a subclass of Notifier::Base' do
|
16
|
-
Backup::Notifier::Campfire.
|
17
|
-
superclass.should == Backup::Notifier::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
after { Backup::Notifier::Campfire.clear_defaults! }
|
22
|
-
|
23
|
-
it 'should load pre-configured defaults through Base' do
|
24
|
-
Backup::Notifier::Campfire.any_instance.expects(:load_defaults!)
|
25
|
-
notifier
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should pass the model reference to Base' do
|
29
|
-
notifier.instance_variable_get(:@model).should == model
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when no pre-configured defaults have been set' do
|
33
|
-
it 'should use the values given' do
|
34
|
-
notifier.api_token.should == 'token'
|
35
|
-
notifier.subdomain.should == 'subdomain'
|
36
|
-
notifier.room_id.should == 'room_id'
|
37
|
-
|
38
|
-
notifier.on_success.should == true
|
39
|
-
notifier.on_warning.should == true
|
40
|
-
notifier.on_failure.should == true
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should use default values if none are given' do
|
44
|
-
notifier = Backup::Notifier::Campfire.new(model)
|
45
|
-
notifier.api_token.should be_nil
|
46
|
-
notifier.subdomain.should be_nil
|
47
|
-
notifier.room_id.should be_nil
|
48
|
-
|
49
|
-
notifier.on_success.should == true
|
50
|
-
notifier.on_warning.should == true
|
51
|
-
notifier.on_failure.should == true
|
52
|
-
end
|
53
|
-
end # context 'when no pre-configured defaults have been set'
|
54
|
-
|
55
|
-
context 'when pre-configured defaults have been set' do
|
56
|
-
before do
|
57
|
-
Backup::Notifier::Campfire.defaults do |n|
|
58
|
-
n.api_token = 'some_token'
|
59
|
-
n.subdomain = 'some_subdomain'
|
60
|
-
n.room_id = 'some_room_id'
|
61
|
-
|
62
|
-
n.on_success = false
|
63
|
-
n.on_warning = false
|
64
|
-
n.on_failure = false
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should use pre-configured defaults' do
|
69
|
-
notifier = Backup::Notifier::Campfire.new(model)
|
70
|
-
notifier.api_token.should == 'some_token'
|
71
|
-
notifier.subdomain.should == 'some_subdomain'
|
72
|
-
notifier.room_id.should == 'some_room_id'
|
73
|
-
|
74
|
-
notifier.on_success.should == false
|
75
|
-
notifier.on_warning.should == false
|
76
|
-
notifier.on_failure.should == false
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should override pre-configured defaults' do
|
80
|
-
notifier = Backup::Notifier::Campfire.new(model) do |n|
|
81
|
-
n.api_token = 'new_token'
|
82
|
-
n.subdomain = 'new_subdomain'
|
83
|
-
n.room_id = 'new_room_id'
|
84
|
-
|
85
|
-
n.on_success = false
|
86
|
-
n.on_warning = true
|
87
|
-
n.on_failure = true
|
88
|
-
end
|
89
|
-
|
90
|
-
notifier.api_token.should == 'new_token'
|
91
|
-
notifier.subdomain.should == 'new_subdomain'
|
92
|
-
notifier.room_id.should == 'new_room_id'
|
93
|
-
|
94
|
-
notifier.on_success.should == false
|
95
|
-
notifier.on_warning.should == true
|
96
|
-
notifier.on_failure.should == true
|
97
|
-
end
|
98
|
-
end # context 'when pre-configured defaults have been set'
|
99
|
-
end # describe '#initialize'
|
100
|
-
|
101
|
-
describe '#notify!' do
|
102
|
-
context 'when status is :success' do
|
103
|
-
it 'should send Success message' do
|
104
|
-
notifier.expects(:send_message).with(
|
105
|
-
'[Backup::Success] test label (test_trigger)'
|
106
|
-
)
|
107
|
-
notifier.send(:notify!, :success)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when status is :warning' do
|
112
|
-
it 'should send Warning message' do
|
113
|
-
notifier.expects(:send_message).with(
|
114
|
-
'[Backup::Warning] test label (test_trigger)'
|
115
|
-
)
|
116
|
-
notifier.send(:notify!, :warning)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'when status is :failure' do
|
121
|
-
it 'should send Failure message' do
|
122
|
-
notifier.expects(:send_message).with(
|
123
|
-
'[Backup::Failure] test label (test_trigger)'
|
124
|
-
)
|
125
|
-
notifier.send(:notify!, :failure)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end # describe '#notify!'
|
129
|
-
|
130
|
-
describe '#send_message' do
|
131
|
-
it 'should send a message' do
|
132
|
-
room = mock
|
133
|
-
Backup::Notifier::Campfire::Interface.expects(:room).
|
134
|
-
with('room_id', 'subdomain', 'token').returns(room)
|
135
|
-
room.expects(:message).with('a message')
|
136
|
-
|
137
|
-
notifier.send(:send_message, 'a message')
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
describe 'Backup::Notifier::Campfire::Interface' do
|
144
|
-
let(:interface) { Backup::Notifier::Campfire::Interface }
|
145
|
-
|
146
|
-
it 'should include HTTParty' do
|
147
|
-
interface.included_modules.should include(HTTParty)
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'should set the proper headers' do
|
151
|
-
interface.headers['Content-Type'].should == 'application/json'
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '.room' do
|
155
|
-
let(:room) { mock }
|
156
|
-
|
157
|
-
it 'should create and return a new Room' do
|
158
|
-
Backup::Notifier::Campfire::Room.expects(:new).
|
159
|
-
with('room_id', 'subdomain', 'api_token').returns(room)
|
160
|
-
|
161
|
-
interface.room('room_id', 'subdomain', 'api_token').should == room
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'Backup::Notifier::Campfire::Room' do
|
167
|
-
let(:room) do
|
168
|
-
Backup::Notifier::Campfire::Room.new('room_id', 'subdomain', 'api_token')
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should set the given values for the room' do
|
172
|
-
room.room_id.should == 'room_id'
|
173
|
-
room.subdomain.should == 'subdomain'
|
174
|
-
room.api_token.should == 'api_token'
|
175
|
-
end
|
176
|
-
|
177
|
-
describe '#message' do
|
178
|
-
it 'should wrap #send_message' do
|
179
|
-
room.expects(:send_message).with('a message')
|
180
|
-
|
181
|
-
room.message('a message')
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe '#send_message' do
|
186
|
-
it 'should pass a JSON formatted HTTParty.post to #post' do
|
187
|
-
room.expects(:post).with(
|
188
|
-
'speak', {
|
189
|
-
:body => MultiJson.encode(
|
190
|
-
{ :message => { :body => 'a message', :type => 'Textmessage' } }
|
191
|
-
)
|
192
|
-
}
|
193
|
-
)
|
194
|
-
room.send(:send_message, 'a message')
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
describe '#post' do
|
199
|
-
let(:interface) { Backup::Notifier::Campfire::Interface }
|
200
|
-
|
201
|
-
it 'should send an HTTParty.post with the given options through Interface' do
|
202
|
-
room.expects(:room_url_for).with('an_action').returns('a_room_url')
|
203
|
-
interface.expects(:base_uri).with('https://subdomain.campfirenow.com')
|
204
|
-
interface.expects(:basic_auth).with('api_token', 'x')
|
205
|
-
interface.expects(:post).with('a_room_url', { :hash => 'of options' })
|
206
|
-
|
207
|
-
room.send(:post, 'an_action', :hash => 'of options')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe '#room_url_for' do
|
212
|
-
it 'should return a properly formated url for the given action' do
|
213
|
-
room.send(:room_url_for, 'my_action').should ==
|
214
|
-
'/room/room_id/my_action.json'
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
@@ -1,211 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Notifier::Hipchat do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:notifier) do
|
8
|
-
Backup::Notifier::Hipchat.new(model) do |notifier|
|
9
|
-
notifier.token = 'token'
|
10
|
-
notifier.from = 'application'
|
11
|
-
notifier.rooms_notified = ['room1', 'room2']
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be a subclass of Notifier::Base' do
|
16
|
-
Backup::Notifier::Hipchat.
|
17
|
-
superclass.should == Backup::Notifier::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
after { Backup::Notifier::Hipchat.clear_defaults! }
|
22
|
-
|
23
|
-
it 'should load pre-configured defaults through Base' do
|
24
|
-
Backup::Notifier::Hipchat.any_instance.expects(:load_defaults!)
|
25
|
-
notifier
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should pass the model reference to Base' do
|
29
|
-
notifier.instance_variable_get(:@model).should == model
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when no pre-configured defaults have been set' do
|
33
|
-
it 'should use the values given' do
|
34
|
-
notifier.token.should == 'token'
|
35
|
-
notifier.from.should == 'application'
|
36
|
-
notifier.rooms_notified.should == ['room1', 'room2']
|
37
|
-
notifier.notify_users.should == false
|
38
|
-
notifier.success_color.should == 'yellow'
|
39
|
-
notifier.warning_color.should == 'yellow'
|
40
|
-
notifier.failure_color.should == 'yellow'
|
41
|
-
|
42
|
-
notifier.on_success.should == true
|
43
|
-
notifier.on_warning.should == true
|
44
|
-
notifier.on_failure.should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should use default values if none are given' do
|
48
|
-
notifier = Backup::Notifier::Hipchat.new(model)
|
49
|
-
notifier.token.should be_nil
|
50
|
-
notifier.from.should be_nil
|
51
|
-
notifier.rooms_notified.should == []
|
52
|
-
notifier.notify_users.should == false
|
53
|
-
notifier.success_color.should == 'yellow'
|
54
|
-
notifier.warning_color.should == 'yellow'
|
55
|
-
notifier.failure_color.should == 'yellow'
|
56
|
-
|
57
|
-
notifier.on_success.should == true
|
58
|
-
notifier.on_warning.should == true
|
59
|
-
notifier.on_failure.should == true
|
60
|
-
end
|
61
|
-
end # context 'when no pre-configured defaults have been set'
|
62
|
-
|
63
|
-
context 'when pre-configured defaults have been set' do
|
64
|
-
before do
|
65
|
-
Backup::Notifier::Hipchat.defaults do |n|
|
66
|
-
n.token = 'old'
|
67
|
-
n.from = 'before'
|
68
|
-
n.success_color = 'green'
|
69
|
-
n.on_failure = false
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should use pre-configured defaults' do
|
74
|
-
notifier = Backup::Notifier::Hipchat.new(model)
|
75
|
-
|
76
|
-
notifier.token.should == 'old'
|
77
|
-
notifier.from.should == 'before'
|
78
|
-
notifier.rooms_notified.should == []
|
79
|
-
notifier.notify_users.should == false
|
80
|
-
notifier.success_color.should == 'green'
|
81
|
-
notifier.warning_color.should == 'yellow'
|
82
|
-
notifier.failure_color.should == 'yellow'
|
83
|
-
|
84
|
-
notifier.on_success.should == true
|
85
|
-
notifier.on_warning.should == true
|
86
|
-
notifier.on_failure.should == false
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should override pre-configured defaults' do
|
90
|
-
notifier = Backup::Notifier::Hipchat.new(model) do |n|
|
91
|
-
n.token = 'new'
|
92
|
-
n.from = 'after'
|
93
|
-
n.failure_color = 'red'
|
94
|
-
n.on_success = false
|
95
|
-
n.on_failure = true
|
96
|
-
end
|
97
|
-
|
98
|
-
notifier.token.should == 'new'
|
99
|
-
notifier.from.should == 'after'
|
100
|
-
notifier.success_color.should == 'green'
|
101
|
-
notifier.warning_color.should == 'yellow'
|
102
|
-
notifier.failure_color.should == 'red'
|
103
|
-
|
104
|
-
notifier.on_success.should == false
|
105
|
-
notifier.on_warning.should == true
|
106
|
-
notifier.on_failure.should == true
|
107
|
-
end
|
108
|
-
end # context 'when pre-configured defaults have been set'
|
109
|
-
end # describe '#initialize'
|
110
|
-
|
111
|
-
describe '#notify!' do
|
112
|
-
before do
|
113
|
-
notifier.success_color = 'green'
|
114
|
-
notifier.warning_color = 'yellow'
|
115
|
-
notifier.failure_color = 'red'
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when status is :success' do
|
119
|
-
it 'should send Success message' do
|
120
|
-
notifier.expects(:send_message).with(
|
121
|
-
'[Backup::Success] test label (test_trigger)', 'green'
|
122
|
-
)
|
123
|
-
notifier.send(:notify!, :success)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context 'when status is :warning' do
|
128
|
-
it 'should send Warning message' do
|
129
|
-
notifier.expects(:send_message).with(
|
130
|
-
'[Backup::Warning] test label (test_trigger)', 'yellow'
|
131
|
-
)
|
132
|
-
notifier.send(:notify!, :warning)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'when status is :failure' do
|
137
|
-
it 'should send Failure message' do
|
138
|
-
notifier.expects(:send_message).with(
|
139
|
-
'[Backup::Failure] test label (test_trigger)', 'red'
|
140
|
-
)
|
141
|
-
notifier.send(:notify!, :failure)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end # describe '#notify!'
|
145
|
-
|
146
|
-
describe '#send_message' do
|
147
|
-
let(:client) { mock }
|
148
|
-
let(:room) { mock }
|
149
|
-
|
150
|
-
it 'should handle rooms_notified being set as a single room string' do
|
151
|
-
notifier.rooms_notified = 'a_room'
|
152
|
-
HipChat::Client.expects(:new).with('token').returns(client)
|
153
|
-
client.expects(:[]).with('a_room').returns(room)
|
154
|
-
room.expects(:send).with(
|
155
|
-
'application',
|
156
|
-
'a message',
|
157
|
-
{:color => 'a color', :notify => false}
|
158
|
-
)
|
159
|
-
|
160
|
-
notifier.send(:send_message, 'a message', 'a color')
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when notify_users is set to true' do
|
164
|
-
before { notifier.notify_users = true }
|
165
|
-
|
166
|
-
it 'should notify rooms with :notify => true' do
|
167
|
-
HipChat::Client.expects(:new).with('token').returns(client)
|
168
|
-
|
169
|
-
client.expects(:[]).with('room1').returns(room)
|
170
|
-
room.expects(:send).with(
|
171
|
-
'application',
|
172
|
-
'a message',
|
173
|
-
{:color => 'a color', :notify => true}
|
174
|
-
)
|
175
|
-
|
176
|
-
client.expects(:[]).with('room2').returns(room)
|
177
|
-
room.expects(:send).with(
|
178
|
-
'application',
|
179
|
-
'a message',
|
180
|
-
{:color => 'a color', :notify => true}
|
181
|
-
)
|
182
|
-
|
183
|
-
notifier.send(:send_message, 'a message', 'a color')
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when notify_users is set to false' do
|
188
|
-
before { notifier.notify_users = false }
|
189
|
-
|
190
|
-
it 'should notify rooms with :notify => false' do
|
191
|
-
HipChat::Client.expects(:new).with('token').returns(client)
|
192
|
-
|
193
|
-
client.expects(:[]).with('room1').returns(room)
|
194
|
-
room.expects(:send).with(
|
195
|
-
'application',
|
196
|
-
'a message',
|
197
|
-
{:color => 'a color', :notify => false}
|
198
|
-
)
|
199
|
-
|
200
|
-
client.expects(:[]).with('room2').returns(room)
|
201
|
-
room.expects(:send).with(
|
202
|
-
'application',
|
203
|
-
'a message',
|
204
|
-
{:color => 'a color', :notify => false}
|
205
|
-
)
|
206
|
-
|
207
|
-
notifier.send(:send_message, 'a message', 'a color')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|