Configure tests and helpers for current backend state

This commit is contained in:
hannah.dagemark 2025-05-09 14:58:37 +02:00 committed by Hannah Dagemark
commit 4edae5e7bb
9 changed files with 85 additions and 11 deletions

View file

@ -0,0 +1,2 @@
module SessionsHelper
end

View file

@ -0,0 +1,2 @@
module UsersHelper
end

View file

@ -0,0 +1,19 @@
require "test_helper"
class SessionsControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get new_sessions_path
assert_response :success
end
test "should get create" do
post sessions_path, params: { email: "test@email.com", password: "testpassword" }
assert_redirected_to root_path
end
test "should get destroy" do
post sessions_path, params: { email: "test@email.com", password: "testpassword" }
delete sessions_path
assert_redirected_to root_path
end
end

View file

@ -1,23 +1,21 @@
require "test_helper"
include ActiveJob::TestHelper
class Test::ImagesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get test_images_index_url
assert_response :success
end
test "should get new" do
get test_images_new_url
get test_images_path
assert_response :success
end
test "should get create" do
get test_images_create_url
assert_response :success
file = fixture_file_upload("test_image.jpg", "image/jpeg")
post test_images_path, params: { image: { file: file, title: "test" } }
assert_redirected_to test_images_path
end
test "should get show" do
get test_images_show_url
assert_response :success
teardown do
perform_enqueued_jobs do
ActiveStorage::Blob.all.each(&:purge_later)
end
end
end

View file

@ -0,0 +1,38 @@
require "test_helper"
class UsersControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:one) # Assuming you have a fixture or factory for @user
end
test "should get new" do
get new_user_path
assert_response :success
end
test "should get create" do
post users_path
assert_response :success
# post users_path, params: { user: { username: "testuser", password: "password123" } }
# assert_redirected_to user_path(User.last)
end
test "should get edit" do
get edit_user_path(@user)
assert_response :success
end
test "should get update" do
patch user_path(@user)
assert_response :success
# Probably also assert a successful redirect later and push correct data params
end
test "should get destroy" do
delete user_path(@user)
assert_response :success
# Possibly this one too I suppose
end
end

View file

@ -0,0 +1 @@
# Keep these, they're silly

BIN
test/fixtures/files/test_image.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 KiB

7
test/fixtures/users.yml vendored Normal file
View file

@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: testuser
status: test
email: test@email.com
password_digest: <%= BCrypt::Password.create('testpassword') %>

7
test/models/user_test.rb Normal file
View file

@ -0,0 +1,7 @@
require "test_helper"
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end