Skip to content

Commit

Permalink
Finalize compatibility with ActiveAdmin 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
workgena committed Dec 8, 2023
1 parent 1c68aa6 commit 610f3e8
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 39 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 3.0
- 3.1
- 3.2
rails:
- '6.1.0'
- '7.0.0'
- '7.1.0'
activeadmin:
- '3.0.0'
- '3.1.0'
exclude:
- rails: '7.1.0'
activeadmin: '3.0.0'
include:
- ruby: 2.6
rails: '5.2.3'
activeadmin: '2.0.0'
- ruby: 2.6
rails: '6.0.2'
activeadmin: '2.6.0'
- ruby: 2.7
rails: '7.0.8'
activeadmin: '2.13.0'
- ruby: 3.2
rails: '7.1.0'
activeadmin: '3.1.0'
env:
RAILS: ${{ matrix.rails }}
AA: ${{ matrix.activeadmin }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ source 'https://rubygems.org'
gemspec

group :test do
default_rails_version = '7.0.0'
default_activeadmin_version = '3.0.0'
default_rails_version = '7.1.0'
default_activeadmin_version = '3.1.0'

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

gem 'sprockets-rails'
gem 'rspec-rails'
gem 'coveralls_reborn', require: false # Test coverage website. Go to https://coveralls.io
gem 'coveralls_reborn', require: false
gem 'sass-rails'
gem 'sqlite3', '~> 1.4.0'
gem 'launchy'
Expand Down
2 changes: 1 addition & 1 deletion active_admin_datetimepicker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "activeadmin", ">= 3.0.0"
spec.add_dependency "activeadmin", ">= 2.0", "<= 3.1"
end
8 changes: 4 additions & 4 deletions spec/filter_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
before do
Author.create!(name: "Ren",
last_name: "from-20-day-of-month",
created_at: (Time.now.change(day: 20) - 1.hour).to_fs(:db))
created_at: (Time.now.change(day: 20) - 1.hour).to_formatted_s(:db))

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

# chose 01 and 20 day of the current month

Expand Down Expand Up @@ -94,8 +94,8 @@
end

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

before do
# chose 01 and 20 day of the current month
Expand Down
7 changes: 4 additions & 3 deletions spec/support/admin.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
def add_author_resource(options = {}, &block)

ActiveAdmin.register Author do
permit_params :name, :birthday

config.filters = true

filter :birthday, as: :date_time_range
filter :created_at, as: :date_time_range
filter :last_seen_at, as: :date_time_range

form do |f|
f.semantic_errors(*f.object.errors.attribute_names)
f.semantic_errors

f.inputs 'General' do
f.input :name
Expand All @@ -18,6 +19,6 @@ def add_author_resource(options = {}, &block)
f.actions
end
end
Rails.application.reload_routes!

Rails.application.reload_routes!
end
60 changes: 47 additions & 13 deletions spec/support/rails_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,51 @@
generate :model, 'author name:string{10}:uniq last_name:string birthday:date'
generate :model, 'post title:string:uniq body:text author:references'

# Add validation
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"
inject_into_file "app/models/post.rb", " validates_presence_of :author\n", after: ":author\n"
# Compatibility with old ransack
inject_into_file "app/models/application_record.rb", after: "primary_abstract_class\n" do
<<-STRING
def self.ransackable_attributes(auth_object=nil)
if respond_to?(:authorizable_ransackable_attributes)
authorizable_ransackable_attributes
else
super
end
end
def self.ransackable_associations(auth_object=nil)
if respond_to?(:authorizable_ransackable_associations)
authorizable_ransackable_associations
else
super
end
end
STRING
end

# Virtual attributes
inject_into_file "app/models/author.rb", after: "ApplicationRecord\n" do
<<-STRING
validates_presence_of :name
validates_uniqueness_of :last_name
attr_accessor :last_seen_at
ransacker :last_seen_at do
Arel.sql('updated_at')
end
STRING
end

# Configure default_url_options in test environment
inject_into_file "config/environments/test.rb", " config.action_mailer.default_url_options = { :host => 'example.com' }\n", after: "config.cache_classes = true\n"
inject_into_file "config/environments/test.rb", after: "config.cache_classes = true\n" do
" config.action_mailer.default_url_options = { :host => 'example.com' }\n"
end

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

run "rm Gemfile"

Expand All @@ -23,13 +57,13 @@
generate :'formtastic:install'

# Install active_admin_date_time_datetimepicker assets
inject_into_file "app/assets/stylesheets/active_admin.scss",
"@import \"active_admin_datetimepicker\";\n",
after: "@import \"active_admin/base\";\n"
inject_into_file "app/assets/stylesheets/active_admin.scss" do
"@import \"active_admin_datetimepicker\";\n"
end

inject_into_file "app/assets/javascripts/active_admin.js",
"//= require active_admin_datetimepicker\n",
after: "//= require active_admin/base\n"
inject_into_file "app/assets/javascripts/active_admin.js" do
"//= require active_admin_datetimepicker\n"
end

run "rm -r test"
run "rm -r spec"
Expand Down

0 comments on commit 610f3e8

Please sign in to comment.