Hi Daniel,
You're trying to do too much in the controller. It's not the
controller's responsibility to ensure that the user is capable of
returning its own article without including anyone else's - that's
the user's (or the Article model's, perhaps) responsibility. Your
controller should be thin and simple, delegating all business logic
onto the model objects. See this article: http://www.pragprog.com/
articles/tell-dont-ask
Once thinned down like this, speccing the controller becomes trivial
- just mock the current_user method and ensure that it receives a
call to "available_articles" or whatever the method name is. Then,
spec that method in the User model. At that point, don't mock
anything you don't have to, and test the behaviour of the User model
(e.g. "it should not return anyone else's article within its
available articles" or something like that).
Hope this helps,
Daniel
On 3 Dec 2007, at 10:33 3 Dec 2007, Fischer, Daniel wrote:
yuck, that seems kind of nasty, no?
user.articles is already scoped...
There has to be a different solution!
On Dec 3, 2007 2:07 AM, Stefan Magnus Landrø
<[EMAIL PROTECTED]> wrote:
Typically, I'd write a method in your user model that returns the
user's articles:
class User do
def find_articles_for_user
Article.find(:all, :conditions => ['userid = ?', id)
end
end
Then you'd use a mock in your controller spec, and make sure you
test that your method is being called.
On the other hand, the user model should be tested directly against
the db.
HTH,
Stefan
2007/12/3, Fischer, Daniel <[EMAIL PROTECTED]>:
Let's say you're using the restful_authentication plugin.
You have a model called articles. On the index action of the
articlescontroller you simply want to spec out that it'll scope the
results to the ownership of the current_user.
It should NOT include any articles other than the articles that
user owns.
How would you properly spec this out?
Thanks for the help!
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
--
Bekk Open Source
http://boss.bekk.no
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users