diff --git a/Gemfile.lock b/Gemfile.lock index a5eac75f01..8f84a2885c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,65 +13,71 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.3) - actionpack (= 6.1.7.3) - activesupport (= 6.1.7.3) + actioncable (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.3) - actionpack (= 6.1.7.3) - activejob (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) + actionmailbox (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) mail (>= 2.7.1) - actionmailer (6.1.7.3) - actionpack (= 6.1.7.3) - actionview (= 6.1.7.3) - activejob (= 6.1.7.3) - activesupport (= 6.1.7.3) + net-imap + net-pop + net-smtp + actionmailer (7.0.4.3) + actionpack (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activesupport (= 7.0.4.3) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.7.3) - actionview (= 6.1.7.3) - activesupport (= 6.1.7.3) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.4.3) + actionview (= 7.0.4.3) + activesupport (= 7.0.4.3) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.3) - actionpack (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) + actiontext (7.0.4.3) + actionpack (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.7.3) - activesupport (= 6.1.7.3) + actionview (7.0.4.3) + activesupport (= 7.0.4.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7.3) - activesupport (= 6.1.7.3) + activejob (7.0.4.3) + activesupport (= 7.0.4.3) globalid (>= 0.3.6) - activemodel (6.1.7.3) - activesupport (= 6.1.7.3) - activerecord (6.1.7.3) - activemodel (= 6.1.7.3) - activesupport (= 6.1.7.3) - activestorage (6.1.7.3) - actionpack (= 6.1.7.3) - activejob (= 6.1.7.3) - activerecord (= 6.1.7.3) - activesupport (= 6.1.7.3) + activemodel (7.0.4.3) + activesupport (= 7.0.4.3) + activerecord (7.0.4.3) + activemodel (= 7.0.4.3) + activesupport (= 7.0.4.3) + activestorage (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activesupport (= 7.0.4.3) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7.3) + activesupport (7.0.4.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.2) public_suffix (>= 2.0.2, < 6.0) administrate-field-image (1.2.0) @@ -179,7 +185,7 @@ GEM kgio (2.11.4) launchy (2.5.2) addressable (~> 2.8) - loofah (2.19.1) + loofah (2.20.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.8.1) @@ -202,7 +208,7 @@ GEM timeout net-smtp (0.3.3) net-protocol - nio4r (2.5.8) + nio4r (2.5.9) nokogiri (1.14.3) mini_portile2 (~> 2.8.0) racc (~> 1.4) @@ -220,21 +226,20 @@ GEM rack-test (2.1.0) rack (>= 1.3) rack-timeout (0.6.3) - rails (6.1.7.3) - actioncable (= 6.1.7.3) - actionmailbox (= 6.1.7.3) - actionmailer (= 6.1.7.3) - actionpack (= 6.1.7.3) - actiontext (= 6.1.7.3) - actionview (= 6.1.7.3) - activejob (= 6.1.7.3) - activemodel (= 6.1.7.3) - activerecord (= 6.1.7.3) - activestorage (= 6.1.7.3) - activesupport (= 6.1.7.3) + rails (7.0.4.3) + actioncable (= 7.0.4.3) + actionmailbox (= 7.0.4.3) + actionmailer (= 7.0.4.3) + actionpack (= 7.0.4.3) + actiontext (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activemodel (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) bundler (>= 1.15.0) - railties (= 6.1.7.3) - sprockets-rails (>= 2.0.0) + railties (= 7.0.4.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -243,12 +248,13 @@ GEM rails-i18n (7.0.6) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) - railties (6.1.7.3) - actionpack (= 6.1.7.3) - activesupport (= 6.1.7.3) + railties (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) method_source rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rainbow (3.1.1) raindrops (0.20.1) rake (13.0.6) diff --git a/gemfiles/rails70.gemfile b/gemfiles/rails70.gemfile index 6c0c785af8..0980d9cdc5 100644 --- a/gemfiles/rails70.gemfile +++ b/gemfiles/rails70.gemfile @@ -12,7 +12,7 @@ gem "pundit" gem "redcarpet" gem "sentry-raven" gem "unicorn" -gem "rails", "~> 6.1" +gem "rails", "~> 7.0" group :development, :test do gem "appraisal" diff --git a/lib/generators/administrate/routes/routes_generator.rb b/lib/generators/administrate/routes/routes_generator.rb index e352f0d0d5..a92b236259 100644 --- a/lib/generators/administrate/routes/routes_generator.rb +++ b/lib/generators/administrate/routes/routes_generator.rb @@ -7,6 +7,7 @@ require "rails/generators/base" require "administrate/generator_helpers" require "administrate/namespace" +require "generators/administrate/test_record" module Administrate module Generators @@ -60,7 +61,10 @@ def valid_dashboard_models end def database_models - ActiveRecord::Base.descendants.reject(&:abstract_class?) + ActiveRecord::Base.descendants. + reject(&:abstract_class?). + reject { |k| k < Administrate::Generators::TestRecord }. + sort_by(&:to_s) end def invalid_dashboard_models diff --git a/lib/generators/administrate/test_record.rb b/lib/generators/administrate/test_record.rb new file mode 100644 index 0000000000..5b6a9cc404 --- /dev/null +++ b/lib/generators/administrate/test_record.rb @@ -0,0 +1,21 @@ +module Administrate + module Generators + # This class serves only to work around a strange behaviour in Rails 7 + # with Ruby 3. + # + # After running the spec for DashboardGenerator, the fake models that + # it generates (eg: Foo, Shipment) linger around despite being removed + # explicitly. This causes RouteGenerator to take them into + # account and generate routes for them, which its spec doesn't expect, + # causing a spec failure. + # + # To avoid this, the spec for DashboardGenerator defines its fake models + # as children of TestRecord. Then RoutesGenerator explicitly filters + # child classes of TestRecord when figuring out what models exist. + # + # Discussion at https://github.com/thoughtbot/administrate/pull/2324 + class TestRecord < ApplicationRecord + self.abstract_class = true + end + end +end diff --git a/spec/administrate/views/fields/select/_edit_spec.rb b/spec/administrate/views/fields/select/_edit_spec.rb index 01b11a7421..b11677acfa 100644 --- a/spec/administrate/views/fields/select/_edit_spec.rb +++ b/spec/administrate/views/fields/select/_edit_spec.rb @@ -36,6 +36,7 @@ def build_template Object.new.tap do |template| template.extend ActionView::Helpers::FormHelper template.extend ActionView::Helpers::FormOptionsHelper + template.extend ActionView::Helpers::FormTagHelper end end end diff --git a/spec/administrate/views/fields/url/_form_spec.rb b/spec/administrate/views/fields/url/_form_spec.rb index 3e0662c432..2c739a62a6 100644 --- a/spec/administrate/views/fields/url/_form_spec.rb +++ b/spec/administrate/views/fields/url/_form_spec.rb @@ -2,7 +2,7 @@ require "administrate/field/url" describe "fields/url/_form", type: :view do - it "displays the resource name" do + it "provides the correct name for the field" do product = build(:product, image_url: nil) url = instance_double( "Administrate::Field::Url", @@ -31,6 +31,7 @@ def build_template Object.new.tap do |template| template.extend ActionView::Helpers::FormHelper template.extend ActionView::Helpers::FormOptionsHelper + template.extend ActionView::Helpers::FormTagHelper end end end diff --git a/spec/generators/dashboard_generator_spec.rb b/spec/generators/dashboard_generator_spec.rb index f9cc1933bc..924c939e09 100644 --- a/spec/generators/dashboard_generator_spec.rb +++ b/spec/generators/dashboard_generator_spec.rb @@ -1,5 +1,6 @@ require "rails_helper" require "generators/administrate/dashboard/dashboard_generator" +require "generators/administrate/test_record" describe Administrate::Generators::DashboardGenerator, :generator do around do |example| @@ -25,7 +26,7 @@ create_table(:foos) { |t| t.timestamps null: false } end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -47,7 +48,7 @@ class Foo < ApplicationRecord create_table(:foos) { |t| t.string :name } end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -72,7 +73,7 @@ class Foo < ApplicationRecord end end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -92,7 +93,7 @@ class Foo < ApplicationRecord create_table(:foos) { |t| t.inet :ip_address } end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -124,7 +125,7 @@ class Foo < ApplicationRecord end end - class InventoryItem < ApplicationRecord + class InventoryItem < Administrate::Generators::TestRecord reset_column_information end @@ -148,7 +149,7 @@ class InventoryItem < ApplicationRecord end end - class Shipment < ApplicationRecord + class Shipment < Administrate::Generators::TestRecord enum status: %i[ready processing shipped] reset_column_information end @@ -169,7 +170,7 @@ class Shipment < ApplicationRecord end end - class Shipment < ApplicationRecord + class Shipment < Administrate::Generators::TestRecord enum status: %i[ready processing shipped] reset_column_information end @@ -195,7 +196,7 @@ class Shipment < ApplicationRecord create_table(:users) { |t| t.boolean :active } end - class User < ApplicationRecord + class User < Administrate::Generators::TestRecord reset_column_information end @@ -220,7 +221,7 @@ class User < ApplicationRecord end end - class Event < ApplicationRecord + class Event < Administrate::Generators::TestRecord reset_column_information end @@ -241,7 +242,7 @@ class Event < ApplicationRecord ActiveRecord::Schema.define do create_table(:comments) { |t| t.references :post } end - class Comment < ApplicationRecord + class Comment < Administrate::Generators::TestRecord belongs_to :post end @@ -263,7 +264,7 @@ class Comment < ApplicationRecord t.references :commentable, polymorphic: true end end - class Comment < ApplicationRecord + class Comment < Administrate::Generators::TestRecord belongs_to :commentable, polymorphic: true end @@ -289,12 +290,12 @@ class Comment < ApplicationRecord end end - class Account < ApplicationRecord + class Account < Administrate::Generators::TestRecord reset_column_information has_one :profile end - class Ticket < ApplicationRecord + class Ticket < Administrate::Generators::TestRecord reset_column_information belongs_to :account end @@ -316,7 +317,7 @@ class Ticket < ApplicationRecord create_table :accounts end - class Account < ApplicationRecord + class Account < Administrate::Generators::TestRecord reset_column_information attribute :tmp_attribute, :boolean end @@ -342,7 +343,7 @@ class Account < ApplicationRecord end end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -376,7 +377,7 @@ def table_attribute_limit end end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -402,7 +403,7 @@ class Foo < ApplicationRecord end end - class Foo < ApplicationRecord + class Foo < Administrate::Generators::TestRecord reset_column_information end @@ -430,7 +431,7 @@ class Foo < ApplicationRecord it "subclasses Admin::ApplicationController by default" do begin ActiveRecord::Schema.define { create_table :foos } - class Foo < ApplicationRecord; end + class Foo < Administrate::Generators::TestRecord; end run_generator ["foo"] load file("app/controllers/admin/foos_controller.rb") @@ -446,7 +447,7 @@ class Foo < ApplicationRecord; end it "uses the given namespace to create controllers" do begin ActiveRecord::Schema.define { create_table :foos } - class Foo < ApplicationRecord; end + class Foo < Administrate::Generators::TestRecord; end module Manager class ApplicationController < Administrate::ApplicationController; end end diff --git a/spec/generators/routes_generator_spec.rb b/spec/generators/routes_generator_spec.rb index baa74e4cd3..ef0b5fe019 100644 --- a/spec/generators/routes_generator_spec.rb +++ b/spec/generators/routes_generator_spec.rb @@ -120,6 +120,6 @@ class ModelWithoutDBTable < ApplicationRecord; end run_generator - expect(routes).to contain('root to: "customers#index') + expect(routes).to contain('root to: "countries#index') end end diff --git a/spec/support/field_matchers.rb b/spec/support/field_matchers.rb index 64b81d2f65..b110c48ae8 100644 --- a/spec/support/field_matchers.rb +++ b/spec/support/field_matchers.rb @@ -5,13 +5,12 @@ def should_permit_param(expected_param, for_attribute:, on_model:) resource_class: on_model, ) - if Rails::VERSION::MAJOR <= 6 - permitted_param = if permitted_param.respond_to?(:transform_keys) - permitted_param.deep_transform_keys(&:to_s) - else - permitted_param.to_s - end - end + permitted_param = + if permitted_param.respond_to?(:transform_keys) + permitted_param.deep_transform_keys(&:to_s) + else + permitted_param.to_s + end expect(permitted_param).to eq(expected_param) end