Created
December 8, 2014 03:30
-
-
Save al2o3cr/245b9592acd5dfde66bd to your computer and use it in GitHub Desktop.
Test case for Rails #17015
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
Parent Load (0.1ms) SELECT "parents".* FROM "parents" WHERE "parents"."id" = ? LIMIT 1 [["id", 1]] | |
(0.0ms) begin transaction | |
SQL (0.0ms) INSERT INTO "students" DEFAULT VALUES | |
SQL (0.0ms) INSERT INTO "student_parents" ("parent_id", "student_id") VALUES (?, ?) [["parent_id", 1], ["student_id", 1]] | |
(0.0ms) commit transaction |
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
Parent Load (0.1ms) SELECT "parents".* FROM "parents" WHERE "parents"."id" = ? LIMIT 1 [["id", 1]] | |
(0.1ms) begin transaction | |
SQL (0.1ms) INSERT INTO "students" DEFAULT VALUES | |
SQL (0.1ms) INSERT INTO "student_parents" ("parent_id") VALUES (?) [["parent_id", 1]] | |
SQL (0.1ms) UPDATE "student_parents" SET "student_id" = ? WHERE "student_parents"."id" = 1 [["student_id", 1]] | |
(0.0ms) commit transaction |
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
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '4.2.0.rc2' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# 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 do |t| | |
end | |
create_table :student_parents do |t| | |
t.integer :student_id | |
t.integer :parent_id | |
end | |
create_table :parents do |t| | |
end | |
end | |
class Parent < ActiveRecord::Base | |
has_many :student_parents | |
has_many :students, through: :student_parents | |
end | |
class StudentParent < ActiveRecord::Base | |
belongs_to :parent | |
belongs_to :student | |
end | |
class Student < ActiveRecord::Base | |
has_many :student_parents | |
has_many :parents, through: :student_parents | |
accepts_nested_attributes_for :student_parents, allow_destroy: true | |
end | |
class BugTest < Minitest::Test | |
def test_association_stuff | |
parent = Parent.create | |
student = Student.create(parent_ids: [parent.id]) | |
assert_equal 1, StudentParent.count | |
assert_equal 1, StudentParent.first.parent_id | |
assert_equal 1, StudentParent.first.student_id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment