<commit_before>require 'spec_helper'

describe "User account actions", :type => :feature do
  # from: http://guides.rubyonrails.org/testing.html
  # The ActionMailer::Base.deliveries array is only reset automatically in
  # ActionMailer::TestCase tests. If you want to have a clean slate outside Action
  # Mailer tests, you can reset it manually with: ActionMailer::Base.deliveries.clear
  before { ActionMailer::Base.deliveries.clear }

  let(:last_email) { ActionMailer::Base.deliveries.last }



  context 'log in' do

    it 'should succeed when using email' do
      user = FactoryGirl.create(:user)
      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: user.email
      fill_in 'Password', with: <PASSWORD>
      click_button I18n.t('devise.shared.links.sign_in')

      expect(current_path).to eq(root_path)
      expect(page).to have_content('Signed in successfully.')
    end

    it 'should succeed when using user_name' do
      user = FactoryGirl.create(:user)
      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: user.user_name
      fill_in 'Password', with: <PASSWORD>
      click_button I18n.t('devise.shared.links.sign_in')

      expect(current_path).to eq(root_path)
      expect(page).to have_content('Signed in successfully.')
    end

    it 'should fail when invalid' do
      user = FactoryGirl.create(:user)
      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: 'user name does not exist'
      fill_in 'Password', with: <PASSWORD>.password
      click_button I18n.t('devise.shared.links.sign_in')

      expect(current_path).to eq(new_user_session_path)
      expect(page).to have_content('Invalid login or password.')
    end

  end

  context 'sign up' do
    it 'should succeed with valid values' do
      #user = FactoryGirl.create(:user)
      user_name = 'tester_tester'
      email = '<EMAIL>'
      password = '<PASSWORD>'
      visit new_user_registration_url

      fill_in 'User name', with: user_name
      fill_in 'Password', with: password, match: :prefer_exact
      fill_in 'Confirm new password', with: password
      fill_in 'Email', with: email
      click_button I18n.t('devise.shared.links.sign_up')

      #expect(current_path).to eq(root_path)
      expect(page).to have_content('Welcome! You have signed up successfully.')
      expect(User.count).to eq(1)
      expect(User.first.user_name).to eq(user_name)
    end

    it 'should fail when invalid' do
      #user = FactoryGirl.create(:user)
      user_name = 'tester_tester!@'
      email = '<EMAIL>'
      password = '<PASSWORD>'
      visit new_user_registration_url

      fill_in 'User name', with: user_name
      fill_in 'Password', with: password, match: :prefer_exact
      fill_in 'Confirm new password', with: password
      fill_in 'Email', with: email
      click_button I18n.t('devise.shared.links.sign_up')

      #expect(current_path).to eq(root_path)
      expect(page).to have_content('Only letters, numbers, spaces ( ), underscores (_) and dashes (-) are valid')
      expect(User.count).to eq(0)
    end
  end

  context 'edit account info' do

    before(:each) do
      @old_password = '<PASSWORD>'
      @user = FactoryGirl.create(:user, password: @old_password)
      login_as @user, scope: :user
    end

    it 'should succeed with valid values' do
      new_password = '<PASSWORD>'
      new_email = '<EMAIL>'
      new_user_name = 'test_name_1'

      visit edit_user_registration_path
      fill_in 'user_user_name', with: new_user_name
      fill_in 'user_email', with: new_email
      fill_in 'user[password]', with: <PASSWORD>
      fill_in 'user[password_confirmation]', with: <PASSWORD>
      fill_in 'user[current_password]', with: <PASSWORD>
      attach_file('user[image]', 'public/images/user/user_span1.png')
      click_button 'Update'

      expect(page).to have_content(new_user_name)
      expect(page).to have_content(I18n.t('devise.registrations.update_needs_confirmation'))
      expect(current_path).to eq(root_path)

      visit edit_user_registration_path
      #expect(page).to have_content('user_span1.png')
      expect(page.find('div img')['src']).to include('user_span1.png')
      expect(page).to have_content(new_user_name)
      expect(page).to have_content('Currently waiting confirmation for: '+new_email)

      logout

      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: new_user_name<commit_msg>fixed ui test after changes<commit_after>require 'spec_helper'

