active_admin_import 4.1.0 → 4.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72a624e96a7c740179d82959a81d6eceee7987813a6dbed662a5113eb41e76d2
4
- data.tar.gz: 07ddbc628d18fa4b3a006a2709858001146f86d94f487368eca2c6e247f03ece
3
+ metadata.gz: 7c8561a4c1622b426312994d56e93252fa2d6c96bd1d0e085e2a8873c3283d4b
4
+ data.tar.gz: 96a38edf7c6e7c7a787ba216b95922ed2ac7fe25d89b2d992617ad40b5209569
5
5
  SHA512:
6
- metadata.gz: '08f7de1d997ace9ecb6e741e95f66be1a14bb1b044683f41d0c27d24ec4b1bd995f0a5e2feb2f20dca07704416e809a5735aa39dc153c7497bbbce650003db4b'
7
- data.tar.gz: 8fc7ac974e5d03f6982fba484cc3ed2c54b9f5c9e3a38dd7a9ec1241100bb95e055639a75ffe79a9b3fffffbe06f3ab7c4a3ac162b8e63cd4316c7a73af2d7c8
6
+ metadata.gz: 7a6224751a88d24ff8ceda5d690a77990c893cd1a4d5bf3a0041d1002bb946d9a54a3f0d0a4294e9bab901bb3700692431066cbcd39456763335f7eea902e039
7
+ data.tar.gz: 110c86f4845a57550024732f881ad8afd9d14ffd569907972e5a0a0c94249fa1a3caa0dbe2cb3f10d266e8b16cb0806dc279d331adeaf5209cf658675faa1113
@@ -1,8 +1,9 @@
1
1
  script: bundle exec rspec spec
2
2
  env:
3
3
  matrix:
4
- - RAILS=5.0.0
5
- - RAILS=5.1.0
4
+ - RAILS=5.1.6.2
5
+ - RAILS=5.2.2.1
6
6
  rvm:
7
- - 2.2.5
8
- - 2.3.1
7
+ - 2.3.8
8
+ - 2.4.5
9
+ - 2.5.5
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.1.1] - 2019-09-20
4
+ - Fix column slicing #168 | @doredesign
5
+ - Handle errors on base #163
6
+
3
7
  ## [4.1.0] - 2019-01-15
4
8
  - Upgrade dependencies: `activerecord-import` to >=0.27.1 | @jkowens
5
9
 
data/Gemfile CHANGED
@@ -11,7 +11,7 @@ group :test do
11
11
  gem 'rails', rails_version
12
12
  gem 'rspec-rails'
13
13
  gem 'coveralls', require: false # Test coverage website. Go to https://coveralls.io
14
- gem 'sqlite3'
14
+ gem 'sqlite3',"~> 1.3.6"
15
15
  gem 'launchy'
16
16
  gem 'database_cleaner'
17
17
  gem 'capybara'
@@ -33,7 +33,10 @@ module ActiveAdminImport
33
33
  limit = options[:limit] || failed.count
34
34
  failed.first(limit).map do |record|
35
35
  errors = record.errors
36
- (errors.full_messages.zip errors.keys.map { |k| record.send k }).map { |ms| ms.join(' - ') }.join(', ')
36
+ failed_values = errors.keys.map do |key|
37
+ key == :base ? nil : record.public_send(key)
38
+ end
39
+ errors.full_messages.zip(failed_values).map { |ms| ms.compact.join(' - ') }.join(', ')
37
40
  end.join(' ; ')
38
41
  end
39
42
  end
@@ -70,7 +70,7 @@ module ActiveAdminImport
70
70
  end
71
71
  end
72
72
 
73
- # Use it when CSV file contain redundant columns
73
+ # Use this method when CSV file contains unnecessary columns
74
74
  #
75
75
  # Example:
76
76
  #
@@ -81,16 +81,22 @@ module ActiveAdminImport
81
81
  # end
82
82
  #
83
83
  def batch_slice_columns(slice_columns)
84
- use_indexes = []
85
- headers.values.each_with_index do |val, index|
86
- use_indexes << index if val.in?(slice_columns)
84
+ # Only set @use_indexes for the first batch so that @use_indexes are in correct
85
+ # position for subsequent batches
86
+ unless defined?(@use_indexes)
87
+ @use_indexes = []
88
+ headers.values.each_with_index do |val, index|
89
+ @use_indexes << index if val.in?(slice_columns)
90
+ end
91
+ return csv_lines if @use_indexes.empty?
92
+
93
+ # slice CSV headers
94
+ @headers = headers.to_a.values_at(*@use_indexes).to_h
87
95
  end
88
- return csv_lines if use_indexes.empty?
89
- # slice CSV headers
90
- @headers = headers.to_a.values_at(*use_indexes).to_h
96
+
91
97
  # slice CSV values
92
98
  csv_lines.map! do |line|
93
- line.values_at(*use_indexes)
99
+ line.values_at(*@use_indexes)
94
100
  end
95
101
  end
96
102
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAdminImport
4
- VERSION = '4.1.0'
4
+ VERSION = '4.1.1'
5
5
  end
@@ -1,3 +1,3 @@
1
- Name,Last name,Birthday
2
- John,Doe,1986-05-01
3
- Jane,Roe,1988-11-16
1
+ Birthday,Name,Last name
2
+ 1986-05-01,John,Doe
3
+ 1988-11-16,Jane,Roe
@@ -5,17 +5,18 @@ describe ActiveAdminImport::ImportResult do
5
5
  context 'failed_message' do
6
6
  let(:import_result) { ActiveAdminImport::ImportResult.new }
7
7
 
8
- before do
9
- Author.create(name: 'John', last_name: 'Doe')
10
- Author.create(name: 'Jane', last_name: 'Roe')
11
8
 
9
+ let(:failed_instances) do
10
+ [
11
+ Author.new(last_name: 'Doe').tap {|r| r.errors.add(:last_name, :taken) },
12
+ Author.new(name: "", last_name: 'Doe').tap {|r| r.errors.add(:name, :blank); r.errors.add(:last_name, :taken) },
13
+ Author.new.tap {|r| r.errors.add(:base, 'custom') }
14
+ ]
15
+ end
16
+
17
+ before do
12
18
  @result = double \
13
- failed_instances: [
14
- # {:last_name=>["has already been taken"]}
15
- Author.create(name: 'Jim', last_name: 'Doe'),
16
- # {:name=>["can't be blank"], :last_name=>["has already been taken"]}
17
- Author.create(name: nil, last_name: 'Doe')
18
- ]
19
+ failed_instances: failed_instances
19
20
  end
20
21
 
21
22
  it 'should work without any failed instances' do
@@ -26,7 +27,7 @@ describe ActiveAdminImport::ImportResult do
26
27
  import_result.add(@result, 4)
27
28
  expect(import_result.failed_message)
28
29
  .to eq(
29
- "Last name has already been taken - Doe ; Name can't be blank - , Last name has already been taken - Doe"
30
+ "Last name has already been taken - Doe ; Name can't be blank - , Last name has already been taken - Doe ; custom"
30
31
  )
31
32
  end
32
33
 
@@ -434,11 +434,14 @@ describe 'import', type: :feature do
434
434
  end
435
435
 
436
436
  context "with slice_columns option" do
437
+ let(:batch_size) { 2 }
438
+
437
439
  before do
438
440
  add_author_resource template_object: ActiveAdminImport::Model.new,
439
441
  before_batch_import: lambda { |importer|
440
442
  importer.batch_slice_columns(slice_columns)
441
- }
443
+ },
444
+ batch_size: batch_size
442
445
  visit "/admin/authors/import"
443
446
  upload_file!(:authors)
444
447
  end
@@ -446,13 +449,23 @@ describe 'import', type: :feature do
446
449
  context "slice last column and superfluous column" do
447
450
  let(:slice_columns) { %w(name last_name not_existing_column) }
448
451
 
449
- it "should not fill `birthday` column" do
450
- expect(Author.pluck(:name, :last_name, :birthday)).to match_array(
451
- [
452
- ["Jane", "Roe", nil],
453
- ["John", "Doe", nil]
454
- ]
455
- )
452
+ shared_examples_for "birthday column removed" do
453
+ it "should not fill `birthday` column" do
454
+ expect(Author.pluck(:name, :last_name, :birthday)).to match_array(
455
+ [
456
+ ["Jane", "Roe", nil],
457
+ ["John", "Doe", nil]
458
+ ]
459
+ )
460
+ end
461
+ end
462
+
463
+ it_behaves_like "birthday column removed"
464
+
465
+ context "when doing more than one batch" do
466
+ let(:batch_size) { 1 }
467
+
468
+ it_behaves_like "birthday column removed"
456
469
  end
457
470
  end
458
471
 
@@ -3,5 +3,5 @@ desc 'Creates a test rails app for the specs to run against'
3
3
  task :setup do
4
4
  require 'rails/version'
5
5
  system('mkdir spec/rails') unless File.exist?('spec/rails')
6
- system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template.rb --skip-spring --skip-turbolinks"
6
+ system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template.rb --skip-spring --skip-turbolinks --skip-bootsnap"
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Fedoronchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-15 00:00:00.000000000 Z
11
+ date: 2019-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-import
@@ -148,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.7.7
151
+ rubygems_version: 3.0.6
153
152
  signing_key:
154
153
  specification_version: 4
155
154
  summary: ActiveAdmin import based on activerecord-import gem.