active_admin_import 6.0.0 → 7.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdc784c6f8a845b491b0dc93e44b073b548bccc182bb3cf6c26cb9f80e59b587
4
- data.tar.gz: 798237101d7d4403ed8fb1d1d4ed466b4b78bc44740e20137887d2c8b6464e3f
3
+ metadata.gz: f72286b16c17763984dba1b9da29ada72f8f7be7e64e5ae64010a1dcd7926af3
4
+ data.tar.gz: 2f50c17a8aed4cf2f02d8f28e2e83976e1af4fb593d5fcd763339f4a221be7ca
5
5
  SHA512:
6
- metadata.gz: '06639b5514e0c5af1f2cfd70f66f7de10b798fc22f9153b4870c0859b3f95fd372cf73f406b15b7df8b3e4d6fc350a911680248e09d15412479c55f092869a0d'
7
- data.tar.gz: 1b49c36c911a6eae50d653eafa4063a139b5d901b81264b213ece4bb995158bf7685f62facce2d5d1a69b76fe2735483296a26f9f697f6fad802d562ca3deef5
6
+ metadata.gz: 8921862e1b2de5bfa6d72f5655fe3cc0fc9d2ac7b4410d8ded785521443daf4b582d8e9b2978645c66bb0446b6d11478d7e72e452c70433274d118baa35e6127
7
+ data.tar.gz: 332150892d0732efeabf1b7a3de70fa81c9910e6f235ac08b83710eb993709281fb62aec6c21388f6ea9786cf7afb9791dffabdd7c651ac4275cd1ffebd57b3f
@@ -22,6 +22,13 @@ jobs:
22
22
  exclude:
23
23
  - rails: '8.0.0'
24
24
  activeadmin: '3.2.0'
25
+ include:
26
+ - ruby: '3.4'
27
+ rails: '7.2.0'
28
+ activeadmin: '4.0.0.beta22'
29
+ - ruby: '3.4'
30
+ rails: '8.0.0'
31
+ activeadmin: '4.0.0.beta22'
25
32
  env:
26
33
  RAILS: ${{ matrix.rails }}
27
34
  AA: ${{ matrix.activeadmin }}
@@ -31,6 +38,11 @@ jobs:
31
38
  with:
32
39
  ruby-version: ${{ matrix.ruby }}
33
40
  bundler-cache: true
41
+ - name: AA v4 environment summary
42
+ if: matrix.activeadmin == '4.0.0.beta22'
43
+ run: |
44
+ bundle exec gem list activeadmin
45
+ bundle info activeadmin
34
46
  - name: Run tests
35
47
  run: bundle exec rspec spec
36
48
  test-mysql:
@@ -98,6 +110,43 @@ jobs:
98
110
  bundler-cache: true
99
111
  - name: Run tests
100
112
  run: bundle exec rspec spec
113
+ test-postgres-aa4:
114
+ name: Ruby 3.4 / Rails 8.0.0 / AA 4.0.0.beta22 / PostgreSQL 16
115
+ runs-on: ubuntu-latest
116
+ env:
117
+ RAILS: '8.0.0'
118
+ AA: '4.0.0.beta22'
119
+ DB: postgres
120
+ DB_HOST: 127.0.0.1
121
+ DB_PORT: 5432
122
+ DB_USERNAME: postgres
123
+ DB_PASSWORD: postgres
124
+ services:
125
+ postgres:
126
+ image: postgres:16
127
+ env:
128
+ POSTGRES_USER: postgres
129
+ POSTGRES_PASSWORD: postgres
130
+ POSTGRES_DB: active_admin_import_test
131
+ ports:
132
+ - 5432:5432
133
+ options: >-
134
+ --health-cmd="pg_isready -U postgres"
135
+ --health-interval=10s
136
+ --health-timeout=5s
137
+ --health-retries=10
138
+ steps:
139
+ - uses: actions/checkout@v4
140
+ - uses: ruby/setup-ruby@v1
141
+ with:
142
+ ruby-version: '3.4'
143
+ bundler-cache: true
144
+ - name: AA v4 environment summary
145
+ run: |
146
+ bundle exec gem list activeadmin
147
+ bundle info activeadmin
148
+ - name: Run tests
149
+ run: bundle exec rspec spec
101
150
  coverage:
102
151
  name: Coverage
103
152
  runs-on: ubuntu-latest
data/Gemfile CHANGED
@@ -4,10 +4,22 @@ gemspec
4
4
  default_rails_version = '7.1.0'
5
5
  default_activeadmin_version = '3.2.0'
6
6
 
7
+ # `~> 4.0.0.beta22` would admit 4.0.0 GA — pin prereleases exactly so the
8
+ # CI cell tests the AA build it claims to test.
9
+ aa_version = ENV['AA'] || default_activeadmin_version
10
+ aa_op = aa_version.match?(/[a-z]/) ? '=' : '~>'
11
+
7
12
  gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}"
8
- gem 'activeadmin', "~> #{ENV['AA'] || default_activeadmin_version}"
9
- gem 'sprockets-rails'
10
- gem 'sass-rails'
13
+ gem 'activeadmin', "#{aa_op} #{aa_version}"
14
+
15
+ if ENV['AA']&.start_with?('4')
16
+ # AA 4 uses Tailwind + importmap; sass-rails conflicts with Tailwind v4.
17
+ gem 'cssbundling-rails'
18
+ gem 'importmap-rails'
19
+ else
20
+ gem 'sprockets-rails'
21
+ gem 'sass-rails'
22
+ end
11
23
 
12
24
  group :test do
13
25
  gem 'simplecov', require: false
@@ -22,6 +34,4 @@ group :test do
22
34
  end
23
35
  gem 'database_cleaner'
24
36
  gem 'capybara'
25
- gem 'cuprite'
26
- gem 'webrick', require: false
27
37
  end
data/README.md CHANGED
@@ -73,6 +73,7 @@ Tool | Description
73
73
  :error_limit |Limit the number of errors reported (default `5`, set to `nil` for all)
74
74
  :headers_rewrites |hash with key (csv header) - value (db column name) rows mapping
75
75
  :if |Controls whether the 'Import' button is displayed. It supports a proc to be evaluated into a boolean value within the activeadmin render context.
76
+ :action_item_html_options |HTML options passed to the index-page "Import …" action_item link. Defaults to `{ class: 'action-item-button' }` so the link matches AA 4's built-in action_items; the class is a no-op on AA 3. Override to drop the class or add your own (`{ class: 'my-btn' }`, `{ class: '', data: { turbo: false } }`, etc.).
76
77
 
77
78
 
78
79
 
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.add_runtime_dependency 'activerecord-import', '>= 2.0'
19
19
  gem.add_runtime_dependency 'rchardet', '>= 1.6'
20
20
  gem.add_runtime_dependency 'rubyzip', '>= 1.2'
21
- gem.add_dependency 'activeadmin', '>= 3.0', '< 4.0'
21
+ gem.add_dependency 'activeadmin', '>= 3.0', '< 4.1'
22
22
  end
@@ -27,6 +27,8 @@ module ActiveAdminImport
27
27
  module DSL
28
28
  CONTEXT_METHOD = :active_admin_import_context
29
29
 
30
+ ACTIVE_ADMIN_V4 = Gem::Version.new(ActiveAdmin::VERSION) >= Gem::Version.new('4.0.0.beta1')
31
+
30
32
  def self.prepare_import_model(template_object, controller, params: nil)
31
33
  model = template_object.is_a?(Proc) ? template_object.call : template_object
32
34
  if params
@@ -45,7 +47,7 @@ module ActiveAdminImport
45
47
  model_name = options[:resource_label].downcase
46
48
  plural_model_name = options[:plural_resource_label].downcase
47
49
  if result.empty?
48
- flash[:warning] = I18n.t('active_admin_import.file_empty_error')
50
+ flash[ACTIVE_ADMIN_V4 ? :alert : :warning] = I18n.t('active_admin_import.file_empty_error')
49
51
  else
50
52
  if result.failed?
51
53
  flash[:error] = I18n.t(
@@ -81,7 +83,8 @@ module ActiveAdminImport
81
83
  if authorized?(ActiveAdminImport::Auth::IMPORT, active_admin_config.resource_class)
82
84
  link_to(
83
85
  I18n.t('active_admin_import.import_model', plural_model: options[:plural_resource_label]),
84
- action: :import
86
+ { action: :import },
87
+ options[:action_item_html_options]
85
88
  )
86
89
  end
87
90
  end
@@ -22,7 +22,8 @@ module ActiveAdminImport
22
22
  :plural_resource_label,
23
23
  :error_limit,
24
24
  :headers_rewrites,
25
- :if
25
+ :if,
26
+ :action_item_html_options
26
27
  ].freeze
27
28
 
28
29
  def self.options_for(config, options = {})
@@ -39,7 +40,10 @@ module ActiveAdminImport
39
40
  plural_resource_label: config.plural_resource_label,
40
41
  error_limit: 5,
41
42
  headers_rewrites: {},
42
- if: true
43
+ if: true,
44
+ # AA 4's built-in action_items hardcode this class for Tailwind styling
45
+ # (lib/active_admin/resource/action_items.rb). It's a no-op on AA 3.
46
+ action_item_html_options: { class: 'action-item-button' }
43
47
  }.deep_merge(options)
44
48
  end
45
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAdminImport
4
- VERSION = '6.0.0'
4
+ VERSION = '7.0.0'
5
5
  end
data/spec/import_spec.rb CHANGED
@@ -41,8 +41,8 @@ describe 'import', type: :feature do
41
41
  end
42
42
 
43
43
  def upload_file!(name, ext = 'csv')
44
- attach_file('active_admin_import_model_file', File.expand_path("./spec/fixtures/files/#{name}.#{ext}"))
45
- find_button('Import').click
44
+ attach_file(ImportFormSelectors.file_input_id, File.expand_path("./spec/fixtures/files/#{name}.#{ext}"))
45
+ find_button(ImportFormSelectors.import_button_text).click
46
46
  end
47
47
 
48
48
  context 'posts index' do
@@ -118,7 +118,7 @@ describe 'import', type: :feature do
118
118
  # reload page
119
119
  visit '/admin/posts/import'
120
120
  # submit form without file
121
- find_button('Import').click
121
+ find_button(ImportFormSelectors.import_button_text).click
122
122
  end
123
123
 
124
124
  it 'should render validation error' do
@@ -171,7 +171,7 @@ describe 'import', type: :feature do
171
171
  # TODO: removing this causes undefined method `ransack' for #<ActiveRecord::Relation []>
172
172
  allow_any_instance_of(Admin::AuthorsController).to receive(:find_collection).and_return(Author.all)
173
173
  visit '/admin/authors'
174
- find_link('Import Authors').click
174
+ find_link(ImportFormSelectors.import_link_text).click
175
175
  expect(current_path).to eq('/admin/authors/import')
176
176
  end
177
177
  end
@@ -228,14 +228,14 @@ describe 'import', type: :feature do
228
228
  end
229
229
 
230
230
  it 'has valid form' do
231
- form = find('#new_active_admin_import_model')
231
+ form = find(ImportFormSelectors.form_css)
232
232
  expect(form['action']).to eq('/admin/authors/do_import')
233
233
  expect(form['enctype']).to eq('multipart/form-data')
234
- file_input = form.find('input#active_admin_import_model_file')
234
+ file_input = form.find(ImportFormSelectors.file_input_css)
235
235
  expect(file_input[:type]).to eq('file')
236
236
  expect(file_input.value).to be_blank
237
- submit_input = form.find('#active_admin_import_model_submit_action input')
238
- expect(submit_input[:value]).to eq('Import')
237
+ submit_input = form.find(ImportFormSelectors.submit_css)
238
+ expect(submit_input[:value]).to eq(ImportFormSelectors.import_button_text)
239
239
  expect(submit_input[:type]).to eq('submit')
240
240
  end
241
241
 
@@ -261,7 +261,7 @@ describe 'import', type: :feature do
261
261
 
262
262
  context 'when no file' do
263
263
  it 'should render error' do
264
- find_button('Import').click
264
+ find_button(ImportFormSelectors.import_button_text).click
265
265
  expect(Author.count).to eq(0)
266
266
  expect(page).to have_content I18n.t('active_admin_import.no_file_error')
267
267
  end
@@ -605,7 +605,7 @@ describe 'import', type: :feature do
605
605
 
606
606
  # Second submission without selecting a file
607
607
  expect do
608
- find_button('Import').click
608
+ find_button(ImportFormSelectors.import_button_text).click
609
609
  expect(page).to have_content(I18n.t('active_admin_import.no_file_error'))
610
610
  end.not_to change { Author.count }
611
611
  end
data/spec/spec_helper.rb CHANGED
@@ -12,9 +12,9 @@ Bundler.setup
12
12
 
13
13
  ENV['RAILS_ENV'] = 'test'
14
14
  require 'rails'
15
+ require 'test_app_paths'
15
16
  ENV['RAILS'] = Rails.version
16
- ENV['DB'] ||= 'sqlite'
17
- ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}-#{ENV['DB']}", __FILE__)
17
+ ENV['RAILS_ROOT'] = TestAppPaths.app_root
18
18
  system 'rake setup' unless File.exist?(ENV['RAILS_ROOT'])
19
19
 
20
20
  require 'active_model'
@@ -28,16 +28,13 @@ ActiveAdmin.application.current_user_method = false
28
28
 
29
29
  require 'rspec/rails'
30
30
  require 'support/admin'
31
+ require 'support/import_form_selectors'
31
32
  require 'capybara/rails'
32
33
  require 'capybara/rspec'
33
- require 'capybara/cuprite'
34
34
 
35
- Capybara.server = :webrick
36
- Capybara.register_driver :cuprite do |app|
37
- Capybara::Cuprite::Driver.new(app, headless: true, window_size: [1280, 800])
38
- end
39
- Capybara.javascript_driver = :cuprite
40
- Capybara.default_max_wait_time = 5
35
+ # Specs exercise ActiveAdmin through Capybara's default rack_test driver — no
36
+ # JavaScript or real browser is needed, so no Cuprite/Chrome or app server.
37
+ Capybara.default_driver = :rack_test
41
38
 
42
39
  RSpec.configure do |config|
43
40
  config.use_transactional_fixtures = false
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Formtastic 6 (AA 4) keeps the same DOM IDs as Formtastic 4 (AA 3) for this
4
+ # form, so one selector set serves both — branch here if a future AA shifts an ID.
5
+ module ImportFormSelectors
6
+ module_function
7
+
8
+ SELECTORS = {
9
+ form_id: 'new_active_admin_import_model',
10
+ file_input_id: 'active_admin_import_model_file',
11
+ file_input_css: 'input#active_admin_import_model_file',
12
+ submit_css: '#active_admin_import_model_submit_action input',
13
+ import_button_text: 'Import',
14
+ import_link_text: 'Import Authors'
15
+ }.freeze
16
+
17
+ def form_id = SELECTORS[:form_id]
18
+ def form_css = "##{form_id}"
19
+ def file_input_id = SELECTORS[:file_input_id]
20
+ def file_input_css = SELECTORS[:file_input_css]
21
+ def submit_css = SELECTORS[:submit_css]
22
+ def import_button_text = SELECTORS[:import_button_text]
23
+ def import_link_text = SELECTORS[:import_link_text]
24
+ end
@@ -50,8 +50,19 @@ gsub_file "config/environment.rb",
50
50
 
51
51
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
52
52
 
53
+ aa_v4 = ENV['AA']&.start_with?('4')
54
+
53
55
  generate :'active_admin:install --skip-users'
54
- generate :'formtastic:install'
56
+
57
+ if aa_v4
58
+ # `active_admin:assets` swaps AA 3's Sprockets SCSS/JS for AA 4's Tailwind CSS
59
+ # stub. We don't compile it — specs assert on DOM and flash text, not styling,
60
+ # so the stub suffices and no Node is needed. `builds/` satisfies cssbundling-rails.
61
+ generate :'active_admin:assets'
62
+ run 'mkdir -p app/assets/builds'
63
+ else
64
+ generate :'formtastic:install'
65
+ end
55
66
 
56
67
  run 'rm -rf test'
57
68
  route "root :to => 'admin/dashboard#index'"
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestAppPaths
4
+ module_function
5
+
6
+ def app_dir_name
7
+ "rails-#{Rails::VERSION::STRING}-#{ENV['DB'] || 'sqlite'}-aa#{ENV['AA'] || 'default'}"
8
+ end
9
+
10
+ # Absolute path under spec/rails/, used as RAILS_ROOT.
11
+ def app_root
12
+ File.expand_path("../rails/#{app_dir_name}", __dir__)
13
+ end
14
+ end
data/tasks/test.rake CHANGED
@@ -1,3 +1,5 @@
1
+ require_relative '../spec/support/test_app_paths'
2
+
1
3
  desc "Creates a test rails app for the specs to run against"
2
4
  task :setup do
3
5
  require 'rails/version'
@@ -8,6 +10,9 @@ task :setup do
8
10
  when 'postgres', 'postgresql' then 'postgresql'
9
11
  else 'sqlite3'
10
12
  end
13
+ aa_v4 = ENV['AA']&.start_with?('4')
14
+
15
+ puts "[setup] ActiveAdmin: #{ENV['AA'] || '(Gemfile default)'} / Rails: #{Rails::VERSION::STRING} / DB: #{rails_db}"
11
16
 
12
17
  rails_new_opts = %W(
13
18
  --skip-turbolinks
@@ -17,5 +22,9 @@ task :setup do
17
22
  -m
18
23
  spec/support/rails_template.rb
19
24
  )
20
- system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING}-#{db} #{rails_new_opts.join(' ')}"
25
+ # v4 drops sprockets-rails (see Gemfile), so skip the asset pipeline to
26
+ # avoid the auto-generated `config/initializers/assets.rb` crashing at boot.
27
+ rails_new_opts.unshift('--skip-asset-pipeline') if aa_v4
28
+
29
+ system "bundle exec rails new spec/rails/#{TestAppPaths.app_dir_name} #{rails_new_opts.join(' ')}"
21
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Fedoronchuk
@@ -60,7 +60,7 @@ dependencies:
60
60
  version: '3.0'
61
61
  - - "<"
62
62
  - !ruby/object:Gem::Version
63
- version: '4.0'
63
+ version: '4.1'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ dependencies:
70
70
  version: '3.0'
71
71
  - - "<"
72
72
  - !ruby/object:Gem::Version
73
- version: '4.0'
73
+ version: '4.1'
74
74
  description: The most efficient way to import for Active Admin
75
75
  email:
76
76
  - fedoronchuk@gmail.com
@@ -135,7 +135,9 @@ files:
135
135
  - spec/spec_helper.rb
136
136
  - spec/support/active_model_lint.rb
137
137
  - spec/support/admin.rb
138
+ - spec/support/import_form_selectors.rb
138
139
  - spec/support/rails_template.rb
140
+ - spec/support/test_app_paths.rb
139
141
  - tasks/test.rake
140
142
  homepage: https://github.com/activeadmin-plugins/active_admin_import
141
143
  licenses: