Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test "GETtting correct activation link on an already activated user gives error message and redirects to root url" do
- # GIVEN a non-yet-registered email address
- email_address = "tester@testing.net"
- # GIVEN the sign-up page has been displayd
- get signup_path
- # GIVEN new user is created
- post signup_path, params: { user: { email: email_address, email_confirmation: email_address, password: "testpassword", password_confirmation: "testpassword" } }
- # GIVEN the URI from activation email
- activation_uri = URI.extract(ActionMailer::Base.deliveries.last.text_part.body.encoded)[0]
- # GIVEN the URI's been used and the user is already activated
- get activation_uri
- # WHEN reading back the newly activated user
- activated_user = User.find_by_email(email_address)
- # EXPECT the user to be activated
- assert activated_user.activated?
- # WHEN using the activation link on an already activated user
- get activation_uri
- # EXPECT redirection to root path
- assert_redirected_to root_url
- follow_redirect!
- # EXPECT flash message
- assert_not flash.empty?
- # EXPECT rendered page to contain activation error information
- assert_select 'div#flash div h5', text: I18n.translate('users.activate.error')
- end
- test "GETtting incorrect activation hash on a non-activated user gives error message and redirects to root url" do
- # GIVEN a non-yet-registered email address
- email_address = "tester@testing.net"
- # GIVEN the sign-up page has been displayd
- get signup_path
- # GIVEN new user is created
- post signup_path, params: { user: { email: email_address, email_confirmation: email_address, password: "testpassword", password_confirmation: "testpassword" } }
- # WEHN GETting the activation URI with invalid activation hash
- activation_uri = "http://localhost:3000/account_activations/waTbfcCoZoPTBEIcewsl8Q/edit?email=#{ERB::Util.url_encode(email_address)}"
- get activation_uri
- # EXPECT redirection to root path
- assert_redirected_to root_url
- follow_redirect!
- # EXPECT flash message
- assert_not flash.empty?
- # EXPECT flash message to contain activation error information
- assert_equal I18n.translate('users.activate.error'), flash[:error]
- # EXPECT rendered page to contain activation error information ('You are being redirected' rendered here)
- assert_select 'div#flash div h5', text: I18n.translate('users.activate.error')
- end
- flash[:error] = "#{t'users.activate.error'}"
- redirect_to root_url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement