From c5f23e849bb09156c36e2f78cee382f48ff0b133 Mon Sep 17 00:00:00 2001 From: Pascal Zumkehr Date: Tue, 9 Jul 2024 14:25:32 +0200 Subject: [PATCH] Support rails 7.1 --- .github/workflows/build.yml | 3 +- .gitignore | 2 + Gemfile.lock | 213 ++++++++++-------- lib/tasks/wagons.rake | 8 +- lib/wagons/extensions/migration.rb | 34 ++- lib/wagons/extensions/test_case.rb | 6 +- lib/wagons/wagon.rb | 6 +- test/ci/rails70.gemfile | 11 + test/dummy/Gemfile | 2 +- .../initializers/backtrace_silencers.rb | 7 - test/dummy/config/initializers/inflections.rb | 15 -- test/dummy/config/initializers/mime_types.rb | 5 - .../dummy/config/initializers/secret_token.rb | 6 +- test/dummy/db/schema.rb | 5 +- wagons.gemspec | 10 +- 15 files changed, 191 insertions(+), 142 deletions(-) create mode 100644 test/ci/rails70.gemfile delete mode 100644 test/dummy/config/initializers/backtrace_silencers.rb delete mode 100644 test/dummy/config/initializers/inflections.rb delete mode 100644 test/dummy/config/initializers/mime_types.rb diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bce421c..5564660 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,11 +15,12 @@ jobs: gemfile: - Gemfile - test/ci/rails61.gemfile + - test/ci/rails70.gemfile env: ROOT_BUNDLE_PATH: ${{ github.workspace }}/vendor/bundle BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.gitignore b/.gitignore index c75f11c..a1c29be 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ log/*.log pkg/ rdoc/ test/dummy/db/*.sqlite3 +test/dummy/db/*.sqlite3-shm +test/dummy/db/*.sqlite3-wal test/dummy/log/*.log test/dummy/tmp/ test/dummy/.sass-cache diff --git a/Gemfile.lock b/Gemfile.lock index 3d37b38..287eb4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,88 +2,105 @@ PATH remote: . specs: wagons (0.8.0) - bundler (>= 1.1) - rails (>= 5.2) + bundler (>= 2.0) + rails (>= 6.1) seed-fu-ndo (>= 0.0.3) GEM remote: https://rubygems.org/ specs: - actioncable (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) + actioncable (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.7.2) - actionpack (= 7.0.7.2) - activejob (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.7.2) - actionpack (= 7.0.7.2) - actionview (= 7.0.7.2) - activejob (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionmailer (7.1.3.4) + actionpack (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activesupport (= 7.1.3.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.7.2) - actionview (= 7.0.7.2) - activesupport (= 7.0.7.2) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.3.4) + actionview (= 7.1.3.4) + activesupport (= 7.1.3.4) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.7.2) - actionpack (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.4) + actionpack (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.7.2) - activesupport (= 7.0.7.2) + actionview (7.1.3.4) + activesupport (= 7.1.3.4) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.7.2) - activesupport (= 7.0.7.2) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.4) + activesupport (= 7.1.3.4) globalid (>= 0.3.6) - activemodel (7.0.7.2) - activesupport (= 7.0.7.2) - activerecord (7.0.7.2) - activemodel (= 7.0.7.2) - activesupport (= 7.0.7.2) - activestorage (7.0.7.2) - actionpack (= 7.0.7.2) - activejob (= 7.0.7.2) - activerecord (= 7.0.7.2) - activesupport (= 7.0.7.2) + activemodel (7.1.3.4) + activesupport (= 7.1.3.4) + activerecord (7.1.3.4) + activemodel (= 7.1.3.4) + activesupport (= 7.1.3.4) + timeout (>= 0.4.0) + activestorage (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activesupport (= 7.1.3.4) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.7.2) + activesupport (7.1.3.4) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - builder (3.2.4) - concurrent-ruby (1.2.2) + base64 (0.2.0) + bigdecimal (3.1.8) + builder (3.3.0) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) - erubi (1.12.0) - globalid (1.2.0) + date (3.3.4) + drb (2.2.1) + erubi (1.13.0) + globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - loofah (2.21.3) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -91,45 +108,52 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) - method_source (1.0.0) + marcel (1.0.4) mini_mime (1.1.5) - mini_portile2 (2.8.5) - minitest (5.19.0) - mocha (2.1.0) + mini_portile2 (2.8.7) + minitest (5.24.1) + mocha (2.4.0) ruby2_keywords (>= 0.0.5) - net-imap (0.3.7) + mutex_m (0.2.0) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) - nokogiri (1.16.2) + nio4r (2.7.3) + nokogiri (1.16.6) mini_portile2 (~> 2.8.2) racc (~> 1.4) open4 (1.3.4) - racc (1.7.3) - rack (2.2.8) + psych (5.1.2) + stringio + racc (1.8.0) + rack (3.1.6) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.7.2) - actioncable (= 7.0.7.2) - actionmailbox (= 7.0.7.2) - actionmailer (= 7.0.7.2) - actionpack (= 7.0.7.2) - actiontext (= 7.0.7.2) - actionview (= 7.0.7.2) - activejob (= 7.0.7.2) - activemodel (= 7.0.7.2) - activerecord (= 7.0.7.2) - activestorage (= 7.0.7.2) - activesupport (= 7.0.7.2) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.4) + actioncable (= 7.1.3.4) + actionmailbox (= 7.1.3.4) + actionmailer (= 7.1.3.4) + actionpack (= 7.1.3.4) + actiontext (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activemodel (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) bundler (>= 1.15.0) - railties (= 7.0.7.2) + railties (= 7.1.3.4) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -141,30 +165,37 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) - method_source + railties (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + reline (0.5.9) + io-console (~> 0.5) ruby2_keywords (0.0.5) seed-fu (2.3.9) activerecord (>= 3.1) activesupport (>= 3.1) seed-fu-ndo (0.0.3) seed-fu (>= 2.2.0) - sqlite3 (1.6.4) + sqlite3 (1.7.3) mini_portile2 (~> 2.8.0) - thor (1.2.2) - timeout (0.4.0) + stringio (3.1.1) + thor (1.3.1) + timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.11) + zeitwerk (2.6.16) PLATFORMS ruby @@ -174,7 +205,7 @@ DEPENDENCIES net-smtp open4 rails-controller-testing - sqlite3 + sqlite3 (~> 1.4) wagons! BUNDLED WITH diff --git a/lib/tasks/wagons.rake b/lib/tasks/wagons.rake index e66c3d2..8c84d4c 100644 --- a/lib/tasks/wagons.rake +++ b/lib/tasks/wagons.rake @@ -199,11 +199,15 @@ namespace :db do end task :_dump_rails do - case ActiveRecord::Base.schema_format + schema_format = + Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('7.1.0') ? + ActiveRecord::Base.schema_format : ActiveRecord.schema_format + + case schema_format when :ruby then Rake::Task["db:schema:dump"].invoke when :sql then Rake::Task["db:structure:dump"].invoke else - raise "unknown schema format #{ActiveRecord::Base.schema_format}" + raise "unknown schema format #{schema_format}" end Rake::Task[:'db:_dump_rails'].reenable end diff --git a/lib/wagons/extensions/migration.rb b/lib/wagons/extensions/migration.rb index d676d9a..19cfc22 100644 --- a/lib/wagons/extensions/migration.rb +++ b/lib/wagons/extensions/migration.rb @@ -19,7 +19,11 @@ def maintain_test_schema_with_wagons! private def load_wagon_schema! - Base.clear_all_connections! + if rails_version_smaller_than('7.1.0') + Base.clear_all_connections! + else + Base.connection_handler.clear_all_connections! + end # Contrary to the original rails approach (#load_schema_if_pending!), # purge the database first to get rid of all wagon tables. @@ -34,7 +38,11 @@ def load_wagon_schema! def load_app_schema(config) Tasks::DatabaseTasks.load_schema(config) - check_pending! + if rails_version_smaller_than('7.1.0') + check_pending! + else + check_all_pending! + end end def app_needs_migration? @@ -47,25 +55,41 @@ def defined_app_migration_versions end def migration_versions_in_db - if Base.connection.table_exists?(SchemaMigration.table_name) + if schema_migration_table_exists? migration_context.get_all_versions.to_set else [].to_set end end + def schema_migration_table_exists? + if rails_version_smaller_than('7.1.0') + Base.connection.table_exists?(SchemaMigration.table_name) + else + SchemaMigration.new(Base.connection).table_exists? + end + end + def migration_context - MigrationContext.new(Migrator.migrations_paths, SchemaMigration) + if rails_version_smaller_than('7.1.0') + MigrationContext.new(Migrator.migrations_paths, SchemaMigration) + else + MigrationContext.new(Migrator.migrations_paths) + end end def maintain_test_schema? - if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('7.0.0') + if rails_version_smaller_than('7.0.0') ActiveRecord::Base.maintain_test_schema else ActiveRecord.maintain_test_schema end end + def rails_version_smaller_than(version) + Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new(version) + end + end end end diff --git a/lib/wagons/extensions/test_case.rb b/lib/wagons/extensions/test_case.rb index 03fd67b..203bb4d 100644 --- a/lib/wagons/extensions/test_case.rb +++ b/lib/wagons/extensions/test_case.rb @@ -4,7 +4,11 @@ class TestCase def self.reset_fixture_path(path) self.fixture_table_names = [] self.fixture_class_names = {} - self.fixture_path = path + if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('7.1.0') + self.fixture_path = path + else + self.fixture_paths = [path] + end fixtures :all end end diff --git a/lib/wagons/wagon.rb b/lib/wagons/wagon.rb index 5257dc7..bb29b83 100644 --- a/lib/wagons/wagon.rb +++ b/lib/wagons/wagon.rb @@ -127,7 +127,11 @@ def migrate_to(version) end def migration_context - ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration) + if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('7.1.0') + ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration) + else + ActiveRecord::MigrationContext.new(migrations_paths) + end end module ClassMethods diff --git a/test/ci/rails70.gemfile b/test/ci/rails70.gemfile new file mode 100644 index 0000000..5cb7c3a --- /dev/null +++ b/test/ci/rails70.gemfile @@ -0,0 +1,11 @@ +source 'https://rubygems.org' + +gemspec :path => '../..' + +gem 'rails', '~> 7.0.0' + +group :test do + gem 'mocha', :require => false + gem 'net-smtp' + gem 'rails-controller-testing' +end diff --git a/test/dummy/Gemfile b/test/dummy/Gemfile index ba0ada2..cc0e05b 100644 --- a/test/dummy/Gemfile +++ b/test/dummy/Gemfile @@ -6,7 +6,7 @@ gem 'wagons', :path => File.expand_path(__FILE__).split("test#{File::SEPARATOR}d group :development, :test do gem 'net-smtp' - gem 'sqlite3' + gem 'sqlite3', '~> 1.4' end group :test do diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 59385cd..0000000 --- a/test/dummy/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb deleted file mode 100644 index 5d8d9be..0000000 --- a/test/dummy/config/initializers/inflections.rb +++ /dev/null @@ -1,15 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end -# -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections do |inflect| -# inflect.acronym 'RESTful' -# end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb deleted file mode 100644 index 72aca7e..0000000 --- a/test/dummy/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/test/dummy/config/initializers/secret_token.rb b/test/dummy/config/initializers/secret_token.rb index a31343e..fdb5604 100644 --- a/test/dummy/config/initializers/secret_token.rb +++ b/test/dummy/config/initializers/secret_token.rb @@ -5,8 +5,4 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -if Rails.version < '4.0' - Dummy::Application.config.secret_token = 'e85c1b61190124d7d5e2660879966e236e6de1db13dd618c12d55901a7b7611b522d5821657f62529a6a6448cbb5e217934734f2e334fde656438ce182213e98' -else - Dummy::Application.config.secret_key_base = 'e85c1b61190124d7d5e2660879966e236e6de1db13dd618c12d55901a7b7611b522d5821657f62529a6a6448cbb5e217934734f2e334fde656438ce182213e98' -end +Dummy::Application.config.secret_key_base = 'e85c1b61190124d7d5e2660879966e236e6de1db13dd618c12d55901a7b7611b522d5821657f62529a6a6448cbb5e217934734f2e334fde656438ce182213e98' diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index b213ae0..5a1df9a 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -11,12 +11,11 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2012_06_06_125104) do - create_table "people", force: :cascade do |t| t.string "name", limit: 255 t.date "birthday" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false end end diff --git a/wagons.gemspec b/wagons.gemspec index ec9d0c5..a782d64 100644 --- a/wagons.gemspec +++ b/wagons.gemspec @@ -9,19 +9,19 @@ Gem::Specification.new do |s| s.version = Wagons::VERSION s.authors = ['Pascal Zumkehr'] s.email = ['spam@codez.ch'] - s.homepage = 'http://github.com/codez/wagons' + s.homepage = 'http://github.com/puzzle/wagons' s.summary = 'Wagons are extensions to your application train running on Rails.' s.description = 'Wagons are plugins that extend your specific Rails application. This framework makes it easy to create and manage them.' - s.files = Dir['lib/**/{*,.[a-z]*}'] + ['MIT-LICENSE', 'Rakefile', 'README.rdoc'] + s.files = Dir['lib/**/{*,.[a-z]*}'] + ['MIT-LICENSE', 'Rakefile', 'README.md'] s.test_files = Dir['test/**/*'] - s.add_dependency 'bundler', '>= 1.1' + s.add_dependency 'bundler', '>= 2.0' - s.add_dependency 'rails', '>= 5.2' + s.add_dependency 'rails', '>= 6.1' s.add_dependency 'seed-fu-ndo', '>= 0.0.3' s.add_development_dependency 'open4' - s.add_development_dependency 'sqlite3' + s.add_development_dependency 'sqlite3', '~> 1.4' end