Permalink
Browse files

add specs for favorites controller

  • Loading branch information...
1 parent f1d4223 commit fcc2628ceb8aabe1fa716090de52fd59a0392225 nicolas committed May 1, 2009
Showing with 22 additions and 3 deletions.
  1. +6 −0 app/controllers/favorites_controller.rb
  2. +16 −3 spec/controllers/favorites_controller_spec.rb
@@ -3,11 +3,17 @@ class FavoritesController < ApplicationController
def create
@question = Question.find(params[:id])
current_user.favorite_questions << @question
+ respond_to do |format|
+ format.js {}
+ end
end
def destroy
@favorite = current_user.favorites.find_by_question_id(params[:id])
@favorite.destroy
+ respond_to do |format|
+ format.js {}
+ end
end
end
@@ -2,9 +2,22 @@
describe FavoritesController do
- #Delete this example and add some real ones
- it "should use FavoritesController" do
- controller.should be_an_instance_of(FavoritesController)
+ describe "handling POST 'create'" do
+ before :each do
+ @mock_question = mock_model(Question)
+ Question.should_receive(:find).with('1').and_return(@mock_question)
+ @mock_user = mock_model(User , :favorite_questions => mock('questions'))
+ @mock_user.favorite_questions.should_receive('<<').with(@mock_question)
+ controller.stub!(:current_user => @mock_user)
+ post :create , :id => '1'
+ end
+ it "should be success" do
+ response.should be_success
+ end
+ it "should assign the question" do
+ assigns[:question].should == @mock_question
+ end
+
end
end

0 comments on commit fcc2628

Please sign in to comment.