From 7a06f74c70f1319e76c124623c7533bff07b21db Mon Sep 17 00:00:00 2001 From: usernaimandrey Date: Thu, 11 Aug 2022 23:20:28 +0300 Subject: [PATCH] fixed_test --- .../posts/comments_controller_test.rb | 2 +- .../posts/likes_controller_test.rb | 41 +++++++++---------- test/controllers/posts_controller_test.rb | 8 ++-- test/fixtures/posts.yml | 10 +++-- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/test/controllers/posts/comments_controller_test.rb b/test/controllers/posts/comments_controller_test.rb index 891c882..59826bd 100644 --- a/test/controllers/posts/comments_controller_test.rb +++ b/test/controllers/posts/comments_controller_test.rb @@ -7,7 +7,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:pety) - @post = posts(:no_like_no_comment) + @post = posts(:post_without_likes) @attributes = { content: Faker::Lorem.sentence, user_id: @user.id, diff --git a/test/controllers/posts/likes_controller_test.rb b/test/controllers/posts/likes_controller_test.rb index 8130be8..7268c4b 100644 --- a/test/controllers/posts/likes_controller_test.rb +++ b/test/controllers/posts/likes_controller_test.rb @@ -7,30 +7,27 @@ class LikesControllerTest < ActionDispatch::IntegrationTest setup do @user = users(:vasy) - @post_no_like = posts(:no_like_no_comment) + @post_without_likes = posts(:post_without_likes) @attributes = { user_id: @user.id, - post_id: @post_no_like.id + post_id: @post_without_likes.id } sign_in @user end test '#create' do - assert_difference @post_no_like.likes_count do - post post_likes_path(@post_no_like), params: @attributes - end + post post_likes_path(@post_without_likes), params: @attributes new_like = PostLike.find_by(@attributes) - assert_redirected_to post_path(@post_no_like) + assert_redirected_to post_path(@post_without_likes) assert { new_like } end test 'destroy' do post = posts(:one) like = post_likes(:one) - assert_difference post.likes_count do - delete post_like_path(post, like) - end + delete post_like_path(post, like) + delete_like = PostLike.find_by(id: like) assert_redirected_to post_path(post) @@ -39,34 +36,36 @@ class LikesControllerTest < ActionDispatch::IntegrationTest test '#create with not authorized' do sign_out @user - assert_no_difference @post_no_like.likes_count do - post post_likes_path(@post_no_like), params: @attributes - end + post post_likes_path(@post_without_likes), params: @attributes new_like = PostLike.find_by(@attributes) assert_redirected_to new_user_session_path assert_not(new_like) end - test 'duble click on like' do - post post_likes_path(@post_no_like), params: @attributes + test 'double click on like' do + post post_likes_path(@post_without_likes), params: @attributes + @post_without_likes.reload + likes_count = @post_without_likes.likes_count - assert_no_difference @post_no_like.likes_count do - post post_likes_path(@post_no_like), params: @attributes - end + post post_likes_path(@post_without_likes), params: @attributes + @post_without_likes.reload assert_response :redirect + assert { likes_count == @post_without_likes.likes_count } end - test 'duble click on unlike' do + test 'double click on unlike' do post = posts(:one) like = post_likes(:one) delete post_like_path(post, like) + post.reload + likes_count = post.likes_count - assert_no_difference post.likes_count do - delete post_like_path(post, like) - end + delete post_like_path(post, like) + post.reload assert_response :redirect + assert { likes_count == post.likes_count } end end diff --git a/test/controllers/posts_controller_test.rb b/test/controllers/posts_controller_test.rb index 6442ecb..cbe5bb1 100644 --- a/test/controllers/posts_controller_test.rb +++ b/test/controllers/posts_controller_test.rb @@ -13,7 +13,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph_by_chars(number: 51, supplemental: false), category_id: categories(:ruby).id, - creator_id: @user.id + creator: @user } end @@ -66,7 +66,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest delete post_path(@post) assert_redirected_to root_path - assert_not(Post.find_by(id: @post)) + assert_not(Post.find_by(id: @post.id)) end test '#destroy with not authorized' do @@ -74,7 +74,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest delete post_path(@post) assert_redirected_to new_user_session_path - assert { Post.find_by(id: @post) } + assert { Post.find_by(id: @post.id) } end test '#destroy created by another user' do @@ -84,6 +84,6 @@ class PostsControllerTest < ActionDispatch::IntegrationTest delete post_path(@post) assert_response 422 - assert { Post.find_by(id: @post) } + assert { Post.find_by(id: @post.id) } end end diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml index 95743c3..07df4c1 100644 --- a/test/fixtures/posts.yml +++ b/test/fixtures/posts.yml @@ -1,11 +1,13 @@ one: title: MyString - body: MyText + body: | + Ruby динамический язык программирования с открытым исходным кодом с упором на простоту и продуктивность. Он обладает элегантным синтаксисом, который приятно читать и легко писать. creator: vasy category: ruby -no_like_no_comment: +post_without_likes: title: MyString - body: MyText + body: | + avaScript входит в число самых популярных языков программирования, а фронтенд-разработка считается одним из самых простых способов начать карьеру в IT. В этой статье поговорим о целесообразности изучения JavaScript, перспективах этого языка, ситуации на рынке труда. Комментарии известных в отрасли экспертов помогут понять, стоит ли учить JavaScript, есть ли шанс получить работу и не устареют ли полученные знания в ближайшее время. creator: pety - category: ruby + category: js