diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e97dadd4..4b651ad8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,7 @@ jobs: matrix: adapter: [ 'mysql2', 'pg', 'sqlite3' ] ruby: ['3.3', '3.4', '4.0'] + rails: ['~> 7.2.0', '~> 8.0.0', '~> 8.1.0'] steps: - name: Checkout @@ -68,19 +69,22 @@ jobs: run: bundle config set path 'vendor/bundle' working-directory: spec/dummyapp - - name: Install dummyapp dependencies (${{ matrix.adapter }}) + - name: Install dummyapp dependencies (${{ matrix.adapter }}, Rails ${{ matrix.rails }}) run: bundle install working-directory: spec/dummyapp env: DATABASE_ADAPTER: ${{ matrix.adapter }} + RAILS_VERSION: ${{ matrix.rails }} - - name: Run dummyapp migrations (${{ matrix.adapter }}) + - name: Run dummyapp migrations (${{ matrix.adapter }}, Rails ${{ matrix.rails }}) run: bin/rails db:create working-directory: spec/dummyapp env: DATABASE_ADAPTER: ${{ matrix.adapter }} + RAILS_VERSION: ${{ matrix.rails }} - - name: Run Integration tests (${{ matrix.adapter }}) + - name: Run Integration tests (${{ matrix.adapter }}, Rails ${{ matrix.rails }}) run: bundle exec rake spec:integration env: DATABASE_ADAPTER: ${{ matrix.adapter }} + RAILS_VERSION: ${{ matrix.rails }} diff --git a/spec/dummyapp/Gemfile b/spec/dummyapp/Gemfile index cf2b05c1..83177a2b 100644 --- a/spec/dummyapp/Gemfile +++ b/spec/dummyapp/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.1.0" +gem "rails", ENV.fetch("RAILS_VERSION", "~> 7.2.0") case ENV['DATABASE_ADAPTER'] # This feels so wrong when 'mysql2' @@ -10,7 +10,11 @@ when 'mysql2' when 'pg' gem 'pg', '>= 1.5', '< 2' when 'sqlite3' - gem 'sqlite3', '>= 1.6', '< 2' + if ENV.fetch("RAILS_VERSION", "~> 7.2.0")[/(\d+)\./, 1].to_i >= 8 + gem 'sqlite3', '>= 2.1' + else + gem 'sqlite3', '>= 1.6', '< 2' + end else raise 'The environment variable DATABASE_ADAPTER must be one of mysql2, pg, or sqlite3' end diff --git a/spec/support/aruba.rb b/spec/support/aruba.rb index 15962c50..ac207d8c 100644 --- a/spec/support/aruba.rb +++ b/spec/support/aruba.rb @@ -18,6 +18,14 @@ def migrations_template_dir end def model_template(name) + # Rails 8 changed TimeWithZone#inspect to ISO 8601 (https://github.com/rails/rails/pull/52371), + # so datetime defaults in schema comments differ from Rails 7.2. spec/templates/rails8/ + # holds those overrides; if we drop Rails 7.2 from the CI matrix, this branch can go away. + if ENV.fetch("RAILS_VERSION", "~> 7.2.0")[/(\d+)\./, 1].to_i >= 8 + rails8_path = File.join(::Aruba.config.root_directory, "spec/templates/rails8/#{ENV["DATABASE_ADAPTER"]}", name) + return rails8_path if File.exist?(rails8_path) + end + File.join(models_template_dir, name) end diff --git a/spec/templates/rails8/mysql2/test_default.rb b/spec/templates/rails8/mysql2/test_default.rb new file mode 100644 index 00000000..c4f360a8 --- /dev/null +++ b/spec/templates/rails8/mysql2/test_default.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float(24) default(12.34) +# integer :integer default(99) +# string :string(255) default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestDefault < ApplicationRecord +end diff --git a/spec/templates/rails8/mysql2/test_default_updated.rb b/spec/templates/rails8/mysql2/test_default_updated.rb new file mode 100644 index 00000000..00dcf2fb --- /dev/null +++ b/spec/templates/rails8/mysql2/test_default_updated.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float(24) default(12.34) +# int_field :integer +# integer :integer default(99) +# string :string(255) default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestDefault < ApplicationRecord +end diff --git a/spec/templates/rails8/mysql2/test_default_with_bottom_annotations.rb b/spec/templates/rails8/mysql2/test_default_with_bottom_annotations.rb new file mode 100644 index 00000000..ff161ee9 --- /dev/null +++ b/spec/templates/rails8/mysql2/test_default_with_bottom_annotations.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +class TestDefault < ApplicationRecord +end + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float(24) default(12.34) +# integer :integer default(99) +# string :string(255) default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# diff --git a/spec/templates/rails8/mysql2/test_sibling_default.rb b/spec/templates/rails8/mysql2/test_sibling_default.rb new file mode 100644 index 00000000..cfb23466 --- /dev/null +++ b/spec/templates/rails8/mysql2/test_sibling_default.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float(24) default(12.34) +# integer :integer default(99) +# string :string(255) default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestSiblingDefault < TestDefault +end diff --git a/spec/templates/rails8/pg/test_default.rb b/spec/templates/rails8/pg/test_default.rb new file mode 100644 index 00000000..ffa54f1a --- /dev/null +++ b/spec/templates/rails8/pg/test_default.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestDefault < ApplicationRecord +end diff --git a/spec/templates/rails8/pg/test_default_updated.rb b/spec/templates/rails8/pg/test_default_updated.rb new file mode 100644 index 00000000..2975b325 --- /dev/null +++ b/spec/templates/rails8/pg/test_default_updated.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# int_field :integer +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestDefault < ApplicationRecord +end diff --git a/spec/templates/rails8/pg/test_default_with_bottom_annotations.rb b/spec/templates/rails8/pg/test_default_with_bottom_annotations.rb new file mode 100644 index 00000000..f45ad47f --- /dev/null +++ b/spec/templates/rails8/pg/test_default_with_bottom_annotations.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +class TestDefault < ApplicationRecord +end + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# diff --git a/spec/templates/rails8/pg/test_sibling_default.rb b/spec/templates/rails8/pg/test_sibling_default.rb new file mode 100644 index 00000000..b54bf384 --- /dev/null +++ b/spec/templates/rails8/pg/test_sibling_default.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :bigint not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestSiblingDefault < TestDefault +end diff --git a/spec/templates/rails8/sqlite3/test_default.rb b/spec/templates/rails8/sqlite3/test_default.rb new file mode 100644 index 00000000..bff272dd --- /dev/null +++ b/spec/templates/rails8/sqlite3/test_default.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :integer not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestDefault < ApplicationRecord +end diff --git a/spec/templates/rails8/sqlite3/test_default_updated.rb b/spec/templates/rails8/sqlite3/test_default_updated.rb new file mode 100644 index 00000000..45adb34f --- /dev/null +++ b/spec/templates/rails8/sqlite3/test_default_updated.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :integer not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# int_field :integer +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestDefault < ApplicationRecord +end diff --git a/spec/templates/rails8/sqlite3/test_default_with_bottom_annotations.rb b/spec/templates/rails8/sqlite3/test_default_with_bottom_annotations.rb new file mode 100644 index 00000000..03540654 --- /dev/null +++ b/spec/templates/rails8/sqlite3/test_default_with_bottom_annotations.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true +class TestDefault < ApplicationRecord +end + +# == Schema Information +# +# Table name: test_defaults +# +# id :integer not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# diff --git a/spec/templates/rails8/sqlite3/test_sibling_default.rb b/spec/templates/rails8/sqlite3/test_sibling_default.rb new file mode 100644 index 00000000..14d552cc --- /dev/null +++ b/spec/templates/rails8/sqlite3/test_sibling_default.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: test_defaults +# +# id :integer not null, primary key +# boolean :boolean default(FALSE) +# date :date default(Tue, 04 Jul 2023) +# datetime :datetime default(2023-07-04 12:34:56.000000000 UTC +00:00) +# decimal :decimal(14, 2) default(43.21) +# float :float default(12.34) +# integer :integer default(99) +# string :string default("hello world!") +# created_at :datetime not null +# updated_at :datetime not null +# +class TestSiblingDefault < TestDefault +end