Skip to content

Commit

Permalink
support for rails 8 (#47)
Browse files Browse the repository at this point in the history
* support for rails 8

* ruby 3.1

* expand matrix

* stree

* association options

* work out kinks

* changelog and bump version
  • Loading branch information
waymondo authored Oct 11, 2024
1 parent 2624617 commit bb353cb
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 15 deletions.
19 changes: 15 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ jobs:
strategy:
matrix:
ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
rails:
- "7.0"
- "7.1"
- "7.0.8.4"
- "7.1.4"
- "7.2.1"
- "8.0.0.beta1"
include:
- rails: "7.0.8.4"
ruby: "3.0"
- rails: "7.0.8.4"
ruby: "3.1"
- rails: "7.1.4"
ruby: "3.0"
- rails: "7.1.4"
ruby: "3.1"
- rails: "7.2.1"
ruby: "3.1"

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.16.0

- Rails 8 support introduced

## 0.15.0

- *Breaking Change* - Support for Ruby 2.7 and Rails 6.1 is dropped
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

gem "debug"
if (rails_version = ENV["RAILS_VERSION"])
gem "rails", "~> #{rails_version}.0"
gem "rails", "~> #{rails_version}"
else
gem "rails"
end
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,14 @@ Instead of storing the previous versions or changes in a separate table, it stor
proprietary JSON format directly on the database row of the record itself. If does not support soft
deletion.

## Testing

Hoardable is tested against a matrix of Ruby 3 versions and Rails 7 & 8. To run tests locally, run:

```
rake
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/waymondo/hoardable.
Expand Down
6 changes: 3 additions & 3 deletions hoardable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "activerecord", ">= 7", "< 8"
spec.add_dependency "activesupport", ">= 7", "< 8"
spec.add_dependency "railties", ">= 7", "< 8"
spec.add_dependency "activerecord", ">= 7"
spec.add_dependency "activesupport", ">= 7"
spec.add_dependency "railties", ">= 7"

spec.add_dependency "fx", ">= 0.8", "< 1"
spec.add_dependency "pg", ">= 1", "< 2"
Expand Down
6 changes: 3 additions & 3 deletions lib/hoardable/has_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module HasOne
def has_one(*args)
options = args.extract_options!
hoardable = options.delete(:hoardable)
association = super(*args, **options)
name = args.first
return unless hoardable || association[name.to_s].options[:class_name].match?(/RichText$/)
association = super(*args, **options).symbolize_keys[name]
return unless hoardable || (association.options[:class_name].match?(/RichText$/))

class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}
reflection = _reflections['#{name}']
reflection = _reflections.symbolize_keys[:#{name}]
return super if reflection.klass.name.match?(/^ActionText/)
return super unless (timestamp = hoardable_client.has_one_at_timestamp)
Expand Down
2 changes: 1 addition & 1 deletion lib/hoardable/schema_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Hoardable
module SchemaStatements
def table_options(table_name)
options = super || {}
if inherited_table_names = parent_table_names(table_name)
if !options[:options] && (inherited_table_names = parent_table_names(table_name))
options[:options] = "INHERITS (#{inherited_table_names.join(", ")})"
end
options
Expand Down
2 changes: 1 addition & 1 deletion lib/hoardable/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Hoardable
VERSION = "0.15.1"
VERSION = "0.16.0"
end
8 changes: 6 additions & 2 deletions test/test_schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class TestSchemaDumper < ActiveSupport::TestCase
private def dump_table_schema(*table_names)
connection = ActiveRecord::Base.connection
ActiveRecord::SchemaDumper.ignore_tables = connection.data_sources - table_names
stream = StringIO.new
ActiveRecord::SchemaDumper.dump(connection, stream).string
if ActiveRecord.version >= Gem::Version.new("7.2.1")
output, = capture_io { ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection_pool) }
output
else
ActiveRecord::SchemaDumper.dump(connection, StringIO.new).string
end
end
end

0 comments on commit bb353cb

Please sign in to comment.