abstract_importer 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +29 -0
- data/CHANGELOG.md +3 -0
- data/abstract_importer.gemspec +1 -1
- data/lib/abstract_importer/strategies/insert_strategy.rb +5 -1
- data/lib/abstract_importer/version.rb +1 -1
- data/test/default_strategy_test.rb +1 -1
- data/test/insert_strategy_test.rb +15 -1
- data/test/support/mock_data_source.rb +6 -0
- data/test/support/mock_objects.rb +7 -0
- data/test/support/schema.rb +7 -0
- data/test/test_helper.rb +9 -5
- metadata +7 -7
- data/.travis.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb6af75a939202a48788cb3cbd6513c074ff514f1d8c7d104b32700ffdcfe63
|
4
|
+
data.tar.gz: 7ce453f1c101cb56a17642d5b0d21414db6cfd7de3221567f5bce75b4850e93f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b17a2f043ce0a0a7fde5e6de5f1bea224d27142c7bfece25a3e890be4bfb0b4110d6413384949a8d3af4eeec19ad688a8e940556a55e65fa6ef9450468332a20
|
7
|
+
data.tar.gz: 70a4b060155c6f3104f57654340af8dc43816cddbd1a83c49295b647241e326f7e1edc163f7bf673a3d251cf7d02b7734c320cfceae85e3e277705676756f096
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Tests
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
ruby:
|
6
|
+
name: Tests
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
services:
|
9
|
+
postgres:
|
10
|
+
image: postgres:10.11
|
11
|
+
env:
|
12
|
+
POSTGRES_PASSWORD: password
|
13
|
+
POSTGRES_DB: abstract_importer_test
|
14
|
+
ports:
|
15
|
+
- 5432:5432
|
16
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
17
|
+
steps:
|
18
|
+
- name: Checkout
|
19
|
+
uses: actions/checkout@v2
|
20
|
+
- name: Setup Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: 2.6
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Run the Tests
|
26
|
+
env:
|
27
|
+
DATABASE_URL: postgres://postgres:password@localhost:5432/abstract_importer_test
|
28
|
+
run: bundle exec rake test
|
29
|
+
|
data/CHANGELOG.md
CHANGED
data/abstract_importer.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "minitest-reporters-turn_reporter"
|
27
27
|
spec.add_development_dependency "rake"
|
28
28
|
spec.add_development_dependency "sqlite3"
|
29
|
-
spec.add_development_dependency "pg"
|
29
|
+
spec.add_development_dependency "pg"
|
30
30
|
spec.add_development_dependency "pry"
|
31
31
|
spec.add_development_dependency "rr"
|
32
32
|
spec.add_development_dependency "database_cleaner"
|
@@ -54,7 +54,11 @@ module AbstractImporter
|
|
54
54
|
def insert_batch(batch)
|
55
55
|
return if batch.empty?
|
56
56
|
|
57
|
-
|
57
|
+
scope = collection.scope
|
58
|
+
if scope.respond_to?(:proxy_association) && scope.proxy_association.reflection.through_reflection?
|
59
|
+
scope = scope.klass
|
60
|
+
end
|
61
|
+
result = scope.public_send(@bulk_operation, batch, @insert_options)
|
58
62
|
add_batch_to_id_map(result) if remap_ids?
|
59
63
|
end
|
60
64
|
|
@@ -147,7 +147,7 @@ class DefaultStrategyTest < ActiveSupport::TestCase
|
|
147
147
|
import!
|
148
148
|
assert_equal 2, account.students.map(&:pet).compact.count, "Expected two students to still be linked to their pets upon import"
|
149
149
|
assert_kind_of Owl, account.students.find_by_name("Harry Potter").pet, "Expected Harry's pet to be an Owl"
|
150
|
-
assert_kind_of Cat, account.students.find_by_name("Hermione Granger").pet, "Expected
|
150
|
+
assert_kind_of Cat, account.students.find_by_name("Hermione Granger").pet, "Expected Hermione's pet to be a Cat"
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -4,7 +4,7 @@ require "test_helper"
|
|
4
4
|
class InsertStrategyTest < ActiveSupport::TestCase
|
5
5
|
|
6
6
|
setup do
|
7
|
-
options.merge!(strategy: {students: :insert})
|
7
|
+
options.merge!(strategy: {students: :insert, perils: :insert})
|
8
8
|
end
|
9
9
|
|
10
10
|
|
@@ -99,6 +99,20 @@ class InsertStrategyTest < ActiveSupport::TestCase
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
context "When importing a has_many through: relationship" do
|
103
|
+
setup do
|
104
|
+
plan do |import|
|
105
|
+
import.locations
|
106
|
+
import.perils
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
should "handle has_many, through: relations" do
|
111
|
+
import!
|
112
|
+
assert_equal 1, account.perils.count
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
102
116
|
|
103
117
|
|
104
118
|
context "Given an ID generator" do
|
@@ -17,6 +17,7 @@ class Parent < ActiveRecord::Base
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class Location < ActiveRecord::Base
|
20
|
+
has_many :perils
|
20
21
|
validates :slug, format: {with: /\A[a-z0-9\-]+\z/}
|
21
22
|
end
|
22
23
|
|
@@ -37,6 +38,8 @@ class Account < ActiveRecord::Base
|
|
37
38
|
has_many :locations
|
38
39
|
has_many :cats
|
39
40
|
has_many :owls
|
41
|
+
|
42
|
+
has_many :perils, through: :locations
|
40
43
|
end
|
41
44
|
|
42
45
|
class Cat < ActiveRecord::Base
|
@@ -52,3 +55,7 @@ end
|
|
52
55
|
class Ability < ActiveRecord::Base
|
53
56
|
belongs_to :pet, inverse_of: :abilities, polymorphic: true
|
54
57
|
end
|
58
|
+
|
59
|
+
class Peril < ActiveRecord::Base
|
60
|
+
belongs_to :location
|
61
|
+
end
|
data/test/support/schema.rb
CHANGED
@@ -72,4 +72,11 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
72
72
|
t.index "legacy_id", :unique => true
|
73
73
|
end
|
74
74
|
|
75
|
+
create_table "perils", :force => true do |t|
|
76
|
+
t.string "name"
|
77
|
+
t.integer "location_id"
|
78
|
+
t.integer "legacy_id"
|
79
|
+
t.index "legacy_id", :unique => true
|
80
|
+
end
|
81
|
+
|
75
82
|
end
|
data/test/test_helper.rb
CHANGED
@@ -22,11 +22,15 @@ require "minitest/autorun"
|
|
22
22
|
|
23
23
|
system "psql -c 'create database abstract_importer_test'"
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
if ENV["DATABASE_URL"]
|
26
|
+
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
|
27
|
+
else
|
28
|
+
ActiveRecord::Base.establish_connection(
|
29
|
+
adapter: "postgresql",
|
30
|
+
host: "localhost",
|
31
|
+
database: "abstract_importer_test",
|
32
|
+
verbosity: "quiet")
|
33
|
+
end
|
30
34
|
|
31
35
|
load File.join(File.dirname(__FILE__), "support", "schema.rb")
|
32
36
|
|
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.7.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:
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -126,16 +126,16 @@ dependencies:
|
|
126
126
|
name: pg
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0
|
131
|
+
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: pry
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -213,9 +213,9 @@ executables: []
|
|
213
213
|
extensions: []
|
214
214
|
extra_rdoc_files: []
|
215
215
|
files:
|
216
|
+
- ".github/workflows/ci.yml"
|
216
217
|
- ".gitignore"
|
217
218
|
- ".ruby-version"
|
218
|
-
- ".travis.yml"
|
219
219
|
- CHANGELOG.md
|
220
220
|
- Gemfile
|
221
221
|
- LICENSE.txt
|
data/.travis.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.6.3
|
4
|
-
|
5
|
-
# Use Postgres 9.5
|
6
|
-
# https://www.brandur.org/fragments/postgres-95-travis
|
7
|
-
dist: trusty
|
8
|
-
sudo: required
|
9
|
-
addons:
|
10
|
-
postgresql: "9.5"
|
11
|
-
|
12
|
-
before_install: gem update bundler
|
13
|
-
script: bundle exec rake test
|
14
|
-
|
15
|
-
# To stop Travis from running tests for a new commit,
|
16
|
-
# add the following to your commit message: [ci skip]
|
17
|
-
# You should add this when you edit documentation or comments, etc.
|