Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created February 20, 2014 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurnn/9117192 to your computer and use it in GitHub Desktop.
Save arthurnn/9117192 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'minitest/autorun'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(adapter: "postgresql", host: "localhost", user: "postgres", database: "test")
class User < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
end
has_many :profile_pictures
end
class ProfilePicture < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
t.integer :user_id
t.timestamps
end
belongs_to :user
end
class ProfileView < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
t.integer :user_id
t.timestamps
end
belongs_to :user
end
class BugTest < MiniTest::Unit::TestCase
def test_home
u = User.create!
ProfilePicture.create!(user: u)
ProfileView.create!(user: u)
id = User.includes(:profile_pictures).joins('LEFT JOIN profile_views ON profile_views.user_id = users.id').order('profile_views.created_at NULLS FIRST').first.id
assert u.id, id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment