Guest User

Untitled

a guest
Jul 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. ## test/functionals/addresses_controller_test.rb
  2. ### Errors occur on lines
  3. require File.dirname(__FILE__) + '/../test_helper'
  4. require 'shoulda'
  5.  
  6. class AddressesControllerTest < ActionController::TestCase
  7.  
  8. context "handle" do
  9. setup do
  10. @user = Factory(:user)
  11. end
  12.  
  13. context "without logging in" do
  14. context ":index" do
  15. setup do
  16. get :index
  17. end
  18. should_redirect_to("new_session_path") { new_session_path }
  19. should_not_set_the_flash
  20. should_not_assign_to :addresses
  21. end
  22.  
  23. context ":show" do
  24. setup do
  25. get :show, :address => Factory(:address)
  26. end
  27. should_redirect_to("new_session_path") { new_session_path }
  28. should_not_set_the_flash
  29. should_not_assign_to :addresses
  30. end
  31.  
  32. context ":edit" do
  33. setup do
  34. get :edit, :address => Factory(:address)
  35. end
  36. should_redirect_to("new_session_path") { new_session_path }
  37. should_not_set_the_flash
  38. should_not_assign_to :addresses
  39. end
  40.  
  41. context ":update" do
  42. setup do
  43. put :update, :id => Factory(:address), :address => {}
  44. end
  45. should_redirect_to("new_session_path") { new_session_path }
  46. should_not_set_the_flash
  47. should_not_assign_to :addresses
  48. end
  49.  
  50. context ":new" do
  51. setup do
  52. get :new
  53. end
  54. should_redirect_to("new_session_path") { new_session_path }
  55. should_not_set_the_flash
  56. should_not_assign_to :addresses
  57. end
  58.  
  59. context ":create" do
  60. setup do
  61. post :create, :address => Factory.attributes_for(:address)
  62. end
  63. should_redirect_to("new_session_path") { new_session_path }
  64. should_not_set_the_flash
  65. should_not_assign_to :addresses
  66. end
  67.  
  68. context ":destroy" do
  69. setup do
  70. delete :destroy, :id => Factory(:address)
  71. end
  72. should_redirect_to("new_session_path") { new_session_path }
  73. should_not_set_the_flash
  74. should_not_assign_to :addresses
  75. end
  76. end
  77.  
  78. context ":index" do
  79. setup do
  80. get :index, {}, {:user_id => @user}
  81. end
  82. should_respond_with :success
  83. should_render_template :index
  84. should_not_set_the_flash
  85. should_assign_to :addresses
  86. end
  87.  
  88. context ":show" do
  89. setup do
  90. get :show, {:id => Factory(:address)}, {:user_id => @user}
  91. end
  92. should_respond_with :success
  93. should_render_template :show
  94. should_not_set_the_flash
  95. should_assign_to :address
  96. end
  97.  
  98. context ":edit" do
  99. setup do
  100. get :edit, {:id => Factory(:address)}, {:user_id => @user}
  101. end
  102. should_respond_with :success
  103. should_render_template :edit
  104. should_not_set_the_flash
  105. should_assign_to :address
  106. end
  107.  
  108. context ":update" do
  109. setup do
  110. put :update, {:id => Factory(:address), :address => {}}, {:user_id => @user}
  111. end
  112. should_redirect_to("address_path") { address_path(assigns(:address)) }
  113. should_set_the_flash_to "Address was successfully updated."
  114. should_assign_to :address
  115. end
  116.  
  117. context ":new" do
  118. setup do
  119. get :new, {}, {:user_id => @user}
  120. end
  121. should_respond_with :success
  122. should_render_template :new
  123. should_not_set_the_flash
  124. should_assign_to :address
  125. end
  126.  
  127. context ":create" do
  128. setup do
  129. post :create, {:address => Factory.attributes_for(:address)}, {:user_id => @user}
  130. end
  131. should_redirect_to("address_path") { address_path(assigns(:address)) }
  132. should_set_the_flash_to "Address was successfully created."
  133. should_assign_to :address
  134. should_change("Address.count", :by => 1) { Address.count }
  135. end
  136.  
  137. context ":destroy" do
  138. setup do
  139. @address = Factory(:address)
  140. delete :destroy, {:id => @address}, {:user_id => @user}
  141. end
  142. should_redirect_to("addresses_path") { addresses_path }
  143. should_set_the_flash_to "Address was successfully deleted."
  144. should_change("Address.count", :by => -1) { Address.count }
  145. end
  146.  
  147. end
  148.  
  149. end
Add Comment
Please, Sign In to add comment