fixed `as_json` correctly returning JSON Ready values

The `as_json` methods introduced in
`ActiveSupport::JSON::Encoding::Encoder` weren't standarized in the
output format, besides having incorrect arguments for certain methods
(rails/rails#11460). The way the encoder works has been rewritten to
standarize the output to JSON Ready values. Part of that refactoring
included the simplification of the circular detection logic and fixing a
few cases in which the detection didn't work.

To fix the issues described in rails/rails#11460, `as_json` had to be
standarized across Rails to return a JSON Ready value, which only
contains primitives that can be directly mapped to JSON primitives
(`Array`, `Hash`, `Numeric`, `String`, `TrueClass`,`FalseClass`,
`NilClass`). This meant rewriting some tests that failed to comply with
this requirement, among other minor changes in `ActiveModel` and
`ActionPack`.

Fixes rails/rails#11460