diff --git a/spec/chrono_model/time_machine/as_of_spec.rb b/spec/chrono_model/time_machine/as_of_spec.rb index 0d00099f..618aed36 100644 --- a/spec/chrono_model/time_machine/as_of_spec.rb +++ b/spec/chrono_model/time_machine/as_of_spec.rb @@ -153,6 +153,8 @@ it { expect(Foo.as_of($t.subbar.ts[3]).includes(:bars, :sub_bars).first.sub_bars.first.name).to eq 'new sub-bar' } it { expect(Foo.as_of(Time.now).includes(:bars, :sub_bars, :sub_sub_bars).first.sub_sub_bars.compact.size).to eq 1 } + + it { expect(Foo.as_of(Time.now).includes(:active_sub_bars).first.name).to eq 'new foo' } end it 'does not raise RecordNotFound when no history records are found' do diff --git a/spec/support/time_machine/structure.rb b/spec/support/time_machine/structure.rb index cf536332..74b2b5fc 100644 --- a/spec/support/time_machine/structure.rb +++ b/spec/support/time_machine/structure.rb @@ -75,6 +75,7 @@ def up adapter.create_table 'sub_bars', temporal: true do |t| t.string :name t.references :bar + t.boolean :active, default: true end adapter.create_table 'sub_sub_bars', temporal: true do |t| @@ -87,6 +88,8 @@ class ::Bar < ActiveRecord::Base belongs_to :foo has_many :sub_bars + has_many :active_sub_bars, -> { active }, class_name: 'SubBar', dependent: nil, inverse_of: false + has_one :baz has_timeline with: :foo @@ -121,6 +124,7 @@ class ::Foo < ActiveRecord::Base has_many :tars, foreign_key: :foo_refering, primary_key: :refee_foo has_many :sub_bars, through: :bars has_many :sub_sub_bars, through: :sub_bars + has_many :active_sub_bars, through: :bars belongs_to :goo, class_name: 'FooGoo', optional: true end @@ -147,6 +151,8 @@ class ::SubBar < ActiveRecord::Base belongs_to :bar has_many :sub_sub_bars + scope :active, -> { where(active: true) } + has_timeline with: :bar end