From c68da235dc7aea3c23f453dec2cbadcf36b06daf Mon Sep 17 00:00:00 2001 From: Ben Tregenna Date: Fri, 10 Jul 2020 14:20:54 +0100 Subject: [PATCH] Fixed up the pame importer tests and checked more expectations no longer creates a mystery empty country during import --- Gemfile | 4 ++-- Gemfile.lock | 8 ++++++-- app/models/pame_evaluation.rb | 2 +- lib/data/seeds/test_pame_data_hidden.csv | 2 +- test/unit/wdpa/pame_importer_test.rb | 23 ++++++++++++++++++++--- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 724cf68ba..5f6665512 100644 --- a/Gemfile +++ b/Gemfile @@ -4,8 +4,8 @@ source 'https://wcmc-gems:SDvUM6ZG@gem-server.unep-wcmc.org/' gem 'rails', '5.2.0' gem 'webpacker', '~> 4.0.2' -#gem 'wcmc-components', path: "../web-components/gems/wcmc_components" -gem 'wcmc-components', '~>0.0.4' +gem 'wcmc-components', path: "../web-components/gems/wcmc_components" +#gem 'wcmc-components', '~>0.0.5' gem 'bourbon' diff --git a/Gemfile.lock b/Gemfile.lock index 1010793be..228dc60c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,6 +5,11 @@ GIT bystander (2.0.0) slack-notifier (~> 1.5.1) +PATH + remote: ../web-components/gems/wcmc_components + specs: + wcmc-components (0.0.5) + GEM remote: https://rubygems.org/ remote: https://wcmc-gems:SDvUM6ZG@gem-server.unep-wcmc.org/ @@ -1282,7 +1287,6 @@ GEM vuejs-rails (2.3.2) warden (1.2.8) rack (>= 2.0.6) - wcmc-components (0.0.4) webmock (1.22.6) addressable (>= 2.3.6) crack (>= 0.3.2) @@ -1365,7 +1369,7 @@ DEPENDENCIES turnout (~> 2.5.0) uglifier (~> 4.1.17) vuejs-rails (~> 2.3.2) - wcmc-components (~> 0.0.4) + wcmc-components! webmock (~> 1.22.0) webpacker (~> 4.0.2) whenever diff --git a/app/models/pame_evaluation.rb b/app/models/pame_evaluation.rb index e4cab05cd..e5600e14f 100644 --- a/app/models/pame_evaluation.rb +++ b/app/models/pame_evaluation.rb @@ -14,7 +14,7 @@ class PameEvaluation < ApplicationRecord ignore_column :designation import_by protected_area: :wdpa_id - import_by country: :iso_3 + import_by countries: :iso_3 TABLE_ATTRIBUTES = [ diff --git a/lib/data/seeds/test_pame_data_hidden.csv b/lib/data/seeds/test_pame_data_hidden.csv index 734d7dc36..d23e0e64b 100644 --- a/lib/data/seeds/test_pame_data_hidden.csv +++ b/lib/data/seeds/test_pame_data_hidden.csv @@ -1,4 +1,4 @@ -evaluation_id,wdpa_id,iso3,methodology,year,url,metadata_id,name,designation,source_data_title,source_resp_party,source_year,source_language,restricted +id,protected_area,countries,methodology,year,url,metadata_id,name,designation,pame_source_data_title,pame_source_resp_party,pame_source_year,pame_source_language,restricted 64,,ARG,Valdiviana,2001,For storage only,3,Lanín,National Park,Áreas Protegidas enfocadas a la Efectividad del Manejo,"Jorge Fabricant – Técnico Dirección de Ordenamiento Territorial, Suelos y Lucha contra la Desertificación, del Ministerio de Ambiente y Desarrollo Sustentable",2018,Spanish,FALSE 66,2,ARG,Parks profiles,2006,For storage only,3,Lanín,National Park,Áreas Protegidas enfocadas a la Efectividad del Manejo,"Jorge Fabricant – Técnico Dirección de Ordenamiento Territorial, Suelos y Lucha contra la Desertificación, del Ministerio de Ambiente y Desarrollo Sustentable",2018,Spanish,TRUE 70,,ARG,Parks profiles,2006,For storage only,3,Los Alerces,National Park,Áreas Protegidas enfocadas a la Efectividad del Manejo,"Jorge Fabricant – Técnico Dirección de Ordenamiento Territorial, Suelos y Lucha contra la Desertificación, del Ministerio de Ambiente y Desarrollo Sustentable",2018,Spanish,TRUE diff --git a/test/unit/wdpa/pame_importer_test.rb b/test/unit/wdpa/pame_importer_test.rb index 8b66ce83d..4e9e1f222 100644 --- a/test/unit/wdpa/pame_importer_test.rb +++ b/test/unit/wdpa/pame_importer_test.rb @@ -10,15 +10,23 @@ class TestPameImporter < ActiveSupport::TestCase FactoryGirl.create(:protected_area, wdpa_id: wdpa_id) end + arg = FactoryGirl.create(:country, iso_3: 'ARG', name: 'Argentina') + Wdpa::PameImporter.import(PAME_EVALUATIONS) pame_evaluations = PameEvaluation.all assert_equal 9, pame_evaluations.count + # make sure we don't create any new countries and that evaluation ends up attached to existing country + assert_equal 1, Country.all.count + assert_equal arg.id, pame_evaluations.first.countries[0].id + # same for PAs don't create any more and should all be attached up + assert_equal 3, ProtectedArea.all.count + assert_equal 1, pame_evaluations.find(64).protected_area.wdpa_id + end -# test "#import pame evaluations with hidden evaluation" do - def badger -# PAME_EVALUATIONS = "#{Rails.root}/lib/data/seeds/test_pame_data_hidden.csv".freeze + test "#import pame evaluations with hidden evaluation" do + PAME_EVALUATIONS = "#{Rails.root}/lib/data/seeds/test_pame_data_hidden.csv".freeze # this csv tests the three cases # nil pa not restricted, with pa with restricted and nil pa restricted. @@ -31,5 +39,14 @@ def badger pame_evaluations = PameEvaluation.all assert_equal 9, pame_evaluations.count + # check nil pa + assert pame_evaluations.find(64).protected_area.nil? + assert !pame_evaluations.find(64).restricted + # pa and restricted + assert_equal 2, pame_evaluations.find(66).protected_area.wdpa_id + assert pame_evaluations.find(66).restricted + # nil pa and restricted + assert pame_evaluations.find(70).protected_area.nil? + assert pame_evaluations.find(70).restricted end end