Guest User

Untitled

a guest
Mar 8th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. UsersController#create:
  2.  
  3. def create
  4. @user = User.new(params[:user])
  5. if @user.save
  6. flash[:notice] = "Account registered!"
  7. redirect_back_or_default account_url
  8. else
  9. render :action => :new
  10. end
  11. end
  12.  
  13. UsersControllerTest:
  14.  
  15. context "on POST to :create" do
  16. setup do
  17. controller.stubs(:require_no_user).returns(true)
  18. @the_user = User.generate!
  19. User.stubs(:new).returns(@the_user)
  20. post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
  21. end
  22.  
  23. should_assign_to(:user) { @the_user }
  24.  
  25. context "with successful creation" do
  26. setup do
  27. @the_user.stubs(:save).returns(true)
  28. end
  29.  
  30. should_respond_with :redirect
  31. should_set_the_flash_to "Account registered!"
  32. should_redirect_to("the user's account") { account_url }
  33. end
  34.  
  35. context "with failed creation" do
  36. setup do
  37. @the_user.stubs(:save).returns(false)
  38. end
  39.  
  40. should_respond_with :success
  41. should_not_set_the_flash
  42. should_render_template :new
  43. end
  44. end
  45.  
  46. Results:
  47.  
  48. 1) Failure:
  49. test: on POST to :create with failed creation should not set the flash. (UsersControllerTest)
  50. method assert_rejects in assertions.rb at line 56
  51. method __bind_1246115268_943483 in macros.rb at line 43
  52. method call in context.rb at line 253
  53. method test: on POST to :create with failed creation should not set the flash. in context.rb at line 253
  54. Did not expect the flash to be set, but was {:notice=>"Account registered!"}
  55.  
  56. 2) Failure:
  57. test: on POST to :create with failed creation should render template :new. (UsersControllerTest)
  58. method __bind_1246115268_974053 in macros.rb at line 193
  59. method call in context.rb at line 253
  60. method test: on POST to :create with failed creation should render template :new. in context.rb at line 253
  61. expecting <"new"> but rendering with <"">
  62.  
  63. 3) Failure:
  64. test: on POST to :create with failed creation should respond with success. (UsersControllerTest)
  65. method assert_accepts in assertions.rb at line 50
  66. method __bind_1246115269_76190 in macros.rb at line 133
  67. method call in context.rb at line 253
  68. method test: on POST to :create with failed creation should respond with success. in context.rb at line 253
  69. Expected response to be a 200, but was 302
Add Comment
Please, Sign In to add comment