Slide 1

Slide 1 text

Please sit as close to the front and center as possible

Slide 2

Slide 2 text

Story Time

Slide 3

Slide 3 text

Story Time

Slide 4

Slide 4 text

Debugging Rails Itself

Slide 5

Slide 5 text

TL;DR: Make Aaron fix it

Slide 6

Slide 6 text

Thank you

Slide 7

Slide 7 text

Debugging Rails Itself

Slide 8

Slide 8 text

Who am I? • Sean Griffin • 10x Hacker Ninja Guru at Shopify • @sgrif on Twitter (please tweet at me during this talk) • Rails Committer • Maintainer of Active Record • Creator of Diesel • Bikeshed co-host

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Anyone can work on Rails

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Do we have a bug in Rails?

Slide 13

Slide 13 text

What even is a bug?

Slide 14

Slide 14 text

Expectations vs reality

Slide 15

Slide 15 text

Features aren't always used as designed

Slide 16

Slide 16 text

Check the docs

Slide 17

Slide 17 text

We think it's a bug. What's next?

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

We need a reproducible test case

Slide 21

Slide 21 text

gemfile(true) do source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem "rails", github: "rails/rails" gem "sqlite3" end

Slide 22

Slide 22 text

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :posts, force: true do |t| end create_table :comments, force: true do |t| t.integer :post_id end end

Slide 23

Slide 23 text

class BugTest < Minitest::Test def test_association_stuff post = Post.create! post.comments << Comment.create! assert_equal 1, post.comments.count assert_equal 1, Comment.count assert_equal post.id, Comment.first.post.id end end

Slide 24

Slide 24 text

The bug needs to be demonstrated with no gems other than Rails

Slide 25

Slide 25 text

Now what?

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

It's time to go bug hunting

Slide 28

Slide 28 text

We need the commit that introduced the bug

Slide 29

Slide 29 text

git bisect (the greatest tool ever)

Slide 30

Slide 30 text

Changing our test script ENV["BUNDLE_GEMFILE"] = "/path/to/rails/Gemfile" require "bundler" Bundler.require

Slide 31

Slide 31 text

Bisecting basics git checkout master git bisect start git bisect bad git checkout 4-2-stable git bisect good

Slide 32

Slide 32 text

Even if you don't fix the bug, bisecting is incredibly useful

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

What if there's no version without the bug?

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

I'm a dinosaur debugger

Slide 37

Slide 37 text

Methods you should know • Kernel#method

Slide 38

Slide 38 text

(Some objects override the method method) Kernel .instance_method(:method) .bind(self) .call

Slide 39

Slide 39 text

Other methods besides the method method • Kernel#method • Method#source_location • Method#super_method • Method#method

Slide 40

Slide 40 text

Methods unrelated to the method method • Kernel#caller • Kernel#raise • Kernel#p

Slide 41

Slide 41 text

git blame

Slide 42

Slide 42 text

git blame context

Slide 43

Slide 43 text

How to not blame people # ~/.gitconfig [alias] context = blame

Slide 44

Slide 44 text

GitHub's UI is helpful for recontexting

Slide 45

Slide 45 text

gif of how to use it

Slide 46

Slide 46 text

Why do we care so much about the commit?

Slide 47

Slide 47 text

Time to fix it!

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

I'm Stuck

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Take a Break

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Find a Pair

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

When you finally fix it

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Anyone can work on Rails

Slide 60

Slide 60 text

Want more Ruby?

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Room 315 2:30 PM

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Please ask me questions now

Slide 67

Slide 67 text

Contact • twitter: @sgrif • github: @sgrif • podcast: bikeshed.fm