Fixed a regression introduced in 84cf156

84cf156 (PR #15694) introduced a subtle regression. There are actually three
distinct entry points to creating an AR object – via .new (i.e. #initialize),
via #init_with (e.g. from YAML or database queries) and via .allocate.

With the patch in 84cf156, attribute methods and respond_to? will not work
correctly when objects are allocated directly, without going through either

The reason this test case didn't catch the regression was that the `Topic`
class is shared between test cases, so by the time this test case is ran the
attribute methods are very likely to be defined.

Switching to use a fresh anonymous class in the test to ensure we surface this
problem in the future.
Why do we need this in allocate, then? We don't support 1.8
On Jun 14, 2014 11:34 AM, "Godfrey Chan" <notifications@github.com> wrote:

> In activerecord/test/cases/attribute_methods_test.rb:
>
> > @@ -143,7 +143,11 @@ def test_id_before_type_cast_with_custom_primary_key
> >
> >    # Syck calls respond_to? before actually calling initialize
>
> The comment is actually correct. The test was added for Syck (the YAML
> implementation in <= 1.8.7), not Psych. In fact, Psych also calls
> <https://github.com/tenderlove/psych/blob/960d30ef5ac4ab93db199852fcd93f3cc3dfe1dd/lib/psych/visitors/to_ruby.rb#L47-L49>
> allocate followed by respond_to?, but it doesn't call respond_to? with
> the attribute method names.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/rails/rails/pull/15718/files#r13781983>.
>