On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote:

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.

Not necessarily.  Have you looked into using a null_object mock?

Scott

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to