Add tests for all models with includes searches
This commit is contained in:
@@ -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"}}
|
||||
|
||||
Reference in New Issue
Block a user