Skip to content

Commit

Permalink
テストの追加とサンプルデータの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
a-terumoto-gs committed Apr 8, 2024
1 parent 21f394f commit 18548b3
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/views/movies/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- title '動画'
- title "動画: #{@movie.title}"
- set_meta_tags description: '動画「#{@movie.title}」ページです。'

header.page-header
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/active_storage/attachments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,24 @@ kimuramitai_profile_image:
name: profile_image
record: kimuramitai (User)
blob: kimuramitai_profile_image_blob

mp4_movie:
name: movie_data
record: movie1 (Movie)
blob: mp4_movie_blob

mp4_thumbnail:
name: thumbnail
record: movie1 (Movie)
blob: mp4_thumbnail_blob

mov_movie:
name: movie_data
record: movie2 (Movie)
blob: mov_movie_blob


mov_thumbnail:
name: thumbnail
record: movie2 (Movie)
blob: mov_thumbnail_blob
8 changes: 8 additions & 0 deletions test/fixtures/active_storage/blobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ komagata_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/av
machida_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/machida.jpg" %>

kimuramitai_profile_image_blob: <%= ActiveStorage::Blob.fixture filename: "users/avatars/default.jpg" %>

mp4_movie_blob: <%= ActiveStorage::Blob.fixture filename: "movies/sample.mp4" %>

mp4_thumbnail_blob: <%= ActiveStorage::Blob.fixture filename: "movies/thumbnail_mp4.png" %>

mov_movie_blob: <%= ActiveStorage::Blob.fixture filename: "movies/sample.mov" %>

mov_thumbnail_blob: <%= ActiveStorage::Blob.fixture filename: "movies/thumbnail_mov.png" %>
Binary file added test/fixtures/files/movies/sample.mov
Binary file not shown.
Binary file added test/fixtures/files/movies/sample.mp4
Binary file not shown.
Binary file added test/fixtures/files/movies/thumbnail_mov.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/files/movies/thumbnail_mp4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 8 additions & 12 deletions test/fixtures/movies.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
movie1:
title: mp4動画
description: mp4の動画です
user: kimura

one:
title: MyString
description: MyText
tags: MyString
public_scope: 1

two:
title: MyString
description: MyText
tags: MyString
public_scope: 1
movie2:
title: mov動画
description: movの動画です
user: kimura
63 changes: 63 additions & 0 deletions test/system/movies_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require 'application_system_test_case'

class MoviesTest < ApplicationSystemTestCase

test 'GET /movies' do
visit_with_auth '/movies', 'kimura'
assert_equal '動画 | FBC', title
end

test 'show movie' do
visit_with_auth "/movies/#{movies(:movie1).id}", 'kimura'
assert_equal '動画: mp4動画 | FBC', title
end

test 'page has a comment form ' do
visit_with_auth "/movies/#{movies(:movie1).id}", 'kimura'
assert_selector '.thread-comment-form'
end

test 'add new mp4 movie' do
visit_with_auth new_movie_path, 'kimura'
assert_equal new_movie_path, current_path
fill_in 'movie[title]', with: '新規動画を作成する'
fill_in 'movie[description]', with: '新規動画を作成する本文です'
attach_file 'movie[movie_data]', 'test/fixtures/files/movies/sample.mp4'
click_button '動画を追加する'
assert_text '動画を追加しました'
end

test 'add new mov movie' do
visit_with_auth new_movie_path, 'kimura'
assert_equal new_movie_path, current_path
fill_in 'movie[title]', with: '新規動画を作成する'
fill_in 'movie[description]', with: '新規動画を作成する本文です'
attach_file 'movie[movie_data]', 'test/fixtures/files/movies/sample.mov'
click_button '動画を追加する'
assert_text '動画を追加しました'
end

test 'doc can relate practice' do
visit_with_auth new_movie_path, 'kimura'
fill_in 'movie[title]', with: '動画に関連プラクティスを指定'
fill_in 'movie[description]', with: '動画に関連プラクティスを指定'
first('.choices__inner').click
find('.choices__item--choice', text: '[UNIX] Linuxのファイル操作の基礎を覚える').click
attach_file 'movie[movie_data]', 'test/fixtures/files/movies/sample.mp4'
click_button '動画を追加する'
assert_text 'Linuxのファイル操作の基礎を覚える'
end

test 'show comment count' do
visit_with_auth "/movies/#{movies(:movie1).id}", 'kimura'
assert_selector '#comment_count', text: 0

fill_in 'new_comment[description]', with: 'コメント数表示のテストです。'
click_button 'コメントする'

visit current_path
assert_selector '#comment_count', text: 1
end
end

0 comments on commit 18548b3

Please sign in to comment.