[rspec-devel] [ rspec-Patches-6720 ] [PATCH] ActiveRecord has_many :through and has_and_belongs_to_many break 'should'

noreply at rubyforge.org noreply at rubyforge.org
Fri Feb 2 13:25:20 EST 2007


Patches item #6720, was opened at 2006-11-17 05:52
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=6720&group_id=797

Category: rails plugin
Group: None
>Status: Closed
Resolution: None
Priority: 3
Submitted By: Wilson Bilkovich (wilson)
>Assigned to: David Chelimsky (dchelimsky)
Summary: [PATCH] ActiveRecord has_many :through and has_and_belongs_to_many break 'should'

Initial Comment:
Here's a stack trace (not mine, it's from aniero's app):
TypeError in 'An instance of a Report model should set the condition relationships based on the condition string on save'
wrong argument type Condition (expected Module)
../vendor/rails/activerecord/lib/active_record/base.rb:1235:in `method_missing'
../vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:110:in `method_missing'
../vendor/rails/activerecord/lib/active_record/base.rb:943:in `with_scope'
../vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:110:in `method_missing'
./spec/models/report_spec.rb:36

After some digging with bitsweat's assistance, it turns out that there are four different method_missing implementations in ActiveRecord that can be invoked when calling methods on associations.

1. AssociationProxy, for has_one and belongs_to
2. HasManyAssociation, for has_many
3. HasAndBelongsToManyAssociation, for habtm
4. HasManyThroughAssociation, for has_many through

AssociationProxy's method_missing is pretty simple, and doesn't need wrapping.
The others, however, make some decisions using respond_to?, etc, etc, and need RSpec to step in ahead of them.

This patch adds the other two necessary.

An example of where this currently fails is:
@record.has_many_association.include? fixtures(:something)

The 'rspec_on_rails' sample app doesn't include any habtm or hmt associations, so I couldn't write any specs to cover this.  It might be worth adding those, so we can catch this kind of fun.

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

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-02-02 18:25

Message:
This will be resolved with the 0.8 release, which won't conflict with method_missing in rails.

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

Comment By: Wilson Bilkovich (wilson)
Date: 2006-12-02 18:17

Message:
I was referring to this one:
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=6980&group_id=797

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-12-02 18:07

Message:
I'm not sure what other ticket this relates to, but it's ok to fix two bugs in one patch.

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

Comment By: Wilson Bilkovich (wilson)
Date: 2006-12-02 18:00

Message:
I haven't yet, but I'm starting a new project this week
(using rspec), so I should get to it soon.

Does this relate to the other recent ticket about the
methods that AssociationProxy undefines? Do we want to fix
both at once?

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

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-12-02 16:49

Message:
Wilson, did you get a chance to write new models and patch the app? If you add new files, make sure to svn add them locally before generating the patch.

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

Comment By: Wilson Bilkovich (wilson)
Date: 2006-11-17 15:07

Message:
OK. I will do that today. I guess it will need a couple of
new models.

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

Comment By: David Chelimsky (dchelimsky)
Date: 2006-11-17 14:35

Message:
Would you like to patch the sample app so we have those specs? The sample app specs get run during the build, and serve as acceptance level tests.

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

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


More information about the rspec-devel mailing list