activerecord-import 0.12.0 → 0.13.0
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 +4 -4
- data/.rubocop.yml +49 -0
- data/.rubocop_todo.yml +36 -0
- data/.travis.yml +31 -7
- data/CHANGELOG.md +19 -0
- data/Gemfile +5 -2
- data/README.markdown +6 -1
- data/Rakefile +5 -2
- data/activerecord-import.gemspec +1 -1
- data/benchmarks/benchmark.rb +67 -68
- data/benchmarks/lib/base.rb +136 -137
- data/benchmarks/lib/cli_parser.rb +106 -107
- data/benchmarks/lib/mysql2_benchmark.rb +19 -21
- data/benchmarks/lib/output_to_csv.rb +2 -1
- data/benchmarks/lib/output_to_html.rb +8 -13
- data/benchmarks/schema/mysql_schema.rb +8 -8
- data/gemfiles/4.0.gemfile +1 -1
- data/gemfiles/4.1.gemfile +1 -1
- data/gemfiles/4.2.gemfile +1 -1
- data/gemfiles/5.0.gemfile +1 -1
- data/lib/activerecord-import.rb +2 -0
- data/lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb +0 -1
- data/lib/activerecord-import/adapters/abstract_adapter.rb +9 -9
- data/lib/activerecord-import/adapters/mysql_adapter.rb +17 -17
- data/lib/activerecord-import/adapters/postgresql_adapter.rb +20 -22
- data/lib/activerecord-import/adapters/sqlite3_adapter.rb +9 -9
- data/lib/activerecord-import/base.rb +3 -3
- data/lib/activerecord-import/import.rb +152 -131
- data/lib/activerecord-import/synchronize.rb +20 -20
- data/lib/activerecord-import/value_sets_parser.rb +7 -6
- data/lib/activerecord-import/version.rb +1 -1
- data/test/adapters/mysql2spatial.rb +1 -1
- data/test/adapters/postgis.rb +1 -1
- data/test/adapters/postgresql.rb +1 -1
- data/test/adapters/spatialite.rb +1 -1
- data/test/adapters/sqlite3.rb +1 -1
- data/test/import_test.rb +121 -70
- data/test/models/book.rb +5 -6
- data/test/models/chapter.rb +2 -2
- data/test/models/discount.rb +3 -0
- data/test/models/end_note.rb +2 -2
- data/test/models/promotion.rb +1 -1
- data/test/models/question.rb +1 -1
- data/test/models/rule.rb +2 -2
- data/test/models/topic.rb +3 -3
- data/test/models/widget.rb +1 -1
- data/test/postgis/import_test.rb +1 -1
- data/test/schema/generic_schema.rb +100 -96
- data/test/schema/mysql_schema.rb +5 -7
- data/test/sqlite3/import_test.rb +0 -2
- data/test/support/active_support/test_case_extensions.rb +12 -15
- data/test/support/assertions.rb +1 -1
- data/test/support/factories.rb +15 -16
- data/test/support/generate.rb +4 -4
- data/test/support/mysql/import_examples.rb +21 -21
- data/test/support/postgresql/import_examples.rb +83 -55
- data/test/support/shared_examples/on_duplicate_key_update.rb +23 -23
- data/test/synchronize_test.rb +2 -2
- data/test/test_helper.rb +6 -8
- data/test/value_sets_bytes_parser_test.rb +14 -17
- data/test/value_sets_records_parser_test.rb +6 -6
- metadata +7 -4
- data/test/travis/build.sh +0 -34
data/test/synchronize_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
3
|
describe ".synchronize" do
|
4
|
-
let(:topics){ Generate(3, :topics) }
|
5
|
-
let(:titles){ %w(one two three) }
|
4
|
+
let(:topics) { Generate(3, :topics) }
|
5
|
+
let(:titles) { %w(one two three) }
|
6
6
|
|
7
7
|
setup do
|
8
8
|
# update records outside of ActiveRecord knowing about it
|
data/test/test_helper.rb
CHANGED
@@ -16,7 +16,7 @@ require "active_record"
|
|
16
16
|
require "active_record/fixtures"
|
17
17
|
require "active_support/test_case"
|
18
18
|
|
19
|
-
if ActiveSupport::VERSION::STRING < "4.
|
19
|
+
if ActiveSupport::VERSION::STRING < "4.0"
|
20
20
|
require 'test/unit'
|
21
21
|
else
|
22
22
|
require 'active_support/testing/autorun'
|
@@ -38,24 +38,22 @@ ActiveRecord::Base.default_timezone = :utc
|
|
38
38
|
require "activerecord-import"
|
39
39
|
ActiveRecord::Base.establish_connection :test
|
40
40
|
|
41
|
-
ActiveSupport::Notifications.subscribe(/active_record.sql/) do |
|
41
|
+
ActiveSupport::Notifications.subscribe(/active_record.sql/) do |_, _, _, _, hsh|
|
42
42
|
ActiveRecord::Base.logger.info hsh[:sql]
|
43
43
|
end
|
44
44
|
|
45
45
|
require "factory_girl"
|
46
|
-
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each{ |file| require file }
|
46
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |file| require file }
|
47
47
|
|
48
48
|
# Load base/generic schema
|
49
49
|
require test_dir.join("schema/version")
|
50
50
|
require test_dir.join("schema/generic_schema")
|
51
51
|
adapter_schema = test_dir.join("schema/#{adapter}_schema.rb")
|
52
|
-
require adapter_schema if File.
|
52
|
+
require adapter_schema if File.exist?(adapter_schema)
|
53
53
|
|
54
|
-
Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }
|
54
|
+
Dir[File.dirname(__FILE__) + "/models/*.rb"].each { |file| require file }
|
55
55
|
|
56
56
|
# Prevent this deprecation warning from breaking the tests.
|
57
57
|
Rake::FileList.send(:remove_method, :import)
|
58
58
|
|
59
|
-
if ENV['AR_VERSION'].to_f >= 4.2
|
60
|
-
ActiveSupport::TestCase.test_order = :sorted
|
61
|
-
end
|
59
|
+
ActiveSupport::TestCase.test_order = :random if ENV['AR_VERSION'].to_f >= 4.2
|
@@ -4,48 +4,48 @@ require 'activerecord-import/value_sets_parser'
|
|
4
4
|
|
5
5
|
describe ActiveRecord::Import::ValueSetsBytesParser do
|
6
6
|
context "#parse - computing insert value sets" do
|
7
|
-
let(:parser){ ActiveRecord::Import::ValueSetsBytesParser }
|
8
|
-
let(:base_sql){ "INSERT INTO atable (a,b,c)" }
|
9
|
-
let(:values){ [
|
7
|
+
let(:parser) { ActiveRecord::Import::ValueSetsBytesParser }
|
8
|
+
let(:base_sql) { "INSERT INTO atable (a,b,c)" }
|
9
|
+
let(:values) { ["(1,2,3)", "(2,3,4)", "(3,4,5)"] }
|
10
10
|
|
11
11
|
context "when the max allowed bytes is 33 and the base SQL is 26 bytes" do
|
12
12
|
it "should return 3 value sets when given 3 value sets of 7 bytes a piece" do
|
13
|
-
value_sets = parser.parse values, :
|
13
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 33
|
14
14
|
assert_equal 3, value_sets.size
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "when the max allowed bytes is 40 and the base SQL is 26 bytes" do
|
19
19
|
it "should return 3 value sets when given 3 value sets of 7 bytes a piece" do
|
20
|
-
value_sets = parser.parse values, :
|
20
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 40
|
21
21
|
assert_equal 3, value_sets.size
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when the max allowed bytes is 41 and the base SQL is 26 bytes" do
|
26
26
|
it "should return 2 value sets when given 2 value sets of 7 bytes a piece" do
|
27
|
-
value_sets = parser.parse values, :
|
27
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 41
|
28
28
|
assert_equal 2, value_sets.size
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context "when the max allowed bytes is 48 and the base SQL is 26 bytes" do
|
33
33
|
it "should return 2 value sets when given 2 value sets of 7 bytes a piece" do
|
34
|
-
value_sets = parser.parse values, :
|
34
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 48
|
35
35
|
assert_equal 2, value_sets.size
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when the max allowed bytes is 49 and the base SQL is 26 bytes" do
|
40
40
|
it "should return 1 value sets when given 1 value sets of 7 bytes a piece" do
|
41
|
-
value_sets = parser.parse values, :
|
41
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 49
|
42
42
|
assert_equal 1, value_sets.size
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
context "when the max allowed bytes is 999999 and the base SQL is 26 bytes" do
|
47
47
|
it "should return 1 value sets when given 1 value sets of 7 bytes a piece" do
|
48
|
-
value_sets = parser.parse values, :
|
48
|
+
value_sets = parser.parse values, reserved_bytes: base_sql.size, max_bytes: 999_999
|
49
49
|
assert_equal 1, value_sets.size
|
50
50
|
end
|
51
51
|
end
|
@@ -54,9 +54,8 @@ describe ActiveRecord::Import::ValueSetsBytesParser do
|
|
54
54
|
values = [
|
55
55
|
"('1','2','3')",
|
56
56
|
"('4','5','6')",
|
57
|
-
"('7','8','9')"
|
57
|
+
"('7','8','9')"]
|
58
58
|
|
59
|
-
values_size_in_bytes = values.sum {|value| value.bytesize }
|
60
59
|
base_sql_size_in_bytes = 15
|
61
60
|
max_bytes = 30
|
62
61
|
|
@@ -64,8 +63,9 @@ describe ActiveRecord::Import::ValueSetsBytesParser do
|
|
64
63
|
assert_equal 3, value_sets.size, 'Three value sets were expected!'
|
65
64
|
|
66
65
|
# Each element in the value_sets array must be an array
|
67
|
-
value_sets.each_with_index
|
68
|
-
assert_kind_of Array, e, "Element #{i} was expected to be an Array!"
|
66
|
+
value_sets.each_with_index do |e, i|
|
67
|
+
assert_kind_of Array, e, "Element #{i} was expected to be an Array!"
|
68
|
+
end
|
69
69
|
|
70
70
|
# Each element in the values array should have a 1:1 correlation to the elements
|
71
71
|
# in the returned value_sets arrays
|
@@ -79,18 +79,15 @@ describe ActiveRecord::Import::ValueSetsBytesParser do
|
|
79
79
|
# each accented e should be 2 bytes, so each entry is 6 bytes instead of 5
|
80
80
|
values = [
|
81
81
|
"('é')",
|
82
|
-
"('é')"
|
82
|
+
"('é')"]
|
83
83
|
|
84
84
|
base_sql_size_in_bytes = 15
|
85
85
|
max_bytes = 26
|
86
86
|
|
87
|
-
values_size_in_bytes = values.sum {|value| value.bytesize }
|
88
87
|
value_sets = parser.parse values, reserved_bytes: base_sql_size_in_bytes, max_bytes: max_bytes
|
89
88
|
|
90
89
|
assert_equal 2, value_sets.size, 'Two value sets were expected!'
|
91
90
|
end
|
92
91
|
end
|
93
92
|
end
|
94
|
-
|
95
93
|
end
|
96
|
-
|
@@ -4,27 +4,27 @@ require 'activerecord-import/value_sets_parser'
|
|
4
4
|
|
5
5
|
describe "ActiveRecord::Import::ValueSetsRecordsParser" do
|
6
6
|
context "#parse - computing insert value sets" do
|
7
|
-
let(:parser){ ActiveRecord::Import::ValueSetsRecordsParser }
|
8
|
-
let(:base_sql){ "INSERT INTO atable (a,b,c)" }
|
9
|
-
let(:values){ [
|
7
|
+
let(:parser) { ActiveRecord::Import::ValueSetsRecordsParser }
|
8
|
+
let(:base_sql) { "INSERT INTO atable (a,b,c)" }
|
9
|
+
let(:values) { ["(1,2,3)", "(2,3,4)", "(3,4,5)"] }
|
10
10
|
|
11
11
|
context "when the max number of records is 1" do
|
12
12
|
it "should return 3 value sets when given 3 values sets" do
|
13
|
-
value_sets = parser.parse values, :
|
13
|
+
value_sets = parser.parse values, max_records: 1
|
14
14
|
assert_equal 3, value_sets.size
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "when the max number of records is 2" do
|
19
19
|
it "should return 2 value sets when given 3 values sets" do
|
20
|
-
value_sets = parser.parse values, :
|
20
|
+
value_sets = parser.parse values, max_records: 2
|
21
21
|
assert_equal 2, value_sets.size
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when the max number of records is 3" do
|
26
26
|
it "should return 1 value sets when given 3 values sets" do
|
27
|
-
value_sets = parser.parse values, :
|
27
|
+
value_sets = parser.parse values, max_records: 3
|
28
28
|
assert_equal 1, value_sets.size
|
29
29
|
end
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Dennis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -47,6 +47,8 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".rubocop_todo.yml"
|
50
52
|
- ".travis.yml"
|
51
53
|
- Brewfile
|
52
54
|
- CHANGELOG.md
|
@@ -110,6 +112,7 @@ files:
|
|
110
112
|
- test/jdbcpostgresql/import_test.rb
|
111
113
|
- test/models/book.rb
|
112
114
|
- test/models/chapter.rb
|
115
|
+
- test/models/discount.rb
|
113
116
|
- test/models/end_note.rb
|
114
117
|
- test/models/group.rb
|
115
118
|
- test/models/promotion.rb
|
@@ -134,7 +137,6 @@ files:
|
|
134
137
|
- test/support/shared_examples/on_duplicate_key_update.rb
|
135
138
|
- test/synchronize_test.rb
|
136
139
|
- test/test_helper.rb
|
137
|
-
- test/travis/build.sh
|
138
140
|
- test/travis/database.yml
|
139
141
|
- test/value_sets_bytes_parser_test.rb
|
140
142
|
- test/value_sets_records_parser_test.rb
|
@@ -178,6 +180,7 @@ test_files:
|
|
178
180
|
- test/jdbcpostgresql/import_test.rb
|
179
181
|
- test/models/book.rb
|
180
182
|
- test/models/chapter.rb
|
183
|
+
- test/models/discount.rb
|
181
184
|
- test/models/end_note.rb
|
182
185
|
- test/models/group.rb
|
183
186
|
- test/models/promotion.rb
|
@@ -202,7 +205,7 @@ test_files:
|
|
202
205
|
- test/support/shared_examples/on_duplicate_key_update.rb
|
203
206
|
- test/synchronize_test.rb
|
204
207
|
- test/test_helper.rb
|
205
|
-
- test/travis/build.sh
|
206
208
|
- test/travis/database.yml
|
207
209
|
- test/value_sets_bytes_parser_test.rb
|
208
210
|
- test/value_sets_records_parser_test.rb
|
211
|
+
has_rdoc:
|
data/test/travis/build.sh
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
# set -e
|
3
|
-
# set +x
|
4
|
-
|
5
|
-
function run {
|
6
|
-
statement=$@
|
7
|
-
logfile=$4.log
|
8
|
-
$statement &> $logfile
|
9
|
-
if [ $? != 0 ] ; then
|
10
|
-
printf "AR_VERSION=$AR_VERSION $statement \e[31mFAILED\e[0m\n"
|
11
|
-
cat $logfile
|
12
|
-
else
|
13
|
-
printf "AR_VERSION=$AR_VERSION $statement \e[32mPASSED\e[0m\n"
|
14
|
-
fi
|
15
|
-
}
|
16
|
-
|
17
|
-
for activerecord_version in "3.1" "3.2" "4.0" "4.1" "4.2" "5.0" ; do
|
18
|
-
export AR_VERSION=$activerecord_version
|
19
|
-
|
20
|
-
bundle update activerecord > /dev/null
|
21
|
-
|
22
|
-
run bundle exec rake test:mysql2 # Run tests for mysql2
|
23
|
-
run bundle exec rake test:mysql2spatial # Run tests for mysql2spatial
|
24
|
-
run bundle exec rake test:postgis # Run tests for postgis
|
25
|
-
run bundle exec rake test:postgresql # Run tests for postgresql
|
26
|
-
run bundle exec rake test:seamless_database_pool # Run tests for seamless_database_pool
|
27
|
-
run bundle exec rake test:spatialite # Run tests for spatialite
|
28
|
-
# so far the version installed in travis seems < 3.7.11 so we cannot test sqlite3 on it
|
29
|
-
# run bundle exec rake test:sqlite3
|
30
|
-
|
31
|
-
#jruby
|
32
|
-
#bundle exec rake test:jdbcmysql # Run tests for jdbcmysql
|
33
|
-
#bundle exec rake test:jdbcpostgresql # Run tests for jdbcpostgresql
|
34
|
-
done
|