Skip to content

Commit

Permalink
fixed_test
Browse files Browse the repository at this point in the history
  • Loading branch information
usernaimandrey committed Aug 11, 2022
1 parent 931b1b4 commit 7a06f74
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/controllers/posts/comments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 20 additions & 21 deletions test/controllers/posts/likes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
8 changes: 4 additions & 4 deletions test/controllers/posts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -66,15 +66,15 @@ 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
sign_out @user
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
Expand All @@ -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
10 changes: 6 additions & 4 deletions test/fixtures/posts.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7a06f74

Please sign in to comment.