Skip to content

Commit

Permalink
feat: support Rails 8.0 (#331)
Browse files Browse the repository at this point in the history
* feat: support Rails 8.0

* build: test rails 8.0

* test: fix more tests

* test: fix test issues + rubocop

* test: skip other adapter test for 7.0 and lower

* build: run samples during tests (#338)

Automatically run all samples as part of the tests.
  • Loading branch information
olavloite authored Jan 3, 2025
1 parent 3fbda54 commit 478eefd
Show file tree
Hide file tree
Showing 79 changed files with 179 additions and 801 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/acceptance-tests-on-emulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ jobs:
max-parallel: 4
matrix:
ruby: ["3.1", "3.2", "3.3"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
# Exclude combinations that are not supported.
exclude:
- ruby: "3.1"
ar: "~> 8.0.0"
env:
AR_VERSION: ${{ matrix.ar }}
steps:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ jobs:
max-parallel: 4
matrix:
ruby: ["3.1", "3.2", "3.3"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
# Exclude combinations that are not supported.
exclude:
- ruby: "3.1"
ar: "~> 8.0.0"
env:
AR_VERSION: ${{ matrix.ar }}
steps:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/nightly-acceptance-tests-on-emulator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ jobs:
max-parallel: 4
matrix:
ruby: ["3.1", "3.2", "3.3"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
# Exclude combinations that are not supported.
exclude:
- ruby: "3.1"
ar: "~> 8.0.0"
env:
AR_VERSION: ${{ matrix.ar }}
steps:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/nightly-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ jobs:
max-parallel: 4
matrix:
# Run acceptance tests all supported combinations of Ruby and ActiveRecord.
ruby: ["3.1", "3.2", "3.3"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
# Exclude combinations that are not supported.
exclude:
- ruby: "3.1"
ar: "~> 8.0.0"
env:
AR_VERSION: ${{ matrix.ar }}
steps:
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/samples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
pull_request:
name: samples
jobs:
test:
runs-on: ubuntu-latest

strategy:
max-parallel: 4
matrix:
ruby: ["3.1", "3.2", "3.3"]
ar: ["~> 6.1.0", "~> 7.0.0", "~> 7.1.0", "~> 7.2.0", "~> 8.0.0"]
# Exclude combinations that are not supported.
exclude:
- ruby: "3.1"
ar: "~> 8.0.0"
env:
AR_VERSION: ${{ matrix.ar }}
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: false
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install
- name: Run samples
run: bundle exec rake all
working-directory: examples/snippets
11 changes: 6 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ source "https://rubygems.org"
# Specify your gem's dependencies in activerecord-spanner.gemspec
gemspec

gem "activerecord", ENV.fetch("AR_VERSION", "~> 7.1.0")
ar_version = ENV.fetch("AR_VERSION", "~> 7.1.0")
gem "activerecord", ar_version
gem "ostruct"
gem "minitest", "~> 5.25.0"
gem "minitest-rg", "~> 5.3.0"
gem "pry", "~> 0.13.0"
gem "pry-byebug", "~> 3.9.0"
gem "pry", "~> 0.14.2"
gem "pry-byebug", "~> 3.10.1"
# Add sqlite3 for testing for compatibility with other adapters.
gem 'sqlite3', '~> 1.4'
gem 'sqlite3'

# Required for samples and testing.
install_if -> { ENV.fetch("AR_VERSION", "~> 7.1.0").dup.to_s.sub("~>", "").strip < "7.1.0" && !ENV["SKIP_COMPOSITE_PK"] } do
install_if -> { ar_version.dup.to_s.sub("~>", "").strip < "7.1.0" && !ENV["SKIP_COMPOSITE_PK"] } do
gem "composite_primary_keys"
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord-spanner-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "google-cloud-spanner", "~> 2.18"
# Pin gRPC to 1.64.3, as 1.65 and 1.66 cause test runs to hang randomly.
spec.add_dependency "grpc", "1.64.3"
spec.add_runtime_dependency "activerecord", [">= 6.1", "< 7.3"]
spec.add_runtime_dependency "activerecord", [">= 6.1", "< 9"]

spec.add_development_dependency "autotest-suffix", "~> 1.1"
spec.add_development_dependency "bundler", "~> 2.0"
Expand Down
32 changes: 27 additions & 5 deletions examples/snippets/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@
require_relative "config/environment"
require "docker"

desc "Lists all available samples."
task :list do
samples = Dir.entries(".").select do |entry|
def fetch_samples
Dir.entries(".").select do |entry|
File.directory?(File.join(".", entry)) \
&& !%w[. ..].include?(entry) \
&& File.exist?(File.join(".", entry, "application.rb"))
&& !%w[. ..].include?(entry) \
&& File.exist?(File.join(".", entry, "application.rb"))
end
end

desc "Lists all available samples."
task :list do
samples = fetch_samples
puts "Available samples: "
samples.sort.each { |dir| puts " #{dir}" }
puts ""
puts "Run a sample with the command `bundle exec rake run\\[<sample-name>\\]`"
end

desc "Runs all samples."
task :all do
samples = fetch_samples
ar_version = ENV.fetch "AR_VERSION", "~> 7.1.0"
less_than_7_1 = ar_version.dup.to_s.sub("~>", "").strip < "7.1.0"
samples.delete "interleaved-tables" if less_than_7_1
samples.delete "interleaved-tables-before-7.1" unless less_than_7_1
samples.delete "bit-reversed-sequence" if less_than_7_1
samples.delete "query-logs" if less_than_7_1
samples.each do |sample|
run_sample sample
end
end

desc "Runs a simple ActiveRecord tutorial on a Spanner emulator."
task :run, [:sample] do |_t, args|
sample = args[:sample]
Expand All @@ -28,7 +46,11 @@ task :run, [:sample] do |_t, args|
puts ""
sample = "quickstart"
end
run_sample sample
end

def run_sample sample
puts "Running #{sample}"
puts "Downloading Spanner emulator image..."
Docker::Image.create "fromImage" => "gcr.io/cloud-spanner-emulator/emulator:latest"
puts "Creating Spanner emulator container..."
Expand Down
6 changes: 1 addition & 5 deletions examples/snippets/array-data-type/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require_relative "models/entity_with_array_types"

class Application
def self.run # rubocop:disable Metrics/AbcSize
def self.run
# Create a record with all array types.
record = EntityWithArrayTypes.create \
col_array_string: ["value1", "value2", "value3"],
Expand All @@ -35,10 +35,6 @@ def self.run # rubocop:disable Metrics/AbcSize
puts "Bytes array: #{record.col_array_bytes.map(&:read)}"
puts "Date array: #{record.col_array_date}"
puts "Timestamp array: #{record.col_array_timestamp}"

puts ""
puts "Press any key to end the application"
$stdin.getch
end
end

Expand Down
1 change: 1 addition & 0 deletions examples/snippets/array-data-type/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ development:
database: testdb
pool: 5
timeout: 5000
schema_dump: false
31 changes: 0 additions & 31 deletions examples/snippets/array-data-type/db/schema.rb

This file was deleted.

4 changes: 0 additions & 4 deletions examples/snippets/bit-reversed-sequence/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def self.run

# List all singers, albums and tracks.
list_singers_albums

puts ""
puts "Press any key to end the application"
$stdin.getch
end

def self.find_album singerid, albumid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ development:
database: testdb
pool: 5
timeout: 5000
schema_dump: false
31 changes: 0 additions & 31 deletions examples/snippets/bit-reversed-sequence/db/schema.rb

This file was deleted.

4 changes: 0 additions & 4 deletions examples/snippets/bulk-insert/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def self.run # rubocop:disable Metrics/AbcSize
puts " with album #{a.title} with id #{a.id}"
end
end

puts ""
puts "Press any key to end the application"
$stdin.getch
end
end

Expand Down
1 change: 1 addition & 0 deletions examples/snippets/bulk-insert/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ development:
database: testdb
pool: 5
timeout: 5000
schema_dump: false
31 changes: 0 additions & 31 deletions examples/snippets/bulk-insert/db/schema.rb

This file was deleted.

4 changes: 0 additions & 4 deletions examples/snippets/commit-timestamp/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def self.run # rubocop:disable Metrics/AbcSize
puts "Singer and album updated:"
puts "#{singer.first_name} #{singer.last_name} (Last updated: #{singer.last_updated.strftime format})"
puts " #{album.title} (Last updated: #{album.last_updated.strftime format})"

puts ""
puts "Press any key to end the application"
$stdin.getch
end
end

Expand Down
1 change: 1 addition & 0 deletions examples/snippets/commit-timestamp/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ development:
database: testdb
pool: 5
timeout: 5000
schema_dump: false
34 changes: 0 additions & 34 deletions examples/snippets/commit-timestamp/db/schema.rb

This file was deleted.

4 changes: 4 additions & 0 deletions examples/snippets/config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

Dir["../../lib/*.rb"].each { |file| require file }

if ActiveRecord.version >= Gem::Version.create("7.2.0")
ActiveRecord::ConnectionAdapters.register "spanner", "ActiveRecord::ConnectionAdapters::SpannerAdapter"
end

Bundler.require

ActiveRecord::Base.establish_connection(
Expand Down
Loading

0 comments on commit 478eefd

Please sign in to comment.