Skip to content

Instantly share code, notes, and snippets.

@dabit
Last active August 29, 2015 14:16
Show Gist options
  • Save dabit/ce178a544680d9d06e87 to your computer and use it in GitHub Desktop.
Save dabit/ce178a544680d9d06e87 to your computer and use it in GitHub Desktop.
.last sort conundrum
# Activate the gem you are reporting the issue against.
# gem install activerecord -v '3.2.19'
gem 'activerecord', '3.2.19'
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 :posts, force: true do |t|
t.string :name
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class BugTest < Minitest::Test
def test_last_stuff
10.times { Post.create!(name: rand(9999).to_s) }
records = Post.find(10, 5, 7, 9, 3)
assert_equal records.last, records[4]
end
def test_default_scope
10.times { Post.create!(name: rand(9999).to_s) }
records = Post.order(:name).where(id: [10, 5, 7, 9, 3])
assert_equal records.last, records[4]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment