On Tuesday, August 5, 2014 3:49:20 PM UTC+2, Vell wrote: > > Hello all, > > I am creating a rails 4.1 engine and am having trouble figuring out how to > test the controllers redirect action back to the main_app.root_path. I have > been struggling with this for a while and am hoping I can get a little > guidance on this. > > Basically if I have a create action such as: > > def create > @user = User.new(user_params) > if @user.save > flash[:success] = "User Saved!" > *redirect_to main_app.root_path* > else > flash[:error] = "User Not Saved! Check Errors" > render :new > end > end > > I get an error that says main_app is nil. I expect this since my spec > directory is in the root of my engine. How would I go about testing > creating a controller test where I would be able to test redirecting back > to routes in the main_app? This should hopefully help me with the next step > of integration testing as well. > > Any advice is greatly appreciated. > > Thanks >
To test a redirect you should so smth like that(to be adapted to your fixtures, or FactiryGirl or whatever you use): it "redirects to the home page upon save" do post :create, contact: FactoryGirl.attributes_for(:contact) expect(response).to redirect_to root_url #or some other url end Sure, in your code, main_app is an undefined variable, that's why you're getting Nil. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscr...@googlegroups.com. To post to this group, send email to rspec@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/1d9fa996-1f2b-4a0e-883f-7c7a596c6f46%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.