<commit_before># == Schema Information
#
# Table name: users
#
#  id                        :integer          not null, primary key
#  email                     :string           default(""), not null
#  first_name                :string
#  last_name                 :string
#  created_at                :datetime         not null
#  updated_at                :datetime         not null
#  identity_url              :string
#  language                  :string           default("en"), not null
#  residence                 :string
#  street                    :string
#  personnel_number          :integer          default(0)
#  remaining_leave           :integer          default(28)
#  remaining_leave_last_year :integer          default(0)
#  superadmin                :boolean          default(FALSE)
#  username                  :string
#  encrypted_password        :string           default(""), not null
#

require 'rails_helper'

RSpec.describe User, type: :model do
  it 'has a valid factory' do
    expect(FactoryGirl.create(:user)).to be_valid
  end

  it 'returns the full name of the user' do
    user = FactoryGirl.create(:user)
    expect(user.name).to eq('<NAME>')
  end

  it 'splits fullname into first and last name' do
    user = FactoryGirl.create(:user, first_name: nil, last_name: nil, name: '<NAME>')
    expect(user.first_name).to eq('Jane')
    expect(user.last_name).to eq('Smith')
  end

  it 'checks functionality of is_wimi? function' do
    user = FactoryGirl.create(:user)
    chair = FactoryGirl.create(:chair)
    expect(user.is_wimi?).to eq(false)
    chairwimi = ChairWimi.create(user: user, chair: chair, application: 'accepted')
    expect(user.is_wimi?).to eq(true)
  end

  it 'checks functionality of is_hiwi? function' do
    user = FactoryGirl.create(:user)
    project = FactoryGirl.create(:project)
    expect(User.find(user.id).is_hiwi?).to eq(false)
    project.users << user
    expect(User.find(user.id).is_hiwi?).to eq(true)
  end

  it 'returns trips in the right order' do
    user = FactoryGirl.create(:user)
    trip_a = FactoryGirl.create(:trip, user: user)
    datespan_a = FactoryGirl.create(:trip_datespan, trip: trip_a, start_date: Date.today + 5, end_date: Date.today + 6, days_abroad: 0)
    trip_b = FactoryGirl.create(:trip, user: user)
    datespan_b = FactoryGirl.create(:trip_datespan, trip: trip_b, start_date: Date.today + 10, end_date: Date.today + 16, days_abroad: 0)
    expect(user.get_desc_sorted_datespans[0]).to eq(datespan_b)
  end
end<commit_msg>adds spec to test zip code validation<commit_after># == Schema Information
#
# Table name: users
#
#  id                        :integer          not null, primary key
#  email                     :string           default(""), not null
#  first_name                :string
#  last_name                 :string
#  created_at                :datetime         not null
#  updated_at                :datetime         not null
#  identity_url              :string
#  language                  :string           default("en"), not null
#  residence                 :string
#  street                    :string
#  personnel_number          :integer          default(0)
#  remaining_leave           :integer          default(28)
#  remaining_leave_last_year :integer          default(0)
#  superadmin                :boolean          default(FALSE)
#  username                  :string
#  encrypted_password        :string           default(""), not null
#

require 'rails_helper'

RSpec.describe User, type: :model do
  it 'has a valid factory' do
    expect(FactoryGirl.create(:user)).to be_valid
  end

  it 'returns the full name of the user' do
    user = FactoryGirl.create(:user)
    expect(user.name).to eq('<NAME>')
  end

  it 'splits fullname into first and last name' do
    user = FactoryGirl.create(:user, first_name: nil, last_name: nil, name: '<NAME>')
    expect(user.first_name).to eq('Jane')
    expect(user.last_name).to eq('Smith')
  end

  it 'checks functionality of is_wimi? function' do
    user = FactoryGirl.create(:user)
    chair = FactoryGirl.create(:chair)
    expect(user.is_wimi?).to eq(false)
    chairwimi = ChairWimi.create(user: user, chair: chair, application: 'accepted')
    expect(user.is_wimi?).to eq(true)
  end

  it 'checks functionality of is_hiwi? function' do
    user = FactoryGirl.create(:user)
    project = FactoryGirl.create(:project)
    expect(User.find(user.id).is_hiwi?).to eq(false)
    project.users << user
    expect(User.find(user.id).is_hiwi?).to eq(true)
  end

  it 'returns trips in the right order' do
    user = FactoryGirl.create(:user)
    trip_a = FactoryGirl.create(:trip, user: user)
    datespan_a = FactoryGirl.create(:trip_datespan, trip: trip_a, start_date: Date.today + 5, end_date: Date.today + 6, days_abroad: 0)
    trip_b = FactoryGirl.create(:trip, user: user)
    datespan_b = FactoryGirl.create(:trip_datespan, trip: trip_b, start_date: Date.today + 10, end_date: Date.today + 16, days_abroad: 0)
    expect(user.get_desc_sorted_datespans[0]).to eq(datespan_b)
  end

  it 'validates the zip code correctly' do
    expect(FactoryGirl.build(:user, zip_code: '')).to be_valid
    expect(FactoryGirl.build(:user, zip_code: '01234')).to be_valid
    expect(FactoryGirl.build(:user, zip_code: 'abc')).to_not be_valid
    expect(FactoryGirl.build(:user, zip_code: 'abcde')).to_not be_valid
  end
end
{'fraction_non_alphanumeric': 0.10898980537534754, 'fraction_numerical': 0.005746061167747915, 'mean_word_length': 2.559366754617414, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '3794766', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1636, 'n_words': 425}