Skip to content

Commit

Permalink
Fixed up the pame importer tests and checked more expectations
Browse files Browse the repository at this point in the history
no longer creates a mystery empty country during import
  • Loading branch information
Ben Tregenna authored and Ben Tregenna committed Jul 10, 2020
1 parent a127625 commit c68da23
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ source 'https://wcmc-gems:[email protected]/'
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'
Expand Down
8 changes: 6 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/pame_evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion lib/data/seeds/test_pame_data_hidden.csv
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 20 additions & 3 deletions test/unit/wdpa/pame_importer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

0 comments on commit c68da23

Please sign in to comment.