[rspec-users] authentication, controller specs. I think I'm missing something simple ....

Joe Van Dyk joevandyk at gmail.com
Sun Jun 10 15:18:05 EDT 2007

On 6/9/07, Rick Tessner <ricktessner at canada.com> wrote:
> On Sat, 2007-09-06 at 14:34 -0700, Joe Van Dyk wrote:
> > Your pasties have wrapped lines in them for some reason, which makes
> > matching up the errors to the lines of code difficult.
> Dang.  Sorry about that.  Looks like it was the things_controller_spec
> was messed up for some reason.  Re-pastied that.
> The three pasties are then:
> things_controller http://pastie.caboo.se/69136
> things_controller_spec http://pastie.caboo.se/69166
> Errors w/ find(:all) http://pastie.caboo.se/69138

I don't have the solution and I've ran into this in the past.  But at
least I can explain what is happening.  :-)

    @thing = mock_model(Thing)

    @current_user = mock_model(User, :things => [@thing])

So, when you do:

You are calling the find method on an array that contains one @thing
object.  The find you are calling is Enumerable#find (the plain old
Ruby version, not the ActiveRecord::Base::find version).
Enumerable#find expects a block.

["hello, "world"].find { |e| e.include?('el') }
would return "hello"

However, in the Rails code, when you call current_user.things.find,
You are calling Thing::find with a scoped find for only the Things
that belong to the current user.  That's an entirely different find

Hope that makes sense.  I don't know what the solution is.

Joe Van Dyk

More information about the rspec-users mailing list