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,22 +3,35 @@ require 'test_helper'
class ForumPostVotesControllerTest < ActionDispatch::IntegrationTest
context "The forum post votes controller" do
setup do
@user = create(:user)
@user = create(:user, name: "cirno")
@other_user = create(:user)
as(@user) do
@forum_topic = create(:forum_topic)
@forum_post = create(:forum_post, topic: @forum_topic)
@forum_post = create(:forum_post, body: "blah", creator: @user)
@bulk_update_request = create(:bulk_update_request, forum_post: @forum_post)
end
end
context "index action" do
setup do
@vote = create(:forum_post_vote, forum_post: @forum_post, creator: build(:user, name: "rumia"), score: 1)
@negative_vote = create(:forum_post_vote, forum_post: @forum_post, score: -1)
@unrelated_vote = as (@user) { create(:forum_post_vote, score: 0) }
end
should "render" do
@forum_post_vote = create(:forum_post_vote, creator: @user, forum_post: @forum_post)
get forum_post_votes_path
assert_response :success
end
should respond_to_search({}).with { [@unrelated_vote, @negative_vote, @vote] }
should respond_to_search(score: -1).with { @negative_vote }
context "using includes" do
should respond_to_search(creator_name: "rumia").with { @vote }
should respond_to_search(forum_post: {creator_name: "cirno"}).with { [@negative_vote, @vote] }
should respond_to_search(forum_post: {body_matches: "blah"}).with { [@negative_vote, @vote] }
end
end
context "create action" do