diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index ad6b4c6ea..63829f140 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -12,6 +12,6 @@ class FavoritesController < ApplicationController end def destroy - Post.find(params[:post_id]).remove_favorite!(CurrentUser.user) + Post.find(params[:id]).remove_favorite!(CurrentUser.user) end end diff --git a/test/functional/favorites_controller_test.rb b/test/functional/favorites_controller_test.rb index 0e08d7027..6037db775 100644 --- a/test/functional/favorites_controller_test.rb +++ b/test/functional/favorites_controller_test.rb @@ -14,6 +14,11 @@ class FavoritesControllerTest < ActionController::TestCase end context "index action" do + setup do + @post = Factory.create(:post) + @post.add_favorite!(@user) + end + context "with a specified tags parameter" do should "redirect to the posts controller" do get :index, {:tags => "abc"}, {:user_id => @user} @@ -24,7 +29,7 @@ class FavoritesControllerTest < ActionController::TestCase should "display the current user's favorites" do get :index, {}, {:user_id => @user.id} assert_response :success - assert_not_nil(assigns(:post_set)) + assert_not_nil(assigns(:favorite_set)) end end @@ -34,8 +39,8 @@ class FavoritesControllerTest < ActionController::TestCase end should "create a favorite for the current user" do - assert_difference("Favorite.count(#{@user.id})", 1) do - post :create, {:format => "js", :id => @post.id}, {:user_id => @user.id} + assert_difference("Favorite.count", 1) do + post :create, {:format => "js", :post_id => @post.id}, {:user_id => @user.id} end end end @@ -43,14 +48,11 @@ class FavoritesControllerTest < ActionController::TestCase context "destroy action" do setup do @post = Factory.create(:post) - Favorite.create( - :user_id => @user.id, - :post_id => @post.id - ) + @post.add_favorite!(@user) end should "remove the favorite from the current user" do - assert_difference("Favorite.count(#{@user.id})", -1) do + assert_difference("Favorite.count", -1) do post :destroy, {:format => "js", :id => @post.id}, {:user_id => @user.id} end end diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 6690481dd..4ba322a38 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -66,9 +66,9 @@ class NotesControllerTest < ActionController::TestCase end should "destroy a note" do - assert_difference("Note.count", -1) do - post :destroy, {:id => @note.id}, {:user_id => @user.id} - end + post :destroy, {:id => @note.id}, {:user_id => @user.id} + @note.reload + assert_equal(false, @note.is_active?) end end