diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-15 20:29:41 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-15 20:29:41 +0000 |
commit | 76c7325b6222d0a95c3e0775e72494f49f878f5c (patch) | |
tree | 36a6fa70c81327fd0829cd1616a07981362c22f8 | |
parent | 6f197cf2fda6ef1888deafb2acffa095cc0906c7 (diff) |
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.
-rw-r--r-- | test/controllers/categories_controller_test.rb | 6 | ||||
-rw-r--r-- | 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 |