Created
August 23, 2015 04:28
-
-
Save hayesr/3756183d34a6305d5143 to your computer and use it in GitHub Desktop.
Timestamp columns are not auto populated for hm:t join tables
This file contains hidden or 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
ENV['FIXTURES_DIR'] = "./" | |
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'rack', github: 'rack/rack' | |
gem 'sqlite3' | |
end | |
require 'active_record' | |
require 'active_record/fixtures' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :students, force: true do |t| | |
end | |
create_table :classrooms, force: true do |t| | |
end | |
create_table :enrollments, force: true do |t| | |
t.integer :classroom_id | |
t.integer :student_id | |
t.timestamps null: false | |
end | |
end | |
class Student < ActiveRecord::Base | |
has_many :enrollments | |
has_many :classrooms, through: :enrollments | |
end | |
class Classroom < ActiveRecord::Base | |
has_many :enrollments | |
has_many :students, through: :enrollments | |
end | |
class Enrollment < ActiveRecord::Base | |
belongs_to :student | |
belongs_to :classroom | |
end | |
class BugTest < Minitest::Test | |
def test_hmt_fixture_loading | |
# One expects these 2 models to be enough, but including enrollments does not work either | |
ActiveRecord::FixtureSet.create_fixtures('./', ['classrooms', 'students']) | |
# => ActiveRecord::StatementInvalid: SQLite3::ConstraintException: NOT NULL constraint failed ... | |
end | |
end |
This file contains hidden or 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
teachers_class: {} |
This file contains hidden or 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
# Attempting to load times explicitly has no effect | |
one: | |
classroom: teachers_class | |
student: jonny | |
created_at: <%= Time.now %> | |
updated_at: <%= Time.now %> |
This file contains hidden or 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
jonny: | |
classrooms: teachers_class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment