tests: add more users controller tests.

This commit is contained in:
evazion
2017-02-06 02:00:48 -06:00
parent 3edd814be5
commit 09ffac07ea

View File

@@ -13,24 +13,33 @@ class UsersControllerTest < ActionController::TestCase
end
context "index action" do
setup do
FactoryGirl.create(:user, :name => "abc")
end
should "list all users" do
get :index
assert_response :success
end
should "list all users for /users?name=<name>" do
get :index, { name: @user.name }
assert_redirected_to(@user)
end
should "raise error for /users?name=<nonexistent>" do
get :index, { name: "nobody" }
assert_response :error
end
should "list all users (with search)" do
get :index, {:search => {:name_matches => "abc"}}
get :index, {:search => {:name_matches => @user.name}}
assert_response :success
end
end
context "show action" do
setup do
@user = FactoryGirl.create(:user)
# flesh out profile to get more test coverage of user presenter.
@user = FactoryGirl.create(:banned_user, can_approve_posts: true, is_super_voter: true)
FactoryGirl.create(:saved_search, user: @user)
FactoryGirl.create(:post, uploader: @user, tag_string: "fav:#{@user.name}")
end
should "render" do
@@ -39,6 +48,13 @@ class UsersControllerTest < ActionController::TestCase
end
end
context "new action" do
should "render" do
get :new
assert_response :success
end
end
context "create action" do
should "create a user" do
assert_difference("User.count", 1) do