<commit_before>require 'rails_helper'

RSpec.describe Office, type: :model do

  let(:office)      { build :office }

  it 'has a valid factory' do
    expect(office).to be_valid
  end

  context 'validations' do
    it 'is invalid with no name' do
      office = build(:invalid_office)
      expect(office).to_not be_valid
      expect(office.errors[:name]).to eq ["can't be blank"]
    end
  end

  context 'responds to' do
    it 'managers' do
      expect(office).to respond_to(:managers)
    end

    it 'jurisdictions' do
      expect(office).to respond_to(:jurisdictions)
    end
  end

  describe 'jurisdiction' do
    it 'can be nil' do
      office.jurisdictions.clear
      expect(office.jurisdictions.count).to eq 0
      expect(office).to be_valid
    end

    it 'can be added' do
      office.save
      office.jurisdictions.clear
      office.jurisdictions << create(:jurisdiction)
      office.save
      expect(office.jurisdictions.count).to eq 1
    end

    it 'can have multiple added' do
      office.save
      office.jurisdictions.clear
      office.jurisdictions << create(:jurisdiction)
      office.jurisdictions << create(:jurisdiction)
      office.save
      expect(office.jurisdictions.count).to eq 2
    end
  end

  describe 'managers' do
    let(:office)      { FactoryGirl.create :office }
    it 'returns a list of user in the manager role' do
      User.delete_all
      FactoryGirl.create_list :user, 3, office: office
      FactoryGirl.create :manager, office: office
      expect(office.managers.count).to eql 1
    end
  end
  describe 'managers_email' do
    let(:office)      { FactoryGirl.create :office }
    context 'managers are empty' do
      before(:each) { User.delete_all }
      it 'returns a text prompt' do
        FactoryGirl.create_list :user, 3, office: office
        expect(office.managers_email).to eql('a manager')
      end
    end
    context 'managers are populated' do
      before(:each) { User.delete_all }
      it 'returns an html string of emails of users in the manager role' do
        manager1 = FactoryGirl.create :manager, office: office
        manager2 = FactoryGirl.create :manager, office: office
        expected = "<a href=\"mailto:#{manager1.email}\">#{manager1.name}</a>, <a href=\"mailto:#{manager2.email}\">#{manager2.name}</a>"
        expect(office.managers_email).to eql(expected)
      end
    end
  end
end
<commit_msg>Updated Office tests<commit_after>require 'rails_helper'

RSpec.describe Office, type: :model do

  let(:office)      { build :office }

  it 'has a valid factory' do
    expect(office).to be_valid
  end

  context 'validations' do
    it 'is invalid with no name' do
      office = build(:invalid_office)
      expect(office).to_not be_valid
      expect(office.errors[:name]).to eq ["can't be blank"]
    end
  end

  context 'responds to' do
    it 'managers' do
      expect(office).to respond_to(:managers)
    end

    it 'jurisdictions' do
      expect(office).to respond_to(:jurisdictions)
    end
  end

  describe 'jurisdiction' do
    before(:each) do
      office.save
      office.jurisdictions.clear
    end

    it 'can be nil' do
      expect(office.jurisdictions.count).to eq 0
      expect(office).to be_valid
    end

    it 'can be added' do
      office.jurisdictions << create(:jurisdiction)
      office.save
      expect(office.jurisdictions.count).to eq 1
    end

    it 'can have multiple added' do
      office.jurisdictions << create(:jurisdiction)
      office.jurisdictions << create(:jurisdiction)
      office.save
      expect(office.jurisdictions.count).to eq 2
    end
  end

  describe 'managers' do
    let(:office)      { FactoryGirl.create :office }
    it 'returns a list of user in the manager role' do
      User.delete_all
      FactoryGirl.create_list :user, 3, office: office
      FactoryGirl.create :manager, office: office
      expect(office.managers.count).to eql 1
    end
  end
  describe 'managers_email' do
    let(:office)      { FactoryGirl.create :office }
    context 'managers are empty' do
      before(:each) { User.delete_all }
      it 'returns a text prompt' do
        FactoryGirl.create_list :user, 3, office: office
        expect(office.managers_email).to eql('a manager')
      end
    end
    context 'managers are populated' do
      before(:each) { User.delete_all }
      it 'returns an html string of emails of users in the manager role' do
        manager1 = FactoryGirl.create :manager, office: office
        manager2 = FactoryGirl.create :manager, office: office
        expected = "<a href=\"mailto:#{manager1.email}\">#{manager1.name}</a>, <a href=\"mailto:#{manager2.email}\">#{manager2.name}</a>"
        expect(office.managers_email).to eql(expected)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1005656819610308, 'fraction_numerical': 0.00502828409805154, 'mean_word_length': 2.773913043478261, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 11, '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': '6116123', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1433, 'n_words': 416}