Add tests for all models with includes searches
This commit is contained in:
@@ -3,17 +3,45 @@ require 'test_helper'
|
||||
class PostVotesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The post vote controller" do
|
||||
setup do
|
||||
@user = create(:gold_user)
|
||||
@post = create(:post)
|
||||
@user = create(:gold_user, name: "meiling")
|
||||
@post = create(:post, tag_string: "dragon")
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "work" do
|
||||
as(@user) { create(:post_vote, post_id: @post.id, user_id: @user.id) }
|
||||
get_auth post_votes_path, @user
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
as(@user) { @post_vote = create(:post_vote, post: @post, user: @user) }
|
||||
as(@admin) { @admin_vote = create(:post_vote, post: @post, user: @admin) }
|
||||
@unrelated_vote = create(:post_vote)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get_auth post_votes_path, @user
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "as a user" do
|
||||
setup do
|
||||
CurrentUser.user = @user
|
||||
end
|
||||
|
||||
should respond_to_search({}).with { @post_vote }
|
||||
end
|
||||
|
||||
context "as a moderator" do
|
||||
setup do
|
||||
CurrentUser.user = @admin
|
||||
end
|
||||
|
||||
should respond_to_search({}).with { [@unrelated_vote, @admin_vote, @post_vote] }
|
||||
should respond_to_search(score: 1).with { [@unrelated_vote, @admin_vote, @post_vote].select{ |v| v.score == 1 } }
|
||||
|
||||
context "using includes" do
|
||||
should respond_to_search(post_tags_match: "dragon").with { [@admin_vote, @post_vote] }
|
||||
should respond_to_search(user_name: "meiling").with { @post_vote }
|
||||
should respond_to_search(user: {level: User::Levels::ADMIN}).with { @admin_vote }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
|
||||
Reference in New Issue
Block a user