<commit_before>require 'rails_helper'

RSpec.describe Asset, :type => :model do

  let(:bus) { create(:bus) }
  let(:buslike_asset) { create(:buslike_asset)}
  let(:lrc) { build_stubbed(:light_rail_car) }
  let(:loco) { build_stubbed(:commuter_locomotive_diesel) }
  let(:shelter) { build_stubbed(:bus_shelter) }
  let(:adminb) { build_stubbed(:administration_building) }

  #------------------------------------------------------------------------------
  #
  # Class Methods
  #
  #------------------------------------------------------------------------------
  describe ".new_asset" do # pending
    it "returns a typed asset" do
      a = Asset.new_asset(bus.asset_subtype)
      rail = Asset.new_asset(lrc.asset_subtype)
      new_loco = Asset.new_asset(loco.asset_subtype)

      expect(a.class).to eq(Vehicle)
      expect(rail.class).to eq(RailCar)
      expect(new_loco.class).to eq(Locomotive)
    end
  end

  describe ".get_typed_asset" do
    it "types an untyped asset" do
      expect(Asset.get_typed_asset(buslike_asset).class).to eq(Vehicle)
    end

    it "types an already typed asset" do
      expect(Asset.get_typed_asset(bus).class).to eq(Vehicle)
    end

    it "returns nil when handed nothing" do
      expect(Asset.get_typed_asset(nil)).to be_nil
    end
  end
  #------------------------------------------------------------------------------
  #
  # Instance Methods
  #
  #------------------------------------------------------------------------------

  describe "#is_typed?" do
    it 'returns true for strongly typed assets' do
      expect(bus.is_typed?).to be(true)
    end

    it 'returns false for Asset' do
      expect(buslike_asset.is_typed?).to be(false)
    end
  end

  describe "#searchable_fields" do
    it 'inherits down the tree' do
      asset_searchables = [
        :object_key,
        :asset_tag,
        :external_id,

        :asset_type,
        :asset_subtype,

        :manufacturer,
        :manufacturer_model,
        :manufacture_year,
        :vendor
      ]
      rolling_stock_searchables = [ :title_number, :fta_vehicle_type, :fta_bus_mode_type ]
      fta_vehicle_searchables = []
      support_vehicle_searchables = [ 'license_plate', 'serial_number']
      vehicle_searchables = ['license_plate', 'serial_number']
      structure_searchables = [:description, :address1, :address2, :city, :state, :zip, :fta_facility_type, :name]

      expect(buslike_asset.searchable_fields).to eql(asset_searchables)
      expect(bus.searchable_fields).to eql(asset_searchables + rolling_stock_searchables + fta_vehicle_searchables + vehicle_searchables)
      expect(lrc.searchable_fields).to eql(asset_searchables + rolling_stock_searchables + fta_vehicle_searchables)
      expect(loco.searchable_fields).to eql(asset_searchables + rolling_stock_searchables + fta_vehicle_searchables)
      expect(shelter.searchable_fields).to eql(asset_searchables + structure_searchables)
      expect(adminb.searchable_fields).to eql(asset_searchables + structure_searchables)
    end
  end

  describe "#cost" do
    describe 'for a concrete asset' do
      it 'returns the correct cost' do
        expect(bus.cost).to eql(250000)
      end
    end

    describe 'for an abstract asset' do
      it 'returns the correct cost' do
        expect(buslike_asset.cost).to eql(250000)
      end
    end
  end

  describe "#name" do
    it 'returns the correct default name for an asset' do<commit_msg>rspec asset searchable fields<commit_after>require 'rails_helper'

RSpec.describe Asset, :type => :model do

  let(:bus) { create(:bus) }
  let(:buslike_asset) { create(:buslike_asset)}
  let(:lrc) { build_stubbed(:light_rail_car) }
  let(:loco) { build_stubbed(:commuter_locomotive_diesel) }
  let(:shelter) { build_stubbed(:bus_shelter) }
  let(:adminb) { build_stubbed(:administration_building) }

  #------------------------------------------------------------------------------
  #
  # Class Methods
  #
  #------------------------------------------------------------------------------
  describe ".new_asset" do # pending
    it "returns a typed asset" do
      a = Asset.new_asset(bus.asset_subtype)
      rail = Asset.new_asset(lrc.asset_subtype)
      new_loco = Asset.new_asset(loco.asset_subtype)

      expect(a.class).to eq(Vehicle)
      expect(rail.class).to eq(RailCar)
      expect(new_loco.class).to eq(Locomotive)
    end
  end

  describe ".get_typed_asset" do
    it "types an untyped asset" do
      expect(Asset.get_typed_asset(buslike_asset).class).to eq(Vehicle)
    end

    it "types an already typed asset" do
      expect(Asset.get_typed_asset(bus).class).to eq(Vehicle)
    end

    it "returns nil when handed nothing" do
      expect(Asset.get_typed_asset(nil)).to be_nil
    end
  end
  #------------------------------------------------------------------------------
  #
  # Instance Methods
  #
  #------------------------------------------------------------------------------

  describe "#is_typed?" do
    it 'returns true for strongly typed assets' do
      expect(bus.is_typed?).to be(true)
    end

    it 'returns false for Asset' do
      expect(buslike_asset.is_typed?).to be(false)
    end
  end

  describe "#searchable_fields" do
    it 'inherits down the tree' do
      asset_searchables = [:object_key, :asset_tag, :external_id, :description, :manufacturer_model]
      
      rolling_stock_searchables = [ :title_number, :fta_vehicle_type, :fta_bus_mode_type ]
      fta_vehicle_searchables = []
      support_vehicle_searchables = [ 'license_plate', 'serial_number']
      vehicle_searchables = ['license_plate', 'serial_number']
      structure_searchables = [:description, :address1, :address2, :city, :state, :zip, :fta_facility_type, :name]

      expect(buslike_asset.searchable_fields).to eql(asset_searchables)
      expect(bus.searchable_fields).to eql(asset_searchables + rolling_stock_searchables + fta_vehicle_searchables + vehicle_searchables)
      expect(lrc.searchable_fields).to eql(asset_searchables + rolling_stock_searchables + fta_vehicle_searchables)
      expect(loco.searchable_fields).to eql(asset_searchables + rolling_stock_searchables + fta_vehicle_searchables)
      expect(shelter.searchable_fields).to eql(asset_searchables + structure_searchables)
      expect(adminb.searchable_fields).to eql(asset_searchables + structure_searchables)
    end
  end

  describe "#cost" do
    describe 'for a concrete asset' do
      it 'returns the correct cost' do
        expect(bus.cost).to eql(250000)
      end
    end

    describe 'for an abstract asset' do
      it 'returns the correct cost' do
        expect(buslike_asset.cost).to eql(250000)
      end
    end
  end

  describe "#name" do
    it 'returns the correct default name for an asset' do
{'fraction_non_alphanumeric': 0.18146889315797252, 'fraction_numerical': 0.0041377272055563765, 'mean_word_length': 2.451300356960734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '801428', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2050, 'n_words': 428}