[rspec-users] Weird bug in association extensions
dchelimsky at gmail.com
Sat May 9 12:17:34 EDT 2009
On Sat, May 9, 2009 at 2:01 AM, court3nay <court3nay at gmail.com> wrote:
> 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?
The only direct handling of AssociationProxy in rspec-rails is if
you're using the change matcher. Does the failing example have 'should
change' in it? Could be an rspec bug in that case. If not, I'm not
sure what else it could be. Can you try converting it to a test/unit
test_case and see if you get the same result?
> 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'
More information about the rspec-users