SHARE
TWEET

Untitled

a guest Dec 13th, 2016 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. test "GETtting correct activation link on an already activated user gives error message and redirects to root url" do
  2.     # GIVEN a non-yet-registered email address
  3.     email_address = "tester@testing.net"
  4.     # GIVEN the sign-up page has been displayd
  5.     get signup_path
  6.     # GIVEN new user is created
  7.     post signup_path, params: { user: { email: email_address, email_confirmation: email_address, password: "testpassword", password_confirmation: "testpassword" } }
  8.     # GIVEN the URI from activation email
  9.     activation_uri = URI.extract(ActionMailer::Base.deliveries.last.text_part.body.encoded)[0]
  10.     # GIVEN the URI's been used and the user is already activated
  11.     get activation_uri
  12.     # WHEN reading back the newly activated user
  13.     activated_user = User.find_by_email(email_address)
  14.     # EXPECT the user to be activated
  15.     assert activated_user.activated?
  16.     # WHEN using the activation link on an already activated user
  17.     get activation_uri
  18.     # EXPECT redirection to root path
  19.     assert_redirected_to root_url
  20.     follow_redirect!
  21.     # EXPECT flash message
  22.     assert_not flash.empty?
  23.     # EXPECT rendered page to contain activation error information
  24.     assert_select 'div#flash div h5', text: I18n.translate('users.activate.error')
  25. end
  26.    
  27. test "GETtting incorrect activation hash on a non-activated user gives error message and redirects to root url" do
  28.     # GIVEN a non-yet-registered email address
  29.     email_address = "tester@testing.net"
  30.     # GIVEN the sign-up page has been displayd
  31.     get signup_path
  32.     # GIVEN new user is created
  33.     post signup_path, params: { user: { email: email_address, email_confirmation: email_address, password: "testpassword", password_confirmation: "testpassword" } }
  34.     # WEHN GETting the activation URI with invalid activation hash
  35.     activation_uri = "http://localhost:3000/account_activations/waTbfcCoZoPTBEIcewsl8Q/edit?email=#{ERB::Util.url_encode(email_address)}"
  36.     get activation_uri
  37.     # EXPECT redirection to root path
  38.     assert_redirected_to root_url
  39.     follow_redirect!
  40.     # EXPECT flash message
  41.     assert_not flash.empty?
  42.     # EXPECT rendered page to contain activation error information ('You are being redirected' rendered here)
  43.     assert_select 'div#flash div h5', text: I18n.translate('users.activate.error')
  44. end
  45.    
  46. flash[:error] = "#{t'users.activate.error'}"
  47. redirect_to root_url
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top