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

@@ -4,8 +4,8 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
context "A comments controller" do
setup do
@mod = FactoryBot.create(:moderator_user)
@user = FactoryBot.create(:member_user)
@post = create(:post)
@user = FactoryBot.create(:member_user, name: "cirno")
@post = create(:post, id: 100)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@@ -87,10 +87,31 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
end
end
should "render by comment" do
@comment = as(@user) { create(:comment, post: @post) }
get comments_path(group_by: "comment")
assert_response :success
context "grouped by comment" do
setup do
@user_comment = create(:comment, post: @post, score: 10, do_not_bump_post: true, creator: @user)
@mod_comment = create(:comment, post: build(:post, tag_string: "touhou"), body: "blah", is_sticky: true, creator: @mod)
@deleted_comment = create(:comment, is_deleted: true)
end
should "render" do
get comments_path(group_by: "comment")
assert_response :success
end
should respond_to_search({}, other_params: {group_by: "comment"}).with { [@deleted_comment, @mod_comment, @user_comment] }
should respond_to_search(body_matches: "blah").with { @mod_comment }
should respond_to_search(score: 10).with { @user_comment }
should respond_to_search(is_sticky: "true").with { @mod_comment }
should respond_to_search(do_not_bump_post: "true").with { @user_comment }
should respond_to_search(is_deleted: "true").with { @deleted_comment }
context "using includes" do
should respond_to_search(post_id: 100).with { @user_comment }
should respond_to_search(post_tags_match: "touhou").with { @mod_comment }
should respond_to_search(creator_name: "cirno").with { @user_comment }
should respond_to_search(creator: {level: User::Levels::MODERATOR}).with { @mod_comment }
end
end
context "for atom feeds" do