dump_truck 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe DumpTruck::TableConfiguration do
4
+ describe '.new' do
5
+ context "with no block" do
6
+ let(:config) do
7
+ DumpTruck::TableConfiguration.new('users')
8
+ end
9
+ subject{config}
10
+
11
+ its(:name){should eq('users')}
12
+ its(:mode){should eq(:none)}
13
+ its(:query){should be_nil}
14
+ end
15
+
16
+ context 'with keep' do
17
+ let(:config) do
18
+ DumpTruck::TableConfiguration.new('users') do
19
+ keep
20
+ end
21
+ end
22
+ subject{config}
23
+
24
+ its(:name){should eq('users')}
25
+ its(:mode){should eq(:all)}
26
+ its(:query){should be_nil}
27
+ end
28
+
29
+ context 'with keep and query' do
30
+ let(:config) do
31
+ DumpTruck::TableConfiguration.new('users') do
32
+ keep 'deleted_at is null'
33
+ end
34
+ end
35
+ subject{config}
36
+
37
+ its(:name){should eq('users')}
38
+ its(:mode){should eq(:some)}
39
+ its(:query){should eq('deleted_at is null')}
40
+ end
41
+
42
+ context 'with truncate' do
43
+ let(:config) do
44
+ DumpTruck::TableConfiguration.new('users') do
45
+ truncate
46
+ end
47
+ end
48
+ subject{config}
49
+
50
+ its(:name){should eq('users')}
51
+ its(:mode){should eq(:none)}
52
+ its(:query){should be_nil}
53
+ end
54
+
55
+ context 'with ignore' do
56
+ let(:config) do
57
+ DumpTruck::TableConfiguration.new('users') do
58
+ ignore
59
+ end
60
+ end
61
+ subject{config}
62
+
63
+ its(:name){should eq('users')}
64
+ its(:mode){should eq(:ignore)}
65
+ its(:query){should be_nil}
66
+ end
67
+ end
68
+
69
+ describe '#obfuscate_value' do
70
+ context 'when no obfuscators are specified' do
71
+ let(:config) do
72
+ DumpTruck::TableConfiguration.new('users') do
73
+ keep
74
+ end
75
+ end
76
+
77
+ it 'uses the default' do
78
+ expect(config.obfuscate_value('email', 'bob@gmail.com', 1)).to eq('bob@gmail.com')
79
+ end
80
+ end
81
+
82
+ context 'when obfuscator is specified with no parameters' do
83
+ let(:config) do
84
+ DumpTruck::TableConfiguration.new('users') do
85
+ keep
86
+
87
+ obfuscate(:email){'jim@gmail.com'}
88
+ end
89
+ end
90
+
91
+ it 'successfully obfuscates' do
92
+ expect(config.obfuscate_value(:email, 'bob@gmail.com', 1)).to eq('jim@gmail.com')
93
+ end
94
+ end
95
+
96
+ context 'when obfuscator is specified with one parameters' do
97
+ let(:config) do
98
+ DumpTruck::TableConfiguration.new('users') do
99
+ keep
100
+
101
+ obfuscate(:email){|value| value.reverse}
102
+ end
103
+ end
104
+
105
+ it 'successfully obfuscates' do
106
+ expect(config.obfuscate_value(:email, 'bob@gmail.com', 1)).to eq('moc.liamg@bob')
107
+ end
108
+ end
109
+
110
+ context 'when obfuscator is specified with two parameters' do
111
+ let(:config) do
112
+ DumpTruck::TableConfiguration.new('users') do
113
+ keep
114
+
115
+ obfuscate(:email){|_, n| "test#{n}@gmail.com"}
116
+ end
117
+ end
118
+
119
+ it 'successfully obfuscates' do
120
+ expect(config.obfuscate_value(:email, 'bob@gmail.com', 1)).to eq('test1@gmail.com')
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe DumpTruck::Truck do
4
+ def sql(fixture)
5
+ File.read(File.expand_path("../fixtures/mysql/#{fixture}.sql", __FILE__))
6
+ end
7
+
8
+ def sql_io(fixture)
9
+ StringIO.new(sql(fixture))
10
+ end
11
+
12
+ let(:sql_dump_file){File.expand_path("../../tmp/app_production.sql.gz", __FILE__)}
13
+ let(:dump_sql){Zlib::GzipReader.open(sql_dump_file){|gz| gz.read}}
14
+
15
+ let(:schema_config) do
16
+ DumpTruck::SchemaConfiguration.new('app_production') do
17
+ target_path(File.expand_path('../../tmp', __FILE__))
18
+
19
+ table(:users){truncate}
20
+ table(:mail_queue){ignore}
21
+ table(:roles) do
22
+ keep
23
+ obfuscate(:name){|description, n| "#{n}"}
24
+ end
25
+ table(:permissions) do
26
+ keep
27
+ obfuscate(:id){|id| id + 1}
28
+ end
29
+ end
30
+ end
31
+
32
+ let(:client) do
33
+ double(DumpTruck::Mysql::Client).tap do |client|
34
+ client.stub(:tables_dump).and_yield(sql_io('tables'))
35
+ client.stub(:data_dump) do |config, &block|
36
+ block.call(sql_io(config.name))
37
+ end
38
+ end
39
+ end
40
+
41
+ let(:translator){DumpTruck::Mysql::Translator.new}
42
+ let(:truck){DumpTruck::Truck.new(schema_config, client, translator)}
43
+
44
+ after(:each){File.delete(sql_dump_file)}
45
+
46
+ it "should successfully dump the output" do
47
+ truck.dump
48
+
49
+ expect(dump_sql).to eq(sql('expected_dump'))
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dump_truck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Allen Madsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.5'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.5'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry-debugger
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: DSL to dump production data for developer use. Allows selection of data
95
+ and obfuscation.
96
+ email:
97
+ - blatyo@gmail.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rspec
104
+ - .travis.yml
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - dump_truck.gemspec
110
+ - lib/dump_truck.rb
111
+ - lib/dump_truck/configuration.rb
112
+ - lib/dump_truck/database_configuration.rb
113
+ - lib/dump_truck/loggable_truck.rb
114
+ - lib/dump_truck/mysql.rb
115
+ - lib/dump_truck/mysql/client.rb
116
+ - lib/dump_truck/mysql/translator.rb
117
+ - lib/dump_truck/schema_configuration.rb
118
+ - lib/dump_truck/table_configuration.rb
119
+ - lib/dump_truck/target.rb
120
+ - lib/dump_truck/truck.rb
121
+ - lib/dump_truck/version.rb
122
+ - spec/configuration_spec.rb
123
+ - spec/databases_configuration_spec.rb
124
+ - spec/dump_truck_spec.rb
125
+ - spec/fixtures/mysql/expected_dump.sql
126
+ - spec/fixtures/mysql/permissions.sql
127
+ - spec/fixtures/mysql/roles.sql
128
+ - spec/fixtures/mysql/tables.sql
129
+ - spec/fixtures/mysql/users.sql
130
+ - spec/mysql/translator_spec.rb
131
+ - spec/schema_configuration_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/table_configuration_spec.rb
134
+ - spec/truck_spec.rb
135
+ homepage: https://github.com/secondrotation/dump_truck
136
+ licenses:
137
+ - MIT
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ segments:
149
+ - 0
150
+ hash: 2425505648015624306
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ segments:
158
+ - 0
159
+ hash: 2425505648015624306
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.23
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: DSL to dump production data for developer use.
166
+ test_files:
167
+ - spec/configuration_spec.rb
168
+ - spec/databases_configuration_spec.rb
169
+ - spec/dump_truck_spec.rb
170
+ - spec/fixtures/mysql/expected_dump.sql
171
+ - spec/fixtures/mysql/permissions.sql
172
+ - spec/fixtures/mysql/roles.sql
173
+ - spec/fixtures/mysql/tables.sql
174
+ - spec/fixtures/mysql/users.sql
175
+ - spec/mysql/translator_spec.rb
176
+ - spec/schema_configuration_spec.rb
177
+ - spec/spec_helper.rb
178
+ - spec/table_configuration_spec.rb
179
+ - spec/truck_spec.rb