aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-11-14 17:16:43 +0000
committerMatthew Lemon <y@yulqen.org>2024-11-14 17:16:43 +0000
commit2022831d4960054aef904e27fd2934beb4e3c65e (patch)
tree77f11b9c629d66b9782d7dc6c77105bb178116d8 /test
parent9292aae8fe1876fe98c90ae0216fb4ea8917b38a (diff)
Adds category model but not wired up to resource yet
Diffstat (limited to 'test')
-rw-r--r--test/controllers/categories_controller_test.rb48
-rw-r--r--test/fixtures/categories.yml11
-rw-r--r--test/models/category_test.rb7
-rw-r--r--test/system/categories_test.rb45
4 files changed, 111 insertions, 0 deletions
diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb
new file mode 100644
index 0000000..a21af3b
--- /dev/null
+++ b/test/controllers/categories_controller_test.rb
@@ -0,0 +1,48 @@
+require "test_helper"
+
+class CategoriesControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ @category = categories(:one)
+ 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
+ assert_difference("Category.count") do
+ post categories_url, params: { category: { badge_foreground_colour: @category.badge_foreground_colour, colour: @category.colour, name: @category.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
diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml
new file mode 100644
index 0000000..9074eff
--- /dev/null
+++ b/test/fixtures/categories.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ name: MyString
+ colour: MyString
+ badge_foreground_colour: MyString
+
+two:
+ name: MyString
+ colour: MyString
+ badge_foreground_colour: MyString
diff --git a/test/models/category_test.rb b/test/models/category_test.rb
new file mode 100644
index 0000000..869357c
--- /dev/null
+++ b/test/models/category_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class CategoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/system/categories_test.rb b/test/system/categories_test.rb
new file mode 100644
index 0000000..acff020
--- /dev/null
+++ b/test/system/categories_test.rb
@@ -0,0 +1,45 @@
+require "application_system_test_case"
+
+class CategoriesTest < ApplicationSystemTestCase
+ setup do
+ @category = categories(:one)
+ end
+
+ test "visiting the index" do
+ visit categories_url
+ assert_selector "h1", text: "Categories"
+ end
+
+ test "should create category" do
+ visit categories_url
+ click_on "New category"
+
+ fill_in "Badge foreground colour", with: @category.badge_foreground_colour
+ fill_in "Colour", with: @category.colour
+ fill_in "Name", with: @category.name
+ click_on "Create Category"
+
+ assert_text "Category was successfully created"
+ click_on "Back"
+ end
+
+ test "should update Category" do
+ visit category_url(@category)
+ click_on "Edit this category", match: :first
+
+ fill_in "Badge foreground colour", with: @category.badge_foreground_colour
+ fill_in "Colour", with: @category.colour
+ fill_in "Name", with: @category.name
+ click_on "Update Category"
+
+ assert_text "Category was successfully updated"
+ click_on "Back"
+ end
+
+ test "should destroy Category" do
+ visit category_url(@category)
+ click_on "Destroy this category", match: :first
+
+ assert_text "Category was successfully destroyed"
+ end
+end