I don't know exactly how you're using the code, but validates_presence_of :user_id seems redundant. If you've setup a relationship from Group to User then Active Record will be enforcing that validation for you. Just a thought ...<br>
<br>Other than that you would probably do (without seeing any of your code):<br><br><div style="margin-left: 40px;">group = mock_model(Group, :to_param => 1)<br>user = mock_model(User, :to_param => 1)<br><br>group.stub!(:user).and_return(user)<br>
</div><br><br><br><div class="gmail_quote">On Mon, Feb 11, 2008 at 8:21 AM, Edvard Majakari <<a href="mailto:edvard@majakari.net">edvard@majakari.net</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Feb 11, 2008 1:43 PM, Wes Shaddix <<a href="mailto:wshaddix@gmail.com">wshaddix@gmail.com</a>> wrote:<br>
> I've got a "group" model that has a user_id attribute and a<br>
> validates_existence_of :user and validates_presence_of :user_id<br>
> validations. What method(s) do I need to stub on the User mock to<br>
> intercept those validation calls? My goal is to isolate the Group model<br>
> from the User model.<br>
<br>
</div>See <a href="http://www.ruby-forum.com/topic/138342" target="_blank">http://www.ruby-forum.com/topic/138342</a><br>
<br>
and <a href="http://tersesystems.com/post/9700067.jhtml" target="_blank">http://tersesystems.com/post/9700067.jhtml</a><br>
<br>
Obvious 'rails mocking associations' seemed to work for me, unless I<br>
misunderstood the question.<br>
<br>
Of course, you could just stub 'valid?' for any AR object as well.<br>
<font color="#888888">--<br>
"One day, when he was naughty, Mr Bunnsy looked over the hedge into<br>
Farmer Fred's field and it was full of fresh green lettuces. Mr<br>
Bunnsy, however, was not full of lettuces. This did not seem fair."<br>
-- Terry Pratchett, Mr. Bunnsy Has An Adventure<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
rspec-users mailing list<br>
<a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Bryan Ray<br><a href="http://www.bryanray.net">http://www.bryanray.net</a><br><br>"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."