Add tests for all models with includes searches
This commit is contained in:
@@ -7,7 +7,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "list all users" do
|
||||
setup do
|
||||
@first_user = User.find(1)
|
||||
@mod_user = create(:moderator_user, name: "yukari")
|
||||
@other_user = create(:builder_user, can_upload_free: true, inviter: @mod_user, created_at: 2.weeks.ago)
|
||||
@uploader = create(:user, created_at: 2.weeks.ago)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get users_path
|
||||
assert_response :success
|
||||
end
|
||||
@@ -28,14 +35,54 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
should "list all users (with search)" do
|
||||
get users_path, params: {:search => {:name_matches => @user.name}}
|
||||
assert_response :success
|
||||
end
|
||||
should respond_to_search({}).with { [@uploader, @other_user, @mod_user, @user, @first_user] }
|
||||
should respond_to_search(min_level: User::Levels::BUILDER).with { [@other_user, @mod_user, @first_user] }
|
||||
should respond_to_search(can_upload_free: "true").with { @other_user }
|
||||
should respond_to_search(name_matches: "yukari").with { @mod_user }
|
||||
|
||||
should "list all users (with blank search parameters)" do
|
||||
get users_path, params: { search: { inviter: { name_matches: "" }, level: "", name: "test" } }
|
||||
assert_redirected_to users_path(search: { name: "test" })
|
||||
context "using includes" do
|
||||
setup do
|
||||
as (@uploader) { @post = create(:post, tag_string: "touhou", uploader: @uploader, is_flagged: true) }
|
||||
as (@user) do
|
||||
create(:note, post: @post)
|
||||
create(:artist_commentary, post: @post)
|
||||
create(:artist)
|
||||
create(:wiki_page)
|
||||
@forum = create(:forum_post, creator: @user, topic: build(:forum_topic, creator: @user))
|
||||
end
|
||||
as (@other_user) do
|
||||
@other_post = create(:post, rating: "e", uploader: @other_user)
|
||||
create(:post_appeal, creator: @other_user, post: @post)
|
||||
create(:comment, creator: @other_user, post: @other_post)
|
||||
create(:forum_post_vote, creator: @other_user, forum_post: @forum)
|
||||
create(:tag_alias, creator: @other_user)
|
||||
create(:tag_implication, creator: @other_user)
|
||||
end
|
||||
as (@mod_user) do
|
||||
create(:post_approval, user: @mod_user, post: @post)
|
||||
create(:user_feedback, user: @other_user, creator: @mod_user)
|
||||
create(:ban, user: @other_user, banner: @mod_user)
|
||||
end
|
||||
end
|
||||
|
||||
should respond_to_search(has_artist_versions: "true").with { @user }
|
||||
should respond_to_search(has_wiki_page_versions: "true").with { @user }
|
||||
should respond_to_search(has_forum_topics: "true").with { @user }
|
||||
should respond_to_search(has_forum_posts: "true").with { @user }
|
||||
should respond_to_search(has_forum_post_votes: "true").with { @other_user }
|
||||
should respond_to_search(has_feedback: "true").with { @other_user }
|
||||
should respond_to_search(has_tag_aliases: "true").with { @other_user }
|
||||
should respond_to_search(has_tag_implications: "true").with { @other_user }
|
||||
should respond_to_search(has_bans: "true").with { @other_user }
|
||||
should respond_to_search(has_artist_commentary_versions: "true").with { @user }
|
||||
should respond_to_search(has_comments: "true").with { @other_user }
|
||||
should respond_to_search(has_note_versions: "true").with { @user }
|
||||
should respond_to_search(has_post_appeals: "true").with { @other_user }
|
||||
should respond_to_search(has_post_approvals: "true").with { @mod_user }
|
||||
should respond_to_search(has_posts: "true").with { [@uploader, @other_user] }
|
||||
should respond_to_search(posts_tags_match: "touhou").with { @uploader }
|
||||
should respond_to_search(posts: {rating: "e"}).with { @other_user }
|
||||
should respond_to_search(inviter: {name: "yukari"}).with { @other_user }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user