Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Array(some_decorator_object) -> undefined method `to_ary' for .... #115

Closed
zdenal opened this Issue Jan 19, 2012 · 2 comments

Comments

Projects
None yet
4 participants

zdenal commented Jan 19, 2012

Hi Casimir,

when I update gem from 0.9.5 to 0.10.0 then I got this error in places where I use something like: Array(some_decorator_object) or [some_decorator_objects].flatten

Thank you for sharing draper with me.

Sincerely,
Zdenal

Contributor

avdgaag commented Mar 12, 2012

This does not seem to happen on Ruby 1.9.3-p125, while it does on 1.9.2-p290. It appears that Kernel#Array on 1.9.3 calls respond_to? before it tries to call to_ary or to_a — which prevents the NoMethodError — while on 1.9.2 it just calls it. I guess Kernel#Array should know how to work around it, but somehow, Draper::Base#method_missing’s behaviour causes Kernel#Array to trip up.

@markburns markburns added a commit to markburns/draper that referenced this issue Mar 14, 2012

@avdgaag @markburns avdgaag + markburns Bugfix: do not confuse Kernel#Array
On 1.9.2 (and maybe earlier) Kernel#Array will choke on a decorator,
because it just invokes `to_ary` and `to_a` without using `respond_to?`
first, like it does in 1.9.3-p125.

As a work-around, make sure to not create a delegation method in
`method_missing` when the model will not respond to it anyway. The
decorator object will then behave like `Kernel#Array` expects it to.

See #115.
6c71bfd

I upgraded to Rails 4, and 1.3.0 of Draper, and I'm getting something like this again. The weird thing is that it only happens about 70% of the time when I run tests. I haven't been able to consistently reproduce it yet. Even if I re-run the specs in the same order it doesn't always happen. I don't want to make a new issue until I know the issue is actually with Draper, and I don't want to flood this page with comments. I've posted what I know so far in this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment