Skip to content

Commit

Permalink
Get class directly
Browse files Browse the repository at this point in the history
  • Loading branch information
evman182 committed Jan 3, 2024
1 parent 57cf090 commit a46be4f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/temporal_tables/temporal_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.temporalize_associations! # rubocop:disable Metrics/MethodLength, Metri

# Calling .history here will ensure that the history class
# for this association is created and initialized
clazz = association.class_name.constantize.history
clazz = association.klass.history

# Recreate the association, updating it to point at the
# history class. The foreign key is explicitly set since it's
Expand Down
14 changes: 14 additions & 0 deletions spec/basic_history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,17 @@
end
end
end

describe Bird do
context 'when a bird and nest exist' do
let(:bird) { Bird.create name: 'Sam' }
let(:nest) { Bird::Nest.create bird: bird, height: 100 }

it 'can create instance of class with nested class name with history entries' do
expect(bird).not_to be_nil
expect(nest).not_to be_nil
expect(bird.history.first).not_to be_nil
expect(nest.history.first).not_to be_nil
end
end
end
5 changes: 5 additions & 0 deletions spec/internal/app/models/bird.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Bird < ActiveRecord::Base
has_one :nest, inverse_of: :bird
end
6 changes: 6 additions & 0 deletions spec/internal/app/models/bird/nest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class Bird::Nest < ActiveRecord::Base
self.table_name = 'nests'
belongs_to :bird, inverse_of: :nest
end
9 changes: 9 additions & 0 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@
create_table :a_very_very_very_very_very_long_table_name, temporal: true do |t|
t.string :name
end

create_table :birds, id: (postgres ? :uuid : :integer), temporal: true, force: true do |t|
t.string :name
end

create_table :nests, id: (postgres ? :uuid : :integer), temporal: true do |t|
t.belongs_to :bird, type: (postgres ? :uuid : :integer)
t.integer :height
end
end

0 comments on commit a46be4f

Please sign in to comment.