Slide 1

Slide 1 text

CLONE THE REPO Grab a USB or clone the railsconf_scripts repo from https://github.com/eileencodes/railsconf_scripts.git $ cd railsconf_scripts # mac/linux users $ bundle install --local # windows users not using a linux VM $ git checkout windows $ bundle install --local

Slide 2

Slide 2 text

BREAKING DOWN THE Demystifying Contributing to Ruby on Rails BARRIER:

Slide 3

Slide 3 text

EILEEN M. UCHITELLE Programmer at Basecamp ! eileencodes.com " @eileencodes # @eileencodes

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Kingston, New York

Slide 6

Slide 6 text

Arya @aryadog

Slide 7

Slide 7 text

PREREQUISITES

Slide 8

Slide 8 text

GOALS

Slide 9

Slide 9 text

to Rails can be INTIMIDATING. CONTRIBUTING

Slide 10

Slide 10 text

to Rails open source can be is INTIMIDATING. CONTRIBUTING #

Slide 11

Slide 11 text

FORMAT

Slide 12

Slide 12 text

CLONE THE REPO Grab a USB or clone the railsconf_scripts repo from github.com/eileencodes/railsconf_scripts $ cd railsconf_scripts/ # mac/linux users $ bundle install --local # windows users not using a linux VM $ git checkout windows $ bundle install --local

Slide 13

Slide 13 text

ENVIRONMENT REQUIREMENTS

Slide 14

Slide 14 text

ENVIRONMENT $ Ruby version manager (rbenv, rvm, chruby) $ Ruby 2.2.2

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

% Ruby version manager (rbenv, rvm, chruby) % Ruby 2.2.2 $ Databases for Active Record $ MySQL $ PostgreSQL $ SQLite3 ENVIRONMENT

Slide 17

Slide 17 text

% Ruby version manager (rbenv, rvm, chruby) % Ruby 2.2.2 % Databases for Active Record % MySQL % PostgreSQL % SQLite3 $ Git & a GitHub Account ENVIRONMENT

Slide 18

Slide 18 text

RUNNING THE TEST SUITE

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

RUNNING TESTS $ cd actionpack $ rake test Finished in 3.237796s, 861.0796 runs/ s, 4508.3137 assertions/s.
 2788 runs, 14597 assertions, 0 failures, 0 errors, 0 skips

Slide 21

Slide 21 text

ACTIVE RECORD $ cd activerecord $ rake test:sqlite3 $ rake test:mysql2 $ rake test:mysql $ rake test:postgresql

Slide 22

Slide 22 text

$ ruby -Ilib:test path/to/test_file.rb RUN A TEST FILE

Slide 23

Slide 23 text

$ ruby -Ilib:test path/to/test_file.rb -n test_name_of_test RUN A SINGLE TEST

Slide 24

Slide 24 text

RUN A SINGLE TEST $ ARCONN=mysql2 ruby -Ilib:test path/ to/test_file.rb -n test_name_of_test

Slide 25

Slide 25 text

$ bundle exec rake TEST=path/to/ test_file.rb -n test_name RUN A SINGLE TEST

Slide 26

Slide 26 text

$ cd activerecord/ $ rake test:sqlite3 $ ruby -Ilib:test test/cases/ reflection_test.rb $ ARCONN=mysql2 ruby -Ilib:test test/ cases/reflection_test.rb -n test_columns RUNNING TESTS

Slide 27

Slide 27 text

GUIDELINES FOR OPENING AN ISSUE

Slide 28

Slide 28 text

OPENING AN ISSUE $ Be clear and include the Rails version

Slide 29

Slide 29 text

OPENING AN ISSUE % Be clear and include the Rails version $ Don’t open security issues on the issues tracker

Slide 30

Slide 30 text

Slide 31

Slide 31 text

OPENING AN ISSUE % Be clear and include the Rails version % Don’t open security issues on the issues tracker $ Don’t open issues that aren’t a bug in Rails

Slide 32

Slide 32 text

OPENING AN ISSUE % Be clear and include the Rails version % Don’t open security issues on the issues tracker % Don’t open issues that aren’t a bug in Rails $ Don’t open a separate issue if you have a PR

Slide 33

Slide 33 text

OPENING AN ISSUE % Be clear and include the Rails version % Don’t open security issues on the issues tracker % Don’t open issues that aren’t a bug in Rails % Don’t open a separate issue if you have a PR $ Don’t open feature request tickets

Slide 34

Slide 34 text

OPENING AN ISSUE % Be clear and include the Rails version % Don’t open security issues on the issues tracker % Don’t open issues that aren’t a bug in Rails % Don’t open a separate issue if you have a PR % Don’t open feature request tickets % Do include a test script or application

Slide 35

Slide 35 text

Examples of executable scripts github.com/rails/rails/blob/master/ guides/bug_report_templates TEST SCRIPTS

Slide 36

Slide 36 text

$ cd railsconf_scripts/ $ open ar_script_example.rb TEST SCRIPTS

Slide 37

Slide 37 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 38

Slide 38 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 39

Slide 39 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 40

Slide 40 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 41

Slide 41 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 42

Slide 42 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 43

Slide 43 text

require 'active_record' require 'minitest/autorun' require 'logger' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base validates_presence_of :name end class BugTest < Minitest::Test def test_assert project = Project.create! assert_not_operator project, :valid? end end

Slide 44

Slide 44 text

TEST SCRIPTS $ cd railsconf_scripts/ $ bundle exec ruby ar_script_example.rb

Slide 45

Slide 45 text

GUIDELINES FOR OPENING A PULL REQUEST

Slide 46

Slide 46 text

OPENING A PR $ Open PR’s against master

Slide 47

Slide 47 text

OPENING A PR % Open PR’s against master $ We don’t accept “cosmetic changes”

Slide 48

Slide 48 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” $ Write clear and descriptive commit messages

Slide 49

Slide 49 text

Short (50 chars or less) summary of changes More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. Further paragraphs come after blank lines. - Bullet points are okay, too - Typically a hyphen or asterisk is used for the bullet, preceded by a single space, with blank lines in between, but conventions vary here

Slide 50

Slide 50 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” % Write clear and descriptive commit messages $ Be prepared to squash your commits

Slide 51

Slide 51 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” % Write clear and descriptive commit messages % Be prepared to squash your commits $ Don’t ping constantly or litter PR’s with +1’s

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” % Write clear and descriptive commit messages % Be prepared to squash your commits % Don’t ping constantly or litter PR’s with +1’s $ We <3 documentation PR’s

Slide 54

Slide 54 text

commit 02d3a253610eaf9c80587913b366e3fa0f56b71f Author: eileencodes Date: Sat Oct 4 11:19:37 2014 -0400 [ci skip] Clarify deletion strategies for collection proxies For detailed testing of behavior see: https://gist.github.com/eileencodes/ 5b0a2fe011dcff6203fe This shows destroy_all always destroys records and fires callbacks. It will never use nullify or delete_all delete_all's behavior varies greatly based on `hm` vs `hm:t` and deletion strategy.

Slide 55

Slide 55 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” % Write clear and descriptive commit messages % Be prepared to squash your commits % Don’t ping constantly or litter PR’s with +1’s % We <3 documentation PR’s $ Keep it simple

Slide 56

Slide 56 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” % Write clear and descriptive commit messages % Be prepared to squash your commits % Don’t ping constantly or litter PR’s with +1’s % We <3 documentation PR’s % Keep it simple $ Use Benchmark/ips

Slide 57

Slide 57 text

$ cd railsconf_scripts/ $ open benchmark_ips_example.rb BENCHMARK/IPS

Slide 58

Slide 58 text

# railsconf_scripts/benchmark_ips_example.rb require 'benchmark/ips' ARRAY = (1..100).to_a def slow ARRAY.shuffle.first end def fast ARRAY.sample end Benchmark.ips do |x| x.report('slow') { slow } x.report('fast') { fast } x.compare! end

Slide 59

Slide 59 text

# railsconf_scripts/benchmark_ips_example.rb require 'benchmark/ips' ARRAY = (1..100).to_a def slow ARRAY.shuffle.first end def fast ARRAY.sample end Benchmark.ips do |x| x.report('slow') { slow } x.report('fast') { fast } x.compare! end

Slide 60

Slide 60 text

# railsconf_scripts/benchmark_ips_example.rb require 'benchmark/ips' ARRAY = (1..100).to_a def slow ARRAY.shuffle.first end def fast ARRAY.sample end Benchmark.ips do |x| x.report('slow') { slow } x.report('fast') { fast } x.compare! end

Slide 61

Slide 61 text

# railsconf_scripts/benchmark_ips_example.rb require 'benchmark/ips' ARRAY = (1..100).to_a def slow ARRAY.shuffle.first end def fast ARRAY.sample end Benchmark.ips do |x| x.report('slow') { slow } x.report('fast') { fast } x.compare! end

Slide 62

Slide 62 text

$ bundle exec ruby benchmark_ips_example.rb Calculating ------------------------------------- slow 26.801k i/100ms fast 131.410k i/100ms ------------------------------------------------- slow 343.594k (± 5.4%) i/s - 1.715M fast 6.348M (±11.8%) i/s - 31.276M Comparison: fast: 6347552.5 i/s slow: 343594.2 i/s - 18.47x slower

Slide 63

Slide 63 text

$ cd railsconf_scripts/ $ bundle exec ruby BENCHMARK/IPS benchmark_ips_example.rb

Slide 64

Slide 64 text

OPENING A PR % Open PR’s against master % We don’t accept “cosmetic changes” % Write clear and descriptive commit messages % Be prepared to squash your commits % Don’t ping constantly or litter PR’s with +1’s % We <3 documentation PR’s % Keep it simple % Use Benchmark/ips $ Write tests

Slide 65

Slide 65 text

WORKING WITH DEPRECATIONS

Slide 66

Slide 66 text

# nodoc example from activerecord/lib/active_record/ reflection.rb:588 class HasManyReflection < AssociationReflection # :nodoc: def initialize(name, scope, options, active_record) super(name, scope, options, active_record) end def macro; :has_many; end def collection?; true; end end

Slide 67

Slide 67 text

# Deprecation from activerecord/lib/active_record/tasks/ # database_tasks.rb:207 def load_schema_for(*args) ActiveSupport::Deprecation.warn(<<-MSG.squish) This method was renamed to `#load_schema` and will be removed in the future. Use `#load_schema` instead. MSG load_schema(*args) end

Slide 68

Slide 68 text

TRAVERSING UNFAMILIAR CODE

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

# actionview/lib/action_view/template/error.rb:118 def source_location if line_number "on line ##{line_number} of " else 'in ' end + file_name end

Slide 71

Slide 71 text

SOURCE LOCATION $ cd railsconf_scripts/ $ open source_location.rb

Slide 72

Slide 72 text

class Project < ActiveRecord::Base has_many :projects end class Comment < ActiveRecord::Base belongs_to :project end class BugTest < Minitest::Test def test_delete_all post = Post.create!(title: "Post title", content: "Lots of content") comment = Comment.create!(content: "I am a comment", post_id: post.id) assert 1, post.comments.count post.comments.delete_all assert 0, post.comments.count end end

Slide 73

Slide 73 text

class Project < ActiveRecord::Base has_many :projects end class Comment < ActiveRecord::Base belongs_to :project end class BugTest < Minitest::Test def test_delete_all post = Post.create!(title: "Post title", content: "Lots of content") comment = Comment.create!(content: "I am a comment", post_id: post.id) assert 1, post.comments.count puts post.comments.method(:delete_all).source_location assert 0, post.comments.count end end

Slide 74

Slide 74 text

SOURCE LOCATION $ cd railsconf_scripts/ $ bundle exec ruby source_location.rb

Slide 75

Slide 75 text

(0.0ms) begin transaction SQL (0.1ms) INSERT INTO "comments" ("content", "post_id") VALUES (?, ?) [["content", "I am a comment"], ["post_id", 1]] (0.0ms) commit transaction (0.1ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]] .../activerecord/lib/active_record/associations/ collection_proxy.rb 442 (0.0ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]]

Slide 76

Slide 76 text

# activerecord/lib/active_record/associations/ collection_proxy.rb:442 def delete_all(dependent = nil) @association.delete_all(dependent) end

Slide 77

Slide 77 text

CTags # OS X $ brew install ctags # Debian-based linux $ sudo apt-get install exuberant-ctags # Red Hat-based linux $ sudo yum install ctags

Slide 78

Slide 78 text

CTags $ cd path/to/rails/ $ ctags -R .

Slide 79

Slide 79 text

CTags $ cd path/to/rails/ $ ctags -R -f .git/tags .

Slide 80

Slide 80 text

CTags Sublime: github.com/SublimeText/CTags TextMate: github.com/textmate/ ctags.tmbundle

Slide 81

Slide 81 text

# .vimrc map rt :!ctags --tag-relative --extra=+f - Rf.git/tags --exclude=.git,pkg —languages=- javascript,sql set tags+=.git/tags

Slide 82

Slide 82 text

CTags $ CTRL + ]

Slide 83

Slide 83 text

CTags $ :ts

Slide 84

Slide 84 text

CTags $ :ts $ N + ENTER

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

# activerecord/lib/active_record/reflection.rb:314 def association_primary_key(klass = nil) options[:primary_key] || primary_key(klass || self.klass) end

Slide 87

Slide 87 text

# activerecord/lib/active_record/reflection.rb:314 def association_primary_key(klass = nil) puts caller options[:primary_key] || primary_key(klass || self.klass) end

Slide 88

Slide 88 text

.../through_association.rb:48:in `construct_join_attributes' .../has_many_through_association.rb:169:in `through_records_for' .../has_many_through_association.rb:180:in `block in delete_through_records' .../has_many_through_association.rb:179:in `each' .../has_many_through_association.rb:179:in `delete_through_records' .../has_many_through_association.rb:154:in `delete_records' .../has_many_through_association.rb:124:in `delete_or_nullify_all_records' .../collection_association.rb:214:in `delete_all' .../collection_proxy.rb:443:in `delete_all’ ar_test_scripts/ar_rails_test.rb:85:in `'

Slide 89

Slide 89 text

.../activerecord/lib/active_record/associations/ through_association.rb:48:in `block in construct_join_attributes’

Slide 90

Slide 90 text

def construct_join_attributes(*records) ensure_mutable if source_reflection.association_primary_key(reflection.klass) == reflection.klass.primary_key join_attributes = { source_reflection.name => records } else join_attributes = { source_reflection.foreign_key => records.map { |record| record.send(source_reflection.association_primary_key( reflection.klass)) } } end if options[:source_type] join_attributes[source_reflection.foreign_type] = records.map { |record| record.class.base_class.name } [...]

Slide 91

Slide 91 text

CALLER $ cd railsconf_scripts/ $ open puts_caller.rb

Slide 92

Slide 92 text

ActiveRecord::Schema.define do create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base after_create :call_me def call_me puts "======== i am a callback ========" end end class BugTest < Minitest::Test def test_create project = Project.create!(name: "whatever") end end

Slide 93

Slide 93 text

create_table :projects do |t| t.string :name end end class Project < ActiveRecord::Base after_create :call_me def call_me puts caller puts "======== i am a callback ========" end end class BugTest < Minitest::Test def test_create project = Project.create!(name: "whatever") end end

Slide 94

Slide 94 text

CALLER $ bundle exec ruby puts_caller.rb

Slide 95

Slide 95 text

.../activesupport/lib/active_support/callbacks.rb:428:in `block in make_lambda' .../activesupport/lib/active_support/callbacks.rb:229:in `call' .../activesupport/lib/active_support/callbacks.rb:229:in `block in halting_and_conditional' .../activesupport/lib/active_support/callbacks.rb:502:in `call' .../activesupport/lib/active_support/callbacks.rb:502:in `block in call' .../activesupport/lib/active_support/callbacks.rb:502:in `each' .../activesupport/lib/active_support/callbacks.rb:502:in `call' .../activesupport/lib/active_support/callbacks.rb:90:in `run_callbacks' .../activerecord/lib/active_record/callbacks.rb:305:in `_create_record' .../activerecord/lib/active_record/timestamp.rb:57:in `_create_record' .../activerecord/lib/active_record/persistence.rb:506:in `create_or_update' .../activerecord/lib/active_record/callbacks.rb:301:in `block in create_or_update' .../activesupport/lib/active_support/callbacks.rb:86:in `run_callbacks' .../activerecord/lib/active_record/callbacks.rb:301:in `create_or_update' .../activerecord/lib/active_record/persistence.rb:151:in `save!' [...]

Slide 96

Slide 96 text

.../activesupport/lib/active_support/callbacks.rb: 428:in `block in make_lambda'

