diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e97dadd4..7cfd021d 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.1.0', '~> 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..8f049c90 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.1.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.1.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..4d01f761 100644 --- a/spec/support/aruba.rb +++ b/spec/support/aruba.rb @@ -9,8 +9,12 @@ def read_file(name) read(name).join("\n") end + def rails8? + ENV.fetch("RAILS_VERSION", "~> 7.1.0")[/(\d+)\./, 1].to_i >= 8 + end + def models_template_dir - File.join(::Aruba.config.root_directory, "spec/templates/#{ENV["DATABASE_ADAPTER"]}") + File.join(::Aruba.config.root_directory, "spec/templates/pre8/#{ENV["DATABASE_ADAPTER"]}") end def migrations_template_dir @@ -18,6 +22,11 @@ def migrations_template_dir end def model_template(name) + if rails8? + 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/mysql2/collapsed_test_model.rb b/spec/templates/pre8/mysql2/collapsed_test_model.rb similarity index 100% rename from spec/templates/mysql2/collapsed_test_model.rb rename to spec/templates/pre8/mysql2/collapsed_test_model.rb diff --git a/spec/templates/mysql2/nested_position_collapsed_test_model.rb b/spec/templates/pre8/mysql2/nested_position_collapsed_test_model.rb similarity index 100% rename from spec/templates/mysql2/nested_position_collapsed_test_model.rb rename to spec/templates/pre8/mysql2/nested_position_collapsed_test_model.rb diff --git a/spec/templates/mysql2/test_child_default.rb b/spec/templates/pre8/mysql2/test_child_default.rb similarity index 100% rename from spec/templates/mysql2/test_child_default.rb rename to spec/templates/pre8/mysql2/test_child_default.rb diff --git a/spec/templates/mysql2/test_default.rb b/spec/templates/pre8/mysql2/test_default.rb similarity index 100% rename from spec/templates/mysql2/test_default.rb rename to spec/templates/pre8/mysql2/test_default.rb diff --git a/spec/templates/mysql2/test_default_updated.rb b/spec/templates/pre8/mysql2/test_default_updated.rb similarity index 100% rename from spec/templates/mysql2/test_default_updated.rb rename to spec/templates/pre8/mysql2/test_default_updated.rb diff --git a/spec/templates/mysql2/test_default_with_bottom_annotations.rb b/spec/templates/pre8/mysql2/test_default_with_bottom_annotations.rb similarity index 100% rename from spec/templates/mysql2/test_default_with_bottom_annotations.rb rename to spec/templates/pre8/mysql2/test_default_with_bottom_annotations.rb diff --git a/spec/templates/mysql2/test_null_false.rb b/spec/templates/pre8/mysql2/test_null_false.rb similarity index 100% rename from spec/templates/mysql2/test_null_false.rb rename to spec/templates/pre8/mysql2/test_null_false.rb diff --git a/spec/templates/mysql2/test_parent.rb b/spec/templates/pre8/mysql2/test_parent.rb similarity index 100% rename from spec/templates/mysql2/test_parent.rb rename to spec/templates/pre8/mysql2/test_parent.rb diff --git a/spec/templates/mysql2/test_sibling_default.rb b/spec/templates/pre8/mysql2/test_sibling_default.rb similarity index 100% rename from spec/templates/mysql2/test_sibling_default.rb rename to spec/templates/pre8/mysql2/test_sibling_default.rb diff --git a/spec/templates/mysql2/test_true_sti.rb b/spec/templates/pre8/mysql2/test_true_sti.rb similarity index 100% rename from spec/templates/mysql2/test_true_sti.rb rename to spec/templates/pre8/mysql2/test_true_sti.rb diff --git a/spec/templates/pg/collapsed_test_model.rb b/spec/templates/pre8/pg/collapsed_test_model.rb similarity index 100% rename from spec/templates/pg/collapsed_test_model.rb rename to spec/templates/pre8/pg/collapsed_test_model.rb diff --git a/spec/templates/pg/nested_position_collapsed_test_model.rb b/spec/templates/pre8/pg/nested_position_collapsed_test_model.rb similarity index 100% rename from spec/templates/pg/nested_position_collapsed_test_model.rb rename to spec/templates/pre8/pg/nested_position_collapsed_test_model.rb diff --git a/spec/templates/pg/test_child_default.rb b/spec/templates/pre8/pg/test_child_default.rb similarity index 100% rename from spec/templates/pg/test_child_default.rb rename to spec/templates/pre8/pg/test_child_default.rb diff --git a/spec/templates/pg/test_default.rb b/spec/templates/pre8/pg/test_default.rb similarity index 100% rename from spec/templates/pg/test_default.rb rename to spec/templates/pre8/pg/test_default.rb diff --git a/spec/templates/pg/test_default_updated.rb b/spec/templates/pre8/pg/test_default_updated.rb similarity index 100% rename from spec/templates/pg/test_default_updated.rb rename to spec/templates/pre8/pg/test_default_updated.rb diff --git a/spec/templates/pg/test_default_with_bottom_annotations.rb b/spec/templates/pre8/pg/test_default_with_bottom_annotations.rb similarity index 100% rename from spec/templates/pg/test_default_with_bottom_annotations.rb rename to spec/templates/pre8/pg/test_default_with_bottom_annotations.rb diff --git a/spec/templates/pg/test_null_false.rb b/spec/templates/pre8/pg/test_null_false.rb similarity index 100% rename from spec/templates/pg/test_null_false.rb rename to spec/templates/pre8/pg/test_null_false.rb diff --git a/spec/templates/pg/test_parent.rb b/spec/templates/pre8/pg/test_parent.rb similarity index 100% rename from spec/templates/pg/test_parent.rb rename to spec/templates/pre8/pg/test_parent.rb diff --git a/spec/templates/pg/test_sibling_default.rb b/spec/templates/pre8/pg/test_sibling_default.rb similarity index 100% rename from spec/templates/pg/test_sibling_default.rb rename to spec/templates/pre8/pg/test_sibling_default.rb diff --git a/spec/templates/pg/test_true_sti.rb b/spec/templates/pre8/pg/test_true_sti.rb similarity index 100% rename from spec/templates/pg/test_true_sti.rb rename to spec/templates/pre8/pg/test_true_sti.rb diff --git a/spec/templates/sqlite3/collapsed_test_model.rb b/spec/templates/pre8/sqlite3/collapsed_test_model.rb similarity index 100% rename from spec/templates/sqlite3/collapsed_test_model.rb rename to spec/templates/pre8/sqlite3/collapsed_test_model.rb diff --git a/spec/templates/sqlite3/nested_position_collapsed_test_model.rb b/spec/templates/pre8/sqlite3/nested_position_collapsed_test_model.rb similarity index 100% rename from spec/templates/sqlite3/nested_position_collapsed_test_model.rb rename to spec/templates/pre8/sqlite3/nested_position_collapsed_test_model.rb diff --git a/spec/templates/sqlite3/test_child_default.rb b/spec/templates/pre8/sqlite3/test_child_default.rb similarity index 100% rename from spec/templates/sqlite3/test_child_default.rb rename to spec/templates/pre8/sqlite3/test_child_default.rb diff --git a/spec/templates/sqlite3/test_default.rb b/spec/templates/pre8/sqlite3/test_default.rb similarity index 100% rename from spec/templates/sqlite3/test_default.rb rename to spec/templates/pre8/sqlite3/test_default.rb diff --git a/spec/templates/sqlite3/test_default_updated.rb b/spec/templates/pre8/sqlite3/test_default_updated.rb similarity index 100% rename from spec/templates/sqlite3/test_default_updated.rb rename to spec/templates/pre8/sqlite3/test_default_updated.rb diff --git a/spec/templates/sqlite3/test_default_with_bottom_annotations.rb b/spec/templates/pre8/sqlite3/test_default_with_bottom_annotations.rb similarity index 100% rename from spec/templates/sqlite3/test_default_with_bottom_annotations.rb rename to spec/templates/pre8/sqlite3/test_default_with_bottom_annotations.rb diff --git a/spec/templates/sqlite3/test_null_false.rb b/spec/templates/pre8/sqlite3/test_null_false.rb similarity index 100% rename from spec/templates/sqlite3/test_null_false.rb rename to spec/templates/pre8/sqlite3/test_null_false.rb diff --git a/spec/templates/sqlite3/test_parent.rb b/spec/templates/pre8/sqlite3/test_parent.rb similarity index 100% rename from spec/templates/sqlite3/test_parent.rb rename to spec/templates/pre8/sqlite3/test_parent.rb diff --git a/spec/templates/sqlite3/test_sibling_default.rb b/spec/templates/pre8/sqlite3/test_sibling_default.rb similarity index 100% rename from spec/templates/sqlite3/test_sibling_default.rb rename to spec/templates/pre8/sqlite3/test_sibling_default.rb diff --git a/spec/templates/sqlite3/test_true_sti.rb b/spec/templates/pre8/sqlite3/test_true_sti.rb similarity index 100% rename from spec/templates/sqlite3/test_true_sti.rb rename to spec/templates/pre8/sqlite3/test_true_sti.rb 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