Skip to content

Commit

Permalink
Merge pull request #58 from miminashi/56-introduce-testing
Browse files Browse the repository at this point in the history
テストを導入した
  • Loading branch information
miminashi authored Sep 23, 2023
2 parents 998fa90 + ad24127 commit f12228c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 19 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: PreCompile assets
run: ./rails assets:precompile RAILS_ENV=test
- name: Create database
run: ./rails db:create
- name: Run tests on docker compose
run: ./rails test
2 changes: 1 addition & 1 deletion app/models/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def fetch_title(video_url)
stdout, stderr, status = Open3.capture3(command)
if status.success?
logger.info("タイトルの取得に成功しました")
return stdout
return stdout.chomp
else
logger.debug stderr
logger.debug("タイトルの取得に失敗しました")
Expand Down
1 change: 1 addition & 0 deletions default_secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3b3af996b321e7ed79a9a85c0a98ef13d079497d28be02d20003a77e6cd65c74d79df4e04a94929de7c797231ffb6f7c9e56745dba6197b955f5a11676356c02
22 changes: 22 additions & 0 deletions docker_compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# SECRET_KEY_BASE が定義されていない場合
if [ -z "${SECRET_KEY_BASE}" ]; then
echo "SECRET_KEY_BASE is not defined" >&2
if [ -f secret.txt ]; then
echo "using secret.txt" >&2
SECRET_KEY_BASE="$(cat secret.txt)"
elif [ -f default_secret.txt ]; then
echo "using default_secret.txt" >&2
echo "+------------- !!!! WARNING !!!! --------------+" >&2
echo "| DO NOT USE default_secret.txt FOR DEPLOYMENT |" >&2
echo "+----------------------------------------------+" >&2
SECRET_KEY_BASE="$(cat default_secret.txt)"
else
echo "no secret files found" >&2
exit 1
fi
fi

export SECRET_KEY_BASE
docker compose -f docker-compose.yml -f docker-compose-development.yml -p ytdlor "$@"
3 changes: 3 additions & 0 deletions rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

./docker_compose run --rm web rails $@
35 changes: 20 additions & 15 deletions test/controllers/archives_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

class ArchivesControllerTest < ActionDispatch::IntegrationTest
setup do
@archive = archives(:one)
#@archive = archives(:one)
@archive = Archive.new(original_url: "https://vimeo.com/1084537")
@archive.save!
#@archive.update_title
#@archive.update_thumbnail
#@archive.update_video
end

test "should get index" do
Expand All @@ -28,21 +33,21 @@ class ArchivesControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

test "should get edit" do
get edit_archive_url(@archive)
assert_response :success
end
#test "should get edit" do
# get edit_archive_url(@archive)
# assert_response :success
#end

test "should update archive" do
patch archive_url(@archive), params: { archive: { original_url: @archive.original_url, status: @archive.status, title: @archive.title } }
assert_redirected_to archive_url(@archive)
end
#test "should update archive" do
# patch archive_url(@archive), params: { archive: { original_url: @archive.original_url, status: @archive.status, title: @archive.title } }
# assert_redirected_to archive_url(@archive)
#end

test "should destroy archive" do
assert_difference("Archive.count", -1) do
delete archive_url(@archive)
end
#test "should destroy archive" do
# assert_difference("Archive.count", -1) do
# delete archive_url(@archive)
# end

assert_redirected_to archives_url
end
# assert_redirected_to archives_url
#end
end
35 changes: 32 additions & 3 deletions test/models/archive_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,36 @@
require "test_helper"

class ArchiveTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@archive = Archive.new(original_url: "https://vimeo.com/1084537")
end

test "should be valid" do
assert @archive.valid?
end

test "original_url should be present" do
@archive.original_url = ""
assert_not @archive.valid?
end

test "should get title" do
@archive.save!
@archive.update_title
assert_equal "Big Buck Bunny", @archive.title
end

test "should get thumbnail" do
# broadcast_replace_to がレンダリングするviewからidが参照されるので, DBに保存しておく
@archive.save!
@archive.update_thumbnail
assert @archive.thumbnail.attached?
end

test "should get video" do
# broadcast_replace_to がレンダリングするviewからidが参照されるので, DBに保存しておく
@archive.save!
@archive.update_video
assert @archive.video.attached?
end
end

0 comments on commit f12228c

Please sign in to comment.