poring_backup 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,19 +15,19 @@ module PoringBackup
15
15
  expect(db.path).to eq 'db_backups'
16
16
  end
17
17
  it "backup file name" do
18
- expect(db.file).to eq 'db_backup.psql'
18
+ expect(db.file).to eq 'db_backup.sql'
19
19
  end
20
20
  it "backup file dir" do
21
21
  expect(db.file_dir).to eq 'db_backups/date_time_dir'
22
22
  end
23
23
  it "backup file path" do
24
- expect(db.file_path).to eq 'db_backups/date_time_dir/db_backup.psql'
24
+ expect(db.file_path).to eq 'db_backups/date_time_dir/db_backup.sql'
25
25
  end
26
26
  it "backup tmp dir" do
27
27
  expect(db.tmp_dir).to eq 'tmp/poring_backups/db_backups/date_time_dir'
28
28
  end
29
29
  it "backup tmp file path" do
30
- expect(db.tmp_file_path).to eq 'tmp/poring_backups/db_backups/date_time_dir/db_backup.psql'
30
+ expect(db.tmp_file_path).to eq 'tmp/poring_backups/db_backups/date_time_dir/db_backup.sql'
31
31
  end
32
32
  end
33
33
 
@@ -13,8 +13,8 @@ module PoringBackup
13
13
  end
14
14
  }
15
15
  context "block" do
16
- it 'sets database' do
17
- expect(pg.instance_variable_get(:@database)).to eq 'new_database_name'
16
+ it 'sets db_name' do
17
+ expect(pg.instance_variable_get(:@db_name)).to eq 'new_database_name'
18
18
  end
19
19
  it 'sets host' do
20
20
  expect(pg.instance_variable_get(:@host)).to eq 'new_host_name'
@@ -0,0 +1,129 @@
1
+ require "rails_helper"
2
+
3
+
4
+ module PoringBackup
5
+ module Notifiers
6
+ describe Slack do
7
+ let(:setting) {
8
+ PoringBackup.config('My Brand') do
9
+
10
+ # before do |logger|
11
+ # #do somethings before backup
12
+ # end
13
+
14
+ # after do |logger|
15
+ # #do somethings after backup
16
+ # end
17
+ database :PostgreSQL do
18
+ database 'database_name_2'
19
+ username 'username'
20
+ password 'password'
21
+ end
22
+
23
+ database :PostgreSQL do
24
+ database 'database_name_1'
25
+ username 'username'
26
+ password 'password'
27
+ end
28
+
29
+ store_with :S3 do
30
+ access_key_id 'access_key_id'
31
+ secret_access_key 'secret_access_key'
32
+ bucket 'bucket_name'
33
+ region 'region'
34
+ path 'your/path'
35
+ end
36
+
37
+ notifier :Slack do
38
+ webhook "https://slack.webhook.uri"
39
+ channel "#channel_name"
40
+ # only_env [:development, :production]
41
+ end
42
+
43
+ end
44
+ @setting = PoringBackup.model
45
+ }
46
+ let(:slack) {
47
+ @slack = PoringBackup::Notifiers::Slack.new(PoringBackup::Setting.new) do
48
+ webhook 'https://slack.webhook.uri'
49
+ channel '#channel_name'
50
+ only_env [:development, :production]
51
+ end
52
+ }
53
+ context "initialize" do
54
+
55
+ it "webhook_uri" do
56
+ expect(slack.webhook_uri).to eq 'https://slack.webhook.uri'
57
+ end
58
+ it "channel_name" do
59
+ expect(slack.channel_name).to eq '#channel_name'
60
+ end
61
+ it "on_envs" do
62
+ expect(slack.on_envs).to eq(["development", "production"])
63
+ end
64
+ end
65
+ context "#notify!" do
66
+ it "return :disabled if env does not in on_envs" do
67
+ slack.only_env [:woring_env]
68
+ expect(slack.notify!).to eq :disabled
69
+ end
70
+ it "return :success if env work" do
71
+ slack.only_env []
72
+ Excon.stub({}, {:body => 'ok', :status => 200})
73
+ expect(slack.notify!).to eq :success
74
+ end
75
+ it "return errors if failure" do
76
+ slack.only_env []
77
+ error_message = 'failed : Invalid channel specified'
78
+ Excon.stub({}, {:body => error_message, :status => 500})
79
+ expect(slack.notify!).to eq error_message
80
+ end
81
+ end
82
+ it "#data" do
83
+ slack = setting.notifiers.first
84
+ data = slack.send :data
85
+ expect_data = {
86
+ :channel=>"#channel_name",
87
+ :username=>"Poring Backup",
88
+ :icon_emoji=>":ghost:",
89
+ :attachments=>[
90
+ {
91
+ :fallback=>"more information at <https://github.com/piya23300/poring_backup|poring_backup gem>",
92
+ :pretext=>"backup at #{setting.created_at}",
93
+ :title=> "My Brand",
94
+ :color=>"#7CD197",
95
+ :fields=>[
96
+ {
97
+ :title=>"Environment",
98
+ :value=>"test",
99
+ :short=>true
100
+ },
101
+ {
102
+ :title=>"Contect",
103
+ :value=>"<https://github.com/piya23300/poring_backup|poring_backup gem>",
104
+ :short=>true
105
+ },
106
+ {
107
+ :title=>"Databases",
108
+ :value=>"[PostgreSQL] database_name_2\n[PostgreSQL] database_name_1",
109
+ :short=>false
110
+ },
111
+ {
112
+ :title=>"Storages",
113
+ :value=>"[S3] bucket: bucket_name, path: your/path",
114
+ :short=>false
115
+ },
116
+ {
117
+ :title=>"Notifier",
118
+ :value=>"[Slack] #channel_name",
119
+ :short=>false
120
+ }
121
+ ]
122
+ }
123
+ ]
124
+ }
125
+ expect(data).to eq expect_data
126
+ end
127
+ end
128
+ end
129
+ end
@@ -4,11 +4,15 @@ module PoringBackup
4
4
  describe Setting do
