drapergem / draper

Decorators/View-Models for Rails Applications
MIT License
5.22k stars 527 forks source link

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

Closed zdenal closed 12 years ago

zdenal commented 12 years ago

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

avdgaag commented 12 years ago

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.

ramontayag commented 10 years ago

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.