Creating a module so that per thread registries can be easily created as
thread local variables.
Created a runtime registry for thread local variables in active record.
Changed the ScopeRegistry and the InstrumentationRegistry to use the
PerThreadRegistry module.
Fix inflector to respect default locale.

The inflector was made aware of locales in 7db0b073fec6bc3e6f213b58c76e7f43fcc2ab97,
but it defaulted to :en. That should actually be our default
locale instead.

Fixes #10125
Merge pull request #10156 from wangjohn/grouping_thread_locals

Grouping thread locals in ActiveRecord
Merge pull request #10158 from steveklabnik/issue_10125

Fix inflector to respect default locale.
Add failing test case for #9654
Reverts rendering behavior when format is unknown

If a request has unknown format (eg. /foo.bar), the renderer
fallbacks to default format.

This patch reverts Rails 3.2 behavior after c2267db commit.

Fixes issue #9654.
Return nil for Mime::NullType#ref
Fixed typo
Merge pull request #10160 from choudhuryanupam/fix_typo_n_grammar

Fixed typo
Removed unused setup
Merge pull request #10162 from choudhuryanupam/fix_activesupport_test

Removed unused setup
Using public send instead of send for the PerThreadRegistry module.
Prevents you from accidentally calling a protected method.
Merge pull request #10165 from wangjohn/public_send_for_instance

Using public send instead of send for the PerThreadRegistry module.
Searching for rails executable correctly

 * Current logic of finding Rails executable in parent directory is
   not returning full path of executable if it is found in one of the
   parent directories
 * To compensate for this, we have to call exec_app_rails recursively
   until the executable is found or we cant do 'chdir' anymore
 * This solution finds the correct executable path from parent
   directory(s) recursively
Merge pull request #10157 from prathamesh-sonpatki/app_loader

Searching for rails executable correctly
code review of 22e5ab3
Revert "Merge pull request #10158 from steveklabnik/issue_10125"

This reverts commit fa3ef8e82ab2f96cf15ef9bc885b2468fad77621, reversing
changes made to e0af93dd3a5eeee2e2a67b05f34afb66cc80c00b.

Reason: Routes, Active Record and the rendering stack should not depend
on the default locale
While merging relations preserve context for joins

Fixes #3002. Also see #5494.

```
class Comment < ActiveRecord::Base
  belongs_to :post
end

class Author < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :author
  has_many :comments
end
```

`Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would
fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.

It is failing because `all` is being called on relation which looks like this after all the merging:
`{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this relation all the context that
`Post` was joined with `Author` is lost and hence the error that `author` was not found on `Comment`.

Ths solution is to build JoinAssociation when two relations with join information are being merged. And later
while building the arel use the  previously built `JoinAssociation` record in `JoinDependency#graft` to
build the right from clause.

Thanks to Jared Armstrong (https://github.com/armstrjare) for most of the work. I ported it to make it
compatible with new code base.