5
5
  it "initialize" do
6
6
  setting = PoringBackup::Setting.new
7
+ expect(setting.app_name).to eq nil
7
8
  expect(setting.tmp_dir).to eq 'tmp/poring_backups'
8
9
  expect(setting.dir).to eq 'poring_backups'
9
10
  expect(setting.databases).to eq []
10
11
  expect(setting.storages).to eq []
11
12
  expect(setting.created_at).not_to eq nil
13
+
14
+ setting = PoringBackup::Setting.new('MyBrandName')
15
+ expect(setting.app_name).to eq 'MyBrandName'
12
16
  end
13
17
  it "generate database object" do
14
18
  setting = PoringBackup::Setting.new do
@@ -34,6 +38,17 @@ module PoringBackup
34
38
  expect(setting.storages.size).to eq 1
35
39
  expect(setting.storages.first).to be_a(Storages::S3)
36
40
  end
41
+ it "generate notifier object" do
42
+ setting = PoringBackup::Setting.new do
43
+ notifier :Slack do
44
+ webhook 'https://slack.webhook.uri'
45
+ channel '#channel_name'
46
+ only_env [:development, :production]
47
+ end
48
+ end
49
+ expect(setting.notifiers.size).to eq 1
50
+ expect(setting.notifiers.first).to be_a(Notifiers::Slack)
51
+ end
37
52
  it "#clear_tmp! will delete tmp directory" do
38
53
  setting = PoringBackup::Setting.new
39
54
  FileUtils.mkdir_p(setting.tmp_dir)
@@ -3,7 +3,7 @@ require "rails_helper"
3
3
 
4
4
  module PoringBackup
5
5
  module Storages
