<commit_before>require 'spec_helper'

describe Location do
  let(:attributes) do
    {
      name: 'Frankfurt',
      description: '',
      location_level_id: 2
    }
  end

  let(:location) { described_class.create(attributes) }

  describe 'validations' do
    it 'requires a name' do
      attributes.delete(:name)

      expect(location).to be_invalid
    end

    it 'does not require a location level id' do
      attributes.delete(:location_level_id)

      expect(location).to be_valid
    end

    it 'allows empty description' do
      location.description = ''

      expect(location).to be_valid
    end
  end

  describe 'has_parent' do
    it 'returns false if no parent exists' do
      expect(location.has_parent?).to be false
    end

    it 'returns true if parent exists' do
      location.parent = FactoryGirl.create :location

      expect(location.has_parent?).to be true
    end
  end

  describe 'location_name' do
    it 'returns the name without parent locations' do
      location = FactoryGirl.create :location
      expect(location.location_name).to eq(location.name)
    end

    it 'returns full path if one parent' do
      parent = FactoryGirl.create :location
      parent.add_child(location)

      expect(location.location_name).to eq(parent.name + " → " + location.name)
    end

    it 'returns full path if more parents' do
      parent1 = FactoryGirl.create :location
      parent2 = FactoryGirl.create(:location, name: 'second parent')
      parent1.add_child(parent2)
      parent2.add_child(location)

      expect(location.location_name).to eq(parent1.name + " → " + parent2.name + " → " + location.name)
    end
  end
end
<commit_msg>fix location specs for multi tenancy<commit_after>require 'spec_helper'

describe Location do
  before :each do
    @owner = FactoryGirl.create(:owner, users: [FactoryGirl.create(:user)])
    allow(User).to receive(:current).and_return(@owner.users.first)
  end

  let(:attributes) do
    {
      name: 'Frankfurt',
      description: '',
      location_level_id: 2
    }
  end

  let(:location) { described_class.create(attributes) }

  describe 'validations' do
    it 'requires a name' do
      attributes.delete(:name)

      expect(location).to be_invalid
    end

    it 'does not require a location level id' do
      attributes.delete(:location_level_id)

      expect(location).to be_valid
    end

    it 'allows empty description' do
      location.description = ''

      expect(location).to be_valid
    end
  end

  describe 'has_parent' do
    it 'returns false if no parent exists' do
      expect(location.has_parent?).to be false
    end

    it 'returns true if parent exists' do
      location.parent = FactoryGirl.create :location

      expect(location.has_parent?).to be true
    end
  end

  describe 'location_name' do
    it 'returns the name without parent locations' do
      location = FactoryGirl.create :location, owner: @owner
      expect(location.location_name).to eq(location.name)
    end

    it 'returns full path if one parent' do
      parent = FactoryGirl.create :location, owner: @owner
      parent.add_child(location)

      expect(location.location_name).to eq(parent.name + " → " + location.name)
    end

    it 'returns full path if more parents' do
      parent1 = FactoryGirl.create :location, owner: @owner
      parent2 = FactoryGirl.create(:location, name: 'second parent', owner: @owner)
      parent1.add_child(parent2)
      parent2.add_child(location)

      expect(location.location_name).to eq(parent1.name + " → " + parent2.name + " → " + location.name)
    end
  end
end

{'fraction_non_alphanumeric': 0.09385382059800665, 'fraction_numerical': 0.004429678848283499, 'mean_word_length': 2.9529540481400436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4865132', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1037, 'n_words': 305}