Skip to content

Instantly share code, notes, and snippets.

@rafaelfranca
Created January 31, 2014 00:09
Show Gist options
  • Save rafaelfranca/8722869 to your computer and use it in GitHub Desktop.
Save rafaelfranca/8722869 to your computer and use it in GitHub Desktop.
default_scope on 4.0
-- create_table(:users)
D, [2014-01-30T22:08:17.324202 #81447] DEBUG -- : (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255))
-> 0.0057s
Run options: --seed 58805
# Running tests:
D, [2014-01-30T22:08:17.647532 #81447] DEBUG -- : (0.1ms) begin transaction
D, [2014-01-30T22:08:17.682862 #81447] DEBUG -- : SQL (0.3ms) INSERT INTO "users" ("name") VALUES (?) [["name", "Rafael"]]
D, [2014-01-30T22:08:17.683633 #81447] DEBUG -- : (0.2ms) commit transaction
D, [2014-01-30T22:08:17.684807 #81447] DEBUG -- : (0.1ms) begin transaction
D, [2014-01-30T22:08:17.685869 #81447] DEBUG -- : SQL (0.1ms) INSERT INTO "users" ("name") VALUES (?) [["name", "Kassio"]]
D, [2014-01-30T22:08:17.686256 #81447] DEBUG -- : (0.1ms) commit transaction
D, [2014-01-30T22:08:17.688274 #81447] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "users" WHERE "users"."name" = 'Kassio'
.
Finished tests in 0.363451s, 2.7514 tests/s, 2.7514 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.0.2'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# 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 :users do |t|
t.string :name
end
end
class User < ActiveRecord::Base
default_scope { where(name: 'Rafael') }
scope :kassio, -> { where(name: 'Kassio') }
end
class BugTest < Minitest::Test
def test_association_stuff
User.create!(name: 'Rafael')
User.create!(name: 'Kassio')
assert_equal 1, User.kassio.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment