Created
January 21, 2014 10:04
-
-
Save senny/8537418 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'bundler' | |
Bundler.setup(:default) | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :posts do |t| | |
t.string :name | |
t.timestamps | |
end | |
create_table :comments do |t| | |
t.integer :post_id | |
end | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class BugTest < Minitest::Test | |
def test_count_stuff | |
post = Post.create! name: "first" | |
post = Post.create! name: "second" | |
post = Post.create! name: "third" | |
assert_equal 3, Post.select("posts.name").count | |
assert_raises(ActiveRecord::StatementInvalid) do | |
Post.select("posts.name, posts.created_at").count | |
end | |
assert_equal 3, Post.select("posts.name, posts.created_at").count(:all) | |
assert_equal 3, Post.select("posts.name, posts.created_at").unscope(:select).count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment