pundit: convert favorites to pundit.

This commit is contained in:
evazion
2020-03-18 03:06:25 -05:00
parent cc2b4abd09
commit f1f489c40b
4 changed files with 37 additions and 21 deletions

View File

@@ -4,51 +4,56 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
context "The favorites controller" do
setup do
@user = create(:user)
@post = create(:post)
@faved_post = create(:post)
@faved_post.add_favorite!(@user)
end
context "index action" do
setup do
@post = create(:post)
@post.add_favorite!(@user)
end
should "redirect the user_id param to an ordfav: search" do
get favorites_path(user_id: @user.id)
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}")
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}", format: "html")
end
should "redirect members to an ordfav: search" do
get_auth favorites_path, @user
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}")
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}", format: "html")
end
should "redirect anonymous users to the posts index" do
get favorites_path
assert_redirected_to posts_path
assert_redirected_to posts_path(format: "html")
end
end
context "create action" do
setup do
@post = create(:post)
end
should "create a favorite for the current user" do
assert_difference("Favorite.count", 1) do
post_auth favorites_path, @user, params: {:format => "js", :post_id => @post.id}
post_auth favorites_path(post_id: @post.id), @user, as: :javascript
assert_response :redirect
end
end
should "allow banned users to create favorites" do
assert_difference("Favorite.count", 1) do
post_auth favorites_path(post_id: @post.id), create(:banned_user), as: :javascript
assert_response :redirect
end
end
end
context "destroy action" do
setup do
@post = create(:post)
@post.add_favorite!(@user)
end
should "remove the favorite from the current user" do
assert_difference("Favorite.count", -1) do
delete_auth favorite_path(@post.id), @user, params: {:format => "js"}
delete_auth favorite_path(@faved_post.id), @user, as: :javascript
assert_response :redirect
end
end
should "allow banned users to destroy favorites" do
assert_difference("Favorite.count", -1) do
delete_auth favorite_path(@faved_post.id), @user, as: :javascript
assert_response :redirect
end
end
end