Testing variables in controllers?


#1

How do you test that your controller fetched the right records?

I have an action that returns a different set of records based on
whether or not the current_user is the “owner” of the profile being
viewed.

Code is here http://pastie.org/308685.

“controller.submissions.size.should == 1” makes sense but it doesn’t
work. Of course, I might be doing this wrong altogether! Very new to
rspec.

Thanks!
Ramon T.


#2

Ramon T. wrote:

How do you test that your controller fetched the right records?

I have an action that returns a different set of records based on
whether or not the current_user is the “owner” of the profile being
viewed.

Code is here http://pastie.org/308685.

“controller.submissions.size.should == 1” makes sense but it doesn’t
work. Of course, I might be doing this wrong altogether! Very new to
rspec.

Thanks!
Ramon T.

From what I read and my little experience with rpsec, you shouldn’t test
for the exact return values. This kind of test should be done when
testing the model alone.


#3

woah!

You’re exposing way too much of your model here, IMO. That is forcing
you to do all that noisy mocking setup in your before block.

Can you make a method on your user object like User#valid_submissions
and have that return the correct submissions?

How do you know whether the user is the profile owner?


#4

On 2008-11-06, at 09:36, Ramon T. wrote:

rspec.

Thanks!
Ramon T.

Hi Ramon. I’d refactor most of what’s in the “before :show do” block
into a couple of User instance methods (or whichever model @user
belongs to). For example: http://pastie.org/308814

Cheers,
Nick


#5

Cool thanks Fernando, Matt, Nick - it seems like I haven’t made my
models fat enough. That seems to be the answer :slight_smile:

Ramon T.