rails_redshift_replicator 0.0.1

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 (116) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/rails_redshift_replicator/application.js +13 -0
  6. data/app/assets/stylesheets/rails_redshift_replicator/application.css +15 -0
  7. data/app/controllers/rails_redshift_replicator/application_controller.rb +5 -0
  8. data/app/helpers/rails_redshift_replicator/application_helper.rb +4 -0
  9. data/app/models/rails_redshift_replicator/replication.rb +98 -0
  10. data/app/views/layouts/rails_redshift_replicator/application.html.erb +14 -0
  11. data/config/locales/rails_redshift_replicator.en.yml +20 -0
  12. data/config/routes.rb +2 -0
  13. data/db/migrate/20160503214955_create_rails_redshift_replicator_replications.rb +24 -0
  14. data/db/migrate/20160509193335_create_table_rails_redshift_replicator_deleted_ids.rb +8 -0
  15. data/lib/generators/rails_redshift_replicator/install_generator.rb +25 -0
  16. data/lib/generators/templates/rails_redshift_replicator.rb +74 -0
  17. data/lib/rails_redshift_replicator.rb +229 -0
  18. data/lib/rails_redshift_replicator/adapters/generic.rb +40 -0
  19. data/lib/rails_redshift_replicator/adapters/mysql2.rb +22 -0
  20. data/lib/rails_redshift_replicator/adapters/postgresql.rb +37 -0
  21. data/lib/rails_redshift_replicator/adapters/sqlite.rb +27 -0
  22. data/lib/rails_redshift_replicator/deleter.rb +67 -0
  23. data/lib/rails_redshift_replicator/engine.rb +14 -0
  24. data/lib/rails_redshift_replicator/exporters/base.rb +215 -0
  25. data/lib/rails_redshift_replicator/exporters/full_replicator.rb +9 -0
  26. data/lib/rails_redshift_replicator/exporters/identity_replicator.rb +9 -0
  27. data/lib/rails_redshift_replicator/exporters/timed_replicator.rb +9 -0
  28. data/lib/rails_redshift_replicator/file_manager.rb +134 -0
  29. data/lib/rails_redshift_replicator/importers/base.rb +158 -0
  30. data/lib/rails_redshift_replicator/importers/full_replicator.rb +17 -0
  31. data/lib/rails_redshift_replicator/importers/identity_replicator.rb +15 -0
  32. data/lib/rails_redshift_replicator/importers/timed_replicator.rb +18 -0
  33. data/lib/rails_redshift_replicator/model/extension.rb +45 -0
  34. data/lib/rails_redshift_replicator/model/hair_trigger_extension.rb +8 -0
  35. data/lib/rails_redshift_replicator/replicable.rb +143 -0
  36. data/lib/rails_redshift_replicator/rlogger.rb +12 -0
  37. data/lib/rails_redshift_replicator/tools/analyze.rb +18 -0
  38. data/lib/rails_redshift_replicator/tools/vacuum.rb +77 -0
  39. data/lib/rails_redshift_replicator/version.rb +3 -0
  40. data/lib/tasks/rails_redshift_replicator_tasks.rake +4 -0
  41. data/spec/dummy/README.rdoc +28 -0
  42. data/spec/dummy/Rakefile +6 -0
  43. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  44. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  45. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  46. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  47. data/spec/dummy/app/models/post.rb +4 -0
  48. data/spec/dummy/app/models/tag.rb +4 -0
  49. data/spec/dummy/app/models/user.rb +5 -0
  50. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/spec/dummy/bin/bundle +3 -0
  52. data/spec/dummy/bin/rails +4 -0
  53. data/spec/dummy/bin/rake +4 -0
  54. data/spec/dummy/bin/setup +29 -0
  55. data/spec/dummy/config.ru +4 -0
  56. data/spec/dummy/config/application.rb +26 -0
  57. data/spec/dummy/config/boot.rb +5 -0
  58. data/spec/dummy/config/database.yml +37 -0
  59. data/spec/dummy/config/environment.rb +5 -0
  60. data/spec/dummy/config/environments/development.rb +41 -0
  61. data/spec/dummy/config/environments/production.rb +79 -0
  62. data/spec/dummy/config/environments/test.rb +42 -0
  63. data/spec/dummy/config/initializers/assets.rb +11 -0
  64. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  65. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  66. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  67. data/spec/dummy/config/initializers/inflections.rb +16 -0
  68. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  69. data/spec/dummy/config/initializers/rails_redshift_replicator.rb +59 -0
  70. data/spec/dummy/config/initializers/session_store.rb +3 -0
  71. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  72. data/spec/dummy/config/locales/en.yml +23 -0
  73. data/spec/dummy/config/locales/rails_redshift_replicator.en.yml +19 -0
  74. data/spec/dummy/config/routes.rb +4 -0
  75. data/spec/dummy/config/secrets.yml +22 -0
  76. data/spec/dummy/db/development.sqlite3 +0 -0
  77. data/spec/dummy/db/migrate/20160504120421_create_test_tables.rb +40 -0
  78. data/spec/dummy/db/migrate/20160509225445_create_triggers_posts_delete_or_tags_delete_or_users_delete.rb +33 -0
  79. data/spec/dummy/db/migrate/20160511000937_create_rails_redshift_replicator_replications.rails_redshift_replicator.rb +25 -0
  80. data/spec/dummy/db/migrate/20160511000938_create_table_rails_redshift_replicator_deleted_ids.rails_redshift_replicator.rb +9 -0
  81. data/spec/dummy/db/schema.rb +99 -0
  82. data/spec/dummy/db/test.sqlite3 +0 -0
  83. data/spec/dummy/log/development.log +1623 -0
  84. data/spec/dummy/log/test.log +95379 -0
  85. data/spec/dummy/public/404.html +67 -0
  86. data/spec/dummy/public/422.html +67 -0
  87. data/spec/dummy/public/500.html +66 -0
  88. data/spec/dummy/public/favicon.ico +0 -0
  89. data/spec/dummy/rails_redshift_replicator_development +0 -0
  90. data/spec/factories/rails_redshift_replicator_replications.rb +31 -0
  91. data/spec/integration/rails_redshift_replicator_spec.rb +148 -0
  92. data/spec/integration/setup_spec.rb +149 -0
  93. data/spec/lib/rails_redshift_replicator/deleter_spec.rb +90 -0
  94. data/spec/lib/rails_redshift_replicator/exporters/base_spec.rb +326 -0
  95. data/spec/lib/rails_redshift_replicator/exporters/full_replicator_spec.rb +33 -0
  96. data/spec/lib/rails_redshift_replicator/exporters/identity_replicator_spec.rb +40 -0
  97. data/spec/lib/rails_redshift_replicator/exporters/timed_replicator_spec.rb +43 -0
  98. data/spec/lib/rails_redshift_replicator/file_manager_spec.rb +90 -0
  99. data/spec/lib/rails_redshift_replicator/importers/base_spec.rb +102 -0
  100. data/spec/lib/rails_redshift_replicator/importers/full_replicator_spec.rb +27 -0
  101. data/spec/lib/rails_redshift_replicator/importers/identity_replicator_spec.rb +26 -0
  102. data/spec/lib/rails_redshift_replicator/importers/timed_replicator_spec.rb +26 -0
  103. data/spec/lib/rails_redshift_replicator/model/extension_spec.rb +36 -0
  104. data/spec/lib/rails_redshift_replicator/replicable_spec.rb +230 -0
  105. data/spec/lib/rails_redshift_replicator/rlogger_spec.rb +22 -0
  106. data/spec/lib/rails_redshift_replicator/tools/analyze_spec.rb +15 -0
  107. data/spec/lib/rails_redshift_replicator/tools/vacuum_spec.rb +65 -0
  108. data/spec/lib/rails_redshift_replicator_spec.rb +110 -0
  109. data/spec/models/rails_redshift_replicator/replication_spec.rb +104 -0
  110. data/spec/spec_helper.rb +36 -0
  111. data/spec/support/csv/invalid_user.csv +12 -0
  112. data/spec/support/csv/valid_post.csv +2 -0
  113. data/spec/support/csv/valid_tags_users.csv +1 -0
  114. data/spec/support/csv/valid_user.csv +2 -0
  115. data/spec/support/rails_redshift_replicator_helpers.rb +95 -0
  116. metadata +430 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,31 @@