6
- describe S3, focus: true do
6
+ describe S3 do
7
7
  let(:aws) {
8
8
  @aws = S3.new(Setting.new) do
9
9
  access_key_id 'new_access_key_id'
@@ -5,6 +5,7 @@ require File.expand_path('../../config/environment', __FILE__)
5
5
  require 'rspec/rails'
6
6
  # Add additional requires below this line. Rails is not loaded until this point!
7
7
  require 'fakefs/spec_helpers'
8
+ require 'excon'
8
9
  # require 'vcr'
9
10
  # require 'aws-sdk'
10
11
 
@@ -37,6 +38,12 @@ ActiveRecord::Migration.maintain_test_schema!
37
38
 
38
39
  RSpec.configure do |config|
39
40
 
41
+ config.before(:all) do
42
+ Excon.defaults[:mock] = true
43
+ end
44
+ config.after(:each) do
45
+ Excon.stubs.clear
46
+ end
40
47
 
41
48
  # config.around(:each) do |example|
42
49
  # VCR.use_cassette(example.metadata[:full_description]) do
@@ -84,4 +84,5 @@ RSpec.configure do |config|
84
84
  # as the one that triggered the failure.
85
85
  Kernel.srand config.seed
86
86
  =end
87
+
87
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poring_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - PiYa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: excon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Poring Backup is database backup that support rails.
70
84
  email:
71
85
  - piya23300@gmail.com
@@ -74,6 +88,7 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - MIT-LICENSE
91
+ - README.rdoc
77
92
  - Rakefile
78
93
  - lib/generators/poring_backup/install_generator.rb
79
94
  - lib/generators/poring_backup/templates/init_backup.rb
@@ -82,6 +97,8 @@ files:
82
97
  - lib/poring_backup/database.rb
83
98
  - lib/poring_backup/databases/postgresql.rb
84
99
  - lib/poring_backup/logger.rb
100
+ - lib/poring_backup/notifier.rb
101
+ - lib/poring_backup/notifiers/slack.rb
85
102
  - lib/poring_backup/railtie.rb
86
103
  - lib/poring_backup/setting.rb
87
104
  - lib/poring_backup/storage.rb
@@ -121,7 +138,6 @@ files:
121
138
  - test/dummy/config/locales/en.yml
122
139
  - test/dummy/config/routes.rb
123
140
  - test/dummy/config/secrets.sample.yml
124
- - test/dummy/config/secrets.yml
125
141
  - test/dummy/db/schema.rb
126
142
  - test/dummy/log/backup_development.log
127
143
  - test/dummy/log/backup_test.log
@@ -133,6 +149,7 @@ files:
133
149
  - test/dummy/public/favicon.ico
134
150
  - test/dummy/spec/lib/database_spec.rb
135
151
  - test/dummy/spec/lib/databases/postgresql_spec.rb
152
+ - test/dummy/spec/lib/notifiers/slack_spec.rb
136
153
  - test/dummy/spec/lib/setting_spec.rb
137
154
  - test/dummy/spec/lib/storage_spec.rb
138
155
  - test/dummy/spec/lib/storages/s3_spec.rb
@@ -195,7 +212,6 @@ test_files:
195
212
  - test/dummy/config/locales/en.yml
196
213
  - test/dummy/config/routes.rb
197
214
  - test/dummy/config/secrets.sample.yml
198
- - test/dummy/config/secrets.yml
199
215
  - test/dummy/config.ru
200
216
  - test/dummy/db/schema.rb
201
217
  - test/dummy/log/backup_development.log
@@ -210,6 +226,7 @@ test_files:
210
226
  - test/dummy/README.rdoc
211
227
  - test/dummy/spec/lib/database_spec.rb
212
228
  - test/dummy/spec/lib/databases/postgresql_spec.rb
229
+ - test/dummy/spec/lib/notifiers/slack_spec.rb
213
230
  - test/dummy/spec/lib/setting_spec.rb
214
231
  - test/dummy/spec/lib/storage_spec.rb
215
232
  - test/dummy/spec/lib/storages/s3_spec.rb
@@ -1,22 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure the secrets in this file are kept private
11
- # if you're sharing your code publicly.
12
-
13
- development:
14
- secret_key_base: 4459d6f08c8cda3f955197392612dd73e888830d77ce3bdd541457e2239b1fbb7d0fd30c5fe809fb03f62ce2b696b7a7b608590934d110135f63f56d854e2aaf
15
-
16
- test:
17
- secret_key_base: 96ee0aa59437e1f8736bd397e2c60b853e69adad08e0a250294c0ddd7b3edfcb39e193d10edd3fca669c1d3f01dd05d27aa23e194b7f18ca96f995053a90e281
18
-
19
- # Do not keep production secrets in the repository,
20
- # instead read values from the environment.
21
- production:
22
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>