Skip to content

How do I write system tests with clearance? #1022

@avk

Description

@avk

I'm struggling with adding clearance to my system tests.

class PiecesTest < ApplicationSystemTestCase
  setup do
    @writer = writers(:one)
    @piece = pieces(:one)
    @fields = {
      draft: t("activerecord.attributes.piece.draft"),
      prose: t("activerecord.attributes.piece.prose"),
      title: t("activerecord.attributes.piece.title"),
      word_count: t("activerecord.attributes.piece.word_count_suffix"),
    }
  end

  test "should add a new prose piece" do
    visit pieces_url(as: @writer)
    click_on t("pieces.actions.new"), match: :first

    check @fields[:prose]
    fill_in @fields[:word_count], with: 5000
    fill_in @fields[:title], with: "Prose Piece"
    fill_in @fields[:draft], with: 1
    click_on t("pieces.actions.submit")

    assert_text t("pieces.actions.created")
  end
end

The backdoor middleware, will only work for the visit call (the first line of the test). It doesn't work with redirects, like the one generated by the click in the second line of the test.

The controller test helpers are also not available if I require "clearance/test_unit".

What else can I try to get this to work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions