Skip to content

Commit

Permalink
Fix support for dbconsole on Rails edge
Browse files Browse the repository at this point in the history
Ref:
- Move dbconsole logic to Active Record connection adapter: rails/rails@4bcb8e4 rails/rails#46093
- Use adapter_class instead of connection_class for adapters: rails/rails@5bb357f rails/rails#46166
  • Loading branch information
tagliala committed Oct 8, 2022
1 parent 6888fa2 commit d1e8729
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/active_record/connection_adapters/chronomodel_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

module ActiveRecord
module ConnectionHandling
def chronomodel_adapter_class
ConnectionAdapters::PostgreSQLAdapter
end

# Install the new adapter in ActiveRecord. This approach is required because
# the PG adapter defines +add_column+ itself, thus making impossible to use
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def chrono?
prepend ChronoModel::Patches::Batches::BatchEnumerator
end

if defined?(Rails::DBConsole)
if defined?(Rails::DBConsole) && Rails.version < '7.1'
Rails::DBConsole.instance_eval do
if Rails.version < '6.1'
prepend ChronoModel::Patches::DBConsole::Config
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model/time_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def subclasses
# implemented with recursion of subclasses
if Class.method_defined?(:subclasses)
def descendants_with_history
subclasses_with_history.concat(subclasses.flat_map(&:descendants))
subclasses_with_history.concat(subclasses.flat_map(&:descendants_with_history))
end
end
else
Expand Down
4 changes: 2 additions & 2 deletions spec/chrono_model/time_machine/sti_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ::Magazine < ::Publication
describe '.descendants_with_history' do
subject { Element.descendants_with_history.map(&:name) }

it { is_expected.to match_array %w[Element::History Publication Magazine] }
it { is_expected.to match_array %w[Element::History Publication Publication::History Magazine Magazine::History] }
end

if Element.respond_to?(:direct_descendants)
Expand All @@ -50,7 +50,7 @@ class ::Magazine < ::Publication
end
end

if Element.respond_to?(:subclasses)
if Rails.version >= '7.0'
describe '.subclasses' do
subject { Element.subclasses.map(&:name) }

Expand Down

0 comments on commit d1e8729

Please sign in to comment.