Skip to content

Commit

Permalink
Add failing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed May 19, 2022
1 parent ffbdc51 commit e328109
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/chrono_model/time_machine/as_of_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
it { expect(Foo.as_of($t.subbar.ts[1]).includes(:bars, :sub_bars).first.sub_bars.first.name).to eq 'bar sub-bar' }
it { expect(Foo.as_of($t.subbar.ts[2]).includes(:bars, :sub_bars).first.sub_bars.first.name).to eq 'sub-bar sub-bar' }
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 }
end

it 'does not raise RecordNotFound when no history records are found' do
Expand Down
15 changes: 15 additions & 0 deletions spec/support/time_machine/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ::Foo < ActiveRecord::Base

has_many :bars
has_many :sub_bars, through: :bars
has_many :sub_sub_bars, through: :sub_bars

belongs_to :goo, class_name: 'FooGoo', optional: true
end
Expand Down Expand Up @@ -93,10 +94,22 @@ class ::SubBar < ActiveRecord::Base
include ChronoModel::TimeMachine

belongs_to :bar
has_many :sub_sub_bars

has_timeline with: :bar
end

adapter.create_table 'sub_sub_bars', temporal: true do |t|
t.string :name
t.references :sub_bar
end

class ::SubSubBar < ActiveRecord::Base
include ChronoModel::TimeMachine

belongs_to :sub_bar
end

adapter.create_table 'bazs' do |t|
t.string :name
t.references :bar
Expand Down Expand Up @@ -126,6 +139,8 @@ class ::Baz < ActiveRecord::Base
$t.subbar = ts_eval { SubBar.create! name: 'sub-bar', bar: $t.bar }
ts_eval($t.subbar) { update! name: 'bar sub-bar' }

ts_eval { SubSubBar.create! name: 'sub-sub-bar', sub_bar: $t.subbar }

ts_eval($t.foo) { update! name: 'new foo' }

ts_eval($t.bar) { update! name: 'bar bar' }
Expand Down

0 comments on commit e328109

Please sign in to comment.