finished dmails and favorites functional tests

This commit is contained in:
albert
2010-12-05 22:27:45 -05:00
parent b18f6340e7
commit 46164eab4f
25 changed files with 226 additions and 48 deletions

View File

@@ -7,22 +7,22 @@ class AdvertisementsControllerTest < ActionController::TestCase
@advertiser = Factory.create(:admin_user)
end
should "render the new page" do
should "get the new page" do
get :new, {}, {:user_id => @advertiser.id}
assert_response :success
end
should "render the edit page" do
should "get the edit page" do
get :edit, {:id => @ad.id}, {:user_id => @advertiser.id}
assert_response :success
end
should "render the index page" do
should "get the index page" do
get :index, {}, {:user_id => @advertiser.id}
assert_response :success
end
should "render the show page" do
should "get the show page" do
get :show, {:id => @ad.id}, {:user_id => @advertiser.id}
assert_response :success
end

View File

@@ -13,12 +13,12 @@ class ArtistVersionsControllerTest < ActionController::TestCase
CurrentUser.ip_addr = nil
end
should "render the index page" do
should "get the index page" do
get :index
assert_response :success
end
should "render the index page when searching for something" do
should "get the index page when searching for something" do
get :index, {:search => {:name_equals => @artist.name}}
assert_response :success
end

View File

@@ -14,22 +14,22 @@ class ArtistsControllerTest < ActionController::TestCase
CurrentUser.ip_addr = nil
end
should "render the new page" do
should "get the new page" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
should "render the edit page" do
should "get the edit page" do
get :edit, {:id => @artist.id}, {:user_id => @user.id}
assert_response :success
end
should "render the show page" do
should "get the show page" do
get :show, {:id => @artist.id}
assert_response :success
end
should "render the index page" do
should "get the index page" do
get :index
assert_response :success
end

View File

@@ -14,22 +14,22 @@ class BansControllerTest < ActionController::TestCase
CurrentUser.ip_addr = nil
end
should "render the new page" do
should "get the new page" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
should "render the edit page" do
should "get the edit page" do
get :edit, {:id => @ban.id}, {:user_id => @user.id}
assert_response :success
end
should "render the show page" do
should "get the show page" do
get :show, {:id => @ban.id}
assert_response :success
end
should "render the index page" do
should "get the index page" do
get :index
assert_response :success
end

View File

@@ -14,7 +14,7 @@ class CommentsControllerTest < ActionController::TestCase
CurrentUser.ip_addr = nil
end
should "render the index page" do
should "get the index page" do
get :index
assert_response :success
end

View File

@@ -1,8 +1,99 @@
require 'test_helper'
class DmailsControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "The dmails controller" do
setup do
@user = Factory.create(:user)
@unrelated_user = Factory.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@dmail = Factory.create(:dmail, :owner => @user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "new action" do
should "get the page" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
context "with a respond_to_id" do
should "prefill the fields" do
get :new, {:respond_to_id => @dmail}, {:user_id => @user.id}
assert_response :success
assert_not_nil assigns(:dmail)
assert_equal(@dmail.from_id, assigns(:dmail).to_id)
end
context "and a forward flag" do
should "not populate the to field" do
get :new, {:respond_to_id => @dmail, :forward => true}, {:user_id => @user.id}
assert_response :success
assert_not_nil assigns(:dmail)
assert_nil(assigns(:dmail).to_id)
end
end
end
end
context "index action" do
should "show dmails owned by the current user" do
get :index, {:owner_id_equals => @dmail.owner_id, :folder => "sent"}, {:user_id => @dmail.owner_id}
assert_response :success
get :index, {:owner_id_equals => @dmail.owner_id, :folder => "received"}, {:user_id => @dmail.owner_id}
assert_response :success
end
should "not show dmails not owned by the current user" do
assert_raises(User::PrivilegeError) do
get :index, {:owner_id_equals => @dmail.owner_id}, {:user_id => @unrelated_user.id}
end
end
end
context "show action" do
should "show dmails owned by the current user" do
get :show, {:id => @dmail.id}, {:user_id => @dmail.owner_id}
assert_response :success
end
should "not show dmails not owned by the current user" do
assert_raises(User::PrivilegeError) do
get :show, {:id => @dmail.id}, {:user_id => @unrelated_user.id}
end
end
end
context "create action" do
should "create two messages, one for the sender and one for the recipient" do
assert_difference("Dmail.count", 2) do
dmail_attribs = Factory.attributes_for(:dmail).merge(:to_id => Factory.create(:user).id)
post :create, {:dmail => dmail_attribs}, {:user_id => @user.id}
assert_redirected_to dmail_path(Dmail.last)
end
end
end
context "destroy action" do
should "allow deletion if the dmail is owned by the current user" do
assert_difference("Dmail.count", -1) do
post :destroy, {:id => @dmail.id}, {:user_id => @dmail.owner_id}
assert_redirected_to dmails_path
end
end
should "not allow deletion if the dmail is not owned by the current user" do
assert_difference("Dmail.count", 0) do
assert_raises(User::PrivilegeError) do
post :destroy, {:id => @dmail.id}, {:user_id => @unrelated_user.id}
end
end
end
end
end
end

View File

@@ -1,8 +1,59 @@
require 'test_helper'
class FavoritesControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "The favorites controller" do
setup do
@user = Factory.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "index action" do
context "with a specified tags parameter" do
should "redirect to the posts controller" do
get :index, {:tags => "abc"}, {:user_id => @user}
assert_redirected_to(posts_path(:tags => "fav:#{@user.name} abc"))
end
end
should "display the current user's favorites" do
get :index, {}, {:user_id => @user.id}
assert_response :success
assert_not_nil(assigns(:post_set))
end
end
context "create action" do
setup do
@post = Factory.create(:post)
end
should "create a favorite for the current user" do
assert_difference("Favorite.count(#{@user.id})", 1) do
post :create, {:id => @post.id}, {:user_id => @user.id}
end
end
end
context "destroy action" do
setup do
@post = Factory.create(:post)
Favorite.create(
:user_id => @user.id,
:post_id => @post.id
)
end
should "remove the favorite from the current user" do
assert_difference("Favorite.count(#{@user.id})", -1) do
post :destroy, {:id => @post.id}, {:user_id => @user.id}
end
end
end
end
end