Slide 97

Slide 97 text

def make_lambda(filter) case filter when Symbol lambda { |target, _, &blk| target.send filter, &blk } when String l = eval "lambda { |value| #{filter} }" lambda { |target, value| target.instance_exec(value, &l) } when Conditionals::Value then filter when ::Proc if filter.arity > 1 return lambda { |target, _, &blk| raise ArgumentError unless block target.instance_exec(target, block, &filter) } end if filter.arity <= 0 lambda { |target, _| target.instance_exec(&filter) } else lambda { |target, _| target.instance_exec(target, &filter) } [...]

Slide 98

Slide 98 text

def test_reject_if_method_without_arguments Pirate.accepts_nested_attributes_for :ship, reject_if: :new_record? pirate = Pirate.new(catchphrase: "Stop wastin' me time") pirate.ship_attributes = { name: 'Black Pearl' } assert_no_difference('Ship.count') { pirate.save! } end

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

def test_reject_if_method_without_arguments Pirate.accepts_nested_attributes_for :ship, reject_if: :new_record? pirate = Pirate.new(catchphrase: "Stop wastin' me time") tp = TracePoint.new(:call) do |*args| p args end tp.enable pirate.ship_attributes = { name: 'Black Pearl' } tp.disable assert_no_difference('Ship.count') { pirate.save! } end

Slide 101

Slide 101 text

def test_reject_if_method_without_arguments Pirate.accepts_nested_attributes_for :ship, reject_if: :new_record? pirate = Pirate.new(catchphrase: "Stop wastin' me time") tp = TracePoint.new(:call) do |*args| p args end tp.enable pirate.ship_attributes = { name: 'Black Pearl' } tp.disable assert_no_difference('Ship.count') { pirate.save! } end

Slide 102

Slide 102 text

def test_reject_if_method_without_arguments Pirate.accepts_nested_attributes_for :ship, reject_if: :new_record? pirate = Pirate.new(catchphrase: "Stop wastin' me time") tp = TracePoint.new(:call) do |*args| p args end tp.enable pirate.ship_attributes = { name: 'Black Pearl' } tp.disable assert_no_difference('Ship.count') { pirate.save! } end

Slide 103

Slide 103 text

def test_reject_if_method_without_arguments Pirate.accepts_nested_attributes_for :ship, reject_if: :new_record? pirate = Pirate.new(catchphrase: "Stop wastin' me time") tp = TracePoint.new(:call) do |*args| p args end tp.enable pirate.ship_attributes = { name: 'Black Pearl' } tp.disable assert_no_difference('Ship.count') { pirate.save! } end

Slide 104

Slide 104 text

def test_reject_if_method_without_arguments Pirate.accepts_nested_attributes_for :ship, reject_if: :new_record? pirate = Pirate.new(catchphrase: "Stop wastin' me time") tp = TracePoint.new(:call) do |*args| p args end tp.enable pirate.ship_attributes = { name: 'Black Pearl' } tp.disable assert_no_difference('Ship.count') { pirate.save! } end

Slide 105

Slide 105 text

`ship_attributes='@.../activerecord/lib/active_record/nested_attributes.rb:347 `assign_nested_attributes_for_one_to_one_association'@.../activerecord/lib/active_record/ nested_attributes.rb:382 `nested_attributes_options'@.../activesupport/lib/active_support/core_ext/class/attribute.rb:106 `nested_attributes_options'@.../activesupport/lib/active_support/core_ext/class/attribute.rb:86 `with_indifferent_access'@.../activesupport/lib/active_support/core_ext/hash/indifferent_access.rb:8 `new_from_hash_copying_default'@.../activesupport/lib/active_support/hash_with_indifferent_access.rb:75 `initialize'@.../activesupport/lib/active_support/hash_with_indifferent_access.rb:58 `update'@.../activesupport/lib/active_support/hash_with_indifferent_access.rb:127 `convert_key'@.../activesupport/lib/active_support/hash_with_indifferent_access.rb:258 `convert_value'@.../activesupport/lib/active_support/hash_with_indifferent_access.rb:262 `ship'@.../activerecord/lib/active_record/associations/builder/association.rb:110 `association'@.../activerecord/lib/active_record/associations.rb:149 `association_instance_get’@.../activerecord/lib/active_record/associations.rb:189 `_reflect_on_association'@.../activerecord/lib/active_record/reflection.rb:109 `_reflections'@.../activesupport/lib/active_support/core_ext/class/attribute.rb:86 `association_class'@.../activerecord/lib/active_record/reflection.rb:435 `macro'@.../activerecord/lib/active_record/reflection.rb:588 `require'@.../activesupport/lib/active_support/dependencies.rb:272 `load_dependency'@.../activesupport/lib/active_support/dependencies.rb:236 `load?'@.../activesupport/lib/active_support/dependencies.rb:311 `mechanism'@.../activesupport/lib/active_support/core_ext/module/attribute_accessors.rb:60 `constant_watch_stack'@.../activesupport/lib/active_support/core_ext/module/attribute_accessors.rb:60 `watching?'@.../activesupport/lib/active_support/dependencies.rb:99 `delegate'@.../activesupport/lib/active_support/core_ext/module/delegation.rb:151 `include?'@/Users/eileen/.rbenv/versions/2.2.0/lib/ruby/2.2.0/set.rb:211 `initialize'@.../activerecord/lib/active_record/associations/association.rb:24 `check_validity!'@.../activerecord/lib/active_record/reflection.rb:331 `check_validity_of_inverse!’@.../activerecord/lib/active_record/reflection.rb:335 ...

Slide 106

Slide 106 text

`ship_attributes='@.../activerecord/lib/active_record/ nested_attributes.rb:347

Slide 107

Slide 107 text

