Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialize temporal classes of subclasses #39

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/temporal_tables/temporal_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def find_sti_class(type_name)
type_name += 'History' unless type_name =~ /History\Z/

begin
# Calling .history makes sure history class is created
type_name.sub(/History$/, '').constantize.history

super
rescue ActiveRecord::SubclassNotFound
superclass.send(:find_sti_class, type_name)
Expand Down
7 changes: 7 additions & 0 deletions spec/basic_history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@
end
end

describe 'when working with STI and using superclass history' do
it 'allows to fetch history entry of subclass history' do
Broom.create person: emily, model: 'Cackler 2000'
expect(FlyingMachine.history.last.class.name).to eql('BroomHistory')
end
end

describe 'when working with STI one level deep' do
let!(:broom) { Broom.create person: emily, model: 'Cackler 2000' }

Expand Down
Loading