HashWithIndifferentAccess#select working as intended

Before this commit, #reject returned a HashWithIndifferentAccess,
whereas #select returned a Hash. Now #select also returns a
HashWithIndifferentAccess.
Remove warnings on Ruby 2.1

Conflicts:
	activesupport/lib/active_support/hash_with_indifferent_access.rb
Replace "data store" with database [ci skip]

Active Record is specifically for databases. Refs #12101.
Fix OrderedHash.select to return self instance.

On ruby 2.1.1 the behavior of .select and .reject has changed.
They will return a Hash new instance, so we need to override them to
keep the instance object class.
Syntax polishing
Tests for indifferent access using full_messages_for. Closes #11916
Merge pull request #14198 from arthurnn/fix_14188

Fix Hash#select and #reject on ruby 2.1.1
Move setting :scope_level_resource to resource_scope

Originally with_scope_level was exclusively for managing scope levels with
resources, however it is now used for other things so it makes more sense
to move the responsibility for setting the :scope_level_resource to the
resource_scope method. This eliminates repeatedly setting it to the same
resource as each resource method scope is evaluated.

(cherry picked from commit ed0fb4ae7ea28cf3eecce6ec02650bcffc7c7657)
Only use shallow nested scope when depth is > 1

By tracking the depth of resource nesting we can push the need for nested
shallow scoping to only those routes that are nested more than one deep.
This allows us to keep the fix for #12498 and fix the regression in #14224.

Fixes #14224.

(cherry picked from commit dcc91a04a177466516dac12abc358c590743fa71)
Pull namespace defaults out of the options hash

If a developer has specified either :path or :as in the options hash then
these should be used as the defaults for :shallow_path and :shallow_prefix.

Fixes #14241.

(cherry picked from commit 8711086f5a2e73cd068434a5fafef258ba9f4fe1)
Copy shallow options from normal options when using scope

If the options :shallow_prefix and :shallow_path are not set in the
scope options then copy them from the normal :as and :path options
if they are set.

(cherry picked from commit af4c9b78ff1c967cc1aaef14d34205ef92db8134)
Merge pull request #8313 from alan/only_save_changed_has_one_objects

Save has_one associations only if record has changes

Conflicts:
	activerecord/CHANGELOG.md

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/autosave_association.rb
Review CHANGELOGs [ci skip]
Fixes STI when 2+ levels deep.

PR #14052 Added a regression where it was only looking for methods in one
level up, So when the method was defined in a 2+ levels up the
inheritance chain, the method was not found as defined.

Conflicts:
	activerecord/test/cases/attribute_methods_test.rb
Use released arel version
Preparing for 4.0.4.rc1 release
Use Sqlite3 adapter in examples

Two bits of example code use sqlite as an adapter, which doesn't exist.
Using the code verbatim will raise a LoadError exception:

    ActiveRecord::Base.establish_connection(
      "adapter"  => "sqlite",
      "database" => "db.sqlite"
    )
    # => LoadError: Could not load 'active_record/connection_adapters/sqlite_adapter'...

Considering this is code a lot of people new to Rails might be running,
it's especially confusing.

Closes #14367 [ci skip]
make tests pass on Ruby 2.2

Apparently we've been using a buggy feature for the past 6 years:

  https://bugs.ruby-lang.org/issues/9593
Merge pull request #14372 from arthurnn/fix_query_cache_binds

Make select_all on query cache accept a Relation without binds.
Conflicts:
	activerecord/CHANGELOG.md
No need to binds be optional