def generate_association_writer(association_name, type) generated_association_methods.module_eval <<-eoruby, __FILE__, __LINE__ + 1 if method_defined?(:#{association_name}_attributes=) remove_method(:#{association_name}_attributes=) end def #{association_name}_attributes=(attributes) assign_nested_attributes_for_#{type} _association(:#{association_name}, attributes) end eoruby end

Slide 108

Slide 108 text

TRACE POINT $ cd railsconf_scripts/ $ open trace_point.rb

Slide 109

Slide 109 text

class User < ActiveRecord::Base has_one :avatar accepts_nested_attributes_for :avatar end class Avatar < ActiveRecord::Base belongs_to :user end class BugTest < Minitest::Test def test_trace_point user = User.new(name: "My Name") user.avatar_attributes = { name: "I am a file name" } user.save! end end

Slide 110

Slide 110 text

end class Avatar < ActiveRecord::Base belongs_to :user end class BugTest < Minitest::Test def test_trace_point user = User.new(name: "My Name") tp = TracePoint.new(:call) do |*args| p args end user.avatar_attributes = { name: "I am a file name" } user.save! end end

Slide 111

Slide 111 text

class Avatar < ActiveRecord::Base belongs_to :user end class BugTest < Minitest::Test def test_trace_point user = User.new(name: "My Name") tp = TracePoint.new(:call) do |*args| p args end tp.enable user.avatar_attributes = { name: "I am a file name" } tp.disable user.save! end end

Slide 112

Slide 112 text

TRACE POINT $ bundle exec ruby trace_point.rb

Slide 113

Slide 113 text

`avatar_attributes='@.../activerecord/lib/active_record/ nested_attributes.rb:347

Slide 114

Slide 114 text

ADVANCED GIT COMMANDS

Slide 115

Slide 115 text

GIT $ git add . $ git commit -m‘Commit message’ $ git checkout practicing-git

Slide 116

Slide 116 text

GIT $ git add upstream $ git bisect $ git reset --[soft|hard] $ git rebase -i $ git reflog

Slide 117

Slide 117 text

GIT REMOTES $ cd path/to/rails/ $ git remote add upstream https://github.com/rails/rails.git

Slide 118

Slide 118 text

GIT REMOTES $ cd path/to/rails/ $ git remote remove upstream $ git remote add upstream https://github.com/rails/rails.git

Slide 119

Slide 119 text

GIT REMOTES $ git pull —-rebase upstream master

Slide 120

Slide 120 text

GIT REMOTES $ git pull —-rebase upstream master $ git push origin master

Slide 121

Slide 121 text

GIT BISECT $ git bisect

Slide 122

Slide 122 text

GIT BISECT $ git bisect start

Slide 123

Slide 123 text

GIT BISECT $ git bisect bad $ git bisect good v4.2.rc3

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

Practice Git Bisect C1 C2 C3 C4 C5 C6 M3 M4 M0

Slide 126

Slide 126 text

AMENDING COMMITS $ git commit --amend

Slide 127

Slide 127 text

GIT RESET $ git reset --soft HEAD@{1}

Slide 128

Slide 128 text

GIT RESET $ git reset --soft HEAD~N

Slide 129

Slide 129 text

GIT RESET $ git reset HEAD

Slide 130

Slide 130 text

Git Reset M1 M2 M3 M4 M0 master HEAD Practice

Slide 131

Slide 131 text

GIT REBASE -I $ git rebase -i master

Slide 132

Slide 132 text

GIT

Slide 133

Slide 133 text

1 pick e92e34f Refactor existing code 2 pick 80601e8 Oops add in missing code 3 pick 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 pick 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 134

Slide 134 text

1 pick e92e34f Refactor existing code 2 pick 80601e8 Oops add in missing code 3 pick 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 pick 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 135

Slide 135 text

1 reword e92e34f Refactor existing code 2 pick 80601e8 Oops add in missing code 3 pick 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 pick 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 136

Slide 136 text

1 reword e92e34f Refactor existing code 2 pick 80601e8 Oops add in missing code 3 edit 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 pick 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 137

Slide 137 text

1 reword e92e34f Refactor existing code 2 pick 80601e8 Oops add in missing code 3 edit 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 squash 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 138

Slide 138 text

1 reword e92e34f Refactor existing code 2 fixup 80601e8 Oops add in missing code 3 edit 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 squash 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 139

Slide 139 text

1 reword e92e34f Refactor existing code 2 fixup 80601e8 Oops add in missing code 3 edit 8d91f76 Remove extra piece I left behind 4 pick 933bd58 Fix bug reported in #9895 5 squash 99302ef Clean up changes 6 pick 5cc3c5a Fix spelling mistake in documentation 7 8 # Rebase 0131d99..5cc3c5a onto 0131d99 9 # 10 # Commands: 11 # p, pick = use commit 12 # r, reword = use commit, but edit the commit message 13 # e, edit = use commit, but stop for amending 14 # s, squash = use commit, but meld into previous commit 15 # f, fixup = like "squash", but discard this commit's log 16 # x, exec = run command (the rest of the line) using shell

Slide 140

Slide 140 text

Practice M1 M2 M3 M4 F1 F2 F1 F2 M0 Interactive Rebase

Slide 141

Slide 141 text

FORCE PUSH $ git push -f origin your-branch

Slide 142

Slide 142 text

GIT REFLOG $ git reflog

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

GIT REFLOG $ git reflog

Slide 145

Slide 145 text

628c168 HEAD@{0}: rebase -i (finish): returning to refs/heads/your-branch 628c168 HEAD@{1}: rebase -i (start): checkout master 628c168 HEAD@{2}: reset: moving to 628c168 bc503a1 HEAD@{3}: rebase -i (finish): returning to refs/heads/your-branch bc503a1 HEAD@{4}: rebase -i (pick): Add Person model and migration 1ad2ff2 HEAD@{5}: rebase -i (pick): Improve README section on git reflog 026457d HEAD@{6}: rebase -i (start): checkout master 633f620 HEAD@{7}: rebase -i (finish): returning to refs/heads/your-branch 633f620 HEAD@{8}: rebase -i (pick): Improve README section on git reflog 19f41a7 HEAD@{9}: commit (amend): Add Person model and migration 50718b1 HEAD@{10}: rebase -i (edit): Add Person model and migration 026457d HEAD@{11}: rebase -i (reword): Update README with sections on rebase and c8c6000 HEAD@{12}: rebase -i (reword): Update README with sections on rebase and 628fbd2 HEAD@{13}: rebase -i (squash): Update README description section 455dab0 HEAD@{14}: rebase -i (fixup): # This is a combination of 2 commits. 4392779 HEAD@{15}: rebase -i (start): checkout master 628c168 HEAD@{16}: rebase -i (finish): returning to refs/heads/your-branch 628c168 HEAD@{17}: rebase -i (start): checkout master 628c168 HEAD@{18}: rebase -i (finish): returning to refs/heads/your-branch 628c168 HEAD@{19}: rebase -i (start): checkout master 628c168 HEAD@{20}: rebase: aborting 1f935f7 HEAD@{21}: rebase -i (edit): Add Person model and migration

Slide 146

Slide 146 text

GIT REFLOG $ git reset -—hard 628c168

Slide 147

Slide 147 text

628168 628168 50718b bc503a1 C1 C2 C3 C4 C0 Git Reflog Practice

Slide 148

Slide 148 text

FINDING ISSUES TO WORK ON

Slide 149

Slide 149 text

WHAT TO WORK ON $ Test release candidates and that master branch

Slide 150

Slide 150 text

WHAT TO WORK ON % Test release candidates and that master branch $ Fix documentation & work on WIP Guides

Slide 151

Slide 151 text

WHAT TO WORK ON % Test release candidates and that master branch % Fix documentation & work on WIP Guides $ Focus on your strengths

Slide 152

Slide 152 text

WHAT TO WORK ON % Test release candidates and that master branch % Fix documentation & work on WIP Guides % Focus on your strengths $ Work on ActiveJob or WebConsole

Slide 153

Slide 153 text

WHAT TO WORK ON % Test release candidates and that master branch % Fix documentation & work on WIP Guides % Focus on your strengths % Work on ActiveJob or WebConsole $ Review open pull requests

Slide 154

Slide 154 text

WHAT TO WORK ON % Test release candidates and that master branch % Fix documentation & work on WIP Guides % Focus on your strengths % Work on ActiveJob or WebConsole % Review open pull requests $ Refactoring methods and tests

Slide 155

Slide 155 text

WHAT TO WORK ON % Test release candidates and that master branch % Fix documentation & work on WIP Guides % Focus on your strengths % Work on ActiveJob or WebConsole % Review open pull requests % Refactoring methods and tests $ Watch the issues tracker

Slide 156

Slide 156 text

WHAT WE COVERED % Getting set up % Guidelines for opening issues % Writing test scripts % Guidelines for opening pull requests % Git % Bisect, Interactive Rebase, Reflog % Traversing unfamiliar code % source_location, CTags, puts caller, TracePoint % Finding issues to work on

Slide 157

Slide 157 text

Thank You!

Slide 158

Slide 158 text

EILEEN M. UCHITELLE Programmer at Basecamp ! eileencodes.com " @eileencodes # @eileencodes Slides: speakerdeck.com/eileencodes