2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
2010-03-10 18:21:43 -05:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
class FavoritesControllerTest < ActionDispatch::IntegrationTest
|
2010-12-05 22:27:45 -05:00
|
|
|
context "The favorites controller" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@user = create(:user)
|
2010-12-05 22:27:45 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
context "index action" do
|
2011-07-22 19:02:53 -04:00
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@post = create(:post)
|
2022-04-07 12:23:20 -04:00
|
|
|
FavoriteManager.add!(user: @user, post: @post)
|
2011-07-22 19:02:53 -04:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
context "with a specified tags parameter" do
|
|
|
|
should "redirect to the posts controller" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth favorites_path, @user, params: {:tags => "fav:#{@user.name} abc"}
|
2010-12-05 22:27:45 -05:00
|
|
|
assert_redirected_to(posts_path(:tags => "fav:#{@user.name} abc"))
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
should "display the current user's favorites" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth favorites_path, @user
|
2010-12-05 22:27:45 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
context "create action" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@post = create(:post)
|
2010-12-05 22:27:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
should "create a favorite for the current user" do
|
2011-07-22 19:02:53 -04:00
|
|
|
assert_difference("Favorite.count", 1) do
|
2018-04-02 13:51:26 -04:00
|
|
|
post_auth favorites_path, @user, params: {:format => "js", :post_id => @post.id}
|
2010-12-05 22:27:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
context "destroy action" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@post = create(:post)
|
2022-04-07 12:23:20 -04:00
|
|
|
FavoriteManager.add!(user: @user, post: @post)
|
2010-12-05 22:27:45 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-12-05 22:27:45 -05:00
|
|
|
should "remove the favorite from the current user" do
|
2011-07-22 19:02:53 -04:00
|
|
|
assert_difference("Favorite.count", -1) do
|
2018-04-02 13:51:26 -04:00
|
|
|
delete_auth favorite_path(@post.id), @user, params: {:format => "js"}
|
2010-12-05 22:27:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
|
|
|
end
|