-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
spec/chrono_model/time_machine/historical_association_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'support/time_machine/structure' | ||
|
||
class Country < ActiveRecord::Base | ||
include ChronoModel::TimeMachine | ||
|
||
has_many :cities | ||
end | ||
|
||
class City < ActiveRecord::Base | ||
include ChronoModel::TimeMachine | ||
|
||
belongs_to :country | ||
end | ||
|
||
RSpec.describe ChronoModel::TimeMachine do | ||
include ChronoTest::TimeMachine::Helpers | ||
|
||
describe 'historical association' do | ||
adapter.create_table :countries, temporal: true do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
|
||
adapter.create_table :cities, temporal: true do |t| | ||
t.references :country | ||
t.string :name | ||
t.timestamps | ||
end | ||
|
||
it 'returns historical association at the last time when record is valid' do | ||
country = Country.create name: 'Country' | ||
city = country.cities.create name: 'City' | ||
|
||
city.transaction do | ||
country.update_column :name, 'Country 2' | ||
city.update_column :name, 'City 2' | ||
end | ||
|
||
expect(country.history.first.cities.first.name).to eq 'City' | ||
end | ||
end | ||
end |