I also have another problem, when I am trying to do the similar strategy for XML based speccing it fails on saying nil.to_xml<div><br class="webkit-block-placeholder"></div><div>Arg..</div><div><br class="webkit-block-placeholder">
</div><div>And all it is, is the following =&gt; (with a before_filter on login required) but still, it&#39;s just current_user.</div><div><br class="webkit-block-placeholder"></div><div><div>&nbsp;&nbsp;def show</div><div>&nbsp;&nbsp; &nbsp;@writing = current_user.writings.find(params[:id])
</div><div>&nbsp;&nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp;respond_to do |format|</div><div>&nbsp;&nbsp; &nbsp; &nbsp;format.html</div><div>&nbsp;&nbsp; &nbsp; &nbsp;format.xml { render :xml =&gt; @writing.to_xml }</div><div>&nbsp;&nbsp; &nbsp;end</div><div>&nbsp;&nbsp;end</div><div><br class="webkit-block-placeholder">
</div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><a href="http://pastie.textmate.org/private/99vq9ipqb6u8cu5bfirlaa">http://pastie.textmate.org/private/99vq9ipqb6u8cu5bfirlaa</a> here is the pastie.
</p></div><br><div class="gmail_quote">On Dec 3, 2007 8:26 PM, Fischer, Daniel &lt;<a href="mailto:me@danielfischer.com">me@danielfischer.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hey cool, thanks for the help guys. One problem though, when I take this approach I can&#39;t decouple the specs anymore. They all &quot;User_xxx receive unexpected message :articles&quot;. It seems silly to include all behaviors in one spec, or put that expectation in each test. Is there a way around this?
<div><br></div><div>Thanks for all the help,</div><div>Daniel Fischer</div><div><a href="http://www.danielfischer.com" target="_blank">http://www.danielfischer.com</a><div><div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">
On Dec 3, 2007 2:44 AM, Daniel N &lt;
<a href="mailto:has.sox@gmail.com" target="_blank">has.sox@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Assuming that there is a call like this in your controller
<div><br></div><div>@articles = current_user.articles</div><div><br></div><div>One way to do this is to stub out the 
controller.current_user to return a mock object of the current_user</div><div><br></div><div>Then put an expectation on the current user that it&#39;s articles method gets called. (return a mocked collection of articles) &nbsp;
</div><div><br></div><div>Then check that @articles is set to the returned mocked collection of articles from current_user.articles</div><div><br></div><div>
phew...</div><div><br></div><div>Ok So one way you might write this could be (This is untested...)</div><div><br></div><div>it &quot;should scope the articles to the currrent_user&quot; do
</div><div><br></div><div>&nbsp;&nbsp;user = mock_model(User)</div><div>&nbsp;&nbsp;articles = [mock_model(Article)]</div><div><br></div><div>&nbsp;&nbsp;controller.stub!(:current_user).and_return(user)</div><div><div>&nbsp;&nbsp;user.should_receive

(:articles).and_return(articles)</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp;get :index</div><div>&nbsp;</div></div><div>&nbsp;&nbsp;assigns[:articles].should == articles</div><div><br></div><div>end</div><div><br>
</div><div>Like I said though, that&#39;s not tested itself. &nbsp;If that&#39;s not exactly right... it&#39;s along the right track of an option that can work.</div><div><br></div><div>HTH</div>
<div>Daniel</div><div><br><div class="gmail_quote"><div>On Dec 3, 2007 9:07 PM, Stefan Magnus Landrø &lt;<a href="mailto:stefan.landro@gmail.com" target="_blank">stefan.landro@gmail.com</a>&gt; wrote:<br></div>
<div><div></div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Typically, I&#39;d write a method in your user model that returns the user&#39;s articles:<br><br>class User do<br><br>&nbsp; def find_articles_for_user<br>&nbsp;&nbsp; Article.find(:all, :conditions =&gt; [&#39;userid = ?&#39;, id)<br>


&nbsp; end
<br><br>end<br><br>Then you&#39;d use a mock in your controller spec, and make sure you test that your method is being called.<br><br>On the other hand, the user model should be tested directly against the db.<br><br>HTH,
<br><br>Stefan<br><br><div><span class="gmail_quote">2007/12/3, Fischer, Daniel &lt;<a href="mailto:daniel@helpmebuyacar.org" target="_blank">daniel@helpmebuyacar.org</a>&gt;:</span><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">


<div><div></div><div>
Let&#39;s say you&#39;re using the restful_authentication plugin.<div><br></div><div>You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it&#39;ll scope the results to the ownership of the current_user.
</div><div><br></div><div>It should NOT include any articles other than the articles that user owns.</div><div><br></div><div>How would you properly spec this out?&nbsp;
</div><div><br></div><div>Thanks for the help!</div></div></div>
<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org" target="_blank">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></blockquote></div><font color="#888888"><br><br clear="all"><br>-- <br>Bekk Open Source<br><a href="http://boss.bekk.no" target="_blank">http://boss.bekk.no</a>
</font><br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org" target="_blank">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></blockquote></div></div></div><br></div>
<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org" target="_blank">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></blockquote></div><br></div></div></div>
</blockquote></div><br></div>