<commit_before>require 'spec_helper'

describe "Users" do

  describe "signs up a new user" do
    # consider merging some of these to improve speed as each hits the DB

    def sign_up
      visit new_user_registration_path
      fill_in 'Email', :with => Faker::Internet.email
      pass = <PASSWORD>
      fill_in 'Password', :with => <PASSWORD>
      fill_in 'Password confirmation', :with => <PASSWORD>
      click_button 'Sign up'
    end

    it "creates a new user" do
      expect{ sign_up }.to change{User.count}.by 1
    end

    it "sends a confirmation email" do
      expect{ sign_up }.to change{ActionMailer::Base.deliveries.size}.by 1
      expect(ActionMailer::Base.deliveries.last.to).to eq [User.last.email]
    end

    it "logs them in" do
      sign_up
      expect(page).to have_content 'signed up successfully'
      expect(page).to have_content 'Log out'
    end

    it "returns them to the page they started from" do
      visit root_path
      sign_up
      expect(current_path).to eq root_path
    end

  end

  describe "fails to sign up an invalid user" do

    def bad_sign_up
      visit new_user_registration_path
      click_button 'Sign up'
    end

    it "does not create a new user" do
      expect{ bad_sign_up }.not_to change{User.count}
    end

    it "returns them to the sign up page" do
      bad_sign_up
      expect(current_path).to eq user_registration_path
    end

    it "displays an error message" do
      bad_sign_up
      expect(page).to have_content 'error'
    end

  end

  it "logs in a user" do
    pass = <PASSWORD>
    u = FactoryGirl.create(:user, password: <PASSWORD>)
    visit new_user_session_path
    fill_in 'Email', with: u.email
    fill_in 'Password', with: <PASSWORD>
    click_button 'Sign in'
    expect(page).to have_content 'Log out'      
  end

  describe "logs out a user" do
    include Warden::Test::Helpers
    # Warden.test_mode! # this is supposedly required with above line but doesn't affect test results
    it "clicks log out link" do
      user = create(:user)
      login_as user # supposedly we also need scope: :user but this doesn't affect test results
      visit root_path
      click_link 'Log out'
      expect(page).to have_content 'Sign in'
    end
  end

  it "sends a password reset email" do
    user = create(:user)
    visit new_user_session_path
    click_link 'Forgot your password?'
    fill_in 'Email', with: user.email
    expect { click_button 'Send' }.to change{ActionMailer::Base.deliveries.size}.by 1
    expect(ActionMailer::Base.deliveries.last.to).to eq [user.email]
    expect(page).to have_content 'You will receive'<commit_msg>adding line of cleanup code in a test that will likely be needed in future but would be hard to realize then<commit_after>require 'spec_helper'

describe "Users" do

  describe "signs up a new user" do
    # consider merging some of these to improve speed as each hits the DB

    def sign_up
      visit new_user_registration_path
      fill_in 'Email', :with => Faker::Internet.email
      pass = <PASSWORD>
      fill_in 'Password', :with => <PASSWORD>
      fill_in 'Password confirmation', :with => <PASSWORD>
      click_button 'Sign up'
    end

    it "creates a new user" do
      expect{ sign_up }.to change{User.count}.by 1
    end

    it "sends a confirmation email" do
      expect{ sign_up }.to change{ActionMailer::Base.deliveries.size}.by 1
      expect(ActionMailer::Base.deliveries.last.to).to eq [User.last.email]
    end

    it "logs them in" do
      sign_up
      expect(page).to have_content 'signed up successfully'
      expect(page).to have_content 'Log out'
    end

    it "returns them to the page they started from" do
      visit root_path
      sign_up
      expect(current_path).to eq root_path
    end

  end

  describe "fails to sign up an invalid user" do

    def bad_sign_up
      visit new_user_registration_path
      click_button 'Sign up'
    end

    it "does not create a new user" do
      expect{ bad_sign_up }.not_to change{User.count}
    end

    it "returns them to the sign up page" do
      bad_sign_up
      expect(current_path).to eq user_registration_path
    end

    it "displays an error message" do
      bad_sign_up
      expect(page).to have_content 'error'
    end

  end

  it "logs in a user" do
    pass = <PASSWORD>
    u = FactoryGirl.create(:user, password: <PASSWORD>)
    visit new_user_session_path
    fill_in 'Email', with: u.email
    fill_in 'Password', with: <PASSWORD>
    click_button 'Sign in'
    expect(page).to have_content 'Log out'      
  end

  describe "logs out a user" do
    include Warden::Test::Helpers
    # Warden.test_mode! # this is supposedly required with above line but doesn't affect test results
    it "clicks log out link" do
      user = create(:user)
      login_as user # supposedly we also need scope: :user but this doesn't affect test results
      visit root_path
      click_link 'Log out'
      expect(page).to have_content 'Sign in'
      Warden.test_reset! # this will be needed if/when using the warden test helpers in multiple tests
    end
  end

  it "sends a password reset email" do
    user = create(:user)
    visit new_user_session_path
    click_link 'Forgot your password?'
    fill_in 'Email', with: user.email
    expect { click_button 'Send' }.to change{ActionMailer::Base.deliveries.size}.by 1
    expect(ActionMailer::Base.deliveries.last.to).to eq [user.email]
    expect(page).to have_content 'You will receive'
{'fraction_non_alphanumeric': 0.07935930105569712, 'fraction_numerical': 0.0010921004732435385, 'mean_word_length': 2.899929027679205, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '93329', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1684, 'n_words': 598}