Question

When I assert_template after calling an action that also sends out an email I'm getting the email template information instead of the one showed in the browser.

The controller action

def create
    @user = User.new(params)
    if @user.save
      respond_to do |format|
        format.html { redirect_to user_path(@user), :notice => "User Created" }
      end
    end
end

The @user.save method have a callback that sends a confirmation email to the user.

The test

  test 'should render show template' do
    post :create, user: {:email => 'test@example.com'}
    assert_template :show  # Here I'm getting the email template that is being sent on after save callback
  end

How can I assert that the browsing user is being correctly redirected to the (user) show action?

Was it helpful?

Solution

Change it to assert_redirected_to

 test 'should render show template' do
    post :create, user: {:email => 'test@example.com'}
    assert_redirected_to(user_path(assigns(:user))
 end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top