From 9440886bb7ac2cb36fbcd0dec0b4c8224c75e143 Mon Sep 17 00:00:00 2001 From: Masato Sugiyama Date: Fri, 8 Nov 2024 20:30:41 +0900 Subject: [PATCH 1/3] CI against Rails 8.0 --- .github/workflows/test.yaml | 5 +++++ Gemfile | 3 +++ gemfiles/8.0.gemfile | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 gemfiles/8.0.gemfile diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4e4483b1..cc09c55e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,6 +37,8 @@ jobs: ruby: - 3.3 env: + - AR_VERSION: '8.0' + RUBYOPT: --enable-frozen-string-literal - AR_VERSION: '7.2' RUBYOPT: --enable-frozen-string-literal - AR_VERSION: '7.1' @@ -46,6 +48,9 @@ jobs: - AR_VERSION: 6.1 RUBYOPT: --enable-frozen-string-literal include: + - ruby: 3.2 + env: + AR_VERSION: '8.0' - ruby: 3.2 env: AR_VERSION: '7.2' diff --git a/Gemfile b/Gemfile index 43ec84dd..0e44f993 100644 --- a/Gemfile +++ b/Gemfile @@ -9,10 +9,13 @@ version = ENV['AR_VERSION'].to_f mysql2_version = '0.3.0' mysql2_version = '0.4.0' if version >= 4.2 mysql2_version = '0.5.0' if version >= 6.1 +mysql2_version = '0.5.6' if version >= 8.0 sqlite3_version = '1.3.0' sqlite3_version = '1.4.0' if version >= 6.0 +sqlite3_version = '2.2.0' if version >= 8.0 pg_version = '0.9' pg_version = '1.1' if version >= 6.1 +pg_version = '1.5' if version >= 8.0 group :development, :test do gem 'rubocop' diff --git a/gemfiles/8.0.gemfile b/gemfiles/8.0.gemfile new file mode 100644 index 00000000..9b2b4f6e --- /dev/null +++ b/gemfiles/8.0.gemfile @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +gem 'activerecord', '~> 8.0.0' From 6f6cc7d1f7c176122af2d193afdb2699d30532d9 Mon Sep 17 00:00:00 2001 From: Masato Sugiyama Date: Sat, 16 Nov 2024 13:07:37 +0900 Subject: [PATCH 2/3] fix query_constraints errors --- test/models/author.rb | 4 +++- test/models/book.rb | 2 +- test/models/composite_book.rb | 2 +- test/models/composite_chapter.rb | 5 ++++- test/models/customer.rb | 2 +- test/models/order.rb | 2 +- test/models/tag_alias.rb | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/models/author.rb b/test/models/author.rb index f4c0446d..92af5061 100644 --- a/test/models/author.rb +++ b/test/models/author.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true class Author < ActiveRecord::Base - if ENV['AR_VERSION'].to_f >= 7.1 + if ENV['AR_VERSION'].to_f >= 8.0 + has_many :composite_books, foreign_key: [:id, :author_id], inverse_of: :author + elsif ENV['AR_VERSION'].to_f >= 7.1 has_many :composite_books, query_constraints: [:id, :author_id], inverse_of: :author end end diff --git a/test/models/book.rb b/test/models/book.rb index 1fdc8cda..6fd4a782 100644 --- a/test/models/book.rb +++ b/test/models/book.rb @@ -2,7 +2,7 @@ class Book < ActiveRecord::Base belongs_to :topic, inverse_of: :books - if ENV['AR_VERSION'].to_f <= 7.0 + if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0 belongs_to :tag, foreign_key: [:tag_id, :parent_id] unless ENV["SKIP_COMPOSITE_PK"] else belongs_to :tag, query_constraints: [:tag_id, :parent_id] unless ENV["SKIP_COMPOSITE_PK"] diff --git a/test/models/composite_book.rb b/test/models/composite_book.rb index c269ed12..7d5538a3 100644 --- a/test/models/composite_book.rb +++ b/test/models/composite_book.rb @@ -3,7 +3,7 @@ class CompositeBook < ActiveRecord::Base self.primary_key = %i[id author_id] belongs_to :author - if ENV['AR_VERSION'].to_f <= 7.0 + if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0 unless ENV["SKIP_COMPOSITE_PK"] has_many :composite_chapters, inverse_of: :composite_book, foreign_key: [:id, :author_id] diff --git a/test/models/composite_chapter.rb b/test/models/composite_chapter.rb index 9b9d66df..b63e4387 100644 --- a/test/models/composite_chapter.rb +++ b/test/models/composite_chapter.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class CompositeChapter < ActiveRecord::Base - if ENV['AR_VERSION'].to_f >= 7.1 + if ENV['AR_VERSION'].to_f >= 8.0 + belongs_to :composite_book, inverse_of: :composite_chapters, + foreign_key: [:composite_book_id, :author_id] + elsif ENV['AR_VERSION'].to_f >= 7.1 belongs_to :composite_book, inverse_of: :composite_chapters, query_constraints: [:composite_book_id, :author_id] end diff --git a/test/models/customer.rb b/test/models/customer.rb index b8312cd8..fb997b9f 100644 --- a/test/models/customer.rb +++ b/test/models/customer.rb @@ -2,7 +2,7 @@ class Customer < ActiveRecord::Base unless ENV["SKIP_COMPOSITE_PK"] - if ENV['AR_VERSION'].to_f <= 7.0 + if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0 has_many :orders, inverse_of: :customer, primary_key: %i(account_id id), diff --git a/test/models/order.rb b/test/models/order.rb index e29e6a9b..c6a03461 100644 --- a/test/models/order.rb +++ b/test/models/order.rb @@ -2,7 +2,7 @@ class Order < ActiveRecord::Base unless ENV["SKIP_COMPOSITE_PK"] - if ENV['AR_VERSION'].to_f <= 7.0 + if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0 belongs_to :customer, inverse_of: :orders, primary_key: %i(account_id id), diff --git a/test/models/tag_alias.rb b/test/models/tag_alias.rb index d9636793..8c9bb135 100644 --- a/test/models/tag_alias.rb +++ b/test/models/tag_alias.rb @@ -2,7 +2,7 @@ class TagAlias < ActiveRecord::Base unless ENV["SKIP_COMPOSITE_PK"] - if ENV['AR_VERSION'].to_f <= 7.0 + if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0 belongs_to :tag, foreign_key: [:tag_id, :parent_id], required: true else belongs_to :tag, query_constraints: [:tag_id, :parent_id], required: true From 3e78374d407d1c29b6d7bc02857777a021dbaaa4 Mon Sep 17 00:00:00 2001 From: Masato Sugiyama Date: Sat, 16 Nov 2024 13:34:02 +0900 Subject: [PATCH 3/3] fix enum errors --- test/models/book.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/models/book.rb b/test/models/book.rb index 6fd4a782..11850f5b 100644 --- a/test/models/book.rb +++ b/test/models/book.rb @@ -10,5 +10,9 @@ class Book < ActiveRecord::Base has_many :chapters, inverse_of: :book has_many :discounts, as: :discountable has_many :end_notes, inverse_of: :book - enum status: [:draft, :published] if ENV['AR_VERSION'].to_f >= 4.1 + if ENV['AR_VERSION'].to_f >= 8.0 + enum :status, [:draft, :published] + elsif ENV['AR_VERSION'].to_f >= 4.1 + enum status: [:draft, :published] + end end