Created
March 11, 2013 08:51
-
-
Save senny/5132876 to your computer and use it in GitHub Desktop.
rails issue reproduction: https://github.com/rails/rails/issues/6769
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
require 'active_record' | |
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:" | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :users do |t| | |
t.timestamps | |
end | |
create_table :activities do |t| | |
t.integer :user_id | |
t.timestamps | |
end | |
end | |
class User < ActiveRecord::Base | |
has_many :activities, :order => "created_at desc" | |
end | |
class Activity < ActiveRecord::Base | |
end | |
u = User.create | |
a2 = u.activities.create | |
a1 = u.activities.create(created_at: 1.day.ago) | |
a3 = u.activities.create | |
users = User.includes(:activities).where("activities.created_at < ?", Time.now).to_a | |
expected_ids = [a3.id, a2.id, a1.id] | |
actual_ids = users.first.activities.map(&:id) | |
if expected_ids != actual_ids | |
raise "Expected #{expected_ids} to match #{actual_ids}" | |
else | |
puts "PASSED!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment