From 76c7325b6222d0a95c3e0775e72494f49f878f5c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sun, 15 Dec 2024 20:29:41 +0000 Subject: Improve category tests with authentication and unique data Added user login in setup to simulate admin access for tests. Ensured unique category names in creation tests to prevent conflicts. Updated category fixture data to reflect more distinct values. --- test/controllers/categories_controller_test.rb | 6 +++++- test/fixtures/categories.yml | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb index a21af3b..2185603 100644 --- a/test/controllers/categories_controller_test.rb +++ b/test/controllers/categories_controller_test.rb @@ -3,6 +3,9 @@ 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 @@ -16,8 +19,9 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest 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: @category.name } } + 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) diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml index 9074eff..056aa82 100644 --- a/test/fixtures/categories.yml +++ b/test/fixtures/categories.yml @@ -6,6 +6,6 @@ one: badge_foreground_colour: MyString two: - name: MyString - colour: MyString - badge_foreground_colour: MyString + name: MyString2 + colour: MyString2 + badge_foreground_colour: MyString2 -- cgit v1.2.3