2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
2011-01-14 15:50:17 -05:00
|
|
|
|
2018-04-02 13:51:26 -04:00
|
|
|
class IpBansControllerTest < ActionDispatch::IntegrationTest
|
2011-01-14 15:50:17 -05:00
|
|
|
context "The ip bans controller" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@admin = create(:admin_user)
|
2011-01-14 15:50:17 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-14 15:50:17 -05:00
|
|
|
context "new action" do
|
|
|
|
should "render" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth new_ip_ban_path, @admin
|
2011-01-14 15:50:17 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "create action" do
|
|
|
|
should "create a new ip ban" do
|
|
|
|
assert_difference("IpBan.count", 1) do
|
2022-04-13 02:54:50 -04:00
|
|
|
post_auth ip_bans_path, @admin, params: { ip_ban: { ip_addr: "1.2.3.4", reason: "xyz" } }
|
2011-01-14 15:50:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-14 15:50:17 -05:00
|
|
|
context "index action" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
as(@admin) do
|
2022-04-13 02:54:50 -04:00
|
|
|
create(:ip_ban, ip_addr: "1.2.3.4")
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2011-01-14 15:50:17 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-14 15:50:17 -05:00
|
|
|
should "render" do
|
2018-04-02 13:51:26 -04:00
|
|
|
get_auth ip_bans_path, @admin
|
2011-01-14 15:50:17 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-14 15:50:17 -05:00
|
|
|
context "with search parameters" do
|
|
|
|
should "render" do
|
2022-04-13 02:54:50 -04:00
|
|
|
get_auth ip_bans_path, @admin, params: { search: { ip_addr: "1.2.3.4" } }
|
2011-01-14 15:50:17 -05:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-14 15:50:17 -05:00
|
|
|
context "destroy action" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
as(@admin) do
|
2022-04-13 02:54:50 -04:00
|
|
|
@ip_ban = create(:ip_ban, ip_addr: "1.2.3.4")
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2011-01-14 15:50:17 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-01-14 15:50:17 -05:00
|
|
|
should "destroy an ip ban" do
|
|
|
|
assert_difference("IpBan.count", -1) do
|
2022-04-13 02:54:50 -04:00
|
|
|
delete_auth ip_ban_path(@ip_ban), @admin, params: { format: "js" }
|
2011-01-14 15:50:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|