Skip to content

Commit

Permalink
Add support for Rails v8
Browse files Browse the repository at this point in the history
  • Loading branch information
leoarnold committed Nov 19, 2024
1 parent 4c621c8 commit e620b7a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run standardrb
uses: standardrb/standard-ruby-action@f533e61f461ccb766b2d9c235abf59be02aea793
Expand All @@ -30,8 +30,8 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.1", "3.2"]
rails: ["6.1", "7.0"]
ruby: ["3.2", "3.3"]
rails: ["6.1", "7.0", "7.1", "7.2", "8.0"]
continue-on-error: [false]

runs-on: ubuntu-latest
Expand All @@ -57,7 +57,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
Expand Down
23 changes: 14 additions & 9 deletions spec/scenic/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view :searches, sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string

Expand All @@ -31,7 +31,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view :searches, sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string
expect(output).to include "~ '\\\\d+'::text"
Expand All @@ -47,7 +47,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view :searches, materialized: true, sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string

Expand All @@ -62,7 +62,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view :"scenic.searches", sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string
expect(output).to include 'create_view "scenic.searches",'
Expand All @@ -77,7 +77,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.execute("CREATE OR REPLACE VIEW scenic.apples AS SELECT * FROM scenic.bananas;")
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)
views = stream.string.lines.grep(/create_view/).map do |view_line|
view_line.match('create_view "(?<name>.*)"')[:name]
end
Expand All @@ -93,7 +93,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view :a_searches_z, sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string

Expand All @@ -106,7 +106,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view :searches, sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string

Expand All @@ -121,7 +121,7 @@ class SearchInAHaystack < ActiveRecord::Base
Search.connection.create_view '"search in a haystack"', sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string
expect(output).to include 'create_view "\"search in a haystack\"",'
Expand All @@ -145,14 +145,19 @@ class SearchInAHaystack < ActiveRecord::Base
sql_definition: view_definition
stream = StringIO.new

ActiveRecord::SchemaDumper.dump(Search.connection, stream)
dump_schema(stream)

output = stream.string
expect(output).to include 'create_view "scenic.\"search in a haystack\"",'
expect(output).to include view_definition

Search.connection.drop_view :'scenic."search in a haystack"'

case ActiveRecord.gem_version
when Gem::Requirement.new(">= 7.1")
Search.connection.drop_schema "scenic"
end

silence_stream($stdout) { eval(output) } # standard:disable Security/Eval

expect(SearchInAHaystack.take.haystack).to eq "needle"
Expand Down
19 changes: 15 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
require "database_cleaner"

require File.expand_path("dummy/config/environment", __dir__)
require "support/rails_configuration_helpers"
require "support/generator_spec_setup"
require "support/view_definition_helpers"

Dir.glob("#{__dir__}/support/**/*.rb").each { |f| require f }

RSpec.configure do |config|
config.order = "random"
config.include DatabaseSchemaHelpers
config.include ViewDefinitionHelpers
config.include RailsConfigurationHelpers
DatabaseCleaner.strategy = :transaction

config.around(:each, db: true) do |example|
ActiveRecord::SchemaMigration.create_table
case ActiveRecord.gem_version
when Gem::Requirement.new(">= 7.2")
ActiveRecord::SchemaMigration
.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool)
.create_table
when Gem::Requirement.new("~> 7.1.0")
ActiveRecord::SchemaMigration
.new(ActiveRecord::Tasks::DatabaseTasks.migration_connection)
.create_table
when Gem::Requirement.new("< 7.1")
ActiveRecord::SchemaMigration.create_table
end

DatabaseCleaner.start
example.run
Expand Down
10 changes: 10 additions & 0 deletions spec/support/database_schema_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module DatabaseSchemaHelpers
def dump_schema(stream)
case ActiveRecord.gem_version
when Gem::Requirement.new(">= 7.2")
ActiveRecord::SchemaDumper.dump(Search.connection_pool, stream)
else
ActiveRecord::SchemaDumper.dump(Search.connection, stream)
end
end
end

0 comments on commit e620b7a

Please sign in to comment.