BigW Consortium Gitlab

signup_spec.rb 2.81 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Signup' do
4
  describe 'signup with no errors' do
5
    context "when sending confirmation email" do
6 7 8
      before do
        stub_application_setting(send_user_confirmation_email: true)
      end
9 10 11

      it 'creates the user account and sends a confirmation email' do
        user = build(:user)
12

13
        visit root_path
14

15 16 17 18 19
        fill_in 'new_user_name',                with: user.name
        fill_in 'new_user_username',            with: user.username
        fill_in 'new_user_email',               with: user.email
        fill_in 'new_user_email_confirmation',  with: user.email
        fill_in 'new_user_password',            with: user.password
20
        click_button "Register"
21

22 23 24
        expect(current_path).to eq users_almost_there_path
        expect(page).to have_content("Please check your email to confirm your account")
      end
25
    end
26 27

    context "when not sending confirmation email" do
28 29 30
      before do
        stub_application_setting(send_user_confirmation_email: false)
      end
31 32 33 34 35 36

      it 'creates the user account and goes to dashboard' do
        user = build(:user)

        visit root_path

37 38 39 40 41
        fill_in 'new_user_name',                with: user.name
        fill_in 'new_user_username',            with: user.username
        fill_in 'new_user_email',               with: user.email
        fill_in 'new_user_email_confirmation',  with: user.email
        fill_in 'new_user_password',            with: user.password
42
        click_button "Register"
43 44 45 46 47

        expect(current_path).to eq dashboard_projects_path
        expect(page).to have_content("Welcome! You have signed up successfully.")
      end
    end
48 49 50 51 52 53 54 55 56
  end

  describe 'signup with errors' do
    it "displays the errors" do
      existing_user = create(:user)
      user = build(:user)

      visit root_path

57 58 59 60
      fill_in 'new_user_name',     with: user.name
      fill_in 'new_user_username', with: user.username
      fill_in 'new_user_email',    with: existing_user.email
      fill_in 'new_user_password', with: user.password
61
      click_button "Register"
62 63

      expect(current_path).to eq user_registration_path
64
      expect(page).to have_content("errors prohibited this user from being saved")
65
      expect(page).to have_content("Email has already been taken")
66
      expect(page).to have_content("Email confirmation doesn't match")
67 68 69 70 71 72 73 74
    end

    it 'does not redisplay the password' do
      existing_user = create(:user)
      user = build(:user)

      visit root_path

75 76 77 78
      fill_in 'new_user_name',     with: user.name
      fill_in 'new_user_username', with: user.username
      fill_in 'new_user_email',    with: existing_user.email
      fill_in 'new_user_password', with: user.password
79
      click_button "Register"
80 81 82 83 84 85

      expect(current_path).to eq user_registration_path
      expect(page.body).not_to match(/#{user.password}/)
    end
  end
end