[rspec-users] Where is current_user?

Harry Bishop lists at ruby-forum.com
Mon Oct 20 01:00:53 EDT 2008


Hi,
  I have a controller that uses the current_user attributes to determine
if a motion is showable.  I can see the motion track through from a
fixture to the show action, but not the current_user.  My rspec test is

describe MotionsController, "handling GET /motions/1" do
  fixtures :people, :motions

  before(:each) do
    @current_user = people(:someuser)
    @request.session[:user_id] = @current_user.id
    @motion = motions(:four)
    controller.stub!(:logged_in?).and_return(true)
    controller.stub!(:retrieve_user).and_return(@current_user)
  end

  it "should match motion and user" do
    showable = controller.is_showable?(@current_user, @motion)
    puts "..Motion is showable = #{showable}"  # is_showable? shows as
true.
  end

  def do_get
    get :show, :id => @motion.id
  end

  it "should be successful" do
    do_get
    response.should be_success
  end
end

In the MotionsController show action the motion is collected with the
params[:id] but the @current_user doesn't show.
The @current_user and @motion are supplied to is_showable? in the
controller for which they have attributes that are compared.
Any reason why @current_user isn't showing up in the show action?

If I take out the controller stubs in before(:each) then the redirect
from session shows as a 302 but the process doesn't proceed to the show
action.

A mock would require rebuilding the User model for all the checks done
in the controller and I am trying to avoid that by using a fixture
called from the database to test the true interaction between user and
motion.

Also, my protected qualifier on is_showable? works in the controller for
a browser initiated request by not with the rspec test.  I removed
protected to get the test done, but how is that supposed to be handled?

Thanks very much for your support,
HR
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list