Skip to content

Instantly share code, notes, and snippets.

@rlue
Last active November 27, 2017 10:19
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 rlue/c12e419c36efb30d8071bd2c8a0252bf to your computer and use it in GitHub Desktop.
Save rlue/c12e419c36efb30d8071bd2c8a0252bf to your computer and use it in GitHub Desktop.
Kaminari Issue #931: #page.size borks for certain AR relations (e.g., ordered by association attributes)
# IMPORTANT: This bug report is specific to postgresql. Create the test DB with
#
# $ createdb kaminari
#
# before running this test case.
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "railties", "5.1.4"
gem "activerecord", "5.1.4"
gem "pg"
gem "kaminari-core"
gem "kaminari-activerecord"
end
require "active_record"
require "minitest/autorun"
require "logger"
require "kaminari/core"
require "kaminari/activerecord"
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "kaminari")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.string :title
end
create_table :comments, force: true 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_pagination_stuff
post = Post.create!(title: 'foo')
post.comments << Comment.create!
# PASSES
assert_equal 1, Post.order('posts.title').page.size
# PASSES
assert_equal 1, Comment.left_outer_joins(:post).order('posts.title').page.size
# RAISES DB ERROR
assert_equal 1, Comment.includes(:post).order('posts.title').page.size
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment