Guest User

Untitled

a guest
Jun 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
  2.  
  3.  
  4. describe RecipesController do
  5. fixtures :all
  6. integrate_views
  7.  
  8. describe "when logged in" do
  9. describe "with a valid recipe" do
  10. describe "should save a new recipe" do
  11. before(:each) do
  12. Recipe.stub(:valid?).and_return(true)
  13. Recipe.stub(:new).and_return(@recipe = mock_model(Recipe, :save! =>true))
  14. @valid_attributes = {
  15. :creator_id=>1, :source=>"foodtv", :qty=>4, :unit_id=>1,
  16. :recipe_components_attributes=>[{:qty=>2, :component_id=> 3, :unit_id=>4},{:qty=>1, :component_id=> 5, :unit_id=>2}],
  17. :tasks_attributes=>[{:description=>"peel",:task_equipments_attributes=>[{:equipment_id=>1},{:equipment_id=>2}]}]
  18. }
  19. end
  20.  
  21. def do_create
  22. #post :create, :recipe=>@valid_attributes
  23. end
  24.  
  25. it "should create the recipe" do
  26. Recipe.should_receive(:new).with(@valid_attributes).and_return(@recipe)
  27. Recipe.should_receive(:save!)
  28. do_create
  29. end
  30.  
  31. it "should save the recipe" do
  32. @recipe.should_receive(:save).and_return(true)
  33. do_create
  34. end
  35.  
  36. it "should be redirect" do
  37. do_create
  38. response.should be_redirect
  39. end
  40.  
  41. it "should assign recipe" do
  42. do_create
  43. assigns(:recipe).should == @recipe
  44. end
  45.  
  46. it "should redirect to the index path" do
  47. do_create
  48. response.should redirect_to(recipes_url)
  49. end
  50. end
  51. end
  52.  
  53. describe "with an invalid recipe" do
  54. before(:each) do
  55. Recipe.stub!(:new).and_return(@recipe = mock_model(Recipe, :save=>false))
  56. end
  57. def do_create
  58. post :create, :recipe=>{:name=>"value"}
  59. end
  60.  
  61. it "should create the recipe" do
  62. Recipe.should_receive(:new).with(@valid_attributes).and_return(@recipe)
  63. do_create
  64. end
  65.  
  66. it "should save the recipe" do
  67. @recipe.should_receive(:save).and_return(false)
  68. do_create
  69. end
  70.  
  71. it "should be success" do
  72. do_create
  73. response.should be_success
  74. end
  75.  
  76. it "should assign recipe" do
  77. do_create
  78. assigns(:recipe).should == @recipe
  79. end
  80.  
  81. it "should re-render the new form" do
  82. do_create
  83. response.should render_template("new")
  84. end
  85. end
  86. end
  87. end
Add Comment
Please, Sign In to add comment