abstract_importer 1.3.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +13 -10
- data/Rakefile +4 -5
- data/abstract_importer.gemspec +10 -9
- data/lib/abstract_importer.rb +2 -2
- data/lib/abstract_importer/base.rb +113 -48
- data/lib/abstract_importer/collection.rb +13 -6
- data/lib/abstract_importer/collection_importer.rb +4 -1
- data/lib/abstract_importer/id_map.rb +18 -16
- data/lib/abstract_importer/import_options.rb +0 -1
- data/lib/abstract_importer/reporters.rb +6 -5
- data/lib/abstract_importer/reporters/base_reporter.rb +7 -2
- data/lib/abstract_importer/reporters/debug_reporter.rb +1 -8
- data/lib/abstract_importer/reporters/dot_reporter.rb +5 -0
- data/lib/abstract_importer/reporters/null_reporter.rb +1 -1
- data/lib/abstract_importer/reporters/progress_reporter.rb +42 -0
- data/lib/abstract_importer/strategies.rb +1 -0
- data/lib/abstract_importer/strategies/base.rb +13 -3
- data/lib/abstract_importer/strategies/default_strategy.rb +1 -1
- data/lib/abstract_importer/strategies/insert_strategy.rb +27 -15
- data/lib/abstract_importer/strategies/replace_strategy.rb +1 -1
- data/lib/abstract_importer/strategies/upsert_strategy.rb +25 -0
- data/lib/abstract_importer/summary.rb +13 -2
- data/lib/abstract_importer/version.rb +1 -1
- data/test/callback_test.rb +3 -3
- data/test/id_map_test.rb +18 -0
- data/test/insert_strategy_test.rb +28 -11
- data/test/support/mock_data_source.rb +6 -0
- data/test/support/mock_objects.rb +6 -0
- data/test/support/schema.rb +15 -0
- data/test/test_helper.rb +10 -6
- data/test/upsert_strategy_test.rb +92 -0
- metadata +49 -15
@@ -41,8 +41,14 @@ end
|
|
41
41
|
|
42
42
|
class Cat < ActiveRecord::Base
|
43
43
|
has_one :student, as: :pet
|
44
|
+
has_many :abilities, as: :pet, inverse_of: :pet
|
44
45
|
end
|
45
46
|
|
46
47
|
class Owl < ActiveRecord::Base
|
47
48
|
has_one :student, as: :pet
|
49
|
+
has_many :abilities, as: :pet, inverse_of: :pet
|
50
|
+
end
|
51
|
+
|
52
|
+
class Ability < ActiveRecord::Base
|
53
|
+
belongs_to :pet, inverse_of: :abilities, polymorphic: true
|
48
54
|
end
|
data/test/support/schema.rb
CHANGED
@@ -11,6 +11,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
11
11
|
t.string "pet_type"
|
12
12
|
t.integer "pet_id"
|
13
13
|
t.index "name", :unique => true
|
14
|
+
t.index "legacy_id", :unique => true
|
14
15
|
end
|
15
16
|
|
16
17
|
create_table "parents", :force => true do |t|
|
@@ -18,12 +19,14 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
18
19
|
t.integer "student_id"
|
19
20
|
t.integer "legacy_id"
|
20
21
|
t.string "name"
|
22
|
+
t.index "legacy_id", :unique => true
|
21
23
|
end
|
22
24
|
|
23
25
|
create_table "locations", :force => true do |t|
|
24
26
|
t.integer "account_id"
|
25
27
|
t.integer "legacy_id"
|
26
28
|
t.string "slug"
|
29
|
+
t.index "legacy_id", :unique => true
|
27
30
|
end
|
28
31
|
|
29
32
|
create_table "students_subjects", :force => true do |t|
|
@@ -35,6 +38,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
35
38
|
t.integer "account_id"
|
36
39
|
t.integer "legacy_id"
|
37
40
|
t.string "name"
|
41
|
+
t.index "legacy_id", :unique => true
|
38
42
|
end
|
39
43
|
|
40
44
|
create_table "grades", :force => true do |t|
|
@@ -43,18 +47,29 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
43
47
|
t.integer "student_id"
|
44
48
|
t.integer "legacy_id"
|
45
49
|
t.string "value"
|
50
|
+
t.index "legacy_id", :unique => true
|
46
51
|
end
|
47
52
|
|
48
53
|
create_table "owls", :force => true do |t|
|
49
54
|
t.integer "account_id"
|
50
55
|
t.integer "legacy_id"
|
51
56
|
t.string "name"
|
57
|
+
t.index "legacy_id", :unique => true
|
52
58
|
end
|
53
59
|
|
54
60
|
create_table "cats", :force => true do |t|
|
55
61
|
t.integer "account_id"
|
56
62
|
t.integer "legacy_id"
|
57
63
|
t.string "name"
|
64
|
+
t.index "legacy_id", :unique => true
|
65
|
+
end
|
66
|
+
|
67
|
+
create_table "abilities", :force => true do |t|
|
68
|
+
t.string "pet_type"
|
69
|
+
t.integer "pet_id"
|
70
|
+
t.integer "legacy_id"
|
71
|
+
t.string "name"
|
72
|
+
t.index "legacy_id", :unique => true
|
58
73
|
end
|
59
74
|
|
60
75
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,9 +5,9 @@ SimpleCov.start do
|
|
5
5
|
add_filter "test/"
|
6
6
|
end
|
7
7
|
|
8
|
-
require "
|
9
|
-
|
10
|
-
|
8
|
+
require "minitest/reporters/turn_reporter"
|
9
|
+
MiniTest::Reporters.use! Minitest::Reporters::TurnReporter.new
|
10
|
+
|
11
11
|
require "pry"
|
12
12
|
require "rr"
|
13
13
|
require "database_cleaner"
|
@@ -16,13 +16,17 @@ require "shoulda/context"
|
|
16
16
|
require "active_record"
|
17
17
|
require "support/mock_data_source"
|
18
18
|
require "support/mock_objects"
|
19
|
+
require "minitest/autorun"
|
20
|
+
|
19
21
|
|
20
22
|
|
23
|
+
system "psql -c 'create database abstract_importer_test'"
|
21
24
|
|
22
25
|
ActiveRecord::Base.establish_connection(
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
+
adapter: "postgresql",
|
27
|
+
host: "localhost",
|
28
|
+
database: "abstract_importer_test",
|
29
|
+
verbosity: "quiet")
|
26
30
|
|
27
31
|
load File.join(File.dirname(__FILE__), "support", "schema.rb")
|
28
32
|
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class UpsertStrategyTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
setup do
|
7
|
+
options.merge!(strategy: {students: :upsert})
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
context "with a simple data source" do
|
13
|
+
setup do
|
14
|
+
plan do |import|
|
15
|
+
import.students
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "import the records in batches" do
|
20
|
+
mock.proxy(Student).insert_many(satisfy { |arg| arg.length == 3 }, anything)
|
21
|
+
import!
|
22
|
+
assert_equal [456, 457, 458], account.students.pluck(:legacy_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "report that it found 3 records" do
|
26
|
+
summary = import!
|
27
|
+
assert_equal 3, summary[:students].total
|
28
|
+
end
|
29
|
+
|
30
|
+
should "report that it created 3 records" do
|
31
|
+
summary = import!
|
32
|
+
assert_equal 3, summary[:students].created
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with a complex data source" do
|
37
|
+
setup do
|
38
|
+
plan do |import|
|
39
|
+
import.students
|
40
|
+
import.parents
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should "preserve mappings" do
|
45
|
+
import!
|
46
|
+
harry = account.students.find_by_name("Harry Potter")
|
47
|
+
assert_equal ["James Potter", "Lily Potter"], harry.parents.pluck(:name)
|
48
|
+
end
|
49
|
+
|
50
|
+
should "preserve mappings even when a record was previously imported" do
|
51
|
+
harry = account.students.create!(name: "Harry Potter", legacy_id: 456)
|
52
|
+
import!
|
53
|
+
assert_equal ["James Potter", "Lily Potter"], harry.parents.pluck(:name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "When records already exist" do
|
58
|
+
setup do
|
59
|
+
plan do |import|
|
60
|
+
import.students
|
61
|
+
end
|
62
|
+
account.students.create!(name: "Ronaldo Weasley", legacy_id: 457)
|
63
|
+
end
|
64
|
+
|
65
|
+
should "not import existing records twice" do
|
66
|
+
import!
|
67
|
+
assert_equal 3, account.students.count
|
68
|
+
end
|
69
|
+
|
70
|
+
should "update the existing record" do
|
71
|
+
import!
|
72
|
+
assert_equal ["Ron Weasley"], account.students.where(legacy_id: 457).pluck(:name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "When the imported records belong to a parent polymorphically" do
|
77
|
+
setup do
|
78
|
+
@account = Owl.create!(name: "Pigwidgeon")
|
79
|
+
plan do |import|
|
80
|
+
import.abilities
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
should "import records just fine" do
|
85
|
+
pet = @account
|
86
|
+
import!
|
87
|
+
assert_equal [["Owl", pet.id]], Ability.pluck(:pet_type, :pet_id)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abstract_importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,28 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: activerecord-insert_many
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
47
|
+
version: 0.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: progressbar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
34
62
|
type: :runtime
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,21 +81,21 @@ dependencies:
|
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '1.3'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
84
|
+
name: minitest-reporters
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- - "
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
89
|
+
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- - "
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
96
|
+
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: minitest-reporters-turn_reporter
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - ">="
|
@@ -81,7 +109,7 @@ dependencies:
|
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: rake
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
@@ -109,7 +137,7 @@ dependencies:
|
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
140
|
+
name: pg
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
143
|
- - ">="
|
@@ -220,21 +248,25 @@ files:
|
|
220
248
|
- lib/abstract_importer/reporters/dot_reporter.rb
|
221
249
|
- lib/abstract_importer/reporters/null_reporter.rb
|
222
250
|
- lib/abstract_importer/reporters/performance_reporter.rb
|
251
|
+
- lib/abstract_importer/reporters/progress_reporter.rb
|
223
252
|
- lib/abstract_importer/strategies.rb
|
224
253
|
- lib/abstract_importer/strategies/base.rb
|
225
254
|
- lib/abstract_importer/strategies/default_strategy.rb
|
226
255
|
- lib/abstract_importer/strategies/insert_strategy.rb
|
227
256
|
- lib/abstract_importer/strategies/replace_strategy.rb
|
257
|
+
- lib/abstract_importer/strategies/upsert_strategy.rb
|
228
258
|
- lib/abstract_importer/summary.rb
|
229
259
|
- lib/abstract_importer/version.rb
|
230
260
|
- test/callback_test.rb
|
231
261
|
- test/default_strategy_test.rb
|
262
|
+
- test/id_map_test.rb
|
232
263
|
- test/insert_strategy_test.rb
|
233
264
|
- test/replace_strategy_test.rb
|
234
265
|
- test/support/mock_data_source.rb
|
235
266
|
- test/support/mock_objects.rb
|
236
267
|
- test/support/schema.rb
|
237
268
|
- test/test_helper.rb
|
269
|
+
- test/upsert_strategy_test.rb
|
238
270
|
homepage: https://github.com/concordia-publishing-house/abstract_importer
|
239
271
|
licenses:
|
240
272
|
- MIT
|
@@ -255,16 +287,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
287
|
version: '0'
|
256
288
|
requirements: []
|
257
289
|
rubyforge_project:
|
258
|
-
rubygems_version: 2.
|
290
|
+
rubygems_version: 2.5.1
|
259
291
|
signing_key:
|
260
292
|
specification_version: 4
|
261
293
|
summary: Provides services for the mass-import of complex relational data
|
262
294
|
test_files:
|
263
295
|
- test/callback_test.rb
|
264
296
|
- test/default_strategy_test.rb
|
297
|
+
- test/id_map_test.rb
|
265
298
|
- test/insert_strategy_test.rb
|
266
299
|
- test/replace_strategy_test.rb
|
267
300
|
- test/support/mock_data_source.rb
|
268
301
|
- test/support/mock_objects.rb
|
269
302
|
- test/support/schema.rb
|
270
303
|
- test/test_helper.rb
|
304
|
+
- test/upsert_strategy_test.rb
|