Add tests for all models with includes searches

This commit is contained in:
BrokenEagle
2020-07-19 04:06:51 +00:00
parent 34ca33e22f
commit a903bd95f9
34 changed files with 893 additions and 360 deletions

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class IpBansControllerTest < ActionDispatch::IntegrationTest
context "The ip bans controller" do
setup do
@admin = create(:admin_user)
@ip_ban = create(:ip_ban)
@admin = create(:admin_user, name: "yukari")
@ip_ban = create(:ip_ban, ip_addr: "6.7.8.9")
end
context "new action" do
@@ -24,21 +24,34 @@ class IpBansControllerTest < ActionDispatch::IntegrationTest
should "log a mod action" do
post_auth ip_bans_path, @admin, params: { ip_ban: { ip_addr: "1.2.3.4", reason: "xyz" }}
assert_equal("ip_ban_create", ModAction.last.category)
assert_equal("ip_ban_create", ModAction.last&.category)
end
end
context "index action" do
setup do
CurrentUser.user = @admin
@subnet_ban = create(:ip_ban, ip_addr: "2.0.0.0/24", creator: @admin)
@other_ban = create(:ip_ban, reason: "malware")
end
should "render access denied for anonymous users" do
get ip_bans_path
assert_response 403
end
should "render" do
get_auth ip_bans_path, @admin
assert_response :success
end
context "with search parameters" do
should "render" do
get_auth ip_bans_path, @admin, params: {:search => {:ip_addr => "1.2.3.4"}}
assert_response :success
end
should respond_to_search({}).with { [@other_ban, @subnet_ban, @ip_ban] }
should respond_to_search(ip_addr: "6.7.8.9").with { @ip_ban }
should respond_to_search(reason_matches: "malware").with { @other_ban }
context "using includes" do
should respond_to_search(creator_name: "yukari").with { @subnet_ban }
should respond_to_search(creator: {level: User::Levels::ADMIN}).with { @subnet_ban }
end
end