1
+ FactoryGirl.define do
2
+ factory :redshift_replication, class: 'RailsRedshiftReplicator::Replication' do
3
+ export_format "csv"
4
+ replication_type "identity_replicator"
5
+ key "rdplibrary/replication/users/users_1442958786.csv"
6
+ source_table "users"
7
+ end
8
+
9
+ factory :user do
10
+ sequence(:login) { |n| "login_#{n}" }
11
+ sequence(:age)
12
+ factory :user_with_tags do
13
+ transient do
14
+ tags_count 5
15
+ end
16
+ after(:create) do |user, evaluator|
17
+ create_list(:tag, evaluator.tags_count, users: [user])
18
+ end
19
+ end
20
+ end
21
+
22
+ factory :post do
23
+ user
24
+ content "text"
25
+ end
26
+
27
+ factory :tag do
28
+ sequence(:name) { |n| "tag_#{n}" }
29
+ end
30
+
31
+ end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+ def redshift_counts(table)
3
+ RailsRedshiftReplicator.connection.exec("SELECT COUNT(1) FROM #{table}").first["count"].to_i
4
+ end
5
+ describe 'Integration Tests' do
6
+ before(:all) { RailsRedshiftReplicator.debug_mode = true}
7
+ let(:user_replicable) { RailsRedshiftReplicator.replicables[:users] }
8
+ let(:post_replicable) { RailsRedshiftReplicator.replicables[:posts] }
9
+ let(:habtm_replicable) { RailsRedshiftReplicator::Replicable.new(:full_replicator, source_table: :tags_users)}
10
+
11
+ before do
12
+ RailsRedshiftReplicator.add_replicable({ "tags_users" => habtm_replicable})
13
+ end
14
+
15
+ describe '.replicate' do
16
+ context 'replicating users' do
17
+ context 'without deleted records', focus: true do
18
+ before(:all) { recreate_users_table }
19
+ before do
20
+ 5.times { create :user }
21
+ end
22
+ let(:file_manager) { RailsRedshiftReplicator::FileManager.new }
23
+ let(:bucket) { RailsRedshiftReplicator.s3_bucket_params[:bucket]}
24
+ let(:s3_bucket) { Aws::S3::Bucket.new(name: bucket, client: file_manager.s3_client) }
25
+ let(:last_replication){ RailsRedshiftReplicator::Replication.last }
26
+ it 'replicates 5 users', focus: true do
27
+ RailsRedshiftReplicator.replicate :users
28
+ expect(redshift_counts('users')).to eq 5
29
+ end
30
+ context 'with auto delete from s3' do
31
+ before { RailsRedshiftReplicator.delete_s3_file_after_import = true }
32
+ it 'deletes files from s3 after replication', focus: true do
33
+ RailsRedshiftReplicator.replicate :users
34
+ expect(file_manager.s3_client.list_objects(bucket: bucket, prefix: last_replication.key).contents).to be_empty
35
+ end
36
+ end
37
+ context 'without auto delete from s3' do
38
+ before { RailsRedshiftReplicator.delete_s3_file_after_import = false }
39
+ it 'keeps files from s3 after replication', focus: true do
40
+ RailsRedshiftReplicator.replicate :users
41
+ expect(file_manager.s3_client.list_objects(bucket: bucket, prefix: last_replication.key).contents).not_to be_empty
42
+ end
43
+ end
44
+
45
+ end
46
+ context 'with deleted records' do
47
+ before(:all) { recreate_users_table }
48
+ before do
49
+ 5.times { create :user }
50
+ end
51
+ it 'replicates 5 users' do
52
+ first_user = User.first
53
+ RailsRedshiftReplicator.replicate :users
54
+ expect(redshift_counts('users')).to eq 5
55
+ first_user.destroy
56
+ expect(User.rrr_deleter.deleted_ids.count).to eq 1
57
+ RailsRedshiftReplicator.replicate :users
58
+ expect(redshift_counts('users')).to eq 4
59
+ end
60
+ end
61
+ context 'with history cap' do
62
+ before(:all) { recreate_users_table }
63
+ before do
64
+ RailsRedshiftReplicator.history_cap = 2
65
+ 10.times {create :redshift_replication, source_table: 'users', state: 'imported'}
66
+ 5.times { create :user }
67
+ end
68
+ it 'caps history after import' do
69
+ RailsRedshiftReplicator.replicate :users
70
+ expect(redshift_counts('users')).to eq 5
71
+ expect(RailsRedshiftReplicator::Replication.count).to eq 2
72
+ end
73
+ end
74
+ context 'forcing full replication' do
75
+ before(:all) { recreate_users_table }
76
+ before do
77
+ 5.times { create :user }
78
+ end
79
+ it 'replicates 5 users 2 times' do
80
+ RailsRedshiftReplicator.replicate :users
81
+ expect(redshift_counts('users')).to eq 5
82
+ RailsRedshiftReplicator.replicables['users'].reset_last_record
83
+ RailsRedshiftReplicator.replicate :users
84
+ expect(redshift_counts('users')).to eq 10
85
+ end
86
+ end
87
+ end
88
+ context 'replicating users and posts' do
89
+ before(:all) do
90
+ recreate_users_table
91
+ recreate_posts_table
92
+ end
93
+ it 'replicates 15 users and 10 posts' do
94
+ 5.times { create :user }
95
+ 10.times { create :post } # creates one user for each post
96
+
97
+ RailsRedshiftReplicator.replicate :users, :posts
98
+ expect(redshift_counts('users')).to eq 15
99
+ expect(redshift_counts('posts')).to eq 10
100
+ end
101
+ context 'replicating users and posts' do
102
+ before(:all) do
103
+ recreate_users_table
104
+ recreate_posts_table
105
+ recreate_tags_users_table
106
+ recreate_tags_table(:custom_tags)
107
+ end
108
+ it 'replicates 15 users, 10 posts, 25 tags_users and 25 tags' do
109
+ 5.times { create :user_with_tags }
110
+ 10.times { create :post } # creates one user for each post
111
+
112
+ RailsRedshiftReplicator.replicate :all
113
+ expect(redshift_counts('users')).to eq 15
114
+ expect(redshift_counts('posts')).to eq 10
115
+ expect(redshift_counts('tags_users')).to eq 25
116
+ expect(redshift_counts('custom_tags')).to eq 25
117
+ end
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ describe ".export" do
124
+ before {User;Post} # Load Models
125
+ it 'calls export for replicables' do
126
+ expect(user_replicable).to receive(:export)
127
+ expect(post_replicable).to receive(:export)
128
+ RailsRedshiftReplicator.export(:users, :posts)
129
+ end
130
+ it 'does not call export for non replicables' do
131
+ expect_any_instance_of(RailsRedshiftReplicator::Replicable).not_to receive(:export)
132
+ RailsRedshiftReplicator.export(:non_replicable)
133
+ end
134
+ end
135
+
136
+ describe ".import" do
137
+ before {User;Post} # Load Models
138
+ it 'calls import for replicables' do
139
+ expect(user_replicable).to receive(:import)
140
+ expect(post_replicable).to receive(:import)
141
+ RailsRedshiftReplicator.import(:users, :posts)
142
+ end
143
+ it 'does not call import for non replicables' do
144
+ expect_any_instance_of(RailsRedshiftReplicator::Replicable).not_to receive(:import)
145
+ RailsRedshiftReplicator.import(:non_replicable)
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+ class Mylogger < Logger;end
3
+ describe 'Setup Tests', :broken do
4
+ describe ".setup" do
5
+ context 'with default configuration' do
6
+ after(:all) { Dotenv.load File.expand_path("../spec/dummy/.env", __FILE__); RailsRedshiftReplicator.reload }
7
+ let(:env) do
8
+ {
9
+ RRR_REDSHIFT_HOST: 'default-host',
10
+ RRR_REDSHIFT_DATABASE: 'default-database',
11
+ RRR_REDSHIFT_PORT: 'default-port',
12
+ RRR_REDSHIFT_USER: 'default-user',
13
+ RRR_REDSHIFT_PASSWORD: 'default-password',
14
+ RRR_AWS_ACCESS_KEY_ID: 'default-key',
15
+ RRR_AWS_SECRET_ACCESS_KEY: 'default-secret',
16
+ RRR_REPLICATION_REGION: 'default-region',
17
+ RRR_REPLICATION_BUCKET: 'default-bucket',
18
+ RRR_REPLICATION_PREFIX: 'default-prefix'
19
+ }
20
+ end
21
+ around do |example|
22
+ ClimateControl.modify(env) do
23
+ RailsRedshiftReplicator.reload
24
+ example.run
25
+ end
26
+ end
27
+ it 'uses default redshift_connection_params' do
28
+ expect(RailsRedshiftReplicator.redshift_connection_params).to eq({
29
+ host: 'default-host',
30
+ dbname: 'default-database',
31
+ port: 'default-port',
32
+ user: 'default-user',
33
+ password: 'default-password'
34
+ })
35
+ end
36
+
37
+ it 'uses default aws_credentials' do
38
+ expect(RailsRedshiftReplicator.aws_credentials).to eq({
39
+ key: 'default-key',
40
+ secret: 'default-secret'
41
+ })
42
+ end
43
+
44
+ it 'uses default s3_bucket_params' do
45
+ expect(RailsRedshiftReplicator.s3_bucket_params).to eq({
46
+ region: 'default-region',
47
+ bucket: 'default-bucket',
48
+ prefix: 'default-prefix'
49
+ })
50
+ end
51
+
52
+ it 'uses default redshift_slices' do
53
+ expect(RailsRedshiftReplicator.redshift_slices).to eq 1
54
+ end
55
+
56
+ it 'uses default local_replication_path' do
57
+ expect(RailsRedshiftReplicator.local_replication_path).to eq '/tmp'
58
+ end
59
+
60
+ it 'uses default debug_mode' do
61
+ expect(RailsRedshiftReplicator.debug_mode).to be_falsy
62
+ end
63
+
64
+ it 'uses default history_cap' do
65
+ expect(RailsRedshiftReplicator.history_cap).to be_nil
66
+ end
67
+
68
+ end
69
+ context 'when changing configuration' do
70
+ after(:all) { Dotenv.load File.expand_path("../spec/dummy/.env", __FILE__); RailsRedshiftReplicator.reload }
71
+ before do
72
+ RailsRedshiftReplicator.setup do |config|
73
+ config.redshift_connection_params = {
74
+ host: 'redshift-host',
75
+ dbname: 'database-name',
76
+ port: 'database-port',
77
+ user: 'database-user',
78
+ password: 'database-password'
79
+ }
80
+
81
+ config.aws_credentials = {
82
+ key: 'aws-key',
83
+ secret: 'aws-secret'
84
+ }
85
+
86
+ config.s3_bucket_params = {
87
+ region: 's3-region',
88
+ bucket: 's3-bucket'
89
+ }
90
+
91
+ config.redshift_slices = '2'
92
+ config.local_replication_path = '/local-tmp'
93
+ config.debug_mode = true
94
+ config.history_cap = 3
95
+ config.logger = Mylogger.new(STDOUT)
96
+ end
97
+ end
98
+
99
+ it 'defines custom logger' do
100
+ expect(RailsRedshiftReplicator.logger).to be_a Mylogger
101
+ end
102
+
103
+ it 'defines redshift_connection_params' do
104
+ expect(RailsRedshiftReplicator.redshift_connection_params).to eq({
105
+ host: 'redshift-host',
106
+ dbname: 'database-name',
107
+ port: 'database-port',
108
+ user: 'database-user',
109
+ password: 'database-password'
110
+ })
111
+ end
112
+
113
+ it 'defines aws_credentials' do
114
+ expect(RailsRedshiftReplicator.aws_credentials).to eq({
115
+ key: 'aws-key',
116
+ secret: 'aws-secret'
117
+ })
118
+ end
119
+
120
+ it 'defines s3_bucket_params' do
121
+ expect(RailsRedshiftReplicator.s3_bucket_params).to eq({
122
+ region: 's3-region',
123
+ bucket: 's3-bucket'
124
+ })
125
+ end
126
+
127
+ it 'defines redshift_slices' do
128
+ expect(RailsRedshiftReplicator.redshift_slices).to eq '2'
129
+ end
130
+
131
+ it 'defines local_replication_path' do
132
+ expect(RailsRedshiftReplicator.local_replication_path).to eq '/local-tmp'
133
+ end
134
+
135
+ it 'defines debug_mode' do
136
+ expect(RailsRedshiftReplicator.debug_mode).to eq true
137
+ expect(RailsRedshiftReplicator.logger.level).to eq Logger::DEBUG
138
+ end
139
+
140
+ it 'defines history_cap' do
141
+ expect(RailsRedshiftReplicator.history_cap).to eq 3
142
+ end
143
+
144
+ it "changes module's configuration parameters" do
145
+ expect { RailsRedshiftReplicator.setup {|config| config.redshift_slices = 10} }.to change(RailsRedshiftReplicator, :redshift_slices).to(10)
146
+ end
147
+ end
148
+ end
149
+ end