Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ruby/rails/activeadmin matrix #84

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@ jobs:
strategy:
matrix:
ruby:
- 2.5
- 2.6
- '3.0.0'
- '3.1.0'
- '3.2.0'
- '3.3.0'
rails:
- '5.2.0'
- '6.0.0'
- '6.1.0'
- '7.0.0'
- '7.1.0'
activeadmin:
- '2.0.0'
- '2.6.0'
- '2.14.0'
- '3.0.0'
- '3.1.0'
- '3.2.0'
exclude:
- rails: '5.2.0'
activeadmin: '2.6.0'
- rails: '6.0.0'
activeadmin: '2.0.0'
- rails: '7.1.0'
activeadmin: '2.14.0'
- rails: '7.1.0'
activeadmin: '3.0.0'
env:
RAILS: ${{ matrix.rails }}
AA: ${{ matrix.activeadmin }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Run tests
Expand Down
9 changes: 5 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ source 'https://rubygems.org'
gemspec

group :test do
default_rails_version = '6.0.0'
default_activeadmin_version = '2.6.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', '3.0.4'
gem 'sprockets-rails'
gem 'rspec-rails'
gem 'coveralls', 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'
gem 'database_cleaner'
gem 'capybara'
gem 'webdrivers'
gem 'byebug'
gem 'webrick', require: false
end
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", ">= 2.0", "< 3.a"
spec.add_dependency "activeadmin", ">= 2.14.0", "< 4.0"
end
18 changes: 10 additions & 8 deletions spec/filter_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
before do
workgena marked this conversation as resolved.
Show resolved Hide resolved
Author.create!(name: "Ren",
last_name: "from-20-day-of-month",
created_at: (Time.now.change(day: 20) - 1.hour).to_s(: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_s(: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,10 +94,11 @@
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_s(:db)) }
let!(:second_author) { Author.create!(name: 'Rey', last_name: 'future', updated_at: 21.days.from_now.to_s(:db)) }

before do
Author.create!(name: 'Ren', last_name: 'One', updated_at: (Time.now.change(day: 1) + 1.hour).to_formatted_s(:db))
Author.create!(name: 'Ron', last_name: 'Two', updated_at: (Time.now.change(day: 20) - 1.hour).to_formatted_s(:db))
Author.create!(name: 'Rey', last_name: 'future', updated_at: Time.now.change(day: 21).to_formatted_s(:db))

# chose 01 and 20 day of the current month
page.find('input#q_last_seen_at_gteq_datetime_picker').click
page.find('.xdsoft_datetimepicker', visible: true)
Expand All @@ -118,9 +119,10 @@
page.has_css?('h4', text: 'Current filters:')
end

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

it 'input#value and placeholder is the same as before form submit' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ENV['RAILS'] = Rails.version
ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)
# Create the test app if it doesn't exists
unless File.exists?(ENV['RAILS_ROOT'])
unless File.exist?(ENV['RAILS_ROOT'])
system 'rake setup'
end

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.keys
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
68 changes: 55 additions & 13 deletions spec/support/rails_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,59 @@
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", 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

def self.ransackable_attributes(auth_object=nil)
if respond_to?(:authorizable_ransackable_attributes)
authorizable_ransackable_attributes
else
%w(birthday created_at last_seen_at updated_at)
end
end

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 +65,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