[rspec-devel] [ rspec-Bugs-5645 ] should_be_empty fails on has_many collections

noreply at rubyforge.org noreply at rubyforge.org
Sun Oct 29 05:23:18 EST 2006


Bugs item #5645, was opened at 2006-09-06 12:31
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=5645&group_id=797

Category: None
Group: None
>Status: Closed
Resolution: None
Priority: 3
Submitted By: Jeff Hoffman (wheeledone)
Assigned to: Nobody (None)
Summary: should_be_empty fails on has_many collections

Initial Comment:
class Context < ActiveRecord::Base
  has_many :action_items
end

class ActionItem < ActiveRecord::Base
  belongs_to :context
end

context "A new context" do
  setup do
    @context = Context.new
  end
  
  specify "should not have any action items" do
    @context.action_items.should_be_empty
  end
end

NoMethodError in 'A new context should not have any action items'
undefined method `empty?' for ActionItem:Class
/myproject/config/../vendor/rails/activerecord/lib/active_record/base.rb:1228:in `method_missing'
/myproject/config/../vendor/rails/activerecord/lib/active_record/base.rb:1228:in `method_missing'
/myproject/config/../vendor/rails/activerecord/lib/active_record/associations/has_many_association.rb:108:in `method_missing'
/myproject/config/../vendor/rails/activerecord/lib/active_record/base.rb:942:in `with_scope'
/myproject/config/../vendor/rails/activerecord/lib/active_record/associations/has_many_association.rb:98:in `method_missing'
./spec/models/context_spec.rb:13:in `should not have any action items'

I tested this on both 1.1.6 and Edge...results were the same with both.

----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2006-10-29 10:23

Message:
Fixed in 0.7

----------------------------------------------------------------------

Comment By: Jeff Hoffman (wheeledone)
Date: 2006-09-07 13:31

Message:
Yes, I am. Want to be on the beta list? :)

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2006-09-07 12:46

Message:
action_items? Jeff - are you building a GTD tool?

----------------------------------------------------------------------

Comment By: Jeff Hoffman (wheeledone)
Date: 2006-09-06 12:34

Message:
Oops, forgot to show the workaround. If I change the
expectation to:

@context.should_satisfy { |c| c.action_items.empty? }

it works fine...and here is a console session showing that
my model is functioning:

$ ./script/console 
Loading development environment.
>> c = Context.new
=> #<Context:0x2288e50 @attributes={"name"=>nil,
"updated_at"=>nil, "lock_version"=>0, "created_at"=>nil},
@new_record=true>
>> c.action_items.empty?
=> true
>>

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=5645&group_id=797


More information about the rspec-devel mailing list