Much base work started
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

This commit is contained in:
Dan Milne
2025-10-31 14:36:14 +11:00
parent 4a35bf6758
commit 88a906064f
97 changed files with 5333 additions and 2774 deletions

View File

@@ -0,0 +1,67 @@
require "test_helper"
class PasswordsControllerTest < ActionDispatch::IntegrationTest
setup { @user = User.take }
test "new" do
get new_password_path
assert_response :success
end
test "create" do
post passwords_path, params: { email_address: @user.email_address }
assert_enqueued_email_with PasswordsMailer, :reset, args: [ @user ]
assert_redirected_to new_session_path
follow_redirect!
assert_notice "reset instructions sent"
end
test "create for an unknown user redirects but sends no mail" do
post passwords_path, params: { email_address: "missing-user@example.com" }
assert_enqueued_emails 0
assert_redirected_to new_session_path
follow_redirect!
assert_notice "reset instructions sent"
end
test "edit" do
get edit_password_path(@user.password_reset_token)
assert_response :success
end
test "edit with invalid password reset token" do
get edit_password_path("invalid token")
assert_redirected_to new_password_path
follow_redirect!
assert_notice "reset link is invalid"
end
test "update" do
assert_changes -> { @user.reload.password_digest } do
put password_path(@user.password_reset_token), params: { password: "new", password_confirmation: "new" }
assert_redirected_to new_session_path
end
follow_redirect!
assert_notice "Password has been reset"
end
test "update with non matching passwords" do
token = @user.password_reset_token
assert_no_changes -> { @user.reload.password_digest } do
put password_path(token), params: { password: "no", password_confirmation: "match" }
assert_redirected_to edit_password_path(token)
end
follow_redirect!
assert_notice "Passwords did not match"
end
private
def assert_notice(text)
assert_select "div", /#{text}/
end
end

View File

@@ -0,0 +1,33 @@
require "test_helper"
class SessionsControllerTest < ActionDispatch::IntegrationTest
setup { @user = User.take }
test "new" do
get new_session_path
assert_response :success
end
test "create with valid credentials" do
post session_path, params: { email_address: @user.email_address, password: "password" }
assert_redirected_to root_path
assert cookies[:session_id]
end
test "create with invalid credentials" do
post session_path, params: { email_address: @user.email_address, password: "wrong" }
assert_redirected_to new_session_path
assert_nil cookies[:session_id]
end
test "destroy" do
sign_in_as(User.take)
delete session_path
assert_redirected_to new_session_path
assert_empty cookies[:session_id]
end
end

View File

@@ -0,0 +1,23 @@
require "test_helper"
class StorageLocationsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get storage_locations_index_url
assert_response :success
end
test "should get show" do
get storage_locations_show_url
assert_response :success
end
test "should get create" do
get storage_locations_create_url
assert_response :success
end
test "should get destroy" do
get storage_locations_destroy_url
assert_response :success
end
end

View File

@@ -0,0 +1,13 @@
require "test_helper"
class VideosControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get videos_index_url
assert_response :success
end
test "should get show" do
get videos_show_url
assert_response :success
end
end

View File

@@ -0,0 +1,13 @@
require "test_helper"
class WorksControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get works_index_url
assert_response :success
end
test "should get show" do
get works_show_url
assert_response :success
end
end

11
test/fixtures/external_ids.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
work: one
source: 1
value: MyString
two:
work: two
source: 1
value: MyString

19
test/fixtures/playback_sessions.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
video: one
user: one
position: 1.5
duration_watched: 1.5
last_watched_at: 2025-10-29 22:39:57
completed: false
play_count: 1
two:
video: two
user: two
position: 1.5
duration_watched: 1.5
last_watched_at: 2025-10-29 22:39:57
completed: false
play_count: 1

23
test/fixtures/storage_locations.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
path: MyString
location_type: 1
writable: false
enabled: false
scan_subdirectories: false
priority: 1
settings: MyText
last_scanned_at: 2025-10-29 22:38:50
two:
name: MyString
path: MyString
location_type: 1
writable: false
enabled: false
scan_subdirectories: false
priority: 1
settings: MyText
last_scanned_at: 2025-10-29 22:38:50

9
test/fixtures/users.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
<% password_digest = BCrypt::Password.create("password") %>
one:
email_address: one@example.com
password_digest: <%= password_digest %>
two:
email_address: two@example.com
password_digest: <%= password_digest %>

11
test/fixtures/video_assets.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
video: one
asset_type: 1
metadata: MyText
two:
video: two
asset_type: 1
metadata: MyText

51
test/fixtures/videos.yml vendored Normal file
View File

@@ -0,0 +1,51 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
work: one
storage_location: one
title: MyString
file_path: MyString
file_hash: MyString
file_size: 1
duration: 1.5
width: 1
height: 1
resolution_label: MyString
video_codec: MyString
audio_codec: MyString
bit_rate: 1
frame_rate: 1.5
format: MyString
has_subtitles: false
version_type: MyString
source_type: 1
source_url: MyString
imported: false
processing_failed: false
error_message: MyText
metadata: MyText
two:
work: two
storage_location: two
title: MyString
file_path: MyString
file_hash: MyString
file_size: 1
duration: 1.5
width: 1
height: 1
resolution_label: MyString
video_codec: MyString
audio_codec: MyString
bit_rate: 1
frame_rate: 1.5
format: MyString
has_subtitles: false
version_type: MyString
source_type: 1
source_url: MyString
imported: false
processing_failed: false
error_message: MyText
metadata: MyText

23
test/fixtures/works.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
year: 1
director: MyString
description: MyText
rating: 9.99
organized: false
poster_path: MyString
backdrop_path: MyString
metadata: MyText
two:
title: MyString
year: 1
director: MyString
description: MyText
rating: 9.99
organized: false
poster_path: MyString
backdrop_path: MyString
metadata: MyText

View File

@@ -0,0 +1,7 @@
# Preview all emails at http://localhost:3000/rails/mailers/passwords_mailer
class PasswordsMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/passwords_mailer/reset
def reset
PasswordsMailer.reset(User.take)
end
end

View File

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

View File

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

View File

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

8
test/models/user_test.rb Normal file
View File

@@ -0,0 +1,8 @@
require "test_helper"
class UserTest < ActiveSupport::TestCase
test "downcases and strips email_address" do
user = User.new(email_address: " DOWNCASED@EXAMPLE.COM ")
assert_equal("downcased@example.com", user.email_address)
end
end

View File

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

View File

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

7
test/models/work_test.rb Normal file
View File

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

View File

@@ -1,6 +1,7 @@
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
require_relative "test_helpers/session_test_helper"
module ActiveSupport
class TestCase

View File

@@ -0,0 +1,19 @@
module SessionTestHelper
def sign_in_as(user)
Current.session = user.sessions.create!
ActionDispatch::TestRequest.create.cookie_jar.tap do |cookie_jar|
cookie_jar.signed[:session_id] = Current.session.id
cookies["session_id"] = cookie_jar[:session_id]
end
end
def sign_out
Current.session&.destroy!
cookies.delete("session_id")
end
end
ActiveSupport.on_load(:action_dispatch_integration_test) do
include SessionTestHelper
end