aboutsummaryrefslogtreecommitdiffstats
path: root/test/controllers/resource_types_controller_test.rb
blob: 3d3ea8de60909ebaaf25a1a36766de65f7db9a83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "test_helper"

class ResourceTypesControllerTest < ActionDispatch::IntegrationTest
  setup do
    @resource_type = resource_types(:one)
    @user = users(:one)
    post session_url, params: { email_address: @user.email_address, password: "password" }
    follow_redirect! # After login
  end

  test "should get index" do
    get resource_types_url
    assert_response :success
  end

  test "should get new" do
    get new_resource_type_url
    assert_response :success
  end

  test "should create resource_type" do
    # Use a unique name to avoid validation conflicts.
    unique_name = "UniqueResourceTypeName#{SecureRandom.hex(8)}"

    # POST request to create a new resource type.
    assert_difference("ResourceType.count", 1) do
      post resource_types_url, params: { resource_type: { name: unique_name } }
    end

    # Assert redirection to the newly created resource.
    assert_redirected_to resource_type_url(ResourceType.last)
  end

  test "should show resource_type" do
    get resource_type_url(@resource_type)
    assert_response :success
  end

  test "should get edit" do
    get edit_resource_type_url(@resource_type)
    assert_response :success
  end

  test "should update resource_type" do
    patch resource_type_url(@resource_type), params: { resource_type: { name: @resource_type.name } }
    assert_redirected_to resource_type_url(@resource_type)
  end

  test "should destroy resource_type" do
    assert_difference("ResourceType.count", -1) do
      delete resource_type_url(@resource_type)
    end

    assert_redirected_to resource_types_url
  end
end