Guest User

Untitled

a guest
Mar 11th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. require File.dirname(__FILE__) + "/common_dsl"
  2.  
  3. module AccountStoriesDSL
  4. include CommonDSL
  5.  
  6. def goes_to_login
  7. get login_path
  8. assert_response :success
  9. assert_template "account/login"
  10. end
  11.  
  12. def goes_to_admin_login
  13. get admin_login_path
  14. assert_response :success
  15. assert_template "account/admin"
  16. end
  17.  
  18. def goes_to_trial_signup
  19. get signup_trial_path
  20. assert_response :success
  21. assert_template "account/signup"
  22. end
  23.  
  24. def goes_to_full_signup
  25. get signup_full_path
  26. assert_response :success
  27. assert_template "account/signup"
  28. end
  29.  
  30. def goes_to_search
  31. get search_path
  32. assert_redirected_to login_path
  33. follow_redirect_and_assert_success!
  34. assert_template "account/login"
  35. end
  36.  
  37. def logs_into_search(email,pwd)
  38. post login_path, :email => email, :password => pwd
  39. assert_redirected_to search_path
  40. end
  41.  
  42. def logs_out
  43. get logout_path
  44. assert_redirected_to root_path
  45. assert_match(/you have been logged out/i, flash[:notice])
  46. assert_nil session[:user]
  47. end
  48.  
  49. def goes_to_company_information_area
  50. get company_information_path
  51. assert_response :success
  52. assert_template "company_information/index"
  53. end
  54.  
  55. def updates_company_information_with_info
  56. user = { :company_name => "company name", :company_url => "url", :description => "description", :fax => "fax", :phone => "phone", :street => "street", :street2 => "street2", :city => "city", :state => "MI", :zip => "zip" }
  57. put company_information_path, :user => user
  58. assert_redirected_to dashboard_path
  59. end
  60.  
  61. def goes_to_settings_area
  62. get settings_path
  63. assert_response :success
  64. assert_template "settings/index"
  65. end
  66.  
  67. def updates_settings_with(options)
  68. if logged_in?
  69. put settings_path(:action => "update_user"), :user => options
  70. updated_model = current_user(true)
  71. model_class = User
  72. elsif admin_logged_in?
  73. put settings_path(:action => "update_admin"), :user => options
  74. updated_model = current_admin(true)
  75. model_class = Admin
  76. else
  77. flunk "Admin or Normal user has to be logged in"
  78. end
  79.  
  80. assert_response :success
  81. assert_template "settings/index"
  82.  
  83. options.each do |k,v|
  84. unless [:password, :password_confirmation].include?(k)
  85. assert_equal v, updated_model[k]
  86. end
  87. end
  88.  
  89. assert_equal updated_model, model_class.authenticate(updated_model.email, options[:password])
  90. end
  91.  
  92. def signs_up_for_trial_with(params)
  93. post signup_path, :user => params.update(:upgrading => "false")
  94. assert_redirected_to dashboard_path
  95. follow_redirect_and_assert_success!
  96.  
  97. assert_equal 2, emails_sent.size # one confirmation, one to admin
  98. the_user = find_last(User)
  99. assert_equal the_user.id, session[:user]
  100. assert the_user.trial?
  101. end
  102.  
  103. def signs_up_for_full_account_with(params)
  104. post signup_path, :user => params.update(:upgrading => "true")
  105. assert_redirected_to dashboard_path
  106. follow_redirect_and_assert_success!
  107.  
  108. assert_equal 4, emails_sent.size # one confirmation, one to admin, another for user invoice, and one more to admin for upgrade
  109. the_user = find_last(User)
  110. assert_equal the_user.id, session[:user]
  111. assert the_user.full?
  112. assert_not_nil the_user.billing_profile
  113. end
  114.  
  115. ##
  116. # Forgot/Reset Password
  117. ##
  118. def goes_to_forgotten_password
  119. get forgot_path
  120. assert_response :success
  121. assert_template "account/forgot"
  122. end
  123.  
  124. def submits_forgotten_password(email)
  125. post forgot_path, :email => email
  126. assert_response :success
  127. assert_match(/an email has been sent to reset the password/i, flash[:notice])
  128. assert_equal 1, emails_sent.size
  129. end
  130.  
  131. def goes_to_reset_password
  132. get reset_path(:code => "resetcode")
  133. assert_response :success
  134. assert_template "account/reset"
  135. end
  136.  
  137. def resets_password_with(password)
  138. post reset_path, :user => { :password => "new-pass", :password_confirmation => "new-pass" }
  139. assert_redirected_to dashboard_path
  140. assert_match(/password was successfully reset/, flash[:notice])
  141. end
  142.  
  143. def goes_to_upgrade_area
  144. get upgrade_path
  145. assert_response :success
  146. assert_template "get_upgrade"
  147. end
  148.  
  149. def upgrades_account_to_full_status
  150. put upgrade_path, :user => { :upgrading => true, :credit_card_number => "4111111111111111", :expiration_month => "8", :expiration_year => 2.years.from_now.year.to_s, :credit_verification_value => "123", :card_type => "visa" }
  151. assert_redirected_to dashboard_path
  152. assert current_user.full?
  153.  
  154. assert_equal 2, emails_sent.size # one for user invoice, and one more to admin for upgrade
  155. end
  156.  
  157. end
Add Comment
Please, Sign In to add comment