Skip to content

Commit 610f3e8

Browse files
committed
Finalize compatibility with ActiveAdmin 3.1
1 parent 1c68aa6 commit 610f3e8

File tree

6 files changed

+73
-39
lines changed

6 files changed

+73
-39
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
ruby:
14-
- 3.0
15-
- 3.1
16-
- 3.2
17-
rails:
18-
- '6.1.0'
19-
- '7.0.0'
20-
- '7.1.0'
21-
activeadmin:
22-
- '3.0.0'
23-
- '3.1.0'
24-
exclude:
25-
- rails: '7.1.0'
26-
activeadmin: '3.0.0'
13+
include:
14+
- ruby: 2.6
15+
rails: '5.2.3'
16+
activeadmin: '2.0.0'
17+
- ruby: 2.6
18+
rails: '6.0.2'
19+
activeadmin: '2.6.0'
20+
- ruby: 2.7
21+
rails: '7.0.8'
22+
activeadmin: '2.13.0'
23+
- ruby: 3.2
24+
rails: '7.1.0'
25+
activeadmin: '3.1.0'
2726
env:
2827
RAILS: ${{ matrix.rails }}
2928
AA: ${{ matrix.activeadmin }}
3029
steps:
31-
- uses: actions/checkout@v2
30+
- uses: actions/checkout@v4
3231
- uses: ruby/setup-ruby@v1
3332
with:
3433
ruby-version: ${{ matrix.ruby }}

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ source 'https://rubygems.org'
44
gemspec
55

66
group :test do
7-
default_rails_version = '7.0.0'
8-
default_activeadmin_version = '3.0.0'
7+
default_rails_version = '7.1.0'
8+
default_activeadmin_version = '3.1.0'
99

1010
gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}"
1111
gem 'activeadmin', "~> #{ENV['AA'] || default_activeadmin_version}"
1212

1313
gem 'sprockets-rails'
1414
gem 'rspec-rails'
15-
gem 'coveralls_reborn', require: false # Test coverage website. Go to https://coveralls.io
15+
gem 'coveralls_reborn', require: false
1616
gem 'sass-rails'
1717
gem 'sqlite3', '~> 1.4.0'
1818
gem 'launchy'

active_admin_datetimepicker.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
1919
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
2020
spec.require_paths = ["lib"]
2121

22-
spec.add_dependency "activeadmin", ">= 3.0.0"
22+
spec.add_dependency "activeadmin", ">= 2.0", "<= 3.1"
2323
end

spec/filter_form_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
before do
5050
Author.create!(name: "Ren",
5151
last_name: "from-20-day-of-month",
52-
created_at: (Time.now.change(day: 20) - 1.hour).to_fs(:db))
52+
created_at: (Time.now.change(day: 20) - 1.hour).to_formatted_s(:db))
5353

5454
Author.create!(name: "Rey",
5555
last_name: "from-the-future",
56-
created_at: (Time.now.change(day: 20) + 2.hours).to_fs(:db))
56+
created_at: (Time.now.change(day: 20) + 2.hours).to_formatted_s(:db))
5757

5858
# chose 01 and 20 day of the current month
5959

@@ -94,8 +94,8 @@
9494
end
9595

9696
context 'filter by virtual attribute last_seen_at - without column&type properties (search by updated_at)' do
97-
let!(:first_author) { Author.create!(name: 'Ren', last_name: 'current', updated_at: Time.now.to_fs(:db)) }
98-
let!(:second_author) { Author.create!(name: 'Rey', last_name: 'future', updated_at: 21.days.from_now.to_fs(:db)) }
97+
let!(:first_author) { Author.create!(name: 'Ren', last_name: 'current', updated_at: Time.now.to_formatted_s(:db)) }
98+
let!(:second_author) { Author.create!(name: 'Rey', last_name: 'future', updated_at: 21.days.from_now.to_formatted_s(:db)) }
9999

100100
before do
101101
# chose 01 and 20 day of the current month

spec/support/admin.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
def add_author_resource(options = {}, &block)
2-
32
ActiveAdmin.register Author do
3+
permit_params :name, :birthday
4+
45
config.filters = true
56

