ferry 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -17
- data/bin/ferry +13 -2
- data/ferry.gemspec +6 -5
- data/lib/ferry/dumper.rb +38 -0
- data/lib/ferry/exporter.rb +3 -5
- data/lib/ferry/importer.rb +36 -9
- data/lib/ferry/version.rb +1 -1
- data/spec/support/emails_import.json +8402 -0
- data/spec/tests/dumper_tests.rb +12 -0
- data/spec/tests/exporter_tests.rb +164 -144
- data/spec/tests/importer_tests.rb +67 -52
- metadata +49 -30
@@ -2,171 +2,191 @@ exporter = Ferry::Exporter.new
|
|
2
2
|
|
3
3
|
Dir.chdir("spec") unless Dir.pwd.split('/').last == "spec"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
it "should error if specified table does not exist" do
|
18
|
-
expect{exporter.to_csv('sqlite3', 'cart')}.to raise_error
|
19
|
-
end
|
5
|
+
# TODO: test db func expo
|
6
|
+
describe "exporting" do
|
7
|
+
describe "sqlite3 db" do
|
8
|
+
before(:all) do
|
9
|
+
connect("sqlite3")
|
10
|
+
Contexts.setup
|
11
|
+
end
|
12
|
+
after(:all) do
|
13
|
+
Contexts.teardown
|
14
|
+
FileUtils.rm_rf('db')
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
file_path = File.expand_path("..",Dir.pwd) + "/spec/db/csv/sqlite3/carts.csv"
|
25
|
-
expect(File).to exist(file_path)
|
26
|
-
lines = CSV.read(file_path)
|
27
|
-
expect(lines.length).to eql(27)
|
28
|
-
expect(lines[0]).to eql(["id", "email"])
|
29
|
-
expect(lines[1]).to eql(["1", "abby@example.com"])
|
30
|
-
expect(lines[26]).to eql(["26", "zach@example.com"])
|
31
|
-
end
|
32
|
-
end
|
17
|
+
it "should error if specified table does not exist" do
|
18
|
+
expect{exporter.to_csv('sqlite3', 'cart')}.to raise_error
|
19
|
+
end
|
33
20
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
expect(output["carts"]["records"][25]).to eql([26,"zach@example.com"])
|
45
|
-
end
|
21
|
+
describe "to_csv" do
|
22
|
+
it "call should create a populated csv file" do
|
23
|
+
exporter.to_csv('sqlite3', 'carts')
|
24
|
+
file_path = File.expand_path("..",Dir.pwd) + "/spec/db/csv/sqlite3/carts.csv"
|
25
|
+
expect(File).to exist(file_path)
|
26
|
+
lines = CSV.read(file_path)
|
27
|
+
expect(lines.length).to eql(27)
|
28
|
+
expect(lines[0]).to eql(["id", "email"])
|
29
|
+
expect(lines[1]).to eql(["1", "abby@example.com"])
|
30
|
+
expect(lines[26]).to eql(["26", "zach@example.com"])
|
46
31
|
end
|
32
|
+
end
|
47
33
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
34
|
+
describe "to_yaml" do
|
35
|
+
it "call should create a populated yaml file" do
|
36
|
+
exporter.to_yaml('sqlite3', 'carts')
|
37
|
+
file_path = File.expand_path("..", Dir.pwd) + "/spec/db/yaml/sqlite3/carts.yml"
|
38
|
+
expect(File).to exist(file_path)
|
39
|
+
output = YAML.load_file(file_path)
|
40
|
+
expect(output["carts"].length).to eql(2)
|
41
|
+
expect(output["carts"].keys).to eql(["columns","records"])
|
42
|
+
expect(output["carts"]["columns"]).to eql(["id","email"])
|
43
|
+
expect(output["carts"]["records"][0]).to eql([1,"abby@example.com"])
|
44
|
+
expect(output["carts"]["records"][25]).to eql([26,"zach@example.com"])
|
59
45
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
it "should error if specified table does not exist" do
|
73
|
-
expect{exporter.to_csv('postgresql', 'cart')}.to raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "to_json" do
|
49
|
+
it "should create a correctly formatted json file" do
|
50
|
+
exporter.to_json('sqlite3', 'carts')
|
51
|
+
file_path = File.expand_path("..", Dir.pwd) + "/spec/db/json/sqlite3/carts.json"
|
52
|
+
file_content = File.read(file_path)
|
53
|
+
expect(File).to exist(file_path)
|
54
|
+
output = JSON.parse(file_content)
|
55
|
+
expect(output.length).to eql(26)
|
56
|
+
expect(output[0]["email"]).to eql("abby@example.com")
|
57
|
+
expect(output[25]["email"]).to eql("zach@example.com")
|
74
58
|
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# describe "export db dumps" do
|
62
|
+
# it "should be able to export a full sql dump to a file" do
|
63
|
+
# pending("waiting to be written")
|
64
|
+
# raise "so were failing for now"
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "postgresql db" do
|
70
|
+
before(:all) do
|
71
|
+
connect("postgresql")
|
72
|
+
Contexts.setup
|
73
|
+
end
|
74
|
+
after(:all) do
|
75
|
+
Contexts.teardown
|
76
|
+
FileUtils.rm_rf('db')
|
77
|
+
end
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
79
|
+
it "should error if specified table does not exist" do
|
80
|
+
expect{exporter.to_csv('postgresql', 'cart')}.to raise_error
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "to_csv" do
|
84
|
+
it "call should create a populated csv file" do
|
85
|
+
exporter.to_csv('postgresql', 'carts')
|
86
|
+
file_path = File.expand_path("..",Dir.pwd) + "/spec/db/csv/postgresql/carts.csv"
|
87
|
+
expect(File).to exist(file_path)
|
88
|
+
lines = CSV.read(file_path)
|
89
|
+
expect(lines.length).to eql(27)
|
90
|
+
expect(lines[0]).to eql(["id", "email"])
|
91
|
+
expect(lines[1]).to eql(["1", "abby@example.com"])
|
92
|
+
expect(lines[26]).to eql(["26", "zach@example.com"])
|
87
93
|
end
|
94
|
+
end
|
88
95
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
96
|
+
describe "to_yaml" do
|
97
|
+
it "call should create a populated yaml file" do
|
98
|
+
exporter.to_yaml('postgresql', 'carts')
|
99
|
+
file_path = File.expand_path("..",Dir.pwd) + "/spec/db/yaml/postgresql/carts.yml"
|
100
|
+
expect(File).to exist(file_path)
|
101
|
+
output = YAML.load_file(file_path)
|
102
|
+
expect(output["carts"].length).to eql(2)
|
103
|
+
expect(output["carts"].keys).to eql(["columns","records"])
|
104
|
+
expect(output["carts"]["columns"]).to eql(["id","email"])
|
105
|
+
expect(output["carts"]["records"][0]).to eql(["1","abby@example.com"])
|
106
|
+
expect(output["carts"]["records"][25]).to eql(["26","zach@example.com"])
|
101
107
|
end
|
108
|
+
end
|
102
109
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
110
|
+
describe "to_json" do
|
111
|
+
it "should create a correctly formatted json file" do
|
112
|
+
exporter.to_json('postgresql', 'carts')
|
113
|
+
file_path = File.expand_path("..", Dir.pwd) + "/spec/db/json/postgresql/carts.json"
|
114
|
+
file_content = File.read(file_path)
|
115
|
+
expect(File).to exist(file_path)
|
116
|
+
output = JSON.parse(file_content)
|
117
|
+
expect(output.length).to eql(26)
|
118
|
+
expect(output[0]["email"]).to eql("abby@example.com")
|
119
|
+
expect(output[25]["email"]).to eql("zach@example.com")
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
FileUtils.rm_rf('db')
|
125
|
-
end
|
123
|
+
# describe "export db dumps" do
|
124
|
+
# it "should be able to export a full sql dump to a file" do
|
125
|
+
# pending("waiting to be written")
|
126
|
+
# raise "so were failing for now"
|
127
|
+
# end
|
128
|
+
# end
|
129
|
+
end
|
126
130
|
|
127
|
-
|
128
|
-
|
129
|
-
|
131
|
+
describe "mysql2 db" do
|
132
|
+
before(:all) do
|
133
|
+
connect("mysql2")
|
134
|
+
Contexts.setup
|
135
|
+
end
|
136
|
+
after(:all) do
|
137
|
+
Contexts.teardown
|
138
|
+
FileUtils.rm_rf('db')
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should error if specified table does not exist" do
|
142
|
+
expect{exporter.to_csv('mysql2', 'cart')}.to raise_error
|
143
|
+
end
|
130
144
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
145
|
+
describe "to_csv" do
|
146
|
+
it "call should create a populated csv file" do
|
147
|
+
exporter.to_csv('mysql2', 'carts')
|
148
|
+
file_path = File.expand_path("..",Dir.pwd) + "/spec/db/csv/mysql2/carts.csv"
|
149
|
+
expect(File).to exist(file_path)
|
150
|
+
lines = CSV.read(file_path)
|
151
|
+
expect(lines.length).to eql(27)
|
152
|
+
expect(lines[0]).to eql(["id", "email"])
|
153
|
+
expect(lines[1]).to eql(["1", "abby@example.com"])
|
154
|
+
expect(lines[26]).to eql(["26", "zach@example.com"])
|
142
155
|
end
|
156
|
+
end
|
143
157
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
158
|
+
describe "to_yaml" do
|
159
|
+
it "call should create a populated yaml file" do
|
160
|
+
exporter.to_yaml('mysql2', 'carts')
|
161
|
+
file_path = File.expand_path("..",Dir.pwd) + "/spec/db/yaml/mysql2/carts.yml"
|
162
|
+
expect(File).to exist(file_path)
|
163
|
+
output = YAML.load_file(file_path)
|
164
|
+
expect(output["carts"].length).to eql(2)
|
165
|
+
expect(output["carts"].keys).to eql(["columns","records"])
|
166
|
+
expect(output["carts"]["columns"]).to eql(["id","email"])
|
167
|
+
expect(output["carts"]["records"][0]).to eql([1,"abby@example.com"])
|
168
|
+
expect(output["carts"]["records"][25]).to eql([26,"zach@example.com"])
|
156
169
|
end
|
170
|
+
end
|
157
171
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
172
|
+
describe "to_json" do
|
173
|
+
it "should create a correctly formatted json file" do
|
174
|
+
exporter.to_json('mysql2', 'carts')
|
175
|
+
file_path = File.expand_path("..", Dir.pwd) + "/spec/db/json/mysql2/carts.json"
|
176
|
+
file_content = File.read(file_path)
|
177
|
+
expect(File).to exist(file_path)
|
178
|
+
output = JSON.parse(file_content)
|
179
|
+
expect(output.length).to eql(26)
|
180
|
+
expect(output[0]["email"]).to eql("abby@example.com")
|
181
|
+
expect(output[25]["email"]).to eql("zach@example.com")
|
169
182
|
end
|
170
183
|
end
|
184
|
+
|
185
|
+
# describe "export db dumps" do
|
186
|
+
# it "should be able to export a full sql dump to a file" do
|
187
|
+
# pending("waiting to be written")
|
188
|
+
# raise "so were failing for now"
|
189
|
+
# end
|
190
|
+
# end
|
171
191
|
end
|
172
192
|
end
|
@@ -2,8 +2,9 @@ importer = Ferry::Importer.new
|
|
2
2
|
|
3
3
|
Dir.chdir("spec") unless Dir.pwd.split('/').last == "spec"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
# TODO: import json tests - will need sample json file
|
6
|
+
# TODO: import db things - will need sample db file
|
7
|
+
describe "import" do
|
7
8
|
describe "sqlite3 db" do
|
8
9
|
|
9
10
|
before(:all) do
|
@@ -18,7 +19,7 @@ describe "#import" do
|
|
18
19
|
|
19
20
|
it "should import a valid csv into ActiveRecord" do
|
20
21
|
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/categories_import.csv"
|
21
|
-
importer.
|
22
|
+
importer.import_csv("sqlite3", "categories", import_path)
|
22
23
|
expect(Category.all.length).to eql(146)
|
23
24
|
expect(Category.find_by(id: 42).name).to eql("outdoor decor")
|
24
25
|
expect(Category.find_by(id: 42).description).to eql("Pellentesque magna odio, blandit in nisi fringilla, commodo.")
|
@@ -27,29 +28,41 @@ describe "#import" do
|
|
27
28
|
expect(Category.find_by(id: 9).name).to eql("boys' clothing")
|
28
29
|
end
|
29
30
|
|
30
|
-
#SQL INSERT tests
|
31
31
|
it "should error if given a non-csv file" do
|
32
|
-
expect{importer.
|
32
|
+
expect{importer.import_csv("sqlite3", "categories", File.expand_path("..",Dir.pwd) + "/spec/support/categories_import.xml")}.to raise_error
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should error if file does not exist" do
|
36
|
-
expect{importer.
|
36
|
+
expect{importer.import_csv("sqlite3", "categories", File.expand_path("..",Dir.pwd) + "/spec/support/invalid.csv")}.to raise_error
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should error if invalid table name" do
|
40
|
-
expect{importer.
|
40
|
+
expect{importer.import_csv("sqlite3", "category", File.expand_path("..",Dir.pwd) + "/spec/support/categories_import.csv")}.to raise_error
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should error if columns are invalid" do
|
44
|
-
expect{importer.
|
44
|
+
expect{importer.import_csv("sqlite3", "categories", File.expand_path("..",Dir.pwd) + "/spec/support/categories_invalid_col.csv")}.to raise_error
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should error if values do not meet db constraints" do
|
48
|
-
expect{importer.
|
48
|
+
expect{importer.import_csv("sqlite3", "categories", File.expand_path("..",Dir.pwd) + "/spec/support/categories_null_name.csv")}.to raise_error
|
49
|
+
expect{importer.import_csv("sqlite3", "categories", File.expand_path("..",Dir.pwd) + "/spec/support/categories_repeat_id.csv")}.to raise_error
|
50
|
+
end
|
49
51
|
|
50
|
-
|
52
|
+
it "should be able to import a json file into ActiveRecord" do
|
53
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.json"
|
54
|
+
importer.import_json("sqlite3", "carts", import_path)
|
55
|
+
expect(Cart.find_by(id: 42).email).to eql("Albert@example.com")
|
56
|
+
expect(Cart.find_by(id: 542).email).to eql("Agustu@example.com")
|
57
|
+
expect(Cart.find_by(id: 1042).email).to eql("Smith@example.com")
|
58
|
+
expect(Cart.find_by(id: 1542).email).to eql("Kare@example.com")
|
59
|
+
expect(Cart.find_by(id: 2042).email).to eql("Yolanda@example.com")
|
51
60
|
end
|
52
61
|
|
62
|
+
# it "should be able to import a full sql dump" do
|
63
|
+
# pending("waiting to be written")
|
64
|
+
# raise "so were failing for now"
|
65
|
+
# end
|
53
66
|
end
|
54
67
|
|
55
68
|
describe "mass insert tests (sqlite)" do
|
@@ -65,8 +78,9 @@ describe "#import" do
|
|
65
78
|
end
|
66
79
|
|
67
80
|
it "should be able to import > 500 records" do
|
68
|
-
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.csv"
|
69
|
-
importer.
|
81
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.csv"
|
82
|
+
importer.import_csv("sqlite3", "carts", import_path)
|
83
|
+
expect(Cart.all.length).to eql(2126)
|
70
84
|
expect(Cart.find_by(id: 42).email).to eql("Albert@example.com")
|
71
85
|
expect(Cart.find_by(id: 542).email).to eql("Agustu@example.com")
|
72
86
|
expect(Cart.find_by(id: 1042).email).to eql("Smith@example.com")
|
@@ -75,33 +89,32 @@ describe "#import" do
|
|
75
89
|
end
|
76
90
|
|
77
91
|
it "should not commit import if any record errors" do
|
78
|
-
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_invalid.csv"
|
79
|
-
expect{importer.
|
92
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_invalid.csv"
|
93
|
+
expect{importer.import_csv("sqlite3", "carts", import_path)}.to raise_error
|
80
94
|
expect(Cart.find_by(id: 42)).to eql(nil)
|
81
95
|
expect(Cart.find_by(id: 542)).to eql(nil)
|
82
96
|
expect(Cart.find_by(id: 1042)).to eql(nil)
|
83
97
|
expect(Cart.find_by(id: 1542)).to eql(nil)
|
84
98
|
expect(Cart.find_by(id: 2042)).to eql(nil)
|
85
99
|
end
|
86
|
-
|
87
100
|
end
|
88
101
|
|
89
102
|
describe "postgresql db" do
|
90
103
|
|
91
|
-
before(:
|
104
|
+
before(:each) do
|
92
105
|
connect("postgresql")
|
93
|
-
# requires you to have a ferry_test db in pg
|
94
106
|
Contexts.setup
|
95
107
|
end
|
96
108
|
|
97
|
-
after(:
|
109
|
+
after(:each) do
|
98
110
|
Contexts.teardown
|
99
|
-
|
111
|
+
Category.delete_all
|
112
|
+
Cart.delete_all
|
100
113
|
end
|
101
114
|
|
102
115
|
it "should import a valid csv into ActiveRecord" do
|
103
116
|
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/categories_import.csv"
|
104
|
-
importer.
|
117
|
+
importer.import_csv("postgresql", "categories", import_path)
|
105
118
|
expect(Category.all.length).to eql(146)
|
106
119
|
expect(Category.find_by(id: 42).name).to eql("outdoor decor")
|
107
120
|
expect(Category.find_by(id: 42).description).to eql("Pellentesque magna odio, blandit in nisi fringilla, commodo.")
|
@@ -110,10 +123,23 @@ describe "#import" do
|
|
110
123
|
expect(Category.find_by(id: 9).name).to eql("boys' clothing")
|
111
124
|
end
|
112
125
|
|
126
|
+
it "should be able to import a json file correctly" do
|
127
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.json"
|
128
|
+
importer.import_json("sqlite3", "carts", import_path)
|
129
|
+
expect(Cart.find_by(id: 42).email).to eql("Albert@example.com")
|
130
|
+
expect(Cart.find_by(id: 542).email).to eql("Agustu@example.com")
|
131
|
+
expect(Cart.find_by(id: 1042).email).to eql("Smith@example.com")
|
132
|
+
expect(Cart.find_by(id: 1542).email).to eql("Kare@example.com")
|
133
|
+
expect(Cart.find_by(id: 2042).email).to eql("Yolanda@example.com")
|
134
|
+
end
|
135
|
+
|
136
|
+
# it "should be able to import a full sql dump" do
|
137
|
+
# pending("waiting to be written")
|
138
|
+
# raise "so were failing for now"
|
139
|
+
# end
|
113
140
|
end
|
114
141
|
|
115
142
|
describe "mass insert tests (postgresql)" do
|
116
|
-
|
117
143
|
before(:each) do
|
118
144
|
connect("postgresql")
|
119
145
|
Contexts.setup
|
@@ -124,44 +150,32 @@ describe "#import" do
|
|
124
150
|
Cart.delete_all
|
125
151
|
end
|
126
152
|
|
127
|
-
it "should be able to import >500 records" do
|
128
|
-
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.csv" #2100 records
|
129
|
-
importer.import("sqlite3", "carts", import_path)
|
130
|
-
expect(Cart.find_by(id: 42).email).to eql("Albert@example.com")
|
131
|
-
expect(Cart.find_by(id: 542).email).to eql("Agustu@example.com")
|
132
|
-
expect(Cart.find_by(id: 1042).email).to eql("Smith@example.com")
|
133
|
-
expect(Cart.find_by(id: 1542).email).to eql("Kare@example.com")
|
134
|
-
expect(Cart.find_by(id: 2042).email).to eql("Yolanda@example.com")
|
135
|
-
end
|
136
|
-
|
137
153
|
it "should not commit import if any record errors" do
|
138
|
-
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_invalid.csv"
|
139
|
-
expect{importer.
|
154
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_invalid.csv"
|
155
|
+
expect{importer.import_csv("sqlite3", "carts", import_path)}.to raise_error
|
140
156
|
expect(Cart.find_by(id: 42)).to eql(nil)
|
141
157
|
expect(Cart.find_by(id: 542)).to eql(nil)
|
142
158
|
expect(Cart.find_by(id: 1042)).to eql(nil)
|
143
159
|
expect(Cart.find_by(id: 1542)).to eql(nil)
|
144
160
|
expect(Cart.find_by(id: 2042)).to eql(nil)
|
145
161
|
end
|
146
|
-
|
147
162
|
end
|
148
163
|
|
149
164
|
describe "mysql2 db" do
|
150
|
-
|
151
165
|
before(:all) do
|
152
166
|
connect("mysql2")
|
153
|
-
# requires you to have a ferry_test db in pg
|
154
167
|
Contexts.setup
|
155
168
|
end
|
156
169
|
|
157
170
|
after(:all) do
|
158
171
|
Contexts.teardown
|
159
172
|
Category.delete_all
|
173
|
+
Cart.delete_all
|
160
174
|
end
|
161
175
|
|
162
176
|
it "should import a valid csv values into ActiveRecord" do
|
163
177
|
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/categories_import.csv"
|
164
|
-
importer.
|
178
|
+
importer.import_csv("mysql2", "categories", import_path)
|
165
179
|
expect(Category.all.length).to eql(146)
|
166
180
|
expect(Category.find_by(id: 42).name).to eql("outdoor decor")
|
167
181
|
expect(Category.find_by(id: 42).description).to eql("Pellentesque magna odio, blandit in nisi fringilla, commodo.")
|
@@ -170,10 +184,23 @@ describe "#import" do
|
|
170
184
|
expect(Category.find_by(id: 9).name).to eql("boys' clothing")
|
171
185
|
end
|
172
186
|
|
187
|
+
it "should be able to import a json file correctly" do
|
188
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.json"
|
189
|
+
importer.import_json("sqlite3", "carts", import_path)
|
190
|
+
expect(Cart.find_by(id: 42).email).to eql("Albert@example.com")
|
191
|
+
expect(Cart.find_by(id: 542).email).to eql("Agustu@example.com")
|
192
|
+
expect(Cart.find_by(id: 1042).email).to eql("Smith@example.com")
|
193
|
+
expect(Cart.find_by(id: 1542).email).to eql("Kare@example.com")
|
194
|
+
expect(Cart.find_by(id: 2042).email).to eql("Yolanda@example.com")
|
195
|
+
end
|
196
|
+
|
197
|
+
# it "should be able to import a full sql dump" do
|
198
|
+
# pending("waiting to be written")
|
199
|
+
# raise "so were failing for now"
|
200
|
+
# end
|
173
201
|
end
|
174
202
|
|
175
203
|
describe "mass insert tests (mysql2)" do
|
176
|
-
|
177
204
|
before(:each) do
|
178
205
|
connect("mysql2")
|
179
206
|
Contexts.setup
|
@@ -185,25 +212,13 @@ describe "#import" do
|
|
185
212
|
end
|
186
213
|
|
187
214
|
it "should be able to import >500 records" do
|
188
|
-
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.csv"
|
189
|
-
importer.
|
215
|
+
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_import.csv"
|
216
|
+
importer.import_csv("sqlite3", "carts", import_path)
|
190
217
|
expect(Cart.find_by(id: 42).email).to eql("Albert@example.com")
|
191
218
|
expect(Cart.find_by(id: 542).email).to eql("Agustu@example.com")
|
192
219
|
expect(Cart.find_by(id: 1042).email).to eql("Smith@example.com")
|
193
220
|
expect(Cart.find_by(id: 1542).email).to eql("Kare@example.com")
|
194
221
|
expect(Cart.find_by(id: 2042).email).to eql("Yolanda@example.com")
|
195
222
|
end
|
196
|
-
|
197
|
-
it "should not commit import if any record errors" do
|
198
|
-
import_path = File.expand_path("..",Dir.pwd) + "/spec/support/emails_invalid.csv" #2100 records, last one is invalid
|
199
|
-
expect{importer.import("sqlite3", "carts", import_path)}.to raise_error
|
200
|
-
expect(Cart.find_by(id: 42)).to eql(nil)
|
201
|
-
expect(Cart.find_by(id: 542)).to eql(nil)
|
202
|
-
expect(Cart.find_by(id: 1042)).to eql(nil)
|
203
|
-
expect(Cart.find_by(id: 1542)).to eql(nil)
|
204
|
-
expect(Cart.find_by(id: 2042)).to eql(nil)
|
205
|
-
end
|
206
|
-
|
207
223
|
end
|
208
|
-
|
209
224
|
end
|