Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
- describe RecipesController do
- fixtures :all
- integrate_views
- describe "when logged in" do
- describe "with a valid recipe" do
- describe "should save a new recipe" do
- before(:each) do
- Recipe.stub(:valid?).and_return(true)
- Recipe.stub(:new).and_return(@recipe = mock_model(Recipe, :save! =>true))
- @valid_attributes = {
- :creator_id=>1, :source=>"foodtv", :qty=>4, :unit_id=>1,
- :recipe_components_attributes=>[{:qty=>2, :component_id=> 3, :unit_id=>4},{:qty=>1, :component_id=> 5, :unit_id=>2}],
- :tasks_attributes=>[{:description=>"peel",:task_equipments_attributes=>[{:equipment_id=>1},{:equipment_id=>2}]}]
- }
- end
- def do_create
- #post :create, :recipe=>@valid_attributes
- end
- it "should create the recipe" do
- Recipe.should_receive(:new).with(@valid_attributes).and_return(@recipe)
- Recipe.should_receive(:save!)
- do_create
- end
- it "should save the recipe" do
- @recipe.should_receive(:save).and_return(true)
- do_create
- end
- it "should be redirect" do
- do_create
- response.should be_redirect
- end
- it "should assign recipe" do
- do_create
- assigns(:recipe).should == @recipe
- end
- it "should redirect to the index path" do
- do_create
- response.should redirect_to(recipes_url)
- end
- end
- end
- describe "with an invalid recipe" do
- before(:each) do
- Recipe.stub!(:new).and_return(@recipe = mock_model(Recipe, :save=>false))
- end
- def do_create
- post :create, :recipe=>{:name=>"value"}
- end
- it "should create the recipe" do
- Recipe.should_receive(:new).with(@valid_attributes).and_return(@recipe)
- do_create
- end
- it "should save the recipe" do
- @recipe.should_receive(:save).and_return(false)
- do_create
- end
- it "should be success" do
- do_create
- response.should be_success
- end
- it "should assign recipe" do
- do_create
- assigns(:recipe).should == @recipe
- end
- it "should re-render the new form" do
- do_create
- response.should render_template("new")
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment