Created
September 5, 2013 17:24
-
-
Save senny/6453323 to your computer and use it in GitHub Desktop.
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
require 'bundler' | |
Bundler.setup(:default) | |
require 'active_record' | |
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 :posts do |t| | |
end | |
create_table :comments do |t| | |
t.integer :post_id | |
end | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post | |
end | |
class BugTest < Minitest::Test | |
def test_association_last | |
post = Post.create! | |
post.comments << Comment.create! | |
post.comments << Comment.create! | |
post.comments << third = Comment.create! | |
assert_equal third, post.comments.last | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmmm having trouble getting this to run — can't locate MiniTest, precisely:
So here's a little test out of my own suite that exhibits the issue, note this is running rails 3.2.14.
This fails with:
And the SQL executed is:
Take Load (0.3ms) SELECT "takes".* FROM "takes" WHERE "takes"."session_id" = 631
(Adding order("created_at") before .last gets it passing)
How should I proceed with this?