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,7 +3,8 @@ require 'test_helper'
class PostAppealsControllerTest < ActionDispatch::IntegrationTest
context "The post appeals controller" do
setup do
@user = create(:user)
@user = create(:user, name: "orin")
@post = create(:post, id: 101, is_deleted: true)
end
context "new action" do
@@ -24,8 +25,10 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
context "index action" do
setup do
as(@user) do
@post = create(:post, :is_deleted => true)
@post_appeal = create(:post_appeal, :post => @post)
@post_appeal = create(:post_appeal, post: @post, creator: @user)
@unrelated_appeal = create(:post_appeal, reason: "Good.")
@resolved_appeal = create(:post_appeal)
@resolved_appeal.post.update(is_deleted: false)
end
end
@@ -34,24 +37,18 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "render for json" do
get post_appeals_path, as: :json
assert_response :success
end
should respond_to_search({}).with { [@resolved_appeal, @unrelated_appeal, @post_appeal] }
should respond_to_search(reason_matches: "Good.").with { @unrelated_appeal }
should respond_to_search(is_resolved: "true").with { @resolved_appeal }
context "with search parameters" do
should "render" do
get_auth post_appeals_path, @user, params: {:search => {:post_id => @post_appeal.post_id}}
assert_response :success
end
context "using includes" do
should respond_to_search(post_id: 101).with { @post_appeal }
should respond_to_search(post: {is_deleted: "true"}).with { [@unrelated_appeal, @post_appeal] }
should respond_to_search(creator_name: "orin").with { @post_appeal }
end
end
context "create action" do
setup do
@post = as(@user) { create(:post, is_deleted: true) }
end
should "create a new appeal" do
assert_difference("PostAppeal.count", 1) do
post_auth post_appeals_path, @user, params: {:format => "js", :post_appeal => {:post_id => @post.id, :reason => "xxx"}}