Skip to content

Instantly share code, notes, and snippets.

@jamesyang124
Last active October 16, 2015 02:55
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 jamesyang124/2e2c09a34c34a81bd4cf to your computer and use it in GitHub Desktop.
Save jamesyang124/2e2c09a34c34a81bd4cf to your computer and use it in GitHub Desktop.

Process:

1. git clone git@github.com:rails/rails.git

2. git branch -b <new_branch>

3. git checkout <new_branch>

4. code work, add CHANGELOG.md

5. git add .

6. git commit -m "msg" OR git commit --amend -m "msg"

5. git checkout master

6. git fetch <remote>

7. git checkout <new_branch>

8. fork rails to your repo.

8. git remote add <your_repo> git@github.com:<your_account>/rails.git

9. git push <your_repo> <new_branch>

10. pull new request, Base from rails/rails.git, Head from  <your_account>/rails.git

11. If need more commits, just repeat step 9.

Pull request rails/rails.git #15584

Run Single Test:

Example: under /activerecord folder

ARCONN=sqlite3 ruby -I test ./test/cases/finder_test.rb -n <test_method>
cd ./activerecord/
bundle exec rake testqlite3
check file ./activerecord/RUNNING_UNIT_TESTS.rdoc

Example: under rails folder

bundle exec rake test
pry-byebug
require 'pry-byebug'
rvm gemset list
rvm <ruby_version or empty for current>@<gem_set_name> do <gem commands ex: gem lsit>

rails issue 15985
rails issue 15892
rails issue 15584
rails issue 15861
rails issue 15985

  • This issue is becuase by default reader methods set force_load to false which eager loading may require reload to reevaluate sql query from that lambda. Workaround is suffix reload or seperate lambda out as a named scope.
# activerecord/lib/active_record/associations/collection_association.rb
class CollectionAssociation < Association #:nodoc:
  # Implements the reader method, e.g. foo.items for Foo.has_many :items
  def reader(force_reload = false)
  if force_reload
    klass.uncached { reload }
  elsif stale_target?
    reload
  end

  # content of proxy are all ok, but proxy.target have not updated yet.
  # need reload, reset, load_records to update it.
  # which may conflict other test cases due to force_load set to false by default.
  # and this methods is dynamic generated by define_readers.
  # Thus hard to alter arguments for it.
  # or call Blog.first.posts(true) to passing true value so force reload.
  @proxy ||= CollectionProxy.new(klass, self)
end

# activerecord/lib/active_record/associations/builder/association.rb
def define_readers
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
    def #{name}(*args)
      association(:#{name}).reader(*args)
    end
  CODE
end

Terminal tricks:

ls support regular expression
ls ./**
which match all files under current dir.

ls ./**/
which match all sub directories for 1 level

ls ./**/[a-zA-Z0-9]*.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment