/favorites: replace favorites view with ordfav: search.
Make /favorites redirect to a ordfav:<user> search instead of having a separate view just for favorites. This duplicated a lot of code for no good reason.
This commit is contained in:
@@ -12,16 +12,19 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
|
||||
@post.add_favorite!(@user)
|
||||
end
|
||||
|
||||
context "with a specified tags parameter" do
|
||||
should "redirect to the posts controller" do
|
||||
get_auth favorites_path, @user, params: {:tags => "fav:#{@user.name} abc"}
|
||||
assert_redirected_to(posts_path(:tags => "fav:#{@user.name} abc"))
|
||||
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}")
|
||||
end
|
||||
|
||||
should "display the current user's favorites" do
|
||||
should "redirect members to an ordfav: search" do
|
||||
get_auth favorites_path, @user
|
||||
assert_response :success
|
||||
assert_redirected_to posts_path(tags: "ordfav:#{@user.name}")
|
||||
end
|
||||
|
||||
should "redirect anonymous users to the posts index" do
|
||||
get favorites_path
|
||||
assert_redirected_to posts_path
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
module PostSets
|
||||
class FavoriteTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = FactoryBot.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post_1 = FactoryBot.create(:post)
|
||||
@post_2 = FactoryBot.create(:post)
|
||||
@post_3 = FactoryBot.create(:post)
|
||||
@post_2.add_favorite!(@user)
|
||||
@post_1.add_favorite!(@user)
|
||||
@post_3.add_favorite!(@user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "a favorite set for before the most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_3.id).first.id
|
||||
@set = PostSets::Favorite.new(@user.id, "b#{id}", limit: 1)
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the second most recent element" do
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know what page it's on" do
|
||||
refute(@set.favorites.is_first_page?)
|
||||
refute(@set.favorites.is_last_page?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a favorite set for after the third most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_2.id).first.id
|
||||
::Favorite.stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, "a#{id}")
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the second most recent element" do
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know what page it's on" do
|
||||
refute(@set.favorites.is_first_page?)
|
||||
refute(@set.favorites.is_last_page?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a favorite set for before the second most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_1.id).first.id
|
||||
::Favorite.stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, "b#{id}")
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the third most recent element" do
|
||||
assert_equal(@post_2.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know what page it's on" do
|
||||
refute(@set.favorites.is_first_page?)
|
||||
assert(@set.favorites.is_last_page?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a favorite set for after the second most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_1.id).first.id
|
||||
::Favorite.stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, "a#{id}")
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
should "return the most recent element" do
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know what page it's on" do
|
||||
assert(@set.favorites.is_first_page?)
|
||||
refute(@set.favorites.is_last_page?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a favorite set for page 2" do
|
||||
setup do
|
||||
::Favorite.stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, 2)
|
||||
end
|
||||
|
||||
context "a numbered paginator" do
|
||||
should "return the second most recent element" do
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know what page it's on" do
|
||||
refute(@set.favorites.is_first_page?)
|
||||
refute(@set.favorites.is_last_page?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a favorite set with no page specified" do
|
||||
setup do
|
||||
::Favorite.stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id)
|
||||
end
|
||||
|
||||
should "return the most recent element" do
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know what page it's on" do
|
||||
assert(@set.favorites.is_first_page?)
|
||||
refute(@set.favorites.is_last_page?)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user