How to test this view with Rspec


#1

= flash_messages

  • @user = User.find(1)

  • if current_user == @user
    %new_forum= link_to ‘new forum’, new_forum_path

  • @forum.each do |f|
    .group
    = link_to f.name, forum_path(f)

    • if current_user == @user
      = link_to ‘edit’, edit_forum_path(f)
      = link_to ‘destroy’, forum_path(f), :method => :delete

==
does anyone have some good example?


#2

Am 14.03.2009 um 14:12 schrieb Zhenning G.:

= flash_messages

  • @user = User.find(1)

move that to the controller or a helper. always.
and if you try to find the admin with that, add a flag on the user
so you can write current_user.admin?

  • @forum.each do |f|
    .group
    = link_to f.name, forum_path(f)

Am I wrong or shouldn’t that read:

  • @forums.each do |f|

And do yourself a favour and write forum not f. Otherwise easily
mistaken as a form.

does anyone have some good example?

About testing. Test with a current_user (e.g.
template.should_receive(:current_user).and_return(User.find(2)),
with an admin and without any user at all.
And of course test with @forums being empty, a special response for
that case would be nice.

ciao, tom


Thomas R. “TomK32” Koll || http://tomk32.de || http://ananasblau.com
just a geek trying to change the world
Skype: TomK32 || Mail: removed_email_address@domain.invalid
http://flickr.com/people/tomk32