Skip to content

Instantly share code, notes, and snippets.

@claudiob
Created December 22, 2016 19:48
Show Gist options
  • Save claudiob/5724f2c0aeaf59b356e3955359eee921 to your computer and use it in GitHub Desktop.
Save claudiob/5724f2c0aeaf59b356e3955359eee921 to your computer and use it in GitHub Desktop.
Rails 5.0.1 breaks the behaviour of .group(enum).count with PostgreSQL adapter
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"
# If you change the version to "5.0.0.1", the test will pass.
# `git bisect` says that 9c28c54879 is the first bad commit.
gem "activerecord", "5.0.1"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection adapter: "postgresql"
ActiveRecord::Base.connection.drop_database "test_group_enum"
ActiveRecord::Base.connection.create_database "test_group_enum"
ActiveRecord::Base.establish_connection adapter: "postgresql", database: "test_group_enum"
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.integer :category
end
end
class Post < ActiveRecord::Base
enum category: %i(sport entertainment)
end
class BugTest < Minitest::Test
def test_association_stuff
Post.create! category: 'sport'
Post.create! category: 'entertainment'
# Up to Rails 5.0.0.1, this was the result:
assert_equal Post.group(:category).count, {1=>1, 0=>1}
# Since Rails 5.0.1 this is the result instead:
# assert_equal Post.group(:category).count, {"sport"=>1, "entertainment"=>1}
# `git bisect` says that 9c28c54879 is the first bad commit.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment