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 PoolsControllerTest < ActionDispatch::IntegrationTest
|
2011-01-20 18:30:36 -05:00
|
|
|
context "The pools controller" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
travel_to(1.month.ago) do
|
|
|
|
@user = create(:user)
|
|
|
|
@mod = create(:moderator_user)
|
|
|
|
end
|
2022-11-26 06:49:35 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@post = create(:post)
|
|
|
|
@pool = create(:pool)
|
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
context "index action" do
|
|
|
|
should "list all pools" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get pools_path
|
2011-01-20 18:30:36 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
should "list all pools (with search)" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get pools_path, params: {:search => {:name_matches => @pool.name}}
|
2011-01-20 18:30:36 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
context "show action" do
|
|
|
|
should "render" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get pool_path(@pool)
|
2011-01-20 18:30:36 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2017-02-06 03:01:39 -05:00
|
|
|
context "gallery action" do
|
|
|
|
should "render" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get gallery_pools_path
|
2017-02-06 03:01:39 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "new action" do
|
|
|
|
should "render" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth new_pool_path, @user
|
2017-02-06 03:01:39 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
context "create action" do
|
|
|
|
should "create a pool" do
|
|
|
|
assert_difference("Pool.count", 1) do
|
2018-04-02 13:51:26 -04:00
|
|
|
post_auth pools_path, @user, params: {:pool => {:name => "xxx", :description => "abc"}}
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
|
|
|
end
|
2017-02-06 03:01:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "edit action" do
|
|
|
|
should "render" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth edit_pool_path(@pool), @user
|
2017-02-06 03:01:39 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
context "update action" do
|
2018-04-02 13:51:26 -04:00
|
|
|
should "update a pool" do
|
2018-11-08 12:32:58 -05:00
|
|
|
put_auth pool_path(@pool), @user, params: { pool: { name: "xyz", post_ids: [@post.id] }}
|
2018-04-02 13:51:26 -04:00
|
|
|
assert_equal("xyz", @pool.reload.name)
|
2018-11-08 12:32:58 -05:00
|
|
|
assert_equal([@post.id], @pool.post_ids)
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
should "not allow updating unpermitted attributes" do
|
2022-02-10 11:53:51 -05:00
|
|
|
put_auth pool_path(@pool), @user, params: { pool: { post_count: -42 }}
|
2018-04-02 13:51:26 -04:00
|
|
|
assert_equal(0, @pool.post_count)
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
context "destroy action" do
|
|
|
|
should "destroy a pool" do
|
2018-04-02 13:51:26 -04:00
|
|
|
delete_auth pool_path(@pool), @mod
|
2022-02-10 11:53:51 -05:00
|
|
|
assert_raises(ActiveRecord::RecordNotFound) do
|
|
|
|
@pool.reload
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2012-03-15 18:26:39 -04:00
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
context "revert action" do
|
|
|
|
setup do
|
2022-11-26 06:49:35 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@post_2 = create(:post)
|
2018-11-08 12:32:58 -05:00
|
|
|
@pool = create(:pool, post_ids: [@post.id])
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2022-11-26 09:20:15 -05:00
|
|
|
as(@user, "1.2.3.4") do
|
2018-11-08 12:32:58 -05:00
|
|
|
@pool.update(post_ids: [@post.id, @post_2.id])
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-20 18:30:36 -05:00
|
|
|
should "revert to a previous version" do
|
2016-09-12 20:38:55 -04:00
|
|
|
@pool.reload
|
|
|
|
version = @pool.versions.first
|
2016-12-14 21:09:45 -05:00
|
|
|
assert_equal([@post.id], version.post_ids)
|
2018-04-02 13:51:26 -04:00
|
|
|
put_auth revert_pool_path(@pool), @mod, params: {:version_id => version.id}
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool.reload
|
2018-11-08 12:32:58 -05:00
|
|
|
assert_equal([@post.id], @pool.post_ids)
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2016-10-11 00:07:28 -04:00
|
|
|
|
|
|
|
should "not allow reverting to a previous version of another pool" do
|
2022-11-26 06:49:35 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@pool2 = create(:pool)
|
|
|
|
end
|
|
|
|
put_auth revert_pool_path(@pool), @user, params: {:version_id => @pool2.versions.first.id }
|
2016-10-11 00:07:28 -04:00
|
|
|
@pool.reload
|
|
|
|
assert_not_equal(@pool.name, @pool2.name)
|
|
|
|
assert_response :missing
|
|
|
|
end
|
2011-01-20 18:30:36 -05:00
|
|
|
end
|
2024-02-27 12:37:22 -05:00
|
|
|
|
|
|
|
should "render the order action" do
|
|
|
|
get_auth edit_pool_order_path(@pool), @user
|
|
|
|
assert_response :success
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
|
|
|
end
|