3

In minitest, prior to Hotwire, a create test might look like the following:


  test "should create user" do
    assert_difference('User.count') do
      post users_url, params: { user: valid_params }
    end

    assert_redirected_to users_path
  end

After changing the create controller action to respond_to :turbo_stream, the above test will no longer execute correctly. I've tried simply passing format: :turbo_stream as part of the params hash...but, this didn't work either.

post users_url, params: { user: valid_params, format: 'turbo_stream' }

There must be a Rails 7 way of testing this. It's possible Minitest hasn't been updated yet for these new features.

Has anyone updated their tests for this new format?

hellion
  • 4,602
  • 6
  • 38
  • 77

1 Answers1

1

Turns out this was easy...this is how you do it

post users_url(format: :turbo_stream), params: { user: valid_params }

and, then instead of testing for a redirect use:

assert_response :success
hellion
  • 4,602
  • 6
  • 38
  • 77