[rspec-users] Weird bug in association extensions
scott at railsnewbie.com
Sat May 9 12:56:57 EDT 2009
> Hey all, just upgraded an older app to latest rspec and rails. This
> code runs fine in console but fails under rspec.
> class User
> has_many :statuses, :extend => Status:::AssociationExtension
> module Status::AssociationExtensions
> def after(status)
> find(:first, :conditions => ['statuses.created_at > ?',
> status.created_at], :order => 'statuses.created_at')
> This code works in the app and from console
> recent = @user.statuses.first
> status = @user.statuses.after(recent)
> But in the spec, I get this: Weird, eh? It thinks that "self.class" ==
> Array and can't find the "find" method on the array instance. Is this
> something in my code somewhere, or did something change with
> association collections?
Personally I just always run the debugger whenever I encounter some
weird fucked up thing like this in rails. Better to know that to guess.
But, if I recall correctly, the association proxy is just an Array which
includes a ton of modules - some of which come from AR.
> NoMethodError in 'StatusesController PUT #update StatusesController
> (unsuccessful save) assigns @status'
> undefined method `find' for #<Class:0x2521c94>
> active_record/base.rb:1964:in `method_missing_without_paginate'
> will_paginate/finder.rb:164:in `method_missing'
> active_record/associations/association_collection.rb:60:in `find'
> active_record/associations/association_proxy.rb:139:in `inspect'
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users