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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1a26d52ad8e17f1b2539d5abbcf996a4c80ac157139a988fefd4a417c4fe03e
4
- data.tar.gz: 388a9123f67dd9b52c35ae50a8added3c6995d2b8d71d703269dd317e13e8918
3
+ metadata.gz: beb6af75a939202a48788cb3cbd6513c074ff514f1d8c7d104b32700ffdcfe63
4
+ data.tar.gz: 7ce453f1c101cb56a17642d5b0d21414db6cfd7de3221567f5bce75b4850e93f
5
5
  SHA512:
6
- metadata.gz: 19531db43b5cd36a2831384fcef16092930b23cc9fa622c1aaa1b1bdc193d73df0d824deda4bdc5ce427d80272bd1d48cd972efea15011187fffa1c5720cb4cf
7
- data.tar.gz: 14d9f5e0d630fc2e15be68bd83ef61ca610bf4cec4442af820cfa429915020320d88416af4c8f2fc5d7779daa8b83900c7b0be7e4a87bc21aa73985dd0a58c17
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
@@ -1,2 +1,5 @@
1
+ ## v1.7.0 (2021 Nov 19)
2
+ * Updated to handle `insert_all` and `upsert_all` to `has_many through:` relations in Rails 6.1+
3
+
1
4
  ## v1.6.0 (2019 Sept 23)
2
5
  * BREAKING: Updated to use Rails 6 and its `insert_all` and `upsert_all` methods and arguments
@@ -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", "~> 0.18"
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
- result = collection.scope.public_send(@bulk_operation, batch, @insert_options)
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
 
@@ -1,3 +1,3 @@
1
1
  module AbstractImporter
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
@@ -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 Harry's pet to be a Cat"
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
@@ -58,5 +58,11 @@ class MockDataSource
58
58
  end
59
59
  end
60
60
 
61
+ def perils
62
+ Enumerator.new do |e|
63
+ e.yield id: 801, name: "Dementors", location_id: 6
64
+ end
65
+ end
66
+
61
67
 
62
68
  end
@@ -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
@@ -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
- ActiveRecord::Base.establish_connection(
26
- adapter: "postgresql",
27
- host: "localhost",
28
- database: "abstract_importer_test",
29
- verbosity: "quiet")
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.6.0
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: 2019-09-25 00:00:00.000000000 Z
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.18'
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.18'
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.