<commit_before>require 'rails_helper'

RSpec.describe Country, type: :model do
  context 'when only location_countries exist' do
    let!(:xml) {Nokogiri::XML(File.read('spec/support/xml_data/NCT00513591.xml'))}
    let!(:opts) {{xml: xml, nct_id: 'NCT00513591'}}
    let!(:country) {Country.create_all_from(opts)}
    let!(:test_country) {Country.first}

    it 'should return the expected country name' do
      expect(test_country.name).to eq('United States')
    end

    it 'should return a nil value for removed' do
      expect(test_country.removed).to eq(nil)
    end
  end

  it "saves multiple current and removed countries" do
    nct_id='NCT01642004'
    xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
    study=Study.new({xml: xml, nct_id: nct_id}).create
    expect(study.countries.size).to eq(25)
    expect(study.countries.select{|x|x.removed==true}.size).to eq(5)
    expect(study.countries.select{|x|x.name=='Peru' and x.removed==nil}.size).to eq(1)
    expect(study.countries.select{|x|x.name=='Peru' and x.removed==true}.size).to eq(0)
    expect(study.countries.select{|x|x.name=='Norway' and x.removed==true}.size).to eq(1)<commit_msg>aact-367:  refreshed test study - seems a country was added to study NCT01642004 in ct.gov<commit_after>require 'rails_helper'

RSpec.describe Country, type: :model do
  context 'when only location_countries exist' do
    let!(:xml) {Nokogiri::XML(File.read('spec/support/xml_data/NCT00513591.xml'))}
    let!(:opts) {{xml: xml, nct_id: 'NCT00513591'}}
    let!(:country) {Country.create_all_from(opts)}
    let!(:test_country) {Country.first}

    it 'should return the expected country name' do
      expect(test_country.name).to eq('United States')
    end

    it 'should return a nil value for removed' do
      expect(test_country.removed).to eq(nil)
    end
  end

  it "saves multiple current and removed countries" do
    nct_id='NCT01642004'
    xml=Nokogiri::XML(File.read("spec/support/xml_data/#{nct_id}.xml"))
    study=Study.new({xml: xml, nct_id: nct_id}).create
    expect(study.countries.size).to eq(26)
    expect(study.countries.select{|x|x.removed==true}.size).to eq(6)
    expect(study.countries.select{|x|x.name=='Peru' and x.removed==nil}.size).to eq(1)
    expect(study.countries.select{|x|x.name=='Peru' and x.removed==true}.size).to eq(0)
    expect(study.countries.select{|x|x.name=='Norway' and x.removed==true}.size).to eq(1)
{'fraction_non_alphanumeric': 0.1586518701191944, 'fraction_numerical': 0.029182079736950268, 'mean_word_length': 4.5697940503432495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '6616974', 'n_tokens_mistral': 951, 'n_tokens_neox': 880, 'n_words': 170}