Skip to content

Instantly share code, notes, and snippets.

@devonestes
Last active July 1, 2016 20:51
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 devonestes/369857bc5459f0771fcd5b0e63bb863d to your computer and use it in GitHub Desktop.
Save devonestes/369857bc5459f0771fcd5b0e63bb863d to your computer and use it in GitHub Desktop.
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 'rails', '~> 4.2.3'
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', database: 'devon_test')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.string :author_type
t.integer :author_id
end
create_table :authors, force: true do |t|
t.string :name
end
end
class Post < ActiveRecord::Base
belongs_to :author, polymorphic: true
end
class Person < ActiveRecord::Base
has_many :posts, as: :author
end
class BugTest < Minitest::Test
def test_count_with_hash_params
Post.create(author_type: 'Dude', author_id: 1)
assert_equal Post.count(author_type: 'Dude', author_id: 1), 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment