aboutsummaryrefslogtreecommitdiffstats
path: root/test/controllers/categories_controller_test.rb
blob: 21856038e1512c497afe5f7b423ae6cefbaa0122 (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
require "test_helper"

class CategoriesControllerTest < ActionDispatch::IntegrationTest
  setup do
    @category = categories(:one)
    @user = users(:one)
    post session_url, params: { email_address: @user.email_address, password: "password", is_admin: true }
    follow_redirect! # After login
  end

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

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

  test "should create category" do
    unique_name = "UniqueCategoryName#{SecureRandom.hex(8)}"
    assert_difference("Category.count") do
      post categories_url, params: { category: { badge_foreground_colour: @category.badge_foreground_colour, colour: @category.colour, name: unique_name } }
    end

    assert_redirected_to category_url(Category.last)
  end

  test "should show category" do
    get category_url(@category)
    assert_response :success
  end

  test "should get edit" do
    get edit_category_url(@category)
    assert_response :success
  end

  test "should update category" do
    patch category_url(@category), params: { category: { badge_foreground_colour: @category.badge_foreground_colour, colour: @category.colour, name: @category.name } }
    assert_redirected_to category_url(@category)
  end

  test "should destroy category" do
    assert_difference("Category.count", -1) do
      delete category_url(@category)
    end

    assert_redirected_to categories_url
  end
end