dump 1.0.2 → 1.0.3
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.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/.travis.database.yml +14 -0
- data/.travis.yml +30 -0
- data/Gemfile +20 -0
- data/LICENSE.txt +1 -1
- data/README.markdown +5 -3
- data/dump.gemspec +1 -2
- data/lib/dump_rake/dump.rb +4 -0
- data/lib/dump_rake/dump_reader.rb +1 -1
- data/lib/dump_rake/dump_writer.rb +1 -1
- data/lib/dump_rake/table_manipulation.rb +1 -1
- data/spec/.gitignore +18 -0
- data/spec/cycle_spec.rb +22 -14
- data/spec/dummy-2.3/config/boot.rb +114 -0
- data/spec/dummy-2.3/config/database.yml +22 -0
- data/spec/dummy-2.3/config/environment.rb +41 -0
- data/spec/dummy-2.3/config/environments/development.rb +17 -0
- data/spec/dummy-2.3/config/environments/production.rb +28 -0
- data/spec/dummy-2.3/config/environments/test.rb +28 -0
- data/spec/dummy-2.3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy-2.3/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/dummy-2.3/config/initializers/inflections.rb +10 -0
- data/spec/{dummy-3.1.3 → dummy-2.3}/config/initializers/mime_types.rb +0 -0
- data/spec/dummy-2.3/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/dummy-2.3/config/initializers/session_store.rb +15 -0
- data/spec/dummy-2.3/config/locales/en.yml +5 -0
- data/spec/dummy-2.3/config/routes.rb +43 -0
- data/spec/dummy-2.3/db/seeds.rb +7 -0
- data/spec/dummy-3.0/.gitignore +4 -0
- data/spec/{dummy-3.1.3 → dummy-3.0}/config.ru +1 -1
- data/spec/dummy-3.0/config/application.rb +42 -0
- data/spec/{dummy-3.1.3 → dummy-3.0}/config/boot.rb +0 -0
- data/spec/dummy-3.0/config/database.yml +22 -0
- data/spec/{dummy-3.1.3 → dummy-3.0}/config/environment.rb +1 -1
- data/spec/dummy-3.0/config/environments/development.rb +26 -0
- data/spec/dummy-3.0/config/environments/production.rb +49 -0
- data/spec/dummy-3.0/config/environments/test.rb +35 -0
- data/spec/{dummy-3.1.3 → dummy-3.0}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/{dummy-3.1.3 → dummy-3.0}/config/initializers/inflections.rb +0 -0
- data/spec/dummy-3.0/config/initializers/mime_types.rb +5 -0
- data/spec/{dummy-3.1.3 → dummy-3.0}/config/initializers/secret_token.rb +1 -1
- data/spec/{dummy-3.1.3 → dummy-3.0}/config/initializers/session_store.rb +2 -2
- data/spec/dummy-3.0/config/locales/en.yml +5 -0
- data/spec/dummy-3.0/config/routes.rb +58 -0
- data/spec/dummy-3.0/db/seeds.rb +7 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/.gitignore +0 -0
- data/spec/dummy-3.1/config.ru +4 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/application.rb +2 -7
- data/spec/dummy-3.1/config/boot.rb +6 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/database.yml +0 -0
- data/spec/dummy-3.1/config/environment.rb +5 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/environments/development.rb +1 -6
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/environments/production.rb +1 -14
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/environments/test.rb +1 -1
- data/spec/dummy-3.1/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy-3.1/config/initializers/inflections.rb +10 -0
- data/spec/dummy-3.1/config/initializers/mime_types.rb +5 -0
- data/spec/dummy-3.1/config/initializers/secret_token.rb +7 -0
- data/spec/dummy-3.1/config/initializers/session_store.rb +8 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/locales/en.yml +0 -0
- data/spec/{dummy-3.1.3 → dummy-3.1}/config/routes.rb +1 -1
- data/spec/{dummy-3.1.3 → dummy-3.1}/db/seeds.rb +0 -0
- data/spec/{dummy-3.1.3/app/mailers → dummy-3.1/log}/.gitkeep +0 -0
- data/spec/dummy-3.2/.gitignore +15 -0
- data/spec/dummy-3.2/config.ru +4 -0
- data/spec/dummy-3.2/config/application.rb +63 -0
- data/spec/dummy-3.2/config/boot.rb +6 -0
- data/spec/dummy-3.2/config/database.yml +25 -0
- data/spec/dummy-3.2/config/environment.rb +5 -0
- data/spec/dummy-3.2/config/environments/development.rb +32 -0
- data/spec/dummy-3.2/config/environments/production.rb +54 -0
- data/spec/dummy-3.2/config/environments/test.rb +37 -0
- data/spec/dummy-3.2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy-3.2/config/initializers/inflections.rb +15 -0
- data/spec/dummy-3.2/config/initializers/mime_types.rb +5 -0
- data/spec/dummy-3.2/config/initializers/secret_token.rb +7 -0
- data/spec/dummy-3.2/config/initializers/session_store.rb +8 -0
- data/spec/dummy-3.2/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy-3.2/config/locales/en.yml +5 -0
- data/spec/dummy-3.2/config/routes.rb +58 -0
- data/spec/dummy-3.2/db/seeds.rb +7 -0
- data/spec/{dummy-3.1.3/app/models → dummy-3.2/log}/.gitkeep +0 -0
- data/spec/dummy-4.0/.gitignore +16 -0
- data/spec/dummy-4.0/config.ru +4 -0
- data/spec/dummy-4.0/config/application.rb +31 -0
- data/spec/dummy-4.0/config/boot.rb +4 -0
- data/spec/dummy-4.0/config/database.yml +25 -0
- data/spec/dummy-4.0/config/environment.rb +5 -0
- data/spec/dummy-4.0/config/environments/development.rb +25 -0
- data/spec/dummy-4.0/config/environments/production.rb +65 -0
- data/spec/dummy-4.0/config/environments/test.rb +36 -0
- data/spec/dummy-4.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy-4.0/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy-4.0/config/initializers/inflections.rb +16 -0
- data/spec/dummy-4.0/config/initializers/mime_types.rb +5 -0
- data/spec/dummy-4.0/config/initializers/secret_token.rb +12 -0
- data/spec/dummy-4.0/config/initializers/session_store.rb +3 -0
- data/spec/dummy-4.0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy-4.0/config/locales/en.yml +23 -0
- data/spec/dummy-4.0/config/routes.rb +56 -0
- data/spec/dummy-4.0/db/seeds.rb +7 -0
- data/spec/{dummy-3.1.3/lib/assets/.gitkeep → dummy-4.0/log/.keep} +0 -0
- data/spec/lib/dump_rake/dump_reader_spec.rb +90 -89
- data/spec/lib/dump_rake/dump_spec.rb +9 -9
- data/spec/lib/dump_rake/dump_writer_spec.rb +79 -78
- data/spec/lib/dump_rake/rails_root_spec.rb +2 -2
- data/spec/lib/dump_rake/table_manipulation_spec.rb +10 -10
- data/spec/lib/dump_rake_spec.rb +34 -34
- data/spec/recipes/dump_spec.rb +34 -34
- data/spec/spec_helper.rb +35 -10
- data/spec/tasks/assets_spec.rb +6 -6
- metadata +240 -183
- data/spec/dummy-3.1.3/.rspec +0 -1
- data/spec/dummy-3.1.3/Gemfile +0 -14
- data/spec/dummy-3.1.3/Gemfile.lock +0 -133
- data/spec/dummy-3.1.3/README +0 -261
- data/spec/dummy-3.1.3/Rakefile +0 -7
- data/spec/dummy-3.1.3/app/assets/images/rails.png +0 -0
- data/spec/dummy-3.1.3/app/assets/javascripts/application.js +0 -9
- data/spec/dummy-3.1.3/app/assets/stylesheets/application.css +0 -7
- data/spec/dummy-3.1.3/app/controllers/application_controller.rb +0 -3
- data/spec/dummy-3.1.3/app/helpers/application_helper.rb +0 -2
- data/spec/dummy-3.1.3/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy-3.1.3/doc/README_FOR_APP +0 -2
- data/spec/dummy-3.1.3/lib/tasks/.gitkeep +0 -0
- data/spec/dummy-3.1.3/log/.gitkeep +0 -0
- data/spec/dummy-3.1.3/public/404.html +0 -26
- data/spec/dummy-3.1.3/public/422.html +0 -26
- data/spec/dummy-3.1.3/public/500.html +0 -26
- data/spec/dummy-3.1.3/public/favicon.ico +0 -0
- data/spec/dummy-3.1.3/public/index.html +0 -241
- data/spec/dummy-3.1.3/public/robots.txt +0 -5
- data/spec/dummy-3.1.3/script/rails +0 -6
- data/spec/dummy-3.1.3/spec/spec_helper.rb +0 -32
- data/spec/dummy-3.1.3/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy-3.1.3/vendor/plugins/.gitkeep +0 -0
|
@@ -11,7 +11,7 @@ describe DumpRake::Dump do
|
|
|
11
11
|
|
|
12
12
|
describe "lock" do
|
|
13
13
|
before do
|
|
14
|
-
@yield_receiver =
|
|
14
|
+
@yield_receiver = double('yield_receiver')
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should not yield if file does not exist" do
|
|
@@ -27,7 +27,7 @@ describe DumpRake::Dump do
|
|
|
27
27
|
it "should not yield if file can not be locked" do
|
|
28
28
|
@yield_receiver.should_not_receive(:fire)
|
|
29
29
|
|
|
30
|
-
@file =
|
|
30
|
+
@file = double('file')
|
|
31
31
|
@file.should_receive(:flock).with(File::LOCK_EX | File::LOCK_NB).and_return(nil)
|
|
32
32
|
@file.should_receive(:flock).with(File::LOCK_UN)
|
|
33
33
|
@file.should_receive(:close)
|
|
@@ -41,7 +41,7 @@ describe DumpRake::Dump do
|
|
|
41
41
|
it "should yield if file can not be locked" do
|
|
42
42
|
@yield_receiver.should_receive(:fire)
|
|
43
43
|
|
|
44
|
-
@file =
|
|
44
|
+
@file = double('file')
|
|
45
45
|
@file.should_receive(:flock).with(File::LOCK_EX | File::LOCK_NB).and_return(true)
|
|
46
46
|
@file.should_receive(:flock).with(File::LOCK_UN)
|
|
47
47
|
@file.should_receive(:close)
|
|
@@ -64,10 +64,10 @@ describe DumpRake::Dump do
|
|
|
64
64
|
|
|
65
65
|
describe "with options" do
|
|
66
66
|
before do
|
|
67
|
-
@time =
|
|
68
|
-
@time.stub
|
|
69
|
-
@time.stub
|
|
70
|
-
Time.stub
|
|
67
|
+
@time = double('time')
|
|
68
|
+
@time.stub(:utc).and_return(@time)
|
|
69
|
+
@time.stub(:strftime).and_return('19650414065945')
|
|
70
|
+
Time.stub(:now).and_return(@time)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "should generate path with no options" do
|
|
@@ -100,7 +100,7 @@ describe DumpRake::Dump do
|
|
|
100
100
|
File.should_receive(:file?).with(path).at_least(1).and_return(true)
|
|
101
101
|
path
|
|
102
102
|
end
|
|
103
|
-
Dir.stub
|
|
103
|
+
Dir.stub(:[]).and_return(paths)
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it "should search for files in dump dir when asked for list" do
|
|
@@ -128,7 +128,7 @@ describe DumpRake::Dump do
|
|
|
128
128
|
File.should_receive(:file?).with(path).at_least(1).and_return(true)
|
|
129
129
|
path
|
|
130
130
|
end
|
|
131
|
-
Dir.stub
|
|
131
|
+
Dir.stub(:[]).and_return(paths)
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
it "should return all dumps if no tags send" do
|
|
@@ -6,16 +6,17 @@ DumpWriter = DumpRake::DumpWriter
|
|
|
6
6
|
describe DumpWriter do
|
|
7
7
|
describe "create" do
|
|
8
8
|
it "should create selves instance and open" do
|
|
9
|
-
@dump =
|
|
9
|
+
@dump = double('dump')
|
|
10
10
|
@dump.should_receive(:open)
|
|
11
11
|
DumpWriter.should_receive(:new).with('/abc/123.tmp').and_return(@dump)
|
|
12
12
|
DumpWriter.create('/abc/123.tmp')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "should call dump subroutines" do
|
|
16
|
-
@dump =
|
|
17
|
-
@dump.stub
|
|
18
|
-
|
|
16
|
+
@dump = double('dump')
|
|
17
|
+
@dump.stub(:open).and_yield(@dump)
|
|
18
|
+
@dump.stub(:silence).and_yield
|
|
19
|
+
DumpWriter.stub(:new).and_return(@dump)
|
|
19
20
|
|
|
20
21
|
@dump.should_receive(:write_schema).ordered
|
|
21
22
|
@dump.should_receive(:write_tables).ordered
|
|
@@ -28,15 +29,15 @@ describe DumpWriter do
|
|
|
28
29
|
|
|
29
30
|
describe "open" do
|
|
30
31
|
it "should create dir for dump" do
|
|
31
|
-
Zlib::GzipWriter.stub
|
|
32
|
+
Zlib::GzipWriter.stub(:open)
|
|
32
33
|
FileUtils.should_receive(:mkpath).with('/abc/def/ghi')
|
|
33
34
|
DumpWriter.new('/abc/def/ghi/123.tgz').open
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
it "should set stream to gzipped tar writer" do
|
|
37
|
-
FileUtils.stub
|
|
38
|
-
@gzip =
|
|
39
|
-
@stream =
|
|
38
|
+
FileUtils.stub(:mkpath)
|
|
39
|
+
@gzip = double('gzip')
|
|
40
|
+
@stream = double('stream')
|
|
40
41
|
Zlib::GzipWriter.should_receive(:open).with(Pathname("123.tgz")).and_yield(@gzip)
|
|
41
42
|
Archive::Tar::Minitar::Output.should_receive(:open).with(@gzip).and_yield(@stream)
|
|
42
43
|
@gzip.should_receive(:mtime=).with(Time.utc(2000))
|
|
@@ -52,23 +53,23 @@ describe DumpWriter do
|
|
|
52
53
|
|
|
53
54
|
describe "subroutines" do
|
|
54
55
|
before do
|
|
55
|
-
@tar =
|
|
56
|
-
@stream =
|
|
56
|
+
@tar = double('tar')
|
|
57
|
+
@stream = double('stream', :tar => @tar)
|
|
57
58
|
@config = {:tables => {}}
|
|
58
59
|
@dump = DumpWriter.new('123.tgz')
|
|
59
|
-
@dump.stub
|
|
60
|
-
@dump.stub
|
|
61
|
-
Progress.stub
|
|
60
|
+
@dump.stub(:stream).and_return(@stream)
|
|
61
|
+
@dump.stub(:config).and_return(@config)
|
|
62
|
+
Progress.stub(:io).and_return(StringIO.new)
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
describe "create_file" do
|
|
65
66
|
it "should create temp file, yield it for writing, create file in tar and write it there" do
|
|
66
|
-
@temp =
|
|
67
|
+
@temp = double('temp', :open => true, :length => 6, :read => 'qwfpgj')
|
|
67
68
|
@temp.should_receive(:write).with('qwfpgj')
|
|
68
|
-
@temp.stub
|
|
69
|
+
@temp.stub(:eof?).and_return(false, true)
|
|
69
70
|
Tempfile.should_receive(:open).and_yield(@temp)
|
|
70
71
|
|
|
71
|
-
@file =
|
|
72
|
+
@file = double('file')
|
|
72
73
|
@file.should_receive(:write).with('qwfpgj')
|
|
73
74
|
|
|
74
75
|
@stream.tar.should_receive(:add_file_simple).with('abc/def.txt', :mode => 0100444, :size => 6).and_yield(@file)
|
|
@@ -87,16 +88,16 @@ describe DumpWriter do
|
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
it "should set ENV[SCHEMA] to path of returned file" do
|
|
90
|
-
@file =
|
|
91
|
-
@dump.stub
|
|
91
|
+
@file = double('file', :path => 'db/schema.rb')
|
|
92
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
92
93
|
DumpRake::Env.should_receive(:with_env).with('SCHEMA' => 'db/schema.rb')
|
|
93
94
|
@dump.write_schema
|
|
94
95
|
end
|
|
95
96
|
|
|
96
97
|
it "should call rake task db:schema:dump" do
|
|
97
|
-
@file =
|
|
98
|
-
@dump.stub
|
|
99
|
-
@task =
|
|
98
|
+
@file = double('file', :path => 'db/schema.rb')
|
|
99
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
100
|
+
@task = double('task')
|
|
100
101
|
Rake::Task.should_receive(:[]).with('db:schema:dump').and_return(@task)
|
|
101
102
|
@task.should_receive(:invoke)
|
|
102
103
|
@dump.write_schema
|
|
@@ -105,14 +106,14 @@ describe DumpWriter do
|
|
|
105
106
|
|
|
106
107
|
describe "write_tables" do
|
|
107
108
|
it "should verify connection" do
|
|
108
|
-
@dump.stub
|
|
109
|
+
@dump.stub(:tables_to_dump).and_return([])
|
|
109
110
|
@dump.should_receive(:verify_connection)
|
|
110
111
|
@dump.write_tables
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
it "should call write_table for each table returned by tables_to_dump" do
|
|
114
|
-
@dump.stub
|
|
115
|
-
@dump.stub
|
|
115
|
+
@dump.stub(:verify_connection)
|
|
116
|
+
@dump.stub(:tables_to_dump).and_return(%w[first second])
|
|
116
117
|
|
|
117
118
|
@dump.should_receive(:write_table).with('first')
|
|
118
119
|
@dump.should_receive(:write_table).with('second')
|
|
@@ -124,32 +125,32 @@ describe DumpWriter do
|
|
|
124
125
|
describe "write_table" do
|
|
125
126
|
it "should get row count and store it to config" do
|
|
126
127
|
@dump.should_receive(:table_row_count).with('first').and_return(666)
|
|
127
|
-
@dump.stub
|
|
128
|
+
@dump.stub(:create_file)
|
|
128
129
|
@dump.write_table('first')
|
|
129
130
|
@config[:tables]['first'].should == 666
|
|
130
131
|
end
|
|
131
132
|
|
|
132
133
|
it "should create_file" do
|
|
133
|
-
@dump.stub
|
|
134
|
+
@dump.stub(:table_row_count).and_return(666)
|
|
134
135
|
@dump.should_receive(:create_file)
|
|
135
136
|
@dump.write_table('first')
|
|
136
137
|
end
|
|
137
138
|
|
|
138
139
|
it "should dump column names and values of each row" do
|
|
139
140
|
@column_definitions = [
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
double('column', :name => 'id'),
|
|
142
|
+
double('column', :name => 'name'),
|
|
143
|
+
double('column', :name => 'associated_id')
|
|
143
144
|
]
|
|
144
|
-
ActiveRecord::Base.connection.stub
|
|
145
|
+
ActiveRecord::Base.connection.stub(:columns).and_return(@column_definitions)
|
|
145
146
|
@rows = [
|
|
146
147
|
{'id' => 1, 'name' => 'a', 'associated_id' => 100},
|
|
147
148
|
{'id' => 2, 'name' => 'b', 'associated_id' => 666},
|
|
148
149
|
]
|
|
149
150
|
|
|
150
|
-
@file =
|
|
151
|
-
@dump.stub
|
|
152
|
-
@dump.stub
|
|
151
|
+
@file = double('file')
|
|
152
|
+
@dump.stub(:table_row_count).and_return(666)
|
|
153
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
153
154
|
|
|
154
155
|
column_names = @column_definitions.map(&:name).sort
|
|
155
156
|
@file.should_receive(:write).with(Marshal.dump(column_names)).ordered
|
|
@@ -168,7 +169,7 @@ describe DumpWriter do
|
|
|
168
169
|
|
|
169
170
|
describe "write_assets" do
|
|
170
171
|
before do
|
|
171
|
-
@dump.stub
|
|
172
|
+
@dump.stub(:assets_root_link).and_yield('/tmp', 'assets')
|
|
172
173
|
end
|
|
173
174
|
|
|
174
175
|
it "should call assets_to_dump" do
|
|
@@ -177,22 +178,22 @@ describe DumpWriter do
|
|
|
177
178
|
end
|
|
178
179
|
|
|
179
180
|
it "should change root to rails app root" do
|
|
180
|
-
@file =
|
|
181
|
-
@dump.stub
|
|
182
|
-
@dump.stub
|
|
181
|
+
@file = double('file')
|
|
182
|
+
@dump.stub(:assets_to_dump).and_return(%w[images videos])
|
|
183
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
183
184
|
|
|
184
185
|
Dir.should_receive(:chdir).with(DumpRake::RailsRoot)
|
|
185
186
|
@dump.write_assets
|
|
186
187
|
end
|
|
187
188
|
|
|
188
189
|
it "should put assets to config" do
|
|
189
|
-
@file =
|
|
190
|
-
@dump.stub
|
|
191
|
-
@dump.stub
|
|
192
|
-
Dir.stub
|
|
193
|
-
@tar =
|
|
194
|
-
Archive::Tar::Minitar::Output.stub
|
|
195
|
-
Dir.stub
|
|
190
|
+
@file = double('file')
|
|
191
|
+
@dump.stub(:assets_to_dump).and_return(%w[images/* videos])
|
|
192
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
193
|
+
Dir.stub(:chdir).and_yield
|
|
194
|
+
@tar = double('tar_writer')
|
|
195
|
+
Archive::Tar::Minitar::Output.stub(:open).and_yield(@tar)
|
|
196
|
+
Dir.stub(:[]).and_return([])
|
|
196
197
|
Dir.should_receive(:[]).with(*%w[images/* videos]).and_return(%w[images/a images/b videos])
|
|
197
198
|
|
|
198
199
|
@dump.write_assets
|
|
@@ -201,12 +202,12 @@ describe DumpWriter do
|
|
|
201
202
|
end
|
|
202
203
|
|
|
203
204
|
it "should use glob to find files" do
|
|
204
|
-
@file =
|
|
205
|
-
@dump.stub
|
|
206
|
-
@dump.stub
|
|
207
|
-
Dir.stub
|
|
208
|
-
@tar =
|
|
209
|
-
Archive::Tar::Minitar::Output.stub
|
|
205
|
+
@file = double('file')
|
|
206
|
+
@dump.stub(:assets_to_dump).and_return(%w[images/* videos])
|
|
207
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
208
|
+
Dir.stub(:chdir).and_yield
|
|
209
|
+
@tar = double('tar_writer')
|
|
210
|
+
Archive::Tar::Minitar::Output.stub(:open).and_yield(@tar)
|
|
210
211
|
|
|
211
212
|
Dir.should_receive(:[]).with(*%w[images/* videos]).and_return(%w[images/a images/b videos])
|
|
212
213
|
Dir.should_receive(:[]).with('images/a/**/*').and_return([])
|
|
@@ -217,12 +218,12 @@ describe DumpWriter do
|
|
|
217
218
|
end
|
|
218
219
|
|
|
219
220
|
it "should pack each file from assets_root_link" do
|
|
220
|
-
@file =
|
|
221
|
-
@dump.stub
|
|
222
|
-
@dump.stub
|
|
223
|
-
Dir.stub
|
|
224
|
-
@tar =
|
|
225
|
-
Archive::Tar::Minitar::Output.stub
|
|
221
|
+
@file = double('file')
|
|
222
|
+
@dump.stub(:assets_to_dump).and_return(%w[images/* videos])
|
|
223
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
224
|
+
Dir.stub(:chdir).and_yield
|
|
225
|
+
@tar = double('tar_writer')
|
|
226
|
+
Archive::Tar::Minitar::Output.stub(:open).and_yield(@tar)
|
|
226
227
|
|
|
227
228
|
Dir.should_receive(:[]).with(*%w[images/* videos]).and_return(%w[images/a images/b videos])
|
|
228
229
|
Dir.should_receive(:[]).with('images/a/**/*').and_return([])
|
|
@@ -235,12 +236,12 @@ describe DumpWriter do
|
|
|
235
236
|
end
|
|
236
237
|
|
|
237
238
|
it "should pack each file" do
|
|
238
|
-
@file =
|
|
239
|
-
@dump.stub
|
|
240
|
-
@dump.stub
|
|
241
|
-
Dir.stub
|
|
242
|
-
@tar =
|
|
243
|
-
Archive::Tar::Minitar::Output.stub
|
|
239
|
+
@file = double('file')
|
|
240
|
+
@dump.stub(:assets_to_dump).and_return(%w[images/* videos])
|
|
241
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
242
|
+
Dir.stub(:chdir).and_yield
|
|
243
|
+
@tar = double('tar_writer')
|
|
244
|
+
Archive::Tar::Minitar::Output.stub(:open).and_yield(@tar)
|
|
244
245
|
|
|
245
246
|
Dir.should_receive(:[]).with(*%w[images/* videos]).and_return(%w[images/a images/b videos])
|
|
246
247
|
Dir.should_receive(:[]).with('images/a/**/*').and_return(%w[a.jpg b.jpg])
|
|
@@ -255,12 +256,12 @@ describe DumpWriter do
|
|
|
255
256
|
end
|
|
256
257
|
|
|
257
258
|
it "should not raise if something fails when packing" do
|
|
258
|
-
@file =
|
|
259
|
-
@dump.stub
|
|
260
|
-
@dump.stub
|
|
261
|
-
Dir.stub
|
|
262
|
-
@tar =
|
|
263
|
-
Archive::Tar::Minitar::Output.stub
|
|
259
|
+
@file = double('file')
|
|
260
|
+
@dump.stub(:assets_to_dump).and_return(%w[videos])
|
|
261
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
262
|
+
Dir.stub(:chdir).and_yield
|
|
263
|
+
@tar = double('tar_writer')
|
|
264
|
+
Archive::Tar::Minitar::Output.stub(:open).and_yield(@tar)
|
|
264
265
|
|
|
265
266
|
Dir.should_receive(:[]).with(*%w[videos]).and_return(%w[videos])
|
|
266
267
|
Dir.should_receive(:[]).with('videos/**/*').and_return(%w[a.mov b.mov])
|
|
@@ -282,8 +283,8 @@ describe DumpWriter do
|
|
|
282
283
|
end
|
|
283
284
|
|
|
284
285
|
it "should dump column names and values of each row" do
|
|
285
|
-
@file =
|
|
286
|
-
@dump.stub
|
|
286
|
+
@file = double('file')
|
|
287
|
+
@dump.stub(:create_file).and_yield(@file)
|
|
287
288
|
@config.replace({:tables => {'first' => 1, 'second' => 2}, :assets => %w[images videos]})
|
|
288
289
|
|
|
289
290
|
@file.should_receive(:write).with(Marshal.dump(@config))
|
|
@@ -293,32 +294,32 @@ describe DumpWriter do
|
|
|
293
294
|
|
|
294
295
|
describe "assets_to_dump" do
|
|
295
296
|
it "should call rake task assets" do
|
|
296
|
-
@task =
|
|
297
|
+
@task = double('task')
|
|
297
298
|
Rake::Task.should_receive(:[]).with('assets').and_return(@task)
|
|
298
299
|
@task.should_receive(:invoke)
|
|
299
300
|
@dump.assets_to_dump
|
|
300
301
|
end
|
|
301
302
|
|
|
302
303
|
it "should return array of assets if separator is colon" do
|
|
303
|
-
@task =
|
|
304
|
-
Rake::Task.stub
|
|
305
|
-
@task.stub
|
|
304
|
+
@task = double('task')
|
|
305
|
+
Rake::Task.stub(:[]).and_return(@task)
|
|
306
|
+
@task.stub(:invoke)
|
|
306
307
|
DumpRake::Env.with_env(:assets => 'images:videos') do
|
|
307
308
|
@dump.assets_to_dump.should == %w[images videos]
|
|
308
309
|
end
|
|
309
310
|
end
|
|
310
311
|
|
|
311
312
|
it "should return array of assets if separator is comma" do
|
|
312
|
-
@task =
|
|
313
|
-
Rake::Task.stub
|
|
314
|
-
@task.stub
|
|
313
|
+
@task = double('task')
|
|
314
|
+
Rake::Task.stub(:[]).and_return(@task)
|
|
315
|
+
@task.stub(:invoke)
|
|
315
316
|
DumpRake::Env.with_env(:assets => 'images,videos') do
|
|
316
317
|
@dump.assets_to_dump.should == %w[images videos]
|
|
317
318
|
end
|
|
318
319
|
end
|
|
319
320
|
|
|
320
321
|
it "should return empty array if calling rake task assets raises an exception" do
|
|
321
|
-
Rake::Task.stub
|
|
322
|
+
Rake::Task.stub(:[]).and_raise('task assets not found')
|
|
322
323
|
DumpRake::Env.with_env(:assets => 'images:videos') do
|
|
323
324
|
@dump.assets_to_dump.should == []
|
|
324
325
|
end
|
|
@@ -16,7 +16,7 @@ end
|
|
|
16
16
|
|
|
17
17
|
describe 'RailsRoot' do
|
|
18
18
|
before do
|
|
19
|
-
@root =
|
|
19
|
+
@root = double('root')
|
|
20
20
|
@root.should_receive(:to_s).and_return(@root)
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -25,7 +25,7 @@ describe 'RailsRoot' do
|
|
|
25
25
|
temp_remove_const DumpRake, :RailsRoot
|
|
26
26
|
|
|
27
27
|
it "should use Rails if it is present" do
|
|
28
|
-
Object.const_set('Rails',
|
|
28
|
+
Object.const_set('Rails', double('rails'))
|
|
29
29
|
Rails.should_receive(:root).and_return(@root)
|
|
30
30
|
load 'dump_rake/rails_root.rb'
|
|
31
31
|
DumpRake::RailsRoot.should === @root
|
|
@@ -143,9 +143,9 @@ describe TableManipulation do
|
|
|
143
143
|
describe "table_chunk_size" do
|
|
144
144
|
it "should return chunk_size based on estimated average for row size" do
|
|
145
145
|
should_receive(:table_columns).with('first').and_return(
|
|
146
|
-
[
|
|
147
|
-
[
|
|
148
|
-
[
|
|
146
|
+
[double(:column, :type => :integer, :limit => nil)] * 3 +
|
|
147
|
+
[double(:column, :type => :string, :limit => nil)] * 3 +
|
|
148
|
+
[double(:column, :type => :text, :limit => nil)]
|
|
149
149
|
)
|
|
150
150
|
table_chunk_size('first').should satisfy { |n|
|
|
151
151
|
(TableManipulation::CHUNK_SIZE_MIN..TableManipulation::CHUNK_SIZE_MAX).include?(n)
|
|
@@ -154,14 +154,14 @@ describe TableManipulation do
|
|
|
154
154
|
|
|
155
155
|
it "should not return value less than CHUNK_SIZE_MIN" do
|
|
156
156
|
should_receive(:table_columns).with('first').and_return(
|
|
157
|
-
[
|
|
157
|
+
[double(:column, :type => :text, :limit => nil)] * 100
|
|
158
158
|
)
|
|
159
159
|
table_chunk_size('first').should == TableManipulation::CHUNK_SIZE_MIN
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
it "should not return value more than CHUNK_SIZE_MAX" do
|
|
163
163
|
should_receive(:table_columns).with('first').and_return(
|
|
164
|
-
[
|
|
164
|
+
[double(:column, :type => :boolean, :limit => 1)] * 10
|
|
165
165
|
)
|
|
166
166
|
table_chunk_size('first').should == TableManipulation::CHUNK_SIZE_MAX
|
|
167
167
|
end
|
|
@@ -169,7 +169,7 @@ describe TableManipulation do
|
|
|
169
169
|
|
|
170
170
|
describe "table_columns" do
|
|
171
171
|
it "should return table column definitions" do
|
|
172
|
-
columns = [
|
|
172
|
+
columns = [double(:column), double(:column), double(:column)]
|
|
173
173
|
ActiveRecord::Base.connection.should_receive(:columns).with('first').and_return(columns)
|
|
174
174
|
table_columns('first').should == columns
|
|
175
175
|
end
|
|
@@ -179,13 +179,13 @@ describe TableManipulation do
|
|
|
179
179
|
it "should return true only if table has column with name id and type :integer" do
|
|
180
180
|
should_receive(:table_primary_key).at_least(3).times.and_return('id')
|
|
181
181
|
|
|
182
|
-
should_receive(:table_columns).with('first').and_return([
|
|
182
|
+
should_receive(:table_columns).with('first').and_return([double(:column, :name => 'id', :type => :integer), double(:column, :name => 'title', :type => :integer)])
|
|
183
183
|
table_has_primary_column?('first').should be_true
|
|
184
184
|
|
|
185
|
-
should_receive(:table_columns).with('second').and_return([
|
|
185
|
+
should_receive(:table_columns).with('second').and_return([double(:column, :name => 'id', :type => :string), double(:column, :name => 'title', :type => :integer)])
|
|
186
186
|
table_has_primary_column?('second').should be_false
|
|
187
187
|
|
|
188
|
-
should_receive(:table_columns).with('third').and_return([
|
|
188
|
+
should_receive(:table_columns).with('third').and_return([double(:column, :name => 'name', :type => :integer), double(:column, :name => 'title', :type => :integer)])
|
|
189
189
|
table_has_primary_column?('third').should be_false
|
|
190
190
|
end
|
|
191
191
|
end
|
|
@@ -248,7 +248,7 @@ describe TableManipulation do
|
|
|
248
248
|
|
|
249
249
|
describe "select_all_by_sql" do
|
|
250
250
|
it "should return all rows returned by database" do
|
|
251
|
-
rows = [
|
|
251
|
+
rows = [double(:row), double(:row), double(:row)]
|
|
252
252
|
ActiveRecord::Base.connection.should_receive(:select_all).with("SELECT * FROM abc WHERE x = y").and_return(rows)
|
|
253
253
|
select_all_by_sql("SELECT * FROM abc WHERE x = y").should == rows
|
|
254
254
|
end
|