describe "User account actions", :type => :feature do
  # from: http://guides.rubyonrails.org/testing.html
  # The ActionMailer::Base.deliveries array is only reset automatically in
  # ActionMailer::TestCase tests. If you want to have a clean slate outside Action
  # Mailer tests, you can reset it manually with: ActionMailer::Base.deliveries.clear
  before { ActionMailer::Base.deliveries.clear }

  let(:last_email) { ActionMailer::Base.deliveries.last }



  context 'log in' do

    it 'should succeed when using email' do
      user = FactoryGirl.create(:user)
      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: user.email
      fill_in 'Password', with: <PASSWORD>
      click_button I18n.t('devise.shared.links.sign_in')

      expect(current_path).to eq(root_path)
      expect(page).to have_content('Signed in successfully.')
    end

    it 'should succeed when using user_name' do
      user = FactoryGirl.create(:user)
      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: user.user_name
      fill_in 'Password', with: <PASSWORD>
      click_button I18n.t('devise.shared.links.sign_in')

      expect(current_path).to eq(root_path)
      expect(page).to have_content('Signed in successfully.')
    end

    it 'should fail when invalid' do
      user = FactoryGirl.create(:user)
      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: 'user name does not exist'
      fill_in 'Password', with: <PASSWORD>
      click_button I18n.t('devise.shared.links.sign_in')

      expect(current_path).to eq(new_user_session_path)
      expect(page).to have_content('Invalid login or password.')
    end

  end

  context 'sign up' do
    it 'should succeed with valid values' do
      #user = FactoryGirl.create(:user)
      user_name = 'tester_tester'
      email = '<EMAIL>'
      password = '<PASSWORD>'
      visit new_user_registration_url

      fill_in 'User name', with: user_name
      fill_in 'Password', with: password, match: :prefer_exact
      fill_in 'Confirm new password', with: password
      fill_in 'Email', with: email
      click_button I18n.t('devise.shared.links.sign_up')

      #expect(current_path).to eq(root_path)
      expect(page).to have_content('Welcome! You have signed up successfully.')
      expect(User.count).to eq(1)
      expect(User.first.user_name).to eq(user_name)
    end

    it 'should fail when invalid' do
      #user = FactoryGirl.create(:user)
      user_name = 'tester_tester!@'
      email = '<EMAIL>'
      password = '<PASSWORD>'
      visit new_user_registration_url

      fill_in 'User name', with: user_name
      fill_in 'Password', with: password, match: :prefer_exact
      fill_in 'Confirm new password', with: password
      fill_in 'Email', with: email
      click_button I18n.t('devise.shared.links.sign_up')

      #expect(current_path).to eq(root_path)
      expect(page).to have_content('Only letters, numbers, spaces ( ), underscores (_) and dashes (-) are valid')
      expect(User.count).to eq(0)
    end
  end

  context 'edit account info' do

    before(:each) do
      @old_password = '<PASSWORD>'
      @user = FactoryGirl.create(:user, password: <PASSWORD>)
      login_as @user, scope: :user
    end

    it 'should succeed with valid values' do
      new_password = '<PASSWORD>'
      new_email = '<EMAIL>'
      new_user_name = 'test_name_1'

      visit edit_user_registration_path
      fill_in 'user_user_name', with: new_user_name
      fill_in 'user_email', with: new_email
      fill_in 'user[password]', with: <PASSWORD>
      fill_in 'user[password_confirmation]', with: <PASSWORD>
      fill_in 'user[current_password]', with: <PASSWORD>
      attach_file('user[image]', 'public/images/user/user_span1.png')
      click_button 'Update'

      expect(page).to have_content(new_user_name)
      expect(page).to have_content(I18n.t('devise.registrations.update_needs_confirmation'))
      expect(current_path).to eq(root_path)

      visit edit_user_registration_path
      #expect(page).to have_content('user_span1.png')
      expect(page.find('.user_image div img')['src']).to include('user_span1.png')
      expect(page).to have_content(new_user_name)
      expect(page).to have_content('Currently waiting confirmation for: '+new_email)

      logout

      visit root_url
      first(:link, I18n.t('devise.shared.links.sign_in')).click

      expect(current_url).to eq(new_user_session_url)
      fill_in 'Login', with: new_user_name
{'fraction_non_alphanumeric': 0.11457255226661146, 'fraction_numerical': 0.005381908507555371, 'mean_word_length': 3.4819109461966606, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3934713', 'n_tokens_mistral': 3180, 'n_tokens_neox': 3067, 'n_words': 706}