[rspec-users] [rspec-rails] warning about polymorphism on child objects

Lille lille.penguini at gmail.com
Sun Mar 20 11:02:15 EDT 2011

...I couldn't handle this lingering difficulty, so I just put the
CommentController into a module and mixed it in. Thus, no longer
soliciting comments on previous problem. Yet, I think the warning
still maybe useful re Rails and comments modeling.


On Mar 19, 10:12 am, Lille <lille.pengu... at gmail.com> wrote:
> Hi,
> I just ran into kind of an issue with child models in a one-to-one
> relationship who are also in a polymorphic association, i.e., their
> foreign key is kept by another model, e.g., 'Comment'.
> So, the path for a child might be "human_parents/1/child", while the
> path to the polymorphic association would be "human_parents/1/child/
> comments". (Imagine that there are many kinds of parents, all capable
> of only one child, e.g., "kangaroo_parents/1/child".)
> The problem, I've found, is that a relatively efficient approach to
> controlling the Comment model, i.e., having a CommentController, is
> not fully testable under rspec-rails, bc the routes are unique within
> the CommentController spec file only by their params. So, when I do
> say 'get :new, :human_parent_id=>2' I can't further specify the action
> on the child, e.g., 'get new comment for the child'.
> >From a rspec-rails testing perspective, then, this should make you
> prefer to distribute the comment controller actions among the child
> controllers and not, as is often proposed, in a single controller.
> If anyone has any thoughts on how I can in fact, run around this
> problem and keep my CommentController, please write.
> Lille
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list