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

Add failing spec for issue #283 #284

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions spec/chrono_model/history_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
expected['sections'] = Section::History if defined?(Section::History)
expected['articles'] = Article::History if defined?(Article::History)

# historical_associations_spec
expected['countries'] = Country::History if defined?(Country::History)
expected['cities'] = City::History if defined?(City::History)

# sti_spec
expected['animals'] = Animal::History if defined?(Animal::History)
expected['elements'] = Element::History if defined?(Element::History)
Expand Down
45 changes: 45 additions & 0 deletions spec/chrono_model/time_machine/historical_association_spec.rb
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
Loading