
needs to raise WrongType error when attempting to add an object of the wrong class to an association
Reported by Adam French | December 12th, 2007 @ 01:32 PM
3)
NameError in 'DataMapper::Associations::HasAndBelongsToManyAssociation should raise an error when attempting to associate an object not of the correct type (assuming added model doesn't inherit from the correct type)'
uninitialized constant WrongType
./spec/associations_spec.rb:393:
4)
NameError in 'DataMapper::Associations::HasAndBelongsToManyAssociation should associate an object which has inherited from the correct type into an association'
uninitialized constant WrongType
./spec/associations_spec.rb:404:
Comments and changes to this ticket
-
Sam Smoot December 27th, 2007 @ 10:41 AM
- Milestone cleared.
- State changed from new to open
I'll try to get to this next... seems like a good minor tweak/code-cleanup task to help out with the association work...
-
Sam Smoot December 27th, 2007 @ 11:50 PM
- State changed from open to resolved
This is resolved in r639. Except an ArgumentError is raised.
-
Seth Engelhard February 8th, 2008 @ 04:40 PM
I don't know for sure, but this seems like the same problem I am getting. I'm not getting an error raised when I assign the wrong type of object to an association.
Here is my spec and the result:
- spec
it "should not belong to a non-profile object" do
@nonprofile = Blog.new(:id => 10)
lambda {
@event = Event.new(valid_connection_attributes.with(:profile => @nonprofile))
}.should raise_error
end
- result
1)
'Event relating to a profile should not belong to a non-profile object' FAILED
expected Exception but nothing was raised
./spec/models/event_spec.rb:29:
-
-
Seth Engelhard February 8th, 2008 @ 08:36 PM
It gives me the same error:
#spec
it "should not belong to a non-profile object" do
@nonprofile = Blog.new(:id => 10)
@event = Event.new(valid_connection_attributes)
lambda {
@event.profile = @nonprofile
}.should raise_error
end
#result
1)
'Event relating to a profile should not belong to a non-profile object' FAILED
expected Exception but nothing was raised
./spec/models/event_spec.rb:30:
-
asceth February 8th, 2008 @ 10:22 PM
If you can post some model code showing how you defined associations so we can reproduce it.
-
Seth Engelhard February 9th, 2008 @ 07:19 PM
Ah ha!
As I was copying my model code to paste it in here I realized that I had the belongs_to association from on model but not he has_many association from the other model. Once I put the has_many declaration in the profile class, the test passed.
Sorry to waste your time due to my oversight! I don't know why I didn't catch it before.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
- Nobody is watching this ticket.