Skip to content

Instantly share code, notes, and snippets.

@ramontayag
Created January 18, 2014 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramontayag/8485526 to your computer and use it in GitHub Desktop.
Save ramontayag/8485526 to your computer and use it in GitHub Desktop.

In my code, I put a begin-rescue block to capture errors when Array(decorated) throws an error during a spec run. Note: @current_site is the one in this example, but it also happens with other objects from here on, if I let the specs run.

2.0.0 (#<Admin::Site::SitesController:0x007fb2dd58d6e8>):0 > @current_site.class
=> SiteDecorator < ApplicationDecorator
2.0.0 (#<Admin::Site::SitesController:0x007fb2dd58d6e8>):0 > Array(@current_site)
NoMethodError: undefined method `to_a' for #<Site:0x007fb2dd5dbf50>
from /Users/ramon/.rvm/gems/ruby-2.0.0-p353/gems/activemodel-4.0.2/lib/active_model/attribute_methods.rb:439:in `method_missing'

Based on the error and its backtrace, it seems that the decorator responds_to to_a but when it finally reaches the object, it blows up. If I open a separate Rails console, and I try to replicate this issue, I am unable to do so. I have a feeling that something is making all future decorated objects respond_to to_a and it breaks the tests from there and onwards.

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