Created
January 31, 2014 00:11
-
-
Save rafaelfranca/8722894 to your computer and use it in GitHub Desktop.
default_scope on 4.1
This file contains 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
-- create_table(:users) | |
D, [2014-01-30T22:10:52.725995 #81566] DEBUG -- : (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) | |
-> 0.0054s | |
Run options: --seed 18199 | |
# Running: | |
D, [2014-01-30T22:10:52.750686 #81566] DEBUG -- : (0.1ms) begin transaction | |
D, [2014-01-30T22:10:52.753069 #81566] DEBUG -- : SQL (0.1ms) INSERT INTO "users" ("name") VALUES (?) [["name", "Rafael"]] | |
D, [2014-01-30T22:10:52.753319 #81566] DEBUG -- : (0.0ms) commit transaction | |
D, [2014-01-30T22:10:52.753790 #81566] DEBUG -- : (0.0ms) begin transaction | |
D, [2014-01-30T22:10:52.754165 #81566] DEBUG -- : SQL (0.1ms) INSERT INTO "users" ("name") VALUES (?) [["name", "Kassio"]] | |
D, [2014-01-30T22:10:52.754323 #81566] DEBUG -- : (0.0ms) commit transaction | |
D, [2014-01-30T22:10:52.755805 #81566] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "users" WHERE "users"."name" = 'Rafael' AND "users"."name" = 'Kassio' | |
F | |
Finished in 0.019731s, 50.6817 runs/s, 50.6817 assertions/s. | |
1) Failure: | |
BugTest#test_association_stuff [scope.rb:40]: | |
Expected: 1 | |
Actual: 0 | |
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips |
This file contains 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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'sqlite3' | |
GEMFILE | |
system 'bundle' | |
end | |
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 :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