67
filter :birthday, as: :date_time_range
78
filter :created_at, as: :date_time_range
89
filter :last_seen_at, as: :date_time_range
910

1011
form do |f|
11-
f.semantic_errors(*f.object.errors.attribute_names)
12+
f.semantic_errors
1213

1314
f.inputs 'General' do
1415
f.input :name
@@ -18,6 +19,6 @@ def add_author_resource(options = {}, &block)
1819
f.actions
1920
end
2021
end
21-
Rails.application.reload_routes!
2222

23+
Rails.application.reload_routes!
2324
end

spec/support/rails_template.rb

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,51 @@
33
generate :model, 'author name:string{10}:uniq last_name:string birthday:date'
44
generate :model, 'post title:string:uniq body:text author:references'
55

6-
# Add validation
7-
inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n\n attr_accessor :last_seen_at\n ransacker :last_seen_at do\n Arel.sql('updated_at')\n end\n def self.ransackable_attributes(auth_object = nil)\n attribute_names\n end\n def self.ransackable_associations(auth_object = nil)\n []\n end\n", after: "ApplicationRecord\n"
8-
inject_into_file "app/models/post.rb", " validates_presence_of :author\n", after: ":author\n"
6+
# Compatibility with old ransack
7+
inject_into_file "app/models/application_record.rb", after: "primary_abstract_class\n" do
8+
<<-STRING
9+
10+
def self.ransackable_attributes(auth_object=nil)
11+
if respond_to?(:authorizable_ransackable_attributes)
12+
authorizable_ransackable_attributes
13+
else
14+
super
15+
end
16+
end
17+
18+
def self.ransackable_associations(auth_object=nil)
19+
if respond_to?(:authorizable_ransackable_associations)
20+
authorizable_ransackable_associations
21+
else
22+
super
23+
end
24+
end
25+
STRING
26+
end
27+
28+
# Virtual attributes
29+
inject_into_file "app/models/author.rb", after: "ApplicationRecord\n" do
30+
<<-STRING
31+
validates_presence_of :name
32+
validates_uniqueness_of :last_name
33+
34+
attr_accessor :last_seen_at
35+
36+
ransacker :last_seen_at do
37+
Arel.sql('updated_at')
38+
end
39+
STRING
40+
end
941

1042
# Configure default_url_options in test environment
11-
inject_into_file "config/environments/test.rb", " config.action_mailer.default_url_options = { :host => 'example.com' }\n", after: "config.cache_classes = true\n"
43+
inject_into_file "config/environments/test.rb", after: "config.cache_classes = true\n" do
44+
" config.action_mailer.default_url_options = { :host => 'example.com' }\n"
45+
end
1246

1347
# Add our local Active Admin to the load path
14-
inject_into_file "config/environment.rb",
15-
"\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n",
16-
after: "require File.expand_path('../application', __FILE__)"
48+
inject_into_file "config/environment.rb", after: "require File.expand_path('../application', __FILE__)" do
49+
"\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n"
50+
end
1751

1852
run "rm Gemfile"
1953

@@ -23,13 +57,13 @@
2357
generate :'formtastic:install'
2458

2559
# Install active_admin_date_time_datetimepicker assets
26-
inject_into_file "app/assets/stylesheets/active_admin.scss",
27-
"@import \"active_admin_datetimepicker\";\n",
28-
after: "@import \"active_admin/base\";\n"
60+
inject_into_file "app/assets/stylesheets/active_admin.scss" do
61+
"@import \"active_admin_datetimepicker\";\n"
62+
end
2963

30-
inject_into_file "app/assets/javascripts/active_admin.js",
31-
"//= require active_admin_datetimepicker\n",
32-
after: "//= require active_admin/base\n"
64+
inject_into_file "app/assets/javascripts/active_admin.js" do
65+
"//= require active_admin_datetimepicker\n"
66+
end
3367

3468
run "rm -r test"
3569
run "rm -r spec"

0 commit comments

Comments
 (0)