# frozen_string_literal: true require 'bundler/inline' gemfile(true) do source 'https://rubygems.org' gem 'chrono_model' # Test against latest Chronomodel: # gem 'chrono_model', github: 'ifad/chronomodel' gem 'pg' end require 'chrono_model' require 'minitest/autorun' require 'logger' # Needs a database called `chronomodel_test` ActiveRecord::Base.establish_connection(adapter: 'chronomodel', database: 'chronomodel_test') ActiveRecord::Base.logger = Logger.new($stdout) ActiveRecord::Schema.define do enable_extension :btree_gist create_table :posts, force: true, temporal: true do |t| t.timestamps end create_table :comments, force: true, temporal: true do |t| t.integer :post_id t.timestamps end end class Post < ActiveRecord::Base include ChronoModel::TimeMachine has_many :comments end class Comment < ActiveRecord::Base include ChronoModel::TimeMachine belongs_to :post end class BugTest < Minitest::Test def test_association_stuff post = Post.create! post.comments << Comment.create! assert_equal 1, post.comments.as_of(Time.now).count assert_equal 1, Comment.as_of(Time.now).count assert_equal post.id, Comment.first.post.as_of(Time.now).id end end
There was an error while loading. Please reload this page.