«

»

Aug 19

rspec, restful_authentication, and login_required

This is partly for myself, and partly for anyone after me…..

I have a controller generated via rspec_scaffold — yes, I know, it might not be what all the cool kids are doing, but it works.  I also have restful_authentication set up to use rspec.  So, when I go to add before_filter :login_required, autotest frowns at me.  After much trial and error, and googling (with false hits and things that didn’t work), I finally achieved a smiley face with the following added to my controller’s spec:

5 comments

1 ping

Skip to comment form

  1. Robby Russell

    Matt,

    Not sure if you know this, but most of your actions will require the login_required to be stubbed, you can move this into it’s own shared group for reuse in each spec group. I decided to post quick tutorial because I don’t see many people using it and/or mentioning it.

    * http://rubyurl.com/OGdn

  2. Matt Williams

    Robby,
    Thanks for the response. Your tutorial has a lot of good ideas; I appreciate it.

  3. srboisvert

    Hi Matt. Just the question I was looking for the answer to. Timely.

    BTW – your greater than symbol got translated to a HTML character entity and could mess up cut-an-pasters..

  4. Julien

    Awesome! Thanks Mike for thise. I will check Robby’s tutorial as well ;)

  5. Jonathan Spooner

    You rock buddy! I’m moving all my unit test over to rspec and this post was a big help!

    I had no idea the controller would be available from my test.

  1. Scott Motte » Blog Archive » Tips for using rspec for beginners

    […] to rspec for restful_auth? – rspec, restful_authentication, and login_required – Also […]

Leave a Reply