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 end module Status::AssociationExtensions def after(status) find(:first, :conditions => [''statuses.created_at > ?'', status.created_at], :order => ''statuses.created_at'') end end 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? 6) NoMethodError in ''StatusesController PUT #update StatusesController (unsuccessful save) assigns @status'' undefined method `find'' for #<Class:0x2521c94> /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:1964:in `method_missing_without_paginate'' /Users/courtenay/dev/entp/tt/vendor/plugins/will_paginate/lib/ will_paginate/finder.rb:164:in `method_missing'' /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/associations/association_collection.rb:60:in `find'' /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/associations/association_collection.rb:395:in `find_target'' /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/associations/association_collection.rb:349:in `load_target'' /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ active_record/associations/association_proxy.rb:139:in `inspect'' spec/controllers/statuses_controller_spec.rb:249: spec/controllers/statuses_controller_spec.rb:282:
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 > ? ?end > > ? ?module Status::AssociationExtensions > ? ? ?def after(status) > ? ? ? ?find(:first, :conditions => [''statuses.created_at > ?'', > status.created_at], :order => ''statuses.created_at'') > ? ? ?end > ? ?end > > 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?> > 6) > NoMethodError in ''StatusesController PUT #update StatusesController > (unsuccessful save) assigns @status'' > undefined method `find'' for #<Class:0x2521c94> > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:1964:in `method_missing_without_paginate'' > /Users/courtenay/dev/entp/tt/vendor/plugins/will_paginate/lib/ > will_paginate/finder.rb:164:in `method_missing'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_collection.rb:60:in `find'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_collection.rb:395:in > `find_target'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_collection.rb:349:in > `load_target'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_proxy.rb:139:in `inspect'' > spec/controllers/statuses_controller_spec.rb:249: > spec/controllers/statuses_controller_spec.rb:282:
court3nay 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 > end > > module Status::AssociationExtensions > def after(status) > find(:first, :conditions => [''statuses.created_at > ?'', > status.created_at], :order => ''statuses.created_at'') > end > end > > 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. http://gist.github.com/10c44efda79f31fd2443 Scott> 6) > NoMethodError in ''StatusesController PUT #update StatusesController > (unsuccessful save) assigns @status'' > undefined method `find'' for #<Class:0x2521c94> > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:1964:in `method_missing_without_paginate'' > /Users/courtenay/dev/entp/tt/vendor/plugins/will_paginate/lib/ > will_paginate/finder.rb:164:in `method_missing'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_collection.rb:60:in `find'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_collection.rb:395:in > `find_target'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_collection.rb:349:in > `load_target'' > /Users/courtenay/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/ > active_record/associations/association_proxy.rb:139:in `inspect'' > spec/controllers/statuses_controller_spec.rb:249: > spec/controllers/statuses_controller_spec.rb:282: > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >