Skip to content

Commit a5fccff

Browse files
gigorokworkgena
andauthored
update ruby/rails/activeadmin matrix (#84)
* update ruby/rails/activeadmin matrix --------- Co-authored-by: Gena <[email protected]>
1 parent 84ebc63 commit a5fccff

File tree

7 files changed

+93
-42
lines changed

7 files changed

+93
-42
lines changed

.github/workflows/ci.yml

+17-12
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,30 @@ jobs:
1111
strategy:
1212
matrix:
1313
ruby:
14-
- 2.5
15-
- 2.6
14+
- '3.0.0'
15+
- '3.1.0'
16+
- '3.2.0'
17+
- '3.3.0'
1618
rails:
17-
- '5.2.0'
18-
- '6.0.0'
19+
- '6.1.0'
20+
- '7.0.0'
21+
- '7.1.0'
1922
activeadmin:
20-
- '2.0.0'
21-
- '2.6.0'
23+
- '2.14.0'
24+
- '3.0.0'
25+
- '3.1.0'
26+
- '3.2.0'
2227
exclude:
23-
- rails: '5.2.0'
24-
activeadmin: '2.6.0'
25-
- rails: '6.0.0'
26-
activeadmin: '2.0.0'
28+
- rails: '7.1.0'
29+
activeadmin: '2.14.0'
30+
- rails: '7.1.0'
31+
activeadmin: '3.0.0'
2732
env:
2833
RAILS: ${{ matrix.rails }}
2934
AA: ${{ matrix.activeadmin }}
3035
steps:
31-
- uses: actions/checkout@v2
32-
- uses: actions/setup-ruby@v1
36+
- uses: actions/checkout@v4
37+
- uses: ruby/setup-ruby@v1
3338
with:
3439
ruby-version: ${{ matrix.ruby }}
3540
- name: Run tests

Gemfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ source 'https://rubygems.org'
44
gemspec
55

66
group :test do
7-
default_rails_version = '6.0.0'
8-
default_activeadmin_version = '2.6.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

13-
gem 'sprockets-rails', '3.0.4'
13+
gem 'sprockets-rails'
1414
gem 'rspec-rails'
15-
gem 'coveralls', 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'
1919
gem 'database_cleaner'
2020
gem 'capybara'
2121
gem 'webdrivers'
2222
gem 'byebug'
23+
gem 'webrick', require: false
2324
end

active_admin_datetimepicker.gemspec

+1-1
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", ">= 2.0", "< 3.a"
22+
spec.add_dependency "activeadmin", ">= 2.14.0", "< 4.0"
2323
end

spec/filter_form_spec.rb

+10-8
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_s(: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_s(: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,10 +94,11 @@
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_s(:db)) }
98-
let!(:second_author) { Author.create!(name: 'Rey', last_name: 'future', updated_at: 21.days.from_now.to_s(:db)) }
99-
10097
before do
98+
Author.create!(name: 'Ren', last_name: 'One', updated_at: (Time.now.change(day: 1) + 1.hour).to_formatted_s(:db))
99+
Author.create!(name: 'Ron', last_name: 'Two', updated_at: (Time.now.change(day: 20) - 1.hour).to_formatted_s(:db))
100+
Author.create!(name: 'Rey', last_name: 'future', updated_at: Time.now.change(day: 21).to_formatted_s(:db))
101+
101102
# chose 01 and 20 day of the current month
102103
page.find('input#q_last_seen_at_gteq_datetime_picker').click
103104
page.find('.xdsoft_datetimepicker', visible: true)
@@ -118,9 +119,10 @@
118119
page.has_css?('h4', text: 'Current filters:')
119120
end
120121

121-
it 'should filter records properly' do
122-
expect(page).to have_text(first_author.name)
123-
expect(page).not_to have_text(second_author.name)
122+
it 'finds the first and second authors, but not the third one, because he is outside of the filtered dates' do
123+
expect(page).to have_text('Ren')
124+
expect(page).to have_text('Ron')
125+
expect(page).not_to have_text('Rey')
124126
end
125127

126128
it 'input#value and placeholder is the same as before form submit' do

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ENV['RAILS'] = Rails.version
1515
ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)
1616
# Create the test app if it doesn't exists
17-
unless File.exists?(ENV['RAILS_ROOT'])
17+
unless File.exist?(ENV['RAILS_ROOT'])
1818
system 'rake setup'
1919
end
2020

spec/support/admin.rb

+4-3
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.keys
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

+55-13
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,59 @@
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", 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+
def self.ransackable_attributes(auth_object=nil)
35+
if respond_to?(:authorizable_ransackable_attributes)
36+
authorizable_ransackable_attributes
37+
else
38+
%w(birthday created_at last_seen_at updated_at)
39+
end
40+
end
41+
42+
attr_accessor :last_seen_at
43+
44+
ransacker :last_seen_at do
45+
Arel.sql('updated_at')
46+
end
47+
STRING
48+
end
949

1050
# 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"
51+
inject_into_file "config/environments/test.rb", after: "config.cache_classes = true\n" do
52+
" config.action_mailer.default_url_options = { :host => 'example.com' }\n"
53+
end
1254

1355
# 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__)"
56+
inject_into_file "config/environment.rb", after: "require File.expand_path('../application', __FILE__)" do
57+
"\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n"
58+
end
1759

1860
run "rm Gemfile"
1961

@@ -23,13 +65,13 @@
2365
generate :'formtastic:install'
2466

2567
# 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"
68+
inject_into_file "app/assets/stylesheets/active_admin.scss" do
69+
"@import \"active_admin_datetimepicker\";\n"
70+
end
2971

30-
inject_into_file "app/assets/javascripts/active_admin.js",
31-
"//= require active_admin_datetimepicker\n",
32-
after: "//= require active_admin/base\n"
72+
inject_into_file "app/assets/javascripts/active_admin.js" do
73+
"//= require active_admin_datetimepicker\n"
74+
end
3375

3476
run "rm -r test"
3577
run "rm -r spec"

0 commit comments

Comments
 (0)