Skip to content

Instantly share code, notes, and snippets.

@cristianbica
Created July 19, 2017 20:47
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 cristianbica/b6f00b2ebb51b10986df3ff788e25885 to your computer and use it in GitHub Desktop.
Save cristianbica/b6f00b2ebb51b10986df3ff788e25885 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", github: "rails/rails"
gem "arel", github: "rails/arel"
gem "sqlite3"
end
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, force: true do |t|
t.references :profile
t.string :email
t.integer :flag, default: 0
end
create_table :profiles, force: true do |t|
t.string :name
end
end
class User < ActiveRecord::Base
belongs_to :profile
before_update do
self.flag = 42
end
end
class Profile < ActiveRecord::Base
has_one :user
end
class BugTest < Minitest::Test
def test_association_stuff
user = User.create!(email: "john@domain.com", profile: Profile.new(name: "John"))
assert_equal 0, user.flag
end
end
ruby before_update_called_on_create.rb
Fetching git://github.com/rails/rails.git
Fetching git://github.com/rails/arel.git
Fetching gem metadata from https://rubygems.org/........
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.6
Using minitest 5.10.2
Using thread_safe 0.3.6
Using builder 3.2.3
Using erubi 1.6.1
Using mini_portile2 2.2.0
Using rack 2.0.3
Using nio4r 2.1.0
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 8.0.0 from git://github.com/rails/arel.git (at master@67a51c6)
Using bundler 1.15.1
Using method_source 0.8.2
Using thor 0.19.4
Using sqlite3 1.3.13
Using tzinfo 1.2.3
Using nokogiri 1.8.0
Using rack-test 0.6.3
Using sprockets 3.7.1
Using websocket-driver 0.6.5
Using mime-types 3.1
Using activesupport 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using loofah 2.0.3
Using mail 2.6.6
Using rails-dom-testing 2.0.3
Using globalid 0.4.0
Using activemodel 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using rails-html-sanitizer 1.0.3
Using activejob 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using activerecord 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using actionview 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using actionpack 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using actioncable 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using actionmailer 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using railties 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
Using sprockets-rails 3.2.0
Using rails 5.2.0.alpha from git://github.com/rails/rails.git (at master@526d4b8)
-- create_table(:users, {:force=>true})
D, [2017-07-19T23:44:11.217374 #7679] DEBUG -- : (0.1ms) DROP TABLE IF EXISTS "users"
D, [2017-07-19T23:44:11.218850 #7679] DEBUG -- : (1.0ms) SELECT sqlite_version(*)
D, [2017-07-19T23:44:11.219418 #7679] DEBUG -- : (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "profile_id" integer, "email" varchar, "flag" integer DEFAULT 0)
D, [2017-07-19T23:44:11.220125 #7679] DEBUG -- : (0.1ms) CREATE INDEX "index_users_on_profile_id" ON "users" ("profile_id")
-> 0.0061s
-- create_table(:profiles, {:force=>true})
D, [2017-07-19T23:44:11.220591 #7679] DEBUG -- : (0.1ms) DROP TABLE IF EXISTS "profiles"
D, [2017-07-19T23:44:11.220938 #7679] DEBUG -- : (0.2ms) CREATE TABLE "profiles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar)
-> 0.0007s
D, [2017-07-19T23:44:11.260424 #7679] DEBUG -- : (0.2ms) CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
D, [2017-07-19T23:44:11.272714 #7679] DEBUG -- : ActiveRecord::InternalMetadata Load (0.2ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ? [["key", "environment"], ["LIMIT", 1]]
D, [2017-07-19T23:44:11.277800 #7679] DEBUG -- : (0.1ms) begin transaction
D, [2017-07-19T23:44:11.279152 #7679] DEBUG -- : SQL (0.1ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["key", "environment"], ["value", "development"], ["created_at", "2017-07-19 20:44:11.278270"], ["updated_at", "2017-07-19 20:44:11.278270"]]
D, [2017-07-19T23:44:11.279584 #7679] DEBUG -- : (0.1ms) commit transaction
Run options: --seed 41792
# Running:
D, [2017-07-19T23:44:11.328134 #7679] DEBUG -- : (0.1ms) begin transaction
D, [2017-07-19T23:44:11.329396 #7679] DEBUG -- : SQL (0.1ms) INSERT INTO "profiles" ("name") VALUES (?) [["name", "John"]]
D, [2017-07-19T23:44:11.330681 #7679] DEBUG -- : SQL (0.1ms) INSERT INTO "users" ("profile_id", "email") VALUES (?, ?) [["profile_id", 1], ["email", "john@domain.com"]]
D, [2017-07-19T23:44:11.331858 #7679] DEBUG -- : SQL (0.1ms) UPDATE "users" SET "flag" = ? WHERE "users"."id" = ? [["flag", 42], ["id", 1]]
D, [2017-07-19T23:44:11.332084 #7679] DEBUG -- : (0.1ms) commit transaction
F
Failure:
BugTest#test_association_stuff [before_update_called_on_create.rb:49]:
Expected: 0
Actual: 42
bin/rails test before_update_called_on_create.rb:47
Finished in 0.025511s, 39.1988 runs/s, 39.1988 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment