Fix failure with minitest 5.0.7

Require minitest/mock in test where stub method is needed.

Apparently this was being "imported" by minitest pride plugin, which
previously required "minitest/autorun", that required "minitest/mock",
making the method available by chance.

It has been changed in minitest:
https://github.com/seattlerb/minitest/commit/595ce955c0d89575726d10fc18d2afd8f334bcbe

So we need to make sure we require what we really need where necessary.
ensure @model_class is initialized
don't depend on object state when reading fixture files
auto link hm:t fixture join tables like habtm
make the duplicate code more similar
reduce duplication somewhat
Use Ruby on Rails Coding Conventions for code examples in the guides

* Indent after private/protected
* Ruby >= 1.9 syntax for hashes
* Prefer method { do_stuff } instead of method{do_stuff} for single-line blocks.

[ci skip]
use polymorphic proxies to remove duplicate code
hm:t join tables may not have a primary key
Merge pull request #12155 from jetthoughts/reformat_guides_code_examples

Use Ruby on Rails Coding Conventions for code examples in the guides
Fix fixtures regression that required table names to map to classes only, not class names
Typo in Changelog.
Merge pull request #12164 from rywall/patch-1

Typo in Changelog. [ci skip]
form_for - fix :namespace and :as options clash

:as option should not overwrite :namespace option when
generating html id attribute of the form element. id should be prefixed
by specified namespace even if :as option is present

Add test case showing the issue and code fixing it