<commit_before>require 'rails_helper'

object_contents = {
  'he/CW_HistoricalEmisisons_metadata_sectors.csv' => <<~END,
    Source,Sector,SubsectorOf
    CAIT,Total excluding LUCF,
    PIK,Total including LUCF,
  END
  'he/CW_HistoricalEmisisons_sampledata_CAIT.csv' => <<~END,
    Country,Source,Sector,Gas,GWP,1990,1991,1992
    ABW,CAIT,Total excluding LUCF,All GHG,AR2,15.21284765,15.28643902,14.01053087,14.02811754
  END
  'he/CW_HistoricalEmisisons_sampledata_PIK.csv' => <<~END,
    Country,Source,Sector,Gas,GWP,1850,1851,1852
    ABW,PIK,Total including LUCF,CH4,AR2,0.00000469,0.00000475,0.00000483
  END
}

RSpec.describe ImportHistoricalEmissions do
  subject { ImportHistoricalEmissions.new.call }

  before :all do
    Aws.config[:s3] = {
      stub_responses: {
        get_object: lambda { |context|
          {body: object_contents[context.params[:key]]}
        }
      }
    }
  end

  before :each do
    FactoryGirl.create(
      :location, iso_code3: 'ABW', wri_standard_name: 'Aruba'
    )
  end

  after :all do
    Aws.config[:s3] = {
      stub_responses: nil
    }
  end

  it 'Creates new historical emission records' do
    expect { subject }.to change { HistoricalEmission.count }.by(2)
  end
end<commit_msg>Update historical emissions import spec<commit_after>require 'rails_helper'

object_contents = {
  'he/CW_HistoricalEmisisons_metadata_sectors.csv' => <<~END,
    Source,Sector,SubsectorOf
    CAIT,Total excluding LUCF,
    PIK,Total including LUCF,
  END
  'he/CW_HistoricalEmisisons_sampledata_CAIT.csv' => <<~END,
    Country,Source,Sector,Gas,GWP,1990,1991,1992
    ABW,CAIT,Total excluding LUCF,All GHG,AR2,15.21284765,15.28643902,14.01053087,14.02811754
  END
  'he/CW_HistoricalEmisisons_sampledata_PIK.csv' => <<~END,
    Country,Source,Sector,Gas,GWP,1850,1851,1852
    ABW,PIK,Total including LUCF,CH4,AR2,0.00000469,0.00000475,0.00000483
  END
}

RSpec.describe ImportHistoricalEmissions do
  subject { ImportHistoricalEmissions.new.call }

  before :all do
    Aws.config[:s3] = {
      stub_responses: {
        get_object: lambda { |context|
          {body: object_contents[context.params[:key]]}
        }
      }
    }
  end

  before :each do
    FactoryGirl.create(
      :location, iso_code3: 'ABW', wri_standard_name: 'Aruba'
    )
  end

  after :all do
    Aws.config[:s3] = {
      stub_responses: nil
    }
  end

  it 'Creates new historical emission records' do
    expect { subject }.to change { HistoricalEmissions::Record.count }.by(2)
  end
end
{'fraction_non_alphanumeric': 0.11451292246520875, 'fraction_numerical': 0.0779324055666004, 'mean_word_length': 3.774193548387097, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '2552849', 'n_tokens_mistral': 1099, 'n_tokens_neox': 942, 'n_words': 155}