From 9696f3f0603d207c95df2eb0742ec08a7482bc15 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Thu, 16 Apr 2026 16:02:50 +0100 Subject: [PATCH 1/8] chore: sort out warnings printed on run by rubocop --- .rubocop.yml | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 04854f23f..4ab794d62 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_gem: rubocop-rails-omakase: rubocop.yml -require: +plugins: - rubocop-capybara - rubocop-factory_bot - rubocop-rails @@ -126,6 +126,16 @@ Layout/IndentationWidth: Layout/ClosingParenthesisIndentation: Enabled: true +Layout/EmptyLinesAfterModuleInclusion: + Enabled: true + +Layout/EmptyLineAfterMultilineCondition: + Enabled: true + +Style/ParenthesesAroundCondition: + Enabled: true + AllowInMultilineConditions: true + # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. # SupportedStyles: space, no_space Layout/SpaceInsideHashLiteralBraces: @@ -191,7 +201,12 @@ Layout/HashAlignment: Rails/NotNullColumn: Enabled: false -Rails/ExampleLength: + +# Harmless. Make this very large. +RSpec/NestedGroups: + Max: 10 + +RSpec/ExampleLength: Enabled: true Max: 10 CountAsOne: @@ -565,6 +580,20 @@ Rails/WhereNotWithMultipleConditions: # new in 2.17 Enabled: true Rails/WhereRange: # new in 2.25 Enabled: true +Rails/EnumSyntax: # new in 2.26 + Enabled: true +Rails/FindByOrAssignmentMemoization: # new in 2.33 + Enabled: true +Rails/HttpStatusNameConsistency: # new in 2.34 + Enabled: true +Rails/MultipleRoutePaths: # new in 2.29 + Enabled: true +Rails/OrderArguments: # new in 2.33 + Enabled: true +Rails/RedirectBackOrTo: # new in 2.34 + Enabled: true +Rails/StrongParametersExpect: # new in 2.29 + Enabled: true Capybara/ClickLinkOrButtonStyle: # new in 2.19 Enabled: true @@ -584,6 +613,10 @@ Capybara/RSpec/HaveSelector: # new in 2.19 Enabled: true Capybara/RSpec/PredicateMatcher: # new in 2.19 Enabled: true +Capybara/FindAllFirst: # new in 2.22 + Enabled: true +Capybara/NegationMatcherAfterVisit: # new in 2.22 + Enabled: true FactoryBot/AssociationStyle: # new in 2.23 Enabled: true FactoryBot/ConsistentParenthesesStyle: # new in 2.14 @@ -612,3 +645,7 @@ RSpecRails/NegationBeValid: # new in 2.23 Enabled: true RSpecRails/TravelAround: # new in 2.19 Enabled: true +RSpec/IncludeExamples: # new in 3.6 + Enabled: true +RSpec/LeakyLocalVariable: # new in 3.8 + Enabled: true \ No newline at end of file From 739cbd3036da3332987c418aa9eca32316b56771 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Mon, 20 Apr 2026 09:44:34 +0100 Subject: [PATCH 2/8] chore: remove some excessively strict cops --- .rubocop.yml | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4ab794d62..a260389b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,9 +11,18 @@ plugins: Rails: Enabled: true + AllCops: TargetRubyVersion: 3.4 TargetRailsVersion: 8.1 + Exclude: + # do not worry about old migrations + - 'db/migrate/201*' + - 'db/migrate/2020*' + - 'db/migrate/2021*' + - 'db/migrate/2022*' + - 'db/migrate/2023*' + - 'db/migrate/2024*' Style/StringLiterals: EnforcedStyle: single_quotes @@ -201,11 +210,22 @@ Layout/HashAlignment: Rails/NotNullColumn: Enabled: false +Rails/UnknownEnv: + Enabled: true + Environments: + - development + - test + - staging + - production -# Harmless. Make this very large. +## +# Increase the limit of these advisory cops. RSpec/NestedGroups: Max: 10 +RSpec/MultipleMemoizedHelpers: + Max: 10 + RSpec/ExampleLength: Enabled: true Max: 10 @@ -215,13 +235,19 @@ RSpec/ExampleLength: - heredoc - method_call -Rails/UnknownEnv: - Enabled: true - Environments: - - development - - test - - staging - - production +# TODO: Not enabled as too many changes required for now. +RSpec/ContextWording: + Enabled: false +RSpec/DescribedClass: + Enabled: false +RSpec/DescribeSymbol: + Enabled: false +RSpec/InstanceVariable: + Enabled: false +RSpec/NamedSubject: + Enabled: false +RSpec/SharedExamples: + Enabled: false Style/Documentation: Enabled: false From 648961d27809a008a9b1baf952adc69430b0ebd7 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Fri, 17 Apr 2026 16:36:08 +0100 Subject: [PATCH 3/8] chore: bundle exec rubocop -a --only Style,Layout app/ lib/ --- app/controllers/admin/exports_controller.rb | 1 + .../status_to_synonym_controller.rb | 2 +- .../admin/taxon_concepts_controller.rb | 1 + app/controllers/api/ranks_controller.rb | 7 ++++--- app/controllers/application_controller.rb | 1 + app/controllers/cites_trade_controller.rb | 1 + app/controllers/trade_controller.rb | 2 ++ .../admin/nomenclature_changes_helper.rb | 1 + app/models/change_type.rb | 1 + app/models/concerns/changeable.rb | 4 +++- app/models/distribution_reference.rb | 1 + app/models/document.rb | 1 + app/models/document_citation_geo_entity.rb | 1 + app/models/document_citation_taxon_concept.rb | 1 + app/models/geo_entity.rb | 1 + app/models/geo_entity_type.rb | 1 + app/models/geo_relationship_type.rb | 1 + app/models/listing_change.rb | 1 + app/models/m_auto_complete_taxon_concept.rb | 1 + app/models/m_taxon_concept.rb | 1 + .../nomenclature_change/constructor_helpers.rb | 1 + app/models/nomenclature_change/lump.rb | 1 + app/models/nomenclature_change/output.rb | 3 +++ .../reassignment_helpers.rb | 1 + app/models/nomenclature_change/split.rb | 3 +++ app/models/nomenclature_change/status_swap.rb | 1 + .../nomenclature_change/status_to_synonym.rb | 2 ++ app/models/rank.rb | 1 + app/models/taxon_concept.rb | 4 ++++ app/models/taxon_relationship.rb | 2 ++ app/models/taxon_relationship_type.rb | 1 + app/models/trade/sandbox_template.rb | 1 + app/models/trade/validation_rule.rb | 1 + app/models/trade_restriction.rb | 1 + app/models/trade_restriction_purpose.rb | 1 + app/models/trade_restriction_source.rb | 1 + app/models/trade_restriction_term.rb | 1 + app/services/checklist/checklist.rb | 2 ++ app/services/checklist/timeline.rb | 4 ++++ app/services/checklist/timeline_event.rb | 1 + app/services/checklist/timeline_interval.rb | 1 + app/services/checklist/timeline_year.rb | 1 + .../checklist/timelines_for_taxon_concept.rb | 1 + app/services/dashboard_stats.rb | 1 + app/services/document_search.rb | 1 + app/services/geo_entity_search.rb | 1 + ...on_concept_filter_by_id_with_descendants.rb | 18 ++++++++++++------ .../reassignment_copy_processor.rb | 2 ++ .../reassignment_transfer_processor.rb | 2 ++ .../nomenclature_change/split/constructor.rb | 1 + .../status_change/constructor_helpers.rb | 1 + app/services/search_params.rb | 1 + app/services/species/search.rb | 1 + app/services/trade/sandbox_search_params.rb | 1 + app/services/trade/shipments_export.rb | 2 ++ .../changes_history_generator_worker.rb | 1 + app/workers/eu_regulation_activation_worker.rb | 1 + app/workers/event_eu_suspension_copy_worker.rb | 1 + .../event_listing_changes_copy_worker.rb | 1 + app/workers/manual_download_worker.rb | 2 +- app/workers/permit_cleanup_worker.rb | 1 + app/workers/quotas_copy_worker.rb | 1 + app/workers/refresh_documents_worker.rb | 1 + app/workers/submission_worker.rb | 1 + lib/tasks/import_distributions.rake | 1 + 65 files changed, 98 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/exports_controller.rb b/app/controllers/admin/exports_controller.rb index b242ef1af..715618b6a 100644 --- a/app/controllers/admin/exports_controller.rb +++ b/app/controllers/admin/exports_controller.rb @@ -7,6 +7,7 @@ def download csv_separator: if filter_params && filter_params[:csv_separator] && filter_params[:csv_separator].downcase.strip.to_sym == :semicolon + :semicolon else :comma diff --git a/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb b/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb index c683d36ca..50f14044c 100644 --- a/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb +++ b/app/controllers/admin/nomenclature_changes/status_to_synonym_controller.rb @@ -87,7 +87,7 @@ def nomenclature_change_status_to_synonym_params name_reassignments_attributes: [ output_reassignment_attribute_names ], distribution_reassignments_attributes: [ output_reassignment_attribute_names ], legislation_reassignments_attributes: [ output_reassignment_attribute_names ] - ], + ] ] ) end diff --git a/app/controllers/admin/taxon_concepts_controller.rb b/app/controllers/admin/taxon_concepts_controller.rb index 3f6884fe6..2a480b74c 100644 --- a/app/controllers/admin/taxon_concepts_controller.rb +++ b/app/controllers/admin/taxon_concepts_controller.rb @@ -133,6 +133,7 @@ def split_stringified_ids_lists params[:taxon_concept].key?(ids_list_key) && (stringified_ids_list = params[:taxon_concept][ids_list_key]) && stringified_ids_list.is_a?(String) + params[:taxon_concept][ids_list_key] = stringified_ids_list.split(',').map(&:to_i) end end diff --git a/app/controllers/api/ranks_controller.rb b/app/controllers/api/ranks_controller.rb index 7aabe54b8..f1aa15632 100644 --- a/app/controllers/api/ranks_controller.rb +++ b/app/controllers/api/ranks_controller.rb @@ -5,8 +5,9 @@ class Api::RanksController < ApplicationController protected def collection - @ranks ||= end_of_association_chain. - select([ :id, :name ]). - map { |d| { value: d.id, text: d.name } } + @ranks ||= + end_of_association_chain. + select([ :id, :name ]). + map { |d| { value: d.id, text: d.name } } end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dbb08db6e..f6951d02d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,6 +22,7 @@ def invalid_request_error(exception) then :bad_request when ActionController::UnknownFormat, ActionDispatch::Http::MimeNegotiation::InvalidType + then :not_acceptable else :unprocessable_entity diff --git a/app/controllers/cites_trade_controller.rb b/app/controllers/cites_trade_controller.rb index 654edcab3..fb599d7d2 100644 --- a/app/controllers/cites_trade_controller.rb +++ b/app/controllers/cites_trade_controller.rb @@ -46,6 +46,7 @@ def search_params Trade::ShipmentsExportFactory.public_report_types.include?( report_type = original_params[:report_type].downcase.strip.to_sym ) + report_type else :comptab diff --git a/app/controllers/trade_controller.rb b/app/controllers/trade_controller.rb index 3227215e7..727ae3adc 100644 --- a/app/controllers/trade_controller.rb +++ b/app/controllers/trade_controller.rb @@ -81,6 +81,7 @@ def params_overrides if params[:filters] && params[:filters][:report_type] && (Trade::ShipmentsExportFactory.report_types & [ report_type = params[:filters][:report_type].downcase.strip.to_sym ]) + report_type else :raw @@ -88,6 +89,7 @@ def params_overrides csv_separator: if params[:filters] && params[:filters][:csv_separator] && params[:filters][:csv_separator].downcase.strip.to_sym == :semicolon + :semicolon else :comma diff --git a/app/helpers/admin/nomenclature_changes_helper.rb b/app/helpers/admin/nomenclature_changes_helper.rb index 8dc68f63d..b264c5e82 100644 --- a/app/helpers/admin/nomenclature_changes_helper.rb +++ b/app/helpers/admin/nomenclature_changes_helper.rb @@ -158,6 +158,7 @@ def outputs_selection(ff) elsif ff.object.taxon_concept && ff.object.new_scientific_name.present? && ff.object.taxon_concept.full_name != ff.object.new_scientific_name + # this scenario occurrs when an existing taxon will change name 'existing_subspecies' else diff --git a/app/models/change_type.rb b/app/models/change_type.rb index 6ec612b94..8b99a5047 100644 --- a/app/models/change_type.rb +++ b/app/models/change_type.rb @@ -28,6 +28,7 @@ class ChangeType < ApplicationRecord include Deletable extend Mobility include Dictionary + build_dictionary :addition, :deletion, :reservation, :reservation_withdrawal, :exception translates :display_name diff --git a/app/models/concerns/changeable.rb b/app/models/concerns/changeable.rb index 24e319cf4..5fcb46369 100644 --- a/app/models/concerns/changeable.rb +++ b/app/models/concerns/changeable.rb @@ -68,6 +68,7 @@ def changeable_after_save_callback # == Changed to fix deprecation warnings == if (taxon_concept.nil? && taxon_concept_id_before_last_save) || (taxon_concept && taxon_concept_id_before_last_save && taxon_concept_id != taxon_concept_id_before_last_save) + previous_taxon_concept = TaxonConcept.find_by(id: taxon_concept_id_before_last_save) if previous_taxon_concept changeable_bump_dependents_timestamp_part_one(previous_taxon_concept, updated_by_id) @@ -118,6 +119,7 @@ def changeable_after_save_callback_on_commit # == Changed to fix deprecation warnings == if (taxon_concept.nil? && taxon_concept_id_before_last_save) || (taxon_concept && taxon_concept_id_before_last_save && taxon_concept_id != taxon_concept_id_before_last_save) + previous_taxon_concept = TaxonConcept.find_by(id: taxon_concept_id_before_last_save) if previous_taxon_concept changeable_bump_dependents_timestamp_part_two @@ -147,6 +149,6 @@ def changeable_bump_dependents_timestamp_part_two end def changeable_clear_show_tc_serializer_cache - Rails.cache.delete_matched("*ShowTaxonConceptSerializer*") + Rails.cache.delete_matched('*ShowTaxonConceptSerializer*') end end diff --git a/app/models/distribution_reference.rb b/app/models/distribution_reference.rb index 3fce8efbe..2390f2fe6 100644 --- a/app/models/distribution_reference.rb +++ b/app/models/distribution_reference.rb @@ -28,6 +28,7 @@ class DistributionReference < ApplicationRecord include TrackWhoDoesIt + # Used by app/models/cms_mapping_manager.rb belongs_to :reference diff --git a/app/models/document.rb b/app/models/document.rb index 90158b3a5..3c5960f2d 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -207,6 +207,7 @@ def sync_sort_index if saved_change_to_sort_index? if primary_language_document && primary_language_document_id != id + primary_language_document.update_attribute( :sort_index, sort_index diff --git a/app/models/document_citation_geo_entity.rb b/app/models/document_citation_geo_entity.rb index f50ec852f..7981df439 100644 --- a/app/models/document_citation_geo_entity.rb +++ b/app/models/document_citation_geo_entity.rb @@ -28,6 +28,7 @@ class DocumentCitationGeoEntity < ApplicationRecord include TrackWhoDoesIt + # Used by app/models/nomenclature_change/reassignment_copy_processor.rb and lib/tasks/elibrary/identification_docs_distributions_importer.rb belongs_to :geo_entity diff --git a/app/models/document_citation_taxon_concept.rb b/app/models/document_citation_taxon_concept.rb index 868573fc3..589f3b67f 100644 --- a/app/models/document_citation_taxon_concept.rb +++ b/app/models/document_citation_taxon_concept.rb @@ -28,6 +28,7 @@ class DocumentCitationTaxonConcept < ApplicationRecord include TrackWhoDoesIt + # Used by other models, not controllers. belongs_to :taxon_concept diff --git a/app/models/geo_entity.rb b/app/models/geo_entity.rb index 11cd63e47..6d7f34b41 100644 --- a/app/models/geo_entity.rb +++ b/app/models/geo_entity.rb @@ -31,6 +31,7 @@ class GeoEntity < ApplicationRecord include Changeable include Deletable extend Mobility + translates :name belongs_to :geo_entity_type has_many :geo_relationships diff --git a/app/models/geo_entity_type.rb b/app/models/geo_entity_type.rb index 81c98452a..e5ca6d29f 100644 --- a/app/models/geo_entity_type.rb +++ b/app/models/geo_entity_type.rb @@ -12,6 +12,7 @@ class GeoEntityType < ApplicationRecord # Look like the only place create GeoEntityType is lib/tasks/import_trade_shipments.rake include Dictionary + build_dictionary :country, :cites_region, :region, :territory, :aquatic_territory, :bru, :trade_entity diff --git a/app/models/geo_relationship_type.rb b/app/models/geo_relationship_type.rb index eadb44e74..8a31abe5d 100644 --- a/app/models/geo_relationship_type.rb +++ b/app/models/geo_relationship_type.rb @@ -12,5 +12,6 @@ class GeoRelationshipType < ApplicationRecord # Used by seed only. include Dictionary + build_dictionary :contains, :intersects end diff --git a/app/models/listing_change.rb b/app/models/listing_change.rb index 70bb9d0ce..f2239f369 100644 --- a/app/models/listing_change.rb +++ b/app/models/listing_change.rb @@ -224,6 +224,7 @@ def listing_change_before_save_callback annotation.full_note_en.blank? && annotation.full_note_fr.blank? && annotation.full_note_es.blank? + ann = annotation self.annotation = nil if ann.reload.listing_changes.empty? diff --git a/app/models/m_auto_complete_taxon_concept.rb b/app/models/m_auto_complete_taxon_concept.rb index 623e43724..06a8631a5 100644 --- a/app/models/m_auto_complete_taxon_concept.rb +++ b/app/models/m_auto_complete_taxon_concept.rb @@ -32,6 +32,7 @@ class MAutoCompleteTaxonConcept < ApplicationRecord extend Mobility + self.table_name = :auto_complete_taxon_concepts_mview self.primary_key = :id diff --git a/app/models/m_taxon_concept.rb b/app/models/m_taxon_concept.rb index 994a06bc4..18f0d17a7 100644 --- a/app/models/m_taxon_concept.rb +++ b/app/models/m_taxon_concept.rb @@ -116,6 +116,7 @@ class MTaxonConcept < ApplicationRecord extend Mobility + self.table_name = :taxon_concepts_mview self.primary_key = :id diff --git a/app/models/nomenclature_change/constructor_helpers.rb b/app/models/nomenclature_change/constructor_helpers.rb index c858ea07e..2771ce22e 100644 --- a/app/models/nomenclature_change/constructor_helpers.rb +++ b/app/models/nomenclature_change/constructor_helpers.rb @@ -181,6 +181,7 @@ def _build_document_reassignment(document_citation, input, outputs) if !dc_ge_ids_to_reassign.empty? || tc_distributions.empty? || dc_geo_entities.empty? + reassignment.reassignment_targets.build(nomenclature_change_output_id: output.id) end end diff --git a/app/models/nomenclature_change/lump.rb b/app/models/nomenclature_change/lump.rb index 24a178486..28b70989b 100644 --- a/app/models/nomenclature_change/lump.rb +++ b/app/models/nomenclature_change/lump.rb @@ -78,6 +78,7 @@ def set_output_name_status output.new_scientific_name.present? || (output.taxon_concept && output.taxon_concept.name_status != 'A') ) + output.new_name_status = 'A' end end diff --git a/app/models/nomenclature_change/output.rb b/app/models/nomenclature_change/output.rb index 58ed4f14f..d6d4113a0 100644 --- a/app/models/nomenclature_change/output.rb +++ b/app/models/nomenclature_change/output.rb @@ -54,6 +54,7 @@ # change. class NomenclatureChange::Output < ApplicationRecord include TrackWhoDoesIt + attr_accessor :output_type # New taxon, Existing subspecies, Existing taxon belongs_to :nomenclature_change @@ -211,6 +212,7 @@ def validate_tmp_taxon_concept if [ :parent_id, :rank, :name_status, :author_year, :full_name ]. include?(attribute) + errors.add(:"new_#{attribute}", message) else errors.add(:new_taxon_concept, message) @@ -231,6 +233,7 @@ def expected_parent_name def default_parent if [ 'S', 'T' ].include?(name_status) && parent_full_name = expected_parent_name + TaxonConcept.where( taxonomy_id: Taxonomy.find_by(name: Taxonomy::CITES_EU).try(:id), rank_id: Rank.find_by(name: rank.parent_rank_name).try(:id), diff --git a/app/models/nomenclature_change/reassignment_helpers.rb b/app/models/nomenclature_change/reassignment_helpers.rb index ba56f76f9..5079b2ca1 100644 --- a/app/models/nomenclature_change/reassignment_helpers.rb +++ b/app/models/nomenclature_change/reassignment_helpers.rb @@ -2,6 +2,7 @@ module NomenclatureChange::ReassignmentHelpers def self.included(base) base.class_eval do include TrackWhoDoesIt + belongs_to :reassignable, polymorphic: true, optional: true has_many :reassignment_targets, inverse_of: :reassignment, diff --git a/app/models/nomenclature_change/split.rb b/app/models/nomenclature_change/split.rb index 1a1639ff8..806d1011c 100644 --- a/app/models/nomenclature_change/split.rb +++ b/app/models/nomenclature_change/split.rb @@ -81,6 +81,7 @@ def required_ranks outputs.map do |o| o.try(:new_rank_id) || o.try(:taxon_concept).try(:rank_id) end.uniq - [ input.try(:taxon_concept).try(:rank_id) ]).empty? + errors.add(:outputs, 'Must be at same rank as input') false end @@ -92,6 +93,7 @@ def set_outputs_name_status output.new_scientific_name.present? || (output.taxon_concept && output.taxon_concept.name_status != 'A') ) + output.new_name_status = 'A' end end @@ -103,6 +105,7 @@ def set_outputs_rank_id output.new_scientific_name.present? || (output.taxon_concept && output.taxon_concept.rank_id != new_output_rank.id) ) + output.new_rank_id = new_output_rank.id end end diff --git a/app/models/nomenclature_change/status_swap.rb b/app/models/nomenclature_change/status_swap.rb index 35f8297e5..ef75c176c 100644 --- a/app/models/nomenclature_change/status_swap.rb +++ b/app/models/nomenclature_change/status_swap.rb @@ -31,6 +31,7 @@ # to secondary output class NomenclatureChange::StatusSwap < NomenclatureChange include NomenclatureChange::StatusChangeHelpers + build_steps( :primary_output, :secondary_output, :notes, :legislation, :summary ) diff --git a/app/models/nomenclature_change/status_to_synonym.rb b/app/models/nomenclature_change/status_to_synonym.rb index 30042f302..c5a3f2f16 100644 --- a/app/models/nomenclature_change/status_to_synonym.rb +++ b/app/models/nomenclature_change/status_to_synonym.rb @@ -33,6 +33,7 @@ # involved between the input and one of the outputs. class NomenclatureChange::StatusToSynonym < NomenclatureChange include NomenclatureChange::StatusChangeHelpers + build_steps( :primary_output, :relay, :accepted_name, :legislation, :summary ) @@ -63,6 +64,7 @@ def required_primary_output_name_status def required_secondary_output if (needs_to_relay_associations? || requires_accepted_name_assignment?) && secondary_output.nil? + errors.add(:secondary_output, 'Must have a secondary output') return false end diff --git a/app/models/rank.rb b/app/models/rank.rb index afcadefac..fc6f73a1e 100644 --- a/app/models/rank.rb +++ b/app/models/rank.rb @@ -24,6 +24,7 @@ class Rank < ApplicationRecord include Deletable extend Mobility include Dictionary + build_dictionary :kingdom, :phylum, :class, :order, :family, :subfamily, :genus, :species, :subspecies, :variety translates :display_name diff --git a/app/models/taxon_concept.rb b/app/models/taxon_concept.rb index 61a51521d..18c13652a 100644 --- a/app/models/taxon_concept.rb +++ b/app/models/taxon_concept.rb @@ -74,6 +74,7 @@ class TaxonConcept < ApplicationRecord include Deletable extend Mobility include TrackWhoDoesIt + has_paper_trail versions: { class_name: 'TaxonConceptVersion' }, on: :destroy, meta: { taxon_concept_id: :id, @@ -228,6 +229,7 @@ class TaxonConcept < ApplicationRecord saved_change_to_taxon_name_id? || saved_change_to_parent_id? || saved_change_to_name_status? + Species::Search.increment_cache_iterator Species::TaxonConceptPrefixMatcher.increment_cache_iterator Checklist::Checklist.increment_cache_iterator @@ -409,6 +411,7 @@ def inherited_standard_taxon_concept_references def expected_full_name(parent) if self.rank && Rank.in_range(Rank::VARIETY, Rank::SPECIES).include?(self.rank.name) + parent.full_name + if self.rank.name == Rank::VARIETY ' var. ' @@ -592,6 +595,7 @@ def parent_at_immediately_higher_rank unless parent.rank.taxonomic_position >= rank.parent_rank_lower_bound && parent.rank.taxonomic_position < rank.taxonomic_position + errors.add(:parent_id, 'must be at immediately higher rank') false end diff --git a/app/models/taxon_relationship.rb b/app/models/taxon_relationship.rb index 48d060d93..924d664bf 100644 --- a/app/models/taxon_relationship.rb +++ b/app/models/taxon_relationship.rb @@ -82,6 +82,7 @@ class TaxonRelationship < ApplicationRecord def update_higher_taxa_for_hybrid_child if other_taxon_concept && taxon_relationship_type && taxon_relationship_type.name == TaxonRelationshipType::HAS_HYBRID + tcd = TaxonConceptData.new(other_taxon_concept) data = tcd.to_h other_taxon_concept.update_column(:data, data) @@ -136,6 +137,7 @@ def intertaxonomic_relationship_uniqueness ). joins(:taxon_relationship_type). where(taxon_relationship_types: { is_intertaxonomic: true }).where.not(taxon_relationship_types: { id: self.taxon_relationship_type_id }).any? + errors.add(:taxon_concept_id, 'these taxon are already related through another relationship.') end end diff --git a/app/models/taxon_relationship_type.rb b/app/models/taxon_relationship_type.rb index 9c785bf37..affdf4b08 100644 --- a/app/models/taxon_relationship_type.rb +++ b/app/models/taxon_relationship_type.rb @@ -14,6 +14,7 @@ class TaxonRelationshipType < ApplicationRecord # Used by seed and rake task. include Dictionary + build_dictionary :equal_to, :includes, :overlaps, :disjunct, :has_synonym, :has_hybrid, :has_trade_name diff --git a/app/models/trade/sandbox_template.rb b/app/models/trade/sandbox_template.rb index 2a61b6111..ce8411acd 100644 --- a/app/models/trade/sandbox_template.rb +++ b/app/models/trade/sandbox_template.rb @@ -60,6 +60,7 @@ def self.ar_klass(table_name) has_paper_trail include ActiveModel::ForbiddenAttributesProtection + # Previously, `attr_accesssible` was used here for: # :appendix, # :taxon_name, diff --git a/app/models/trade/validation_rule.rb b/app/models/trade/validation_rule.rb index edeb0ec18..c77c9f3b7 100644 --- a/app/models/trade/validation_rule.rb +++ b/app/models/trade/validation_rule.rb @@ -94,6 +94,7 @@ def sanitized_sandbox_scope Trade::SandboxTemplate.column_names + [ 'point_of_view', 'importer', 'exporter', 'rank' ] ).include? scope_column + res[scope_column] = scope_def end end diff --git a/app/models/trade_restriction.rb b/app/models/trade_restriction.rb index dff1495ba..ea0ffc849 100644 --- a/app/models/trade_restriction.rb +++ b/app/models/trade_restriction.rb @@ -207,6 +207,7 @@ def self.to_csv(file_path, filters) until ( objs = export_query(filters).limit(limit).offset(offset) ).empty? + objs.each do |q| row = [] row += Species::RestrictionsExport.fill_taxon_columns(q) diff --git a/app/models/trade_restriction_purpose.rb b/app/models/trade_restriction_purpose.rb index 3b4604a32..4956c8501 100644 --- a/app/models/trade_restriction_purpose.rb +++ b/app/models/trade_restriction_purpose.rb @@ -27,6 +27,7 @@ class TradeRestrictionPurpose < ApplicationRecord include TrackWhoDoesIt + # Relationship model between TradeCode(purpose) and TradeRestriction belongs_to :trade_restriction diff --git a/app/models/trade_restriction_source.rb b/app/models/trade_restriction_source.rb index 3c28f876d..69316fe43 100644 --- a/app/models/trade_restriction_source.rb +++ b/app/models/trade_restriction_source.rb @@ -27,6 +27,7 @@ class TradeRestrictionSource < ApplicationRecord include TrackWhoDoesIt + # Relationship model between TradeCode(source) and TradeRestriction belongs_to :trade_restriction diff --git a/app/models/trade_restriction_term.rb b/app/models/trade_restriction_term.rb index 7cfcbbbcb..c86828782 100644 --- a/app/models/trade_restriction_term.rb +++ b/app/models/trade_restriction_term.rb @@ -27,6 +27,7 @@ class TradeRestrictionTerm < ApplicationRecord include TrackWhoDoesIt + # Relationship model between TradeCode(term) and TradeRestriction belongs_to :trade_restriction belongs_to :term, class_name: 'TradeCode' diff --git a/app/services/checklist/checklist.rb b/app/services/checklist/checklist.rb index 9518555ef..149962aaa 100644 --- a/app/services/checklist/checklist.rb +++ b/app/services/checklist/checklist.rb @@ -2,6 +2,7 @@ class Checklist::Checklist include ActiveModel::SerializerSupport include CacheIterator include SearchCache # this provides #cached_results and #cached_total_cnt + attr_accessor :animalia, :plantae, :authors, :synonyms, :synonyms_with_authors, :english_common_names, :spanish_common_names, :french_common_names, :total_cnt attr_reader :query @@ -142,6 +143,7 @@ def self.summarise_filters(params) !@countries.empty?) && (@countries_count > 0 || @regions_count > 0) + summary << I18n.t('filter_summary.on_appx') else summary << I18n.t('filter_summary.from_appx') diff --git a/app/services/checklist/timeline.rb b/app/services/checklist/timeline.rb index 0cf25c3a2..3853751ea 100644 --- a/app/services/checklist/timeline.rb +++ b/app/services/checklist/timeline.rb @@ -1,5 +1,6 @@ class Checklist::Timeline include ActiveModel::SerializerSupport + attr_reader :id, :appendix, :party_id, :timeline_events, :timeline_intervals, :parties, :timelines, :continues_in_present, :has_nested_timelines def initialize(options) @@ -56,6 +57,7 @@ def change_consecutive_additions_to_amendments ) && event.is_addition? && (event.party_id.nil? || event.party_id == prev_event.party_id) + event.change_type_name = 'AMENDMENT' end prev_event = event @@ -73,6 +75,7 @@ def add_intervals (event.is_deletion? && next_event.is_addition?) || (event.is_reservation_withdrawal? && next_event.is_reservation?) ) + Checklist::TimelineInterval.new( taxon_concept_id: @taxon_concept_id, listing_change_id: event.id, @@ -86,6 +89,7 @@ def add_intervals # the timeline if appdx III is still current if ((event.is_addition? || event.is_amendment? || event.is_deletion?) && @current) || (event.is_reservation? && event.is_current) + @continues_in_present = true Checklist::TimelineInterval.new( taxon_concept_id: @taxon_concept_id, diff --git a/app/services/checklist/timeline_event.rb b/app/services/checklist/timeline_event.rb index 43371c1a4..fb85fda90 100644 --- a/app/services/checklist/timeline_event.rb +++ b/app/services/checklist/timeline_event.rb @@ -1,5 +1,6 @@ class Checklist::TimelineEvent include ActiveModel::SerializerSupport + attr_accessor :id, :change_type_name, :species_listing_name, :effective_at, :party_id, :is_current, :pos, :auto_note, :short_note, :full_note, :hash_full_note, :hash_ann_symbol, :hash_ann_parent_symbol, diff --git a/app/services/checklist/timeline_interval.rb b/app/services/checklist/timeline_interval.rb index d0b97ffd8..1e81a8fed 100644 --- a/app/services/checklist/timeline_interval.rb +++ b/app/services/checklist/timeline_interval.rb @@ -1,5 +1,6 @@ class Checklist::TimelineInterval include ActiveModel::SerializerSupport + attr_accessor :id, :start_pos, :end_pos # options to be passed: # :start_pos - start position (%) diff --git a/app/services/checklist/timeline_year.rb b/app/services/checklist/timeline_year.rb index 3e21e1fae..d24c4b256 100644 --- a/app/services/checklist/timeline_year.rb +++ b/app/services/checklist/timeline_year.rb @@ -1,5 +1,6 @@ class Checklist::TimelineYear include ActiveModel::SerializerSupport + attr_accessor :id, :year, :pos # options to be passed: # :year - year on the timeline diff --git a/app/services/checklist/timelines_for_taxon_concept.rb b/app/services/checklist/timelines_for_taxon_concept.rb index b0961ee56..cfb50b343 100644 --- a/app/services/checklist/timelines_for_taxon_concept.rb +++ b/app/services/checklist/timelines_for_taxon_concept.rb @@ -1,5 +1,6 @@ class Checklist::TimelinesForTaxonConcept include ActiveModel::SerializerSupport + attr_reader :id, :taxon_concept_id, :raw_timelines, :timelines, :timeline_years, :has_descendant_timelines, :has_events, :has_reservations diff --git a/app/services/dashboard_stats.rb b/app/services/dashboard_stats.rb index a51867dce..56455800d 100644 --- a/app/services/dashboard_stats.rb +++ b/app/services/dashboard_stats.rb @@ -64,6 +64,7 @@ def trade_stats_per_reporter_type(reporter_type) if @time_range_start && @time_range_end && @time_range_start <= @time_range_end + shipments_for_country = shipments_for_country.where(year: @time_range_start..@time_range_end) end diff --git a/app/services/document_search.rb b/app/services/document_search.rb index 96ad20b18..fde1f4efa 100644 --- a/app/services/document_search.rb +++ b/app/services/document_search.rb @@ -4,6 +4,7 @@ class DocumentSearch # documents #index endpoints. include CacheIterator include SearchCache # this provides #cached_results and #cached_total_cnt + attr_reader :page, :per_page, :offset, :event_type, :events_ids, :document_type, :title_query diff --git a/app/services/geo_entity_search.rb b/app/services/geo_entity_search.rb index bb34f25aa..be38c1a0c 100644 --- a/app/services/geo_entity_search.rb +++ b/app/services/geo_entity_search.rb @@ -22,6 +22,7 @@ def initialize_params(options) @locale = if options[:locale] && [ 'en', 'es', 'fr' ].include?(options[:locale].downcase) + options[:locale] else I18n.locale diff --git a/app/services/m_taxon_concept_filter_by_id_with_descendants.rb b/app/services/m_taxon_concept_filter_by_id_with_descendants.rb index de1f54d31..37d262f54 100644 --- a/app/services/m_taxon_concept_filter_by_id_with_descendants.rb +++ b/app/services/m_taxon_concept_filter_by_id_with_descendants.rb @@ -10,14 +10,20 @@ def relation(ancestor_ranks = nil) Rank::GENUS, Rank::FAMILY, Rank::ORDER, Rank::CLASS, Rank::PHYLUM, Rank::KINGDOM ] # TODO: SUBFAMILY is missing here. we don't have it in listings mviews. - fields_to_check = ( - [ :id ] + - ancestor_ranks.map { |r| "#{r.downcase}_id" } - ).map { |c| "#{@table}.#{c}" } + + fields_to_check = + ( + [ :id ] + ancestor_ranks.map do |r| + "#{r.downcase}_id" + end + ).map do |c| + "#{@table}.#{c}" + end + @relation.where( <<-SQL.squish - ARRAY[#{fields_to_check.join(', ')}] && - ARRAY[#{@ids.join(', ')}] + ARRAY[#{fields_to_check.join(', ')}] && + ARRAY[#{@ids.join(', ')}] SQL ) end diff --git a/app/services/nomenclature_change/reassignment_copy_processor.rb b/app/services/nomenclature_change/reassignment_copy_processor.rb index 550f33c44..ad1b660a3 100644 --- a/app/services/nomenclature_change/reassignment_copy_processor.rb +++ b/app/services/nomenclature_change/reassignment_copy_processor.rb @@ -24,6 +24,7 @@ def copied_object_before_save(reassignment, reassignable) reassignable elsif reassignable.is_a?(TaxonRelationship) && reassignable.taxon_relationship_type.name == TaxonRelationshipType::HAS_TRADE_NAME + reassignable.taxon_concept_id = new_taxon_concept.id reassignable @@ -79,6 +80,7 @@ def copied_object_before_save(reassignment, reassignable) reassignable.is_a?(CitesSuspension) || reassignable.is_a?(Quota) || reassignable.is_a?(EuSuspension) || reassignable.is_a?(EuOpinion) ) + copied_object.assign_attributes(notes(copied_object, reassignment)) end diff --git a/app/services/nomenclature_change/reassignment_transfer_processor.rb b/app/services/nomenclature_change/reassignment_transfer_processor.rb index f0170ac3c..dc6954771 100644 --- a/app/services/nomenclature_change/reassignment_transfer_processor.rb +++ b/app/services/nomenclature_change/reassignment_transfer_processor.rb @@ -21,6 +21,7 @@ def transferred_object_before_save(reassignment, reassignable) if reassignment.kind_of?(NomenclatureChange::ParentReassignment) || reassignment.kind_of?(NomenclatureChange::OutputParentReassignment) + reassignable.parent_id = new_taxon_concept.id reassignable @@ -63,6 +64,7 @@ def transferred_object_before_save(reassignment, reassignable) reassignable.is_a?(CitesSuspension) || reassignable.is_a?(Quota) || reassignable.is_a?(EuSuspension) || reassignable.is_a?(EuOpinion) ) + transferred_object.assign_attributes( notes(transferred_object, reassignment) ) diff --git a/app/services/nomenclature_change/split/constructor.rb b/app/services/nomenclature_change/split/constructor.rb index b2351030c..5df57ac8c 100644 --- a/app/services/nomenclature_change/split/constructor.rb +++ b/app/services/nomenclature_change/split/constructor.rb @@ -115,6 +115,7 @@ def output_split_from(output, input, lng) output_html = if output.scientific_name.present? && output.new_scientific_name.present? + taxon_concept_html( output.display_full_name, output.display_rank_name, output.scientific_name, output.rank.name diff --git a/app/services/nomenclature_change/status_change/constructor_helpers.rb b/app/services/nomenclature_change/status_change/constructor_helpers.rb index 4fba91372..52bf007d6 100644 --- a/app/services/nomenclature_change/status_change/constructor_helpers.rb +++ b/app/services/nomenclature_change/status_change/constructor_helpers.rb @@ -22,6 +22,7 @@ def build_input if @nomenclature_change.needs_to_relay_associations? && ( input.nil? || input.taxon_concept_id != output.taxon_concept_id ) + # we need to create an input with same taxon as this output @nomenclature_change.build_input( taxon_concept_id: output.taxon_concept_id diff --git a/app/services/search_params.rb b/app/services/search_params.rb index 457dd3cb5..d307061ab 100644 --- a/app/services/search_params.rb +++ b/app/services/search_params.rb @@ -5,6 +5,7 @@ class SearchParams include ActiveModel::Conversion extend ActiveModel::Naming + attr_accessor :taxonomy, :rank, :taxon_concept, :scientific_name, :name_status def initialize(attributes = {}) diff --git a/app/services/species/search.rb b/app/services/species/search.rb index c3e0f0a6b..bceb23930 100644 --- a/app/services/species/search.rb +++ b/app/services/species/search.rb @@ -1,6 +1,7 @@ class Species::Search include CacheIterator include SearchCache # this provides #cached_results and #cached_total_cnt + attr_reader :page, :per_page # Constructs a query to retrieve taxon concepts based on user defined diff --git a/app/services/trade/sandbox_search_params.rb b/app/services/trade/sandbox_search_params.rb index 836ba4dfd..36a13c688 100644 --- a/app/services/trade/sandbox_search_params.rb +++ b/app/services/trade/sandbox_search_params.rb @@ -4,6 +4,7 @@ # Array parameters are sorted for caching purposes. class Trade::SandboxSearchParams < Hash include SearchParamSanitiser + def initialize(params) sanitized_params = { annual_report_upload_id: sanitise_positive_integer(params[:annual_report_upload_id], nil), diff --git a/app/services/trade/shipments_export.rb b/app/services/trade/shipments_export.rb index 326b59744..3b5e394e0 100644 --- a/app/services/trade/shipments_export.rb +++ b/app/services/trade/shipments_export.rb @@ -1,9 +1,11 @@ # Implements "raw" shipments export class Trade::ShipmentsExport < Species::CsvCopyExport include Trade::ShipmentReportQueries + PUBLIC_CSV_LIMIT = 1000000 PUBLIC_WEB_LIMIT = 50000 include ActiveModel::SerializerSupport + delegate :report_type, to: :@search delegate :page, to: :@search delegate :per_page, to: :@search diff --git a/app/workers/changes_history_generator_worker.rb b/app/workers/changes_history_generator_worker.rb index 2e6b34eeb..f1ad3a952 100644 --- a/app/workers/changes_history_generator_worker.rb +++ b/app/workers/changes_history_generator_worker.rb @@ -2,6 +2,7 @@ class ChangesHistoryGeneratorWorker include Sidekiq::Worker + sidekiq_options queue: :admin def perform(aru_id, user_id) diff --git a/app/workers/eu_regulation_activation_worker.rb b/app/workers/eu_regulation_activation_worker.rb index 5dff77d23..02eaf10ee 100644 --- a/app/workers/eu_regulation_activation_worker.rb +++ b/app/workers/eu_regulation_activation_worker.rb @@ -1,5 +1,6 @@ class EuRegulationActivationWorker include Sidekiq::Worker + sidekiq_options queue: :admin, retry: false, backtrace: 50 def perform(event_id, state) diff --git a/app/workers/event_eu_suspension_copy_worker.rb b/app/workers/event_eu_suspension_copy_worker.rb index f5568f8b4..f5397ca17 100644 --- a/app/workers/event_eu_suspension_copy_worker.rb +++ b/app/workers/event_eu_suspension_copy_worker.rb @@ -1,5 +1,6 @@ class EventEuSuspensionCopyWorker include Sidekiq::Worker + sidekiq_options queue: :admin, retry: false, backtrace: 50 def perform(from_event_id, to_event_id) diff --git a/app/workers/event_listing_changes_copy_worker.rb b/app/workers/event_listing_changes_copy_worker.rb index ebd85f808..a73f32689 100644 --- a/app/workers/event_listing_changes_copy_worker.rb +++ b/app/workers/event_listing_changes_copy_worker.rb @@ -1,5 +1,6 @@ class EventListingChangesCopyWorker include Sidekiq::Worker + sidekiq_options queue: :admin, retry: false, backtrace: 50 def perform(from_event_id, to_event_id) diff --git a/app/workers/manual_download_worker.rb b/app/workers/manual_download_worker.rb index 576cb6cef..26dbe402e 100644 --- a/app/workers/manual_download_worker.rb +++ b/app/workers/manual_download_worker.rb @@ -81,7 +81,7 @@ def zip_file_generator else # Download the file from S3, put in temp folder. path_to_file = Rails.root.join(tmp_dir_path, document.file.filename.to_s).to_s - File.open(path_to_file, "wb") do |out| + File.open(path_to_file, 'wb') do |out| # stream download in chunks document.file.blob.service.download(document.file.blob.key) do |chunk| out.write(chunk) diff --git a/app/workers/permit_cleanup_worker.rb b/app/workers/permit_cleanup_worker.rb index a8561816d..6caabfc60 100644 --- a/app/workers/permit_cleanup_worker.rb +++ b/app/workers/permit_cleanup_worker.rb @@ -1,5 +1,6 @@ class PermitCleanupWorker include Sidekiq::Worker + sidekiq_options queue: :admin, backtrace: 50 def perform(permits_ids = []) diff --git a/app/workers/quotas_copy_worker.rb b/app/workers/quotas_copy_worker.rb index 25bd69bc2..e40447d3e 100644 --- a/app/workers/quotas_copy_worker.rb +++ b/app/workers/quotas_copy_worker.rb @@ -1,5 +1,6 @@ class QuotasCopyWorker include Sidekiq::Worker + sidekiq_options queue: :admin, retry: false, backtrace: 50 def perform(options) diff --git a/app/workers/refresh_documents_worker.rb b/app/workers/refresh_documents_worker.rb index a7bb2385e..2eb298596 100644 --- a/app/workers/refresh_documents_worker.rb +++ b/app/workers/refresh_documents_worker.rb @@ -1,5 +1,6 @@ class RefreshDocumentsWorker include Sidekiq::Worker + sidekiq_options queue: :admin, backtrace: 50, lock: :until_and_while_executing def perform diff --git a/app/workers/submission_worker.rb b/app/workers/submission_worker.rb index 7a0f0b70a..e138a482f 100644 --- a/app/workers/submission_worker.rb +++ b/app/workers/submission_worker.rb @@ -1,5 +1,6 @@ class SubmissionWorker include Sidekiq::Worker + sidekiq_options queue: :admin def perform(aru_id, submitter_id) diff --git a/lib/tasks/import_distributions.rake b/lib/tasks/import_distributions.rake index f48dba70a..81e27dc7f 100644 --- a/lib/tasks/import_distributions.rake +++ b/lib/tasks/import_distributions.rake @@ -50,6 +50,7 @@ namespace :import do if ActiveModel::Type::Boolean.new.cast( ENV.fetch('IMPORT_DISTRIBUTIONS_DELETE_EXISTING', nil) ) + deletion_result = ApplicationRecord.connection.execute( <<-SQL.squish WITH distributions_to_delete AS ( From fed6f0cb4e9bdba2e08a19849075007ea2a9c1d3 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Fri, 17 Apr 2026 16:38:52 +0100 Subject: [PATCH 4/8] chore: bundle exec rubocop -A --only Style,Layout app/ lib/ --- app/models/user.rb | 2 +- lib/tasks/helpers_for_import.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index bd3469f0f..cf868b0b0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -146,7 +146,7 @@ def send_devise_notification(notification, *) def sync_with_captive_breeding_db # Only interested if role, name, encrypted_password, and email is changed. # Or user deleted. - return unless (previous_changes.keys & %w[email role name encrypted_password]).present? || destroyed? + return unless previous_changes.keys.intersect?(%w[email role name encrypted_password]) || destroyed? role_was = previous_changes['role']&.first action = diff --git a/lib/tasks/helpers_for_import.rb b/lib/tasks/helpers_for_import.rb index a1f1a2388..3061fc7a6 100644 --- a/lib/tasks/helpers_for_import.rb +++ b/lib/tasks/helpers_for_import.rb @@ -590,14 +590,14 @@ def copy_data_into_table( row_count += 1 row_as_hash = - csv_row.map do |cell| + csv_row.to_h do |cell| [ m.csv_to_db( table_name, cell[0] )&.split(/\s+/)&.first || cell[0], cell[1] ] - end.to_h + end row_values = From 7397b4358115279c69ecc5fa200ac6fd45151b25 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Fri, 17 Apr 2026 16:46:46 +0100 Subject: [PATCH 5/8] chore: bundle exec rubocop -A app/ lib/ --- app/controllers/admin/ahoy_events_controller.rb | 2 +- app/controllers/admin/ahoy_visits_controller.rb | 2 +- app/controllers/admin/change_types_controller.rb | 2 +- .../admin/cites_captivity_processes_controller.rb | 2 +- app/controllers/admin/cites_suspensions_controller.rb | 4 ++-- app/controllers/admin/ec_srgs_controller.rb | 2 +- .../admin/eu_council_regulations_controller.rb | 2 +- .../admin/eu_implementing_regulations_controller.rb | 2 +- app/controllers/admin/eu_opinions_controller.rb | 4 ++-- app/controllers/admin/eu_regulations_controller.rb | 4 ++-- .../admin/eu_suspension_regulations_controller.rb | 4 ++-- .../admin/nomenclature_changes/build_controller.rb | 2 +- .../admin/nomenclature_changes_controller.rb | 2 +- app/controllers/admin/purposes_controller.rb | 2 +- app/controllers/admin/quotas_controller.rb | 2 +- app/controllers/admin/sources_controller.rb | 2 +- .../admin/taxon_cites_suspensions_controller.rb | 2 +- .../admin/taxon_concept_term_pairs_controller.rb | 2 +- .../admin/taxon_eu_suspensions_controller.rb | 2 +- .../admin/taxon_listing_changes_controller.rb | 4 ++-- .../admin/term_trade_codes_pairs_controller.rb | 4 ++-- app/controllers/admin/terms_controller.rb | 2 +- app/controllers/admin/units_controller.rb | 2 +- app/controllers/admin/users_controller.rb | 2 +- app/controllers/api/v1/documents_controller.rb | 2 +- app/controllers/checklist/downloads_controller.rb | 2 +- app/controllers/pages_controller.rb | 8 ++++---- app/models/api_request.rb | 2 +- app/models/captive_breeding_record.rb | 6 +++++- app/models/m_taxon_concept.rb | 6 +++--- app/models/taxon_concept.rb | 2 +- app/models/trade_restriction.rb | 2 +- app/models/trade_restrictions/quota.rb | 2 +- app/models/user.rb | 2 +- .../species/show_taxon_concept_serializer.rb | 10 +++++----- app/services/checklist/pdf/history_annotations_key.rb | 2 +- app/services/dashboard_stats.rb | 2 +- app/services/document_search.rb | 2 +- app/services/species/common_names_export.rb | 2 +- app/services/species/documents_export.rb | 2 +- app/services/species/id_manual_documents_export.rb | 2 +- app/services/species/listings_export.rb | 2 +- app/services/species/orphaned_taxon_concepts_export.rb | 2 +- .../species/species_reference_output_export.rb | 2 +- .../species/standard_reference_output_export.rb | 2 +- .../species/synonyms_and_trade_names_export.rb | 2 +- app/services/species/taxon_concept_suggest_search.rb | 2 +- .../species/taxon_concepts_distributions_export.rb | 2 +- app/services/species/taxon_concepts_names_export.rb | 2 +- app/services/taxon_concept_view_stats.rb | 2 +- app/services/trade/filter.rb | 2 +- lib/modules/downloads_cache.rb | 4 ++-- lib/modules/material_doc_ids_retriever.rb | 2 +- lib/tasks/helpers_for_import.rb | 2 +- 54 files changed, 74 insertions(+), 70 deletions(-) diff --git a/app/controllers/admin/ahoy_events_controller.rb b/app/controllers/admin/ahoy_events_controller.rb index 1839181f0..d1525bef3 100644 --- a/app/controllers/admin/ahoy_events_controller.rb +++ b/app/controllers/admin/ahoy_events_controller.rb @@ -2,6 +2,6 @@ class Admin::AhoyEventsController < Admin::SimpleCrudController authorize_resource class: 'Ahoy::Event' def index - @ahoy_events = Ahoy::Event.order('time DESC').page(params[:page]) + @ahoy_events = Ahoy::Event.order(time: :desc).page(params[:page]) end end diff --git a/app/controllers/admin/ahoy_visits_controller.rb b/app/controllers/admin/ahoy_visits_controller.rb index 3e5058f2d..faacfbb3c 100644 --- a/app/controllers/admin/ahoy_visits_controller.rb +++ b/app/controllers/admin/ahoy_visits_controller.rb @@ -2,6 +2,6 @@ class Admin::AhoyVisitsController < Admin::SimpleCrudController authorize_resource class: 'Ahoy::Visit' def index - @ahoy_visits = Ahoy::Visit.order('started_at DESC').page(params[:page]) + @ahoy_visits = Ahoy::Visit.order(started_at: :desc).page(params[:page]) end end diff --git a/app/controllers/admin/change_types_controller.rb b/app/controllers/admin/change_types_controller.rb index 41312061b..f49e28a27 100644 --- a/app/controllers/admin/change_types_controller.rb +++ b/app/controllers/admin/change_types_controller.rb @@ -5,7 +5,7 @@ def collection @change_types ||= end_of_association_chain.includes( :designation ).order( - 'designation_id, name' + :designation_id, :name ).page( params[:page] ).search( diff --git a/app/controllers/admin/cites_captivity_processes_controller.rb b/app/controllers/admin/cites_captivity_processes_controller.rb index 37d237884..d575a1c4e 100644 --- a/app/controllers/admin/cites_captivity_processes_controller.rb +++ b/app/controllers/admin/cites_captivity_processes_controller.rb @@ -44,7 +44,7 @@ def load_lib_objects @status = CitesCaptivityProcess::STATUS @events = Event.where( "type IN ('CitesAc','CitesPc')" - ).order('effective_at DESC') + ).order(effective_at: :desc) end def collection diff --git a/app/controllers/admin/cites_suspensions_controller.rb b/app/controllers/admin/cites_suspensions_controller.rb index 514c86517..cbab431f8 100644 --- a/app/controllers/admin/cites_suspensions_controller.rb +++ b/app/controllers/admin/cites_suspensions_controller.rb @@ -50,13 +50,13 @@ def load_lib_objects @suspension_notifications = CitesSuspensionNotification.select( [ :id, :name ] ).order( - 'effective_at DESC' + effective_at: :desc ) end def collection @cites_suspensions ||= end_of_association_chain.order( - 'start_date DESC' + start_date: :desc ).page( params[:page] ).search( diff --git a/app/controllers/admin/ec_srgs_controller.rb b/app/controllers/admin/ec_srgs_controller.rb index e2490110f..99905afca 100644 --- a/app/controllers/admin/ec_srgs_controller.rb +++ b/app/controllers/admin/ec_srgs_controller.rb @@ -8,7 +8,7 @@ class Admin::EcSrgsController < Admin::EventsController def collection @ec_srgs ||= end_of_association_chain.order( - 'designation_id, effective_at DESC' + :designation_id, effective_at: :desc ).includes(:designation).page( params[:page] ).search( diff --git a/app/controllers/admin/eu_council_regulations_controller.rb b/app/controllers/admin/eu_council_regulations_controller.rb index 3500210a1..5c3ab68f6 100644 --- a/app/controllers/admin/eu_council_regulations_controller.rb +++ b/app/controllers/admin/eu_council_regulations_controller.rb @@ -7,7 +7,7 @@ class Admin::EuCouncilRegulationsController < Admin::EventsController def collection @eu_council_regulations ||= end_of_association_chain.order( - 'effective_at DESC, name ASC' + effective_at: :desc, name: :asc ).page( params[:page] ).search( diff --git a/app/controllers/admin/eu_implementing_regulations_controller.rb b/app/controllers/admin/eu_implementing_regulations_controller.rb index cd458e24e..05044b0c7 100644 --- a/app/controllers/admin/eu_implementing_regulations_controller.rb +++ b/app/controllers/admin/eu_implementing_regulations_controller.rb @@ -7,7 +7,7 @@ class Admin::EuImplementingRegulationsController < Admin::EventsController def collection @eu_implementing_regulations ||= end_of_association_chain.order( - 'effective_at DESC, name ASC' + effective_at: :desc, name: :asc ).page( params[:page] ).search( diff --git a/app/controllers/admin/eu_opinions_controller.rb b/app/controllers/admin/eu_opinions_controller.rb index 380112ab1..2bca51343 100644 --- a/app/controllers/admin/eu_opinions_controller.rb +++ b/app/controllers/admin/eu_opinions_controller.rb @@ -49,12 +49,12 @@ def load_lib_objects @ec_srgs = Event.where( "type = 'EcSrg' OR type = 'EuRegulation' AND name IN ('No 338/97', 'No 938/97', 'No 750/2013')" - ).order('effective_at DESC') + ).order(effective_at: :desc) # this will only return intersessional docs @documents = Document.where( "event_id IS NULL AND type = 'Document::CommissionNotes'" ).order( - 'date DESC, title' + date: :desc, title: :asc ) end diff --git a/app/controllers/admin/eu_regulations_controller.rb b/app/controllers/admin/eu_regulations_controller.rb index 8d9869d85..b9b0b1be8 100644 --- a/app/controllers/admin/eu_regulations_controller.rb +++ b/app/controllers/admin/eu_regulations_controller.rb @@ -19,7 +19,7 @@ def deactivate def collection @eu_regulations ||= end_of_association_chain.order( - 'effective_at DESC, name ASC' + effective_at: :desc, name: :asc ).page( params[:page] ).search( @@ -29,7 +29,7 @@ def collection def load_associations @eu_regulations_for_dropdown = EuRegulation. - order('effective_at DESC, name ASC') + order(effective_at: :desc, name: :asc) end private diff --git a/app/controllers/admin/eu_suspension_regulations_controller.rb b/app/controllers/admin/eu_suspension_regulations_controller.rb index 5f9cc3a78..fa7d8e34f 100644 --- a/app/controllers/admin/eu_suspension_regulations_controller.rb +++ b/app/controllers/admin/eu_suspension_regulations_controller.rb @@ -25,7 +25,7 @@ def collection @eu_suspension_regulations ||= end_of_association_chain.includes( [ :creator, :updater ] ).order( - 'effective_at DESC, name ASC' + effective_at: :desc, name: :asc ).page( params[:page] ).search( @@ -35,7 +35,7 @@ def collection def load_associations @eu_suspension_regulations_for_dropdown = EuSuspensionRegulation.order( - 'effective_at DESC, name ASC' + effective_at: :desc, name: :asc ) end diff --git a/app/controllers/admin/nomenclature_changes/build_controller.rb b/app/controllers/admin/nomenclature_changes/build_controller.rb index 7cfb85ec4..553c2e81a 100644 --- a/app/controllers/admin/nomenclature_changes/build_controller.rb +++ b/app/controllers/admin/nomenclature_changes/build_controller.rb @@ -97,7 +97,7 @@ def set_nomenclature_change end def set_events - @events = CitesCop.order('effective_at DESC') + @events = CitesCop.order(effective_at: :desc) end def set_taxonomy diff --git a/app/controllers/admin/nomenclature_changes_controller.rb b/app/controllers/admin/nomenclature_changes_controller.rb index 643b5da23..ef1c40042 100644 --- a/app/controllers/admin/nomenclature_changes_controller.rb +++ b/app/controllers/admin/nomenclature_changes_controller.rb @@ -17,7 +17,7 @@ def collection @collection ||= NomenclatureChange.includes( [ :event, :creator ] ).order( - 'created_at DESC' + created_at: :desc ).page( params[:page] ).per(10).search( diff --git a/app/controllers/admin/purposes_controller.rb b/app/controllers/admin/purposes_controller.rb index 0ca268dd7..9eb7b419a 100644 --- a/app/controllers/admin/purposes_controller.rb +++ b/app/controllers/admin/purposes_controller.rb @@ -18,7 +18,7 @@ def create def collection @purposes ||= end_of_association_chain.order( - 'code' + :code ).page( params[:page] ).search( diff --git a/app/controllers/admin/quotas_controller.rb b/app/controllers/admin/quotas_controller.rb index 5c1e003b5..7bb78d2d6 100644 --- a/app/controllers/admin/quotas_controller.rb +++ b/app/controllers/admin/quotas_controller.rb @@ -35,7 +35,7 @@ def count def collection @quotas ||= end_of_association_chain.order( - 'start_date DESC' + start_date: :desc ).page( params[:page] ).search( diff --git a/app/controllers/admin/sources_controller.rb b/app/controllers/admin/sources_controller.rb index e4c2e56f8..d072521c0 100644 --- a/app/controllers/admin/sources_controller.rb +++ b/app/controllers/admin/sources_controller.rb @@ -18,7 +18,7 @@ def create def collection @sources ||= end_of_association_chain.order( - 'code' + :code ).page( params[:page] ).search( diff --git a/app/controllers/admin/taxon_cites_suspensions_controller.rb b/app/controllers/admin/taxon_cites_suspensions_controller.rb index 1870fb243..bd0cff891 100644 --- a/app/controllers/admin/taxon_cites_suspensions_controller.rb +++ b/app/controllers/admin/taxon_cites_suspensions_controller.rb @@ -61,7 +61,7 @@ def load_lib_objects @suspension_notifications = CitesSuspensionNotification.select( [ :id, :name ] ).order( - 'effective_at DESC' + effective_at: :desc ) end diff --git a/app/controllers/admin/taxon_concept_term_pairs_controller.rb b/app/controllers/admin/taxon_concept_term_pairs_controller.rb index c6a9e451e..6e079501c 100644 --- a/app/controllers/admin/taxon_concept_term_pairs_controller.rb +++ b/app/controllers/admin/taxon_concept_term_pairs_controller.rb @@ -14,7 +14,7 @@ def load_term_codes def collection @taxon_concept_term_pairs ||= end_of_association_chain.order( - 'term_id' + :term_id ).page( params[:page] ).search( diff --git a/app/controllers/admin/taxon_eu_suspensions_controller.rb b/app/controllers/admin/taxon_eu_suspensions_controller.rb index e75dd7f85..fdffd5bc9 100644 --- a/app/controllers/admin/taxon_eu_suspensions_controller.rb +++ b/app/controllers/admin/taxon_eu_suspensions_controller.rb @@ -73,7 +73,7 @@ def load_lib_objects name: GeoEntityType::SETS[GeoEntityType::DEFAULT_SET] } ) - @eu_regulations = EuSuspensionRegulation.order('effective_at DESC') + @eu_regulations = EuSuspensionRegulation.order(effective_at: :desc) @eu_decision_types = EuDecisionType.suspensions end diff --git a/app/controllers/admin/taxon_listing_changes_controller.rb b/app/controllers/admin/taxon_listing_changes_controller.rb index 7fcfe020f..24971f2e9 100644 --- a/app/controllers/admin/taxon_listing_changes_controller.rb +++ b/app/controllers/admin/taxon_listing_changes_controller.rb @@ -108,9 +108,9 @@ def load_change_types end @events = if @designation.is_eu? - EuRegulation.order('effective_at DESC') + EuRegulation.order(effective_at: :desc) elsif @designation.is_cites? - CitesCop.order('effective_at DESC') + CitesCop.order(effective_at: :desc) else [] end diff --git a/app/controllers/admin/term_trade_codes_pairs_controller.rb b/app/controllers/admin/term_trade_codes_pairs_controller.rb index 9758b327e..719897484 100644 --- a/app/controllers/admin/term_trade_codes_pairs_controller.rb +++ b/app/controllers/admin/term_trade_codes_pairs_controller.rb @@ -38,7 +38,7 @@ def load_trade_code_types (params[:term_trade_codes_pair] && params[:term_trade_codes_pair][:trade_code_type]) || 'Unit' @trade_code_codes = TradeCode.where(type: @trade_code_type). - select([ :id, :code ]).order('code') + select([ :id, :code ]).order(:code) @trade_code_codes_obj = @trade_code_codes.map { |c| { 'value' => c.id, 'text' => c.code } }.to_json end @@ -46,7 +46,7 @@ def collection @term_trade_codes_pairs ||= end_of_association_chain.where( trade_code_type: @trade_code_type ).order( - 'term_id' + :term_id ).page( params[:page] ).search( diff --git a/app/controllers/admin/terms_controller.rb b/app/controllers/admin/terms_controller.rb index e98ccefff..08fc92b38 100644 --- a/app/controllers/admin/terms_controller.rb +++ b/app/controllers/admin/terms_controller.rb @@ -18,7 +18,7 @@ def create def collection @terms ||= end_of_association_chain.order( - 'code' + :code ).page( params[:page] ).search( diff --git a/app/controllers/admin/units_controller.rb b/app/controllers/admin/units_controller.rb index 677e91c93..c5bd57d4c 100644 --- a/app/controllers/admin/units_controller.rb +++ b/app/controllers/admin/units_controller.rb @@ -18,7 +18,7 @@ def create def collection @units ||= end_of_association_chain.order( - 'code' + :code ).page( params[:page] ).search( diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 0d310040f..9497c9337 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -53,7 +53,7 @@ def load_associations 'geo_entity_types.name' => [ GeoEntityType::COUNTRY, GeoEntityType::TERRITORY ], is_current: true ). - order('name_en') + order(:name_en) end private diff --git a/app/controllers/api/v1/documents_controller.rb b/app/controllers/api/v1/documents_controller.rb index d7bb8d6c7..0da6ec02d 100644 --- a/app/controllers/api/v1/documents_controller.rb +++ b/app/controllers/api/v1/documents_controller.rb @@ -47,7 +47,7 @@ def index children_ids = taxa.map(&:children).map do |children| - children.pluck(:id) if children.present? + (children.presence&.pluck(:id)) end.flatten.uniq.compact ancestor_ids = MaterialDocIdsRetriever.ancestors_ids( diff --git a/app/controllers/checklist/downloads_controller.rb b/app/controllers/checklist/downloads_controller.rb index ab6e5be77..0f497e705 100644 --- a/app/controllers/checklist/downloads_controller.rb +++ b/app/controllers/checklist/downloads_controller.rb @@ -6,7 +6,7 @@ class Checklist::DownloadsController < ApplicationController # Lists a set of downloads for a given list of IDs def index ids = params[:ids] || '' - @downloads = Download.where(id: ids).order('updated_at DESC').limit(5) + @downloads = Download.where(id: ids).order(updated_at: :desc).limit(5) @downloads = @downloads.map { |v| v.attributes.except('filename', 'path') } @downloads.each do |v| v['updated_at'] = v['updated_at'].strftime('%A, %e %b %Y %H:%M') diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 8a649b0de..c9d71be8a 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -13,28 +13,28 @@ def eu_legislation :id, :description, :extended_description, :effective_at, :multilingual_url, :is_current ] - ).order('effective_at DESC') + ).order(effective_at: :desc) @eu_suspension_regulations = EuSuspensionRegulation.select( [ :id, :description, :extended_description, :effective_at, :multilingual_url, :is_current ] - ).order('effective_at DESC') + ).order(effective_at: :desc) @eu_implementing_regulations = EuImplementingRegulation.select( [ :id, :description, :extended_description, :effective_at, :multilingual_url, :is_current ] - ).order('effective_at DESC') + ).order(effective_at: :desc) @eu_council_regulations = EuCouncilRegulation.select( [ :id, :description, :extended_description, :effective_at, :multilingual_url, :is_current ] - ).order('effective_at DESC') + ).order(effective_at: :desc) end def api diff --git a/app/models/api_request.rb b/app/models/api_request.rb index 4c1844988..0ea8d8d95 100644 --- a/app/models/api_request.rb +++ b/app/models/api_request.rb @@ -46,7 +46,7 @@ def self.top_50_most_active_users ).group(:user_id). where.not(user_id: nil) self.from("(#{subquery.to_sql}) AS api_requests"). - order('cnt DESC').limit(50) + order(cnt: :desc).limit(50) end def self.recent_requests(user = nil) diff --git a/app/models/captive_breeding_record.rb b/app/models/captive_breeding_record.rb index d1cbd3d74..070f643ad 100644 --- a/app/models/captive_breeding_record.rb +++ b/app/models/captive_breeding_record.rb @@ -1,4 +1,8 @@ -class CaptiveBreedingRecord < ActiveRecord::Base +## +# Base class for accessing Captive Breeding Database, NOT the SAPI db. +# Used for periodically synchronising users to the Captive Breeding Database. + +class CaptiveBreedingRecord < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord self.abstract_class = true connects_to database: { writing: :captive_breeding, reading: :captive_breeding } diff --git a/app/models/m_taxon_concept.rb b/app/models/m_taxon_concept.rb index 18f0d17a7..4452ff76a 100644 --- a/app/models/m_taxon_concept.rb +++ b/app/models/m_taxon_concept.rb @@ -144,12 +144,12 @@ class MTaxonConcept < ApplicationRecord class_name: 'MCitesListingChange' has_many :current_cites_additions, - -> { where(is_current: true, change_type_name: ChangeType::ADDITION).order('effective_at DESC, species_listing_name ASC') }, + -> { where(is_current: true, change_type_name: ChangeType::ADDITION).order(effective_at: :desc, species_listing_name: :asc) }, foreign_key: :taxon_concept_id, class_name: 'MCitesListingChange' has_many :current_cms_additions, - -> { where(is_current: true, change_type_name: ChangeType::ADDITION).order('effective_at DESC, species_listing_name ASC') }, + -> { where(is_current: true, change_type_name: ChangeType::ADDITION).order(effective_at: :desc, species_listing_name: :asc) }, foreign_key: :taxon_concept_id, class_name: 'MCmsListingChange' @@ -176,7 +176,7 @@ class MTaxonConcept < ApplicationRecord scope :at_level_of_listing, -> { where(cites_listed: 't') } - scope :taxonomic_layout, -> { order('taxonomic_position') } + scope :taxonomic_layout, -> { order(:taxonomic_position) } scope :alphabetical_layout, -> { order([ 'kingdom_position', 'full_name' ]) } translates :rank_display_name, :all_distribution_ary, :native_distribution_ary, diff --git a/app/models/taxon_concept.rb b/app/models/taxon_concept.rb index 18c13652a..47a5714bc 100644 --- a/app/models/taxon_concept.rb +++ b/app/models/taxon_concept.rb @@ -152,7 +152,7 @@ class TaxonConcept < ApplicationRecord has_many :taxon_concept_references, -> { includes :reference }, dependent: :destroy has_many :references, through: :taxon_concept_references - has_many :quotas, -> { order 'start_date DESC' } + has_many :quotas, -> { order start_date: :desc } has_many :current_quotas, -> { where 'is_current = true' }, class_name: 'Quota' has_many :cites_suspensions diff --git a/app/models/trade_restriction.rb b/app/models/trade_restriction.rb index ea0ffc849..bcec927de 100644 --- a/app/models/trade_restriction.rb +++ b/app/models/trade_restriction.rb @@ -141,7 +141,7 @@ def self.export(filters) return false unless export_query(filters).any? path = "public/downloads/#{self.to_s.tableize}/" - latest = self.order('updated_at DESC'). + latest = self.order(updated_at: :desc). limit(1).first.updated_at.strftime('%d%m%Y-%H%M%S') public_file_name = "#{self.to_s.downcase}s_#{latest}_#{filters[:csv_separator]}_separated.csv" file_name = Digest::SHA1.hexdigest( diff --git a/app/models/trade_restrictions/quota.rb b/app/models/trade_restrictions/quota.rb index 8346bf489..d7be194db 100644 --- a/app/models/trade_restrictions/quota.rb +++ b/app/models/trade_restrictions/quota.rb @@ -79,7 +79,7 @@ def end_date_formatted def self.years_array self.select('EXTRACT(year from start_date)::VARCHAR years'). - group(:years).order('years DESC').map(&:years) + group(:years).order(years: :desc).map(&:years) end def self.count_matching(params) diff --git a/app/models/user.rb b/app/models/user.rb index cf868b0b0..7ee96bb0d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -112,7 +112,7 @@ def can_be_deleted? Reference, TaxonConceptReference, DistributionReference, Trade::AnnualReportUpload, Trade::Shipment ] - for i in 0..tracked_objects.length - 1 + for i in 0..(tracked_objects.length - 1) if tracked_objects[i].where([ 'created_by_id = :id OR updated_by_id = :id', id: self.id ]).limit(1).count > 0 return false end diff --git a/app/serializers/species/show_taxon_concept_serializer.rb b/app/serializers/species/show_taxon_concept_serializer.rb index 72d17ee7f..47904dbb8 100644 --- a/app/serializers/species/show_taxon_concept_serializer.rb +++ b/app/serializers/species/show_taxon_concept_serializer.rb @@ -67,12 +67,12 @@ def taxonomy def accepted_names object.accepted_names. - order('full_name') + order(:full_name) end def synonyms object.synonyms. - order('full_name') + order(:full_name) end def object_and_children @@ -107,7 +107,7 @@ def common_names ELSE false END AS convention_language SQL - ).group('language_name_en').order('language_name_en').all + ).group('language_name_en').order(:language_name_en).all end def distributions_with_tags_and_references @@ -118,7 +118,7 @@ def distributions_with_tags_and_references ).select( "name_en AS name, name_en AS country, ARRAY_TO_STRING(tags, ',') AS tags_list, ARRAY_TO_STRING(citations, '; ') AS country_references" ).order( - 'name_en' + :name_en ).all end @@ -134,7 +134,7 @@ def distributions_with_tags_and_references_trimmed ).select( "iso_code2, ARRAY_TO_STRING(tags, ',') AS tags_list" ).order( - 'iso_code2' + :iso_code2 ).all end diff --git a/app/services/checklist/pdf/history_annotations_key.rb b/app/services/checklist/pdf/history_annotations_key.rb index 8ec2b0eba..eea7fc0f8 100644 --- a/app/services/checklist/pdf/history_annotations_key.rb +++ b/app/services/checklist/pdf/history_annotations_key.rb @@ -12,7 +12,7 @@ def annotations_key def hash_annotations_key tex = '\\hashAnnotationsHistoryInfo' + "\n\n" - cops = CitesCop.order('effective_at') + cops = CitesCop.order(:effective_at) cops.each do |cop| annotations = cop.hash_annotations.order(Arel.sql('SUBSTRING(symbol FROM 2)::INT')) if annotations.empty? diff --git a/app/services/dashboard_stats.rb b/app/services/dashboard_stats.rb index 56455800d..5a2b202fe 100644 --- a/app/services/dashboard_stats.rb +++ b/app/services/dashboard_stats.rb @@ -79,7 +79,7 @@ def trade_stats_per_reporter_type(reporter_type) includes(:m_taxon_concept). select('taxon_concept_id, sum(quantity) as count_all'). group(:taxon_concept_id). - order('count_all desc'). + order(count_all: :desc). limit(@trade_limit) { totals: shipments_for_country.count, diff --git a/app/services/document_search.rb b/app/services/document_search.rb index fde1f4efa..e45188701 100644 --- a/app/services/document_search.rb +++ b/app/services/document_search.rb @@ -209,7 +209,7 @@ def add_ordering_for_admin if @events_ids.present? @query.order([ 'date_raw DESC', :title, 'id DESC' ]) else - @query.order('created_at DESC', 'id DESC') + @query.order(created_at: :desc, id: :desc) end end diff --git a/app/services/species/common_names_export.rb b/app/services/species/common_names_export.rb index 67199c463..337054236 100644 --- a/app/services/species/common_names_export.rb +++ b/app/services/species/common_names_export.rb @@ -1,7 +1,7 @@ class Species::CommonNamesExport < Species::CsvCopyExport def query rel = MTaxonConcept.from(table_name). - order('taxonomic_position, common_name_language, common_name') + order(:taxonomic_position, :common_name_language, :common_name) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/species/documents_export.rb b/app/services/species/documents_export.rb index e4edf9a7c..1a607f47a 100644 --- a/app/services/species/documents_export.rb +++ b/app/services/species/documents_export.rb @@ -1,7 +1,7 @@ class Species::DocumentsExport < Species::CsvCopyExport def query rel = Document.from("#{table_name} AS documents"). - order('event_type, date_raw, title') + order(:event_type, :date_raw, :title) rel.select(sql_columns) end diff --git a/app/services/species/id_manual_documents_export.rb b/app/services/species/id_manual_documents_export.rb index fe077f628..71a19a743 100644 --- a/app/services/species/id_manual_documents_export.rb +++ b/app/services/species/id_manual_documents_export.rb @@ -2,7 +2,7 @@ class Species::IdManualDocumentsExport < Species::CsvCopyExport def query rel = Document.from("#{table_name} AS documents"). where(document_type: [ 'Document::IdManual', 'Document::VirtualCollege' ]). - order('volume, manual_id') + order(:volume, :manual_id) rel.select(sql_columns) end diff --git a/app/services/species/listings_export.rb b/app/services/species/listings_export.rb index e746fb4aa..eecaa2345 100644 --- a/app/services/species/listings_export.rb +++ b/app/services/species/listings_export.rb @@ -28,7 +28,7 @@ def query table_name ).select( sql_columns_with_table_name - ).order('taxonomic_position') + ).order(:taxonomic_position) rel = if @geo_entities_ids diff --git a/app/services/species/orphaned_taxon_concepts_export.rb b/app/services/species/orphaned_taxon_concepts_export.rb index a42f60a43..4df497d6d 100644 --- a/app/services/species/orphaned_taxon_concepts_export.rb +++ b/app/services/species/orphaned_taxon_concepts_export.rb @@ -1,7 +1,7 @@ class Species::OrphanedTaxonConceptsExport < Species::CsvCopyExport def query rel = TaxonConcept.from(table_name). - order('full_name') + order(:full_name) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/species/species_reference_output_export.rb b/app/services/species/species_reference_output_export.rb index 4cf90ab96..d8484e389 100644 --- a/app/services/species/species_reference_output_export.rb +++ b/app/services/species/species_reference_output_export.rb @@ -1,7 +1,7 @@ class Species::SpeciesReferenceOutputExport < Species::CsvCopyExport def query rel = MTaxonConcept.from(table_name). - order('name_status, taxonomic_position') + order(:name_status, :taxonomic_position) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/species/standard_reference_output_export.rb b/app/services/species/standard_reference_output_export.rb index 7ec4e0fe8..11d82fd7a 100644 --- a/app/services/species/standard_reference_output_export.rb +++ b/app/services/species/standard_reference_output_export.rb @@ -1,7 +1,7 @@ class Species::StandardReferenceOutputExport < Species::CsvCopyExport def query rel = MTaxonConcept.from(table_name). - order('name_status, taxonomic_position') + order(:name_status, :taxonomic_position) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/species/synonyms_and_trade_names_export.rb b/app/services/species/synonyms_and_trade_names_export.rb index e1a921109..5b830495e 100644 --- a/app/services/species/synonyms_and_trade_names_export.rb +++ b/app/services/species/synonyms_and_trade_names_export.rb @@ -1,7 +1,7 @@ class Species::SynonymsAndTradeNamesExport < Species::CsvCopyExport def query rel = MTaxonConcept.from(table_name). - order('name_status, rank_name, full_name') + order(:name_status, :rank_name, :full_name) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/species/taxon_concept_suggest_search.rb b/app/services/species/taxon_concept_suggest_search.rb index e4d3e04b4..d8605adab 100644 --- a/app/services/species/taxon_concept_suggest_search.rb +++ b/app/services/species/taxon_concept_suggest_search.rb @@ -4,7 +4,7 @@ def results @query.order( 'length(name_for_matching) ASC' - ).limit(@per_page * 2).order('name_for_matching').each do |row, i| + ).limit(@per_page * 2).order(:name_for_matching).each do |row, i| # filter out 'panthera leo leo' if we have already seen 'panthera leo' seen_before = filtered_results.find do |existing_result| diff --git a/app/services/species/taxon_concepts_distributions_export.rb b/app/services/species/taxon_concepts_distributions_export.rb index 03244049a..e05619bf8 100644 --- a/app/services/species/taxon_concepts_distributions_export.rb +++ b/app/services/species/taxon_concepts_distributions_export.rb @@ -1,7 +1,7 @@ class Species::TaxonConceptsDistributionsExport < Species::CsvCopyExport def query rel = TaxonConcept.from(table_name). - order('taxonomic_position, geo_entity_name') + order(:taxonomic_position, :geo_entity_name) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/species/taxon_concepts_names_export.rb b/app/services/species/taxon_concepts_names_export.rb index 148049a05..ed380a2e7 100644 --- a/app/services/species/taxon_concepts_names_export.rb +++ b/app/services/species/taxon_concepts_names_export.rb @@ -1,7 +1,7 @@ class Species::TaxonConceptsNamesExport < Species::CsvCopyExport def query rel = TaxonConcept.from(table_name). - order('name_status, taxonomic_position') + order(:name_status, :taxonomic_position) rel = rel.where("#{table_name}.taxonomy_id" => @taxonomy.id) if @taxonomy rel.select(sql_columns) end diff --git a/app/services/taxon_concept_view_stats.rb b/app/services/taxon_concept_view_stats.rb index fb284d631..8cefee136 100644 --- a/app/services/taxon_concept_view_stats.rb +++ b/app/services/taxon_concept_view_stats.rb @@ -22,6 +22,6 @@ def query where([ 'time > ? AND time <= ?', @start_date, @end_date ]). where([ "properties->>'taxonomy_name' = ?", @taxonomy ]). group("properties->>'id', properties->>'full_name'"). - order('number_of_visits DESC') + order(number_of_visits: :desc) end end diff --git a/app/services/trade/filter.rb b/app/services/trade/filter.rb index 74f3a5d46..2dd6458e6 100644 --- a/app/services/trade/filter.rb +++ b/app/services/trade/filter.rb @@ -11,7 +11,7 @@ def query_with_limit end def results - query_with_limit.order('year DESC').to_a + query_with_limit.order(year: :desc).to_a end def total_cnt diff --git a/lib/modules/downloads_cache.rb b/lib/modules/downloads_cache.rb index 3aac3cea9..ed357a2a1 100644 --- a/lib/modules/downloads_cache.rb +++ b/lib/modules/downloads_cache.rb @@ -153,12 +153,12 @@ def self.update_checklist_downloads modules.each do |m| elapsed_time = Benchmark.realtime do - puts m::Index.new(params).generate + Rails.logger.debug m::Index.new(params).generate end Rails.logger.debug { "#{Time.now} #{m}::Index download #{locale} generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do - puts m::History.new(params).generate + Rails.logger.debug m::History.new(params).generate end Rails.logger.debug { "#{Time.now} #{m}::History download #{locale} generated in #{elapsed_time}s" } end diff --git a/lib/modules/material_doc_ids_retriever.rb b/lib/modules/material_doc_ids_retriever.rb index 4d75b78f3..12292f417 100644 --- a/lib/modules/material_doc_ids_retriever.rb +++ b/lib/modules/material_doc_ids_retriever.rb @@ -25,7 +25,7 @@ def self.run(params) params['taxon_name'], { synonyms: true, common_names: true, subspecies: false } ).order( - 'rank_id ASC, full_name' + :rank_id, :full_name ).pluck(:id) end diff --git a/lib/tasks/helpers_for_import.rb b/lib/tasks/helpers_for_import.rb index 3061fc7a6..09ce91005 100644 --- a/lib/tasks/helpers_for_import.rb +++ b/lib/tasks/helpers_for_import.rb @@ -458,7 +458,7 @@ def db_columns_from_csv_headers(path_to_file, table_name, include_data_type = tr db_columns = csv_columns.map { |col| m.csv_to_db(table_name, col) } db_columns = db_columns.map { |col| col&.sub(/\s\w+$/, '') } unless include_data_type - db_columns.select(&:present?) + db_columns.compact_blank end def create_table_from_csv_headers(path_to_file, table_name) From b9c837ed4213ea515170a7318e23e38c758ef8a6 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Fri, 17 Apr 2026 17:27:20 +0100 Subject: [PATCH 6/8] chore: bundle exec rubocop -A --only Style,Layout config spec db Gemfile --- config/environments/production.rb | 14 +++++++------- config/routes.rb | 12 ++++++++---- ..._create_active_storage_tables.active_storage.rb | 2 +- .../admin/taxon_listing_changes_controller_spec.rb | 6 +++--- spec/spec_helper.rb | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index dec3831ef..a8a27c628 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -127,21 +127,21 @@ # Custom email settings config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - address: "smtp.sendgrid.net", + address: 'smtp.sendgrid.net', port: 587, - domain: "unep-wcmc.org", - user_name: ENV['MAIL_USERNAME'], - password: ENV['MAIL_PASSWORD'], + domain: 'unep-wcmc.org', + user_name: ENV.fetch('MAIL_USERNAME', nil), + password: ENV.fetch('MAIL_PASSWORD', nil), authentication: :login, enable_starttls_auto: true } config.action_mailer.default_url_options = { - host: "www.speciesplus.net" + host: 'www.speciesplus.net' } config.action_mailer.default_options = { - from: "no-reply@unep-wcmc.org", - reply_to: "no-reply@unep-wcmc.org" + from: 'no-reply@unep-wcmc.org', + reply_to: 'no-reply@unep-wcmc.org' } end diff --git a/config/routes.rb b/config/routes.rb index 481f14a42..2ee4af530 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,10 +10,14 @@ # - Use digests to stop length information leaking (see also ActiveSupport::SecurityUtils.variable_size_secure_compare) sidekiq_username = Rails.application.credentials.sidekiq.username! sidekiq_password = Rails.application.credentials.sidekiq.password! - ActiveSupport::SecurityUtils.secure_compare(Digest::SHA256.hexdigest(username), - Digest::SHA256.hexdigest(sidekiq_username)) & - ActiveSupport::SecurityUtils.secure_compare(Digest::SHA256.hexdigest(password), - Digest::SHA256.hexdigest(sidekiq_password)) + ActiveSupport::SecurityUtils.secure_compare( + Digest::SHA256.hexdigest(username), + Digest::SHA256.hexdigest(sidekiq_username) + ) & + ActiveSupport::SecurityUtils.secure_compare( + Digest::SHA256.hexdigest(password), + Digest::SHA256.hexdigest(sidekiq_password) + ) end end diff --git a/db/migrate/20250320134111_create_active_storage_tables.active_storage.rb b/db/migrate/20250320134111_create_active_storage_tables.active_storage.rb index e4706aa21..6bd8bd082 100644 --- a/db/migrate/20250320134111_create_active_storage_tables.active_storage.rb +++ b/db/migrate/20250320134111_create_active_storage_tables.active_storage.rb @@ -52,6 +52,6 @@ def primary_and_foreign_key_types setting = config.options[config.orm][:primary_key_type] primary_key_type = setting || :primary_key foreign_key_type = setting || :bigint - [primary_key_type, foreign_key_type] + [ primary_key_type, foreign_key_type ] end end diff --git a/spec/controllers/admin/taxon_listing_changes_controller_spec.rb b/spec/controllers/admin/taxon_listing_changes_controller_spec.rb index c747d02a8..4021f7f8f 100644 --- a/spec/controllers/admin/taxon_listing_changes_controller_spec.rb +++ b/spec/controllers/admin/taxon_listing_changes_controller_spec.rb @@ -101,9 +101,9 @@ post :create, params: { - listing_change: { change_type_id: 0 }, - taxon_concept_id: @taxon_concept.id, - designation_id: @designation.id + listing_change: { change_type_id: 0 }, + taxon_concept_id: @taxon_concept.id, + designation_id: @designation.id } expect(response).to render_template('new') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3565585a4..4c283c747 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -122,8 +122,8 @@ end end -def build_attributes(*args) - FactoryBot.build(*args).attributes.delete_if do |k, v| +def build_attributes(*) + FactoryBot.build(*).attributes.delete_if do |k, v| [ 'id', 'created_at', 'updated_at', 'touched_at' ].member?(k) end end From 71ea52eae5d08dbc5c9926ee939f8ec4aea1794e Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Mon, 20 Apr 2026 09:18:30 +0100 Subject: [PATCH 7/8] chore: bundle exec rubocop -a config spec db Gemfile --- .../admin/cites_acs_controller_spec.rb | 3 +- .../admin/cites_cops_controller_spec.rb | 2 +- ..._extraordinary_meetings_controller_spec.rb | 3 +- .../cites_hash_annotations_controller_spec.rb | 3 +- .../admin/cites_pcs_controller_spec.rb | 3 +- ...uspension_notifications_controller_spec.rb | 3 +- .../cites_suspensions_controller_spec.rb | 12 ++- .../admin/cites_tcs_controller_spec.rb | 3 +- .../admin/designations_controller_spec.rb | 2 +- .../admin/distributions_controller_spec.rb | 10 ++ .../admin/ec_srgs_controller_spec.rb | 3 +- .../eu_council_regulations_controller_spec.rb | 3 +- .../eu_hash_annotations_controller_spec.rb | 3 +- ...mplementing_regulations_controller_spec.rb | 3 +- .../admin/eu_regulations_controller_spec.rb | 4 +- ..._suspension_regulations_controller_spec.rb | 4 +- .../admin/eu_suspensions_controller_spec.rb | 4 +- .../admin/event_documents_controller_spec.rb | 2 +- .../admin/events_controller_spec.rb | 10 +- .../admin/exports_controller_spec.rb | 18 +++- .../admin/geo_entities_controller_spec.rb | 7 +- .../hybrid_relationships_controller_spec.rb | 8 +- .../admin/instruments_controller_spec.rb | 8 +- .../admin/listing_changes_controller_spec.rb | 5 +- .../nomenclature_changes_controller_spec.rb | 2 + .../admin/references_controller_spec.rb | 8 +- .../synonym_relationships_controller_spec.rb | 8 +- .../admin/taxon_commons_controller_spec.rb | 3 +- .../taxon_concept_comments_controller_spec.rb | 1 + ...axon_concept_references_controller_spec.rb | 2 +- .../taxon_listing_changes_controller_spec.rb | 8 +- .../taxon_relationships_controller_spec.rb | 15 ++- .../admin/taxonomies_controller_spec.rb | 10 +- ...ade_names_relationships_controller_spec.rb | 8 +- .../admin/users_controller_spec.rb | 6 ++ .../api/document_tags_controller_spec.rb | 3 +- .../api/documents_controller_spec.rb | 26 ++--- .../controllers/api/events_controller_spec.rb | 3 +- .../api/geo_entities_controller_spec.rb | 2 + .../api/purposes_controller_spec.rb | 3 +- .../api/sources_controller_spec.rb | 3 +- .../api/taxon_concepts_controller_spec.rb | 2 +- spec/controllers/api/terms_controller_spec.rb | 3 +- spec/controllers/api/units_controller_spec.rb | 3 +- .../checklist/geo_entities_controller_spec.rb | 2 + .../taxon_concepts_controller_spec.rb | 1 + .../cites_trade/exports_controller_spec.rb | 6 +- .../cites_trade/shipments_controller_spec.rb | 25 ++--- spec/controllers/pages_controller_spec.rb | 4 +- .../registrations_controller_spec.rb | 15 +-- .../species/exports_controller_spec.rb | 15 +-- .../annual_report_uploads_controller_spec.rb | 25 +++-- .../trade/exports_controller_spec.rb | 5 +- .../trade/shipments_controller_spec.rb | 71 ++++++++------ .../validation_errors_controller_spec.rb | 4 +- .../trade/validation_rules_controller_spec.rb | 2 +- spec/factories.rb | 30 +++--- spec/factories/document_tag.rb | 6 +- spec/factories/documents.rb | 10 +- spec/factories/nomenclature_changes.rb | 20 ++-- spec/factories/trade.rb | 34 +++---- .../admin/nomenclature_changes_helper_spec.rb | 31 ++++-- spec/helpers/admin_helper_spec.rb | 3 + spec/helpers/listing_changes_helper_spec.rb | 16 +++- spec/integration/login_spec.rb | 3 + spec/models/annotation_spec.rb | 10 ++ spec/models/api_request_spec.rb | 6 +- spec/models/change_type_spec.rb | 2 + spec/models/common_name_spec.rb | 8 +- spec/models/designation_spec.rb | 17 ++++ spec/models/document_spec.rb | 11 +++ spec/models/eu_decision_spec.rb | 20 ++-- spec/models/eu_decisions/eu_opinion_spec.rb | 1 + .../models/eu_decisions/eu_suspension_spec.rb | 8 +- spec/models/event_spec.rb | 8 ++ spec/models/events/cites_cop_spec.rb | 4 + .../cites_suspension_notification_spec.rb | 20 +++- spec/models/events/eu_regulation_spec.rb | 12 +++ spec/models/geo_entity_spec.rb | 29 ++++-- spec/models/html_to_latex_spec.rb | 12 +++ spec/models/hybrid_relationship_spec.rb | 2 + spec/models/listing_change_spec.rb | 10 ++ spec/models/nomenclature_change/input_spec.rb | 3 + spec/models/nomenclature_change/lump_spec.rb | 11 +++ .../output_reassignment_spec.rb | 3 + .../models/nomenclature_change/output_spec.rb | 19 +++- .../nomenclature_change/reassignment_spec.rb | 3 + .../reassignment_target_spec.rb | 3 + ...name_reassignments_constructor_examples.rb | 4 + ...n_name_reassignments_processor_examples.rb | 3 +- ...tion_reassignments_constructor_examples.rb | 4 + ...bution_reassignments_processor_examples.rb | 5 +- ...ment_reassignments_constructor_examples.rb | 2 + ...cument_reassignments_processor_examples.rb | 5 +- ...tion_reassignments_constructor_examples.rb | 4 + ...lation_reassignments_processor_examples.rb | 16 +++- ...name_reassignments_constructor_examples.rb | 4 + .../name_reassignments_processor_examples.rb | 3 +- ..._names_reassignments_processor_examples.rb | 3 +- ...bution_reassignments_processor_examples.rb | 3 +- ...cument_reassignments_processor_examples.rb | 3 +- ...lation_reassignments_processor_examples.rb | 17 +++- ...t_name_reassignments_processor_examples.rb | 3 +- ...erence_reassignments_processor_examples.rb | 3 +- ...ipment_reassignments_processor_examples.rb | 3 +- ...rent_reassignments_constructor_examples.rb | 4 + ...parent_reassignments_processor_examples.rb | 4 +- ...ence_reassignments_constructor_examples.rb | 4 + ...erence_reassignments_processor_examples.rb | 3 +- ...ipment_reassignments_processor_examples.rb | 3 +- spec/models/nomenclature_change/split_spec.rb | 9 ++ .../status_to_accepted_spec.rb | 7 ++ .../status_to_synonym_spec.rb | 11 +++ spec/models/nomenclature_change_spec.rb | 13 +++ spec/models/preset_tag_spec.rb | 5 + spec/models/rank_spec.rb | 17 ++++ spec/models/sapi/geoip_spec.rb | 4 +- spec/models/synonym_relationship_spec.rb | 2 + spec/models/taxon_common_spec.rb | 2 + spec/models/taxon_concept/agalychnis_spec.rb | 8 ++ spec/models/taxon_concept/agave_spec.rb | 6 ++ spec/models/taxon_concept/ailuropoda_spec.rb | 4 + .../taxon_concept/arctocephalus_spec.rb | 24 +++-- .../taxon_concept/boa_constrictor_spec.rb | 30 ++++++ .../taxon_concept/caiman_latirostris_spec.rb | 14 +++ spec/models/taxon_concept/callback_spec.rb | 7 ++ spec/models/taxon_concept/canis_lupus_spec.rb | 4 + .../taxon_concept/caretta_caretta_cms_spec.rb | 3 + .../taxon_concept/cervus_elaphus_cms_spec.rb | 4 + .../taxon_concept/cervus_elaphus_spec.rb | 25 +++++ spec/models/taxon_concept/colophon_spec.rb | 6 ++ spec/models/taxon_concept/dalbergia_spec.rb | 3 + spec/models/taxon_concept/destroy_spec.rb | 57 ++++++++--- spec/models/taxon_concept/diospyros_spec.rb | 6 ++ .../taxon_concept/falconiformes_spec.rb | 25 +++++ spec/models/taxon_concept/hybrids_spec.rb | 13 ++- .../loxodonta_africana_cms_spec.rb | 5 + .../taxon_concept/loxodonta_africana_spec.rb | 7 ++ .../taxon_concept/mellivora_capensis_spec.rb | 4 + spec/models/taxon_concept/moschus_spec.rb | 8 ++ .../taxon_concept/natator_depressus_spec.rb | 1 + .../taxon_concept/notomys_aquilo_spec.rb | 2 + .../taxon_concept/panax_ginseng_spec.rb | 2 + spec/models/taxon_concept/pereskia_spec.rb | 6 ++ .../platysternon_megacephalum_spec.rb | 2 + .../taxon_concept/pristis_microdon_spec.rb | 2 + .../taxon_concept/pseudomys_fieldi_spec.rb | 3 + .../taxon_concept/psittaciformes_spec.rb | 27 ++++++ spec/models/taxon_concept/synonyms_spec.rb | 21 +++- spec/models/taxon_concept/tapiridae_spec.rb | 9 ++ spec/models/taxon_concept/trade_names_spec.rb | 21 +++- spec/models/taxon_concept/uroplatus_spec.rb | 13 +++ spec/models/taxon_concept/validation_spec.rb | 28 ++++++ spec/models/taxon_concept/varanidae_spec.rb | 11 +++ spec/models/taxon_relationship_spec.rb | 10 ++ spec/models/taxonomy_spec.rb | 13 +++ .../models/trade/annual_report_upload_spec.rb | 27 ++++-- .../distinct_values_validation_rule_spec.rb | 41 +++++--- .../trade/inclusion_validation_rule_spec.rb | 91 ++++++++++++------ .../pov_inclusion_validation_rule_spec.rb | 67 ++++++++----- spec/models/trade/sandbox_template_spec.rb | 8 +- .../scoped_inclusion_validation_rule_spec.rb | 33 ++++--- spec/models/trade/shipment_spec.rb | 54 ++++++++--- ...cept_appendix_year_validation_rule_spec.rb | 91 ++++++++++++------ ...xon_concept_source_validation_rule_spec.rb | 23 +++-- spec/models/trade/validation_rule_spec.rb | 21 ++-- spec/models/trade_codes/purpose_spec.rb | 8 +- spec/models/trade_codes/source_spec.rb | 10 +- spec/models/trade_codes/term_spec.rb | 10 +- spec/models/trade_codes/unit_spec.rb | 8 +- spec/models/trade_restriction_spec.rb | 39 +++++--- .../cites_suspension_spec.rb | 32 ++++++- spec/models/trade_restrictions/quota_spec.rb | 14 ++- spec/models/user_spec.rb | 15 ++- spec/services/checklist/annotations_spec.rb | 4 + .../appendix_population_and_region_spec.rb | 13 +++ .../checklist/appendix_population_spec.rb | 34 ++++++- spec/services/checklist/appendix_spec.rb | 5 +- spec/services/checklist/checklist_spec.rb | 5 + spec/services/checklist/common_names_spec.rb | 14 +-- .../checklist/higher_taxa_injector_spec.rb | 30 ++++++ .../checklist/higher_taxa_item_spec.rb | 11 ++- spec/services/checklist/order_spec.rb | 35 ++++--- .../pdf/history_annotations_key_spec.rb | 8 +- spec/services/checklist/pdf/history_spec.rb | 22 ++++- .../pdf/index_annotations_key_spec.rb | 15 ++- .../checklist/pdf/index_fetcher_spec.rb | 11 ++- .../checklist/scientific_name_spec.rb | 3 + spec/services/checklist/synonyms_spec.rb | 2 +- .../taxon_concept_prefix_matcher_spec.rb | 7 ++ spec/services/checklist/timeline_spec.rb | 2 + .../timelines_for_taxon_concept_spec.rb | 25 +++-- spec/services/dashboard_stats_species_spec.rb | 1 + spec/services/dashboard_stats_trade_spec.rb | 6 +- spec/services/document_search_spec.rb | 10 +- spec/services/geo_entity_search_spec.rb | 21 +++- .../delete_unreassigned_processor_spec.rb | 2 +- .../full_reassignment_spec.rb | 31 ++++-- .../lump/constructor_spec.rb | 56 +++++++++-- .../output_taxon_concept_processor_spec.rb | 11 ++- .../lump/processor_spec.rb | 74 ++++++++++++-- .../reassignment_copy_processor_spec.rb | 7 ++ .../reassignment_transfer_processor_spec.rb | 15 +++ .../split/constructor_spec.rb | 56 +++++++++-- .../output_taxon_concept_processor_spec.rb | 14 ++- .../split/processor_spec.rb | 74 ++++++++++++-- .../status_swap/constructor_spec.rb | 22 ++++- .../status_swap/processor_spec.rb | 18 ++-- .../status_to_accepted/processor_spec.rb | 14 ++- .../status_to_synonym/constructor_spec.rb | 6 +- .../output_taxon_concept_processor_spec.rb | 8 +- .../status_to_synonym/processor_spec.rb | 12 ++- .../species/common_names_export_spec.rb | 13 +-- .../services/species/documents_export_spec.rb | 15 +-- .../invisible_subspecies_search_spec.rb | 1 + spec/services/species/listings_export_spec.rb | 40 ++++---- .../orphaned_taxon_concepts_export_spec.rb | 13 +-- spec/services/species/search_spec.rb | 4 + .../species/species_reference_output_spec.rb | 13 +-- .../species/standard_reference_output_spec.rb | 13 +-- .../synonyms_and_trade_names_export_spec.rb | 13 +-- .../taxon_concept_prefix_matcher_spec.rb | 3 +- .../species/taxon_concepts_export_spec.rb | 13 +-- .../species/trade_name_prefix_matcher_spec.rb | 2 +- .../species/visible_subspecies_search_spec.rb | 3 +- spec/services/taxon_concept_data_spec.rb | 10 ++ .../taxon_concept_prefix_matcher_spec.rb | 50 +++++----- spec/services/trade/filter_spec.rb | 96 +++++++++++++++---- spec/services/trade/permit_matcher_spec.rb | 16 +++- .../reported_taxon_concept_resolver_spec.rb | 12 ++- spec/services/trade/sandbox_filter_spec.rb | 4 +- spec/services/trade/sandbox_spec.rb | 7 +- .../trade/shipments_comptab_export_spec.rb | 8 +- spec/services/trade/shipments_export_spec.rb | 8 +- .../shipments_gross_exports_export_spec.rb | 10 +- .../shipments_gross_imports_export_spec.rb | 10 +- .../shipments_net_exports_export_spec.rb | 10 +- .../shipments_net_imports_export_spec.rb | 10 +- spec/shared/shipments.rb | 2 +- spec/spec_helper.rb | 12 +-- spec/support/controller_macros.rb | 10 +- spec/support/sapi_helpers.rb | 44 ++++++++- .../eu_regulation_activation_worker_spec.rb | 1 + .../event_listing_changes_copy_worker_spec.rb | 4 + spec/workers/quotas_copy_worker_spec.rb | 33 ++++--- spec/workers/submission_worker_spec.rb | 22 ++++- 246 files changed, 2511 insertions(+), 712 deletions(-) diff --git a/spec/controllers/admin/cites_acs_controller_spec.rb b/spec/controllers/admin/cites_acs_controller_spec.rb index 6b7e0ad83..390ac205f 100644 --- a/spec/controllers/admin/cites_acs_controller_spec.rb +++ b/spec/controllers/admin/cites_acs_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_ac1 = create_cites_ac(name: 'Ac1') @cites_ac2 = create_cites_ac(name: 'Ac2') end @@ -14,6 +14,7 @@ get :index expect(assigns(:cites_acs)).to eq([ @cites_ac1, @cites_ac2 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/cites_cops_controller_spec.rb b/spec/controllers/admin/cites_cops_controller_spec.rb index e98266aba..d29342c21 100644 --- a/spec/controllers/admin/cites_cops_controller_spec.rb +++ b/spec/controllers/admin/cites_cops_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_cop1 = create_cites_cop(name: 'CoP2') @cites_cop2 = create_cites_cop(name: 'CoP1') end diff --git a/spec/controllers/admin/cites_extraordinary_meetings_controller_spec.rb b/spec/controllers/admin/cites_extraordinary_meetings_controller_spec.rb index 2685c4677..abfe56f95 100644 --- a/spec/controllers/admin/cites_extraordinary_meetings_controller_spec.rb +++ b/spec/controllers/admin/cites_extraordinary_meetings_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_ex1 = create_cites_extraordinary_meeting(name: 'Ex1') @cites_ex2 = create_cites_extraordinary_meeting(name: 'Ex2') end @@ -14,6 +14,7 @@ get :index expect(assigns(:cites_extraordinary_meetings)).to eq([ @cites_ex1, @cites_ex2 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/cites_hash_annotations_controller_spec.rb b/spec/controllers/admin/cites_hash_annotations_controller_spec.rb index 070ade3fe..2b56c62e2 100644 --- a/spec/controllers/admin/cites_hash_annotations_controller_spec.rb +++ b/spec/controllers/admin/cites_hash_annotations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do cop1 = create_cites_cop(name: 'CoP1') cop2 = create_cites_cop(name: 'CoP2') @annotation1 = create( @@ -22,6 +22,7 @@ get :index expect(assigns(:annotations)).to eq([ @annotation2, @annotation1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/cites_pcs_controller_spec.rb b/spec/controllers/admin/cites_pcs_controller_spec.rb index 9a347600b..368a42838 100644 --- a/spec/controllers/admin/cites_pcs_controller_spec.rb +++ b/spec/controllers/admin/cites_pcs_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_pc1 = create_cites_pc(name: 'Pc1') @cites_pc2 = create_cites_pc(name: 'Pc2') end @@ -14,6 +14,7 @@ get :index expect(assigns(:cites_pcs)).to eq([ @cites_pc1, @cites_pc2 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/cites_suspension_notifications_controller_spec.rb b/spec/controllers/admin/cites_suspension_notifications_controller_spec.rb index e22b470a6..f2715403c 100644 --- a/spec/controllers/admin/cites_suspension_notifications_controller_spec.rb +++ b/spec/controllers/admin/cites_suspension_notifications_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_suspension_notification1 = create_cites_suspension_notification(name: 'B') @cites_suspension_notification2 = create_cites_suspension_notification(name: 'A') end @@ -18,6 +18,7 @@ ] ) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/cites_suspensions_controller_spec.rb b/spec/controllers/admin/cites_suspensions_controller_spec.rb index d3c6da2df..27515bda3 100644 --- a/spec/controllers/admin/cites_suspensions_controller_spec.rb +++ b/spec/controllers/admin/cites_suspensions_controller_spec.rb @@ -12,6 +12,7 @@ get :index expect(response).to render_template('index') end + it 'assigns @cites_suspensions' do get :index assigns(:cites_suspensions) @@ -23,6 +24,7 @@ get :new expect(response).to render_template('new') end + it 'assigns @geo_entities (country and territory) with two objects' do geo_entity_type_t = create(:geo_entity_type, name: 'TERRITORY') territory = create(:geo_entity, geo_entity_type_id: geo_entity_type_t.id) @@ -45,6 +47,7 @@ ) end end + it 'renders new when not successful' do post :create, params: { cites_suspension: { notes: 'DUMMY' } } @@ -53,16 +56,18 @@ end describe 'GET edit' do - before(:each) do + before do @cites_suspension = create( :cites_suspension, start_notification: create_cites_suspension_notification ) end + it 'renders the edit template' do get :edit, params: { id: @cites_suspension.id } expect(response).to render_template('edit') end + it 'assigns @geo_entities (country and territory) with two objects' do geo_entity_type_t = create(:geo_entity_type, name: 'TERRITORY') territory = create(:geo_entity, geo_entity_type_id: geo_entity_type_t.id) @@ -73,7 +78,7 @@ end describe 'PUT update' do - before(:each) do + before do @cites_suspension = create( :cites_suspension, start_notification: create_cites_suspension_notification @@ -104,12 +109,13 @@ end describe 'DELETE destroy' do - before(:each) do + before do @cites_suspension = create( :cites_suspension, start_notification: create_cites_suspension_notification ) end + it 'redirects after delete' do delete :destroy, params: { id: @cites_suspension.id } expect(response).to redirect_to( diff --git a/spec/controllers/admin/cites_tcs_controller_spec.rb b/spec/controllers/admin/cites_tcs_controller_spec.rb index c8eb21cea..19b688983 100644 --- a/spec/controllers/admin/cites_tcs_controller_spec.rb +++ b/spec/controllers/admin/cites_tcs_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_tc1 = create_cites_tc(name: 'Tc1') @cites_tc2 = create_cites_tc(name: 'Tc2') end @@ -14,6 +14,7 @@ get :index expect(assigns(:cites_tcs)).to eq([ @cites_tc1, @cites_tc2 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/designations_controller_spec.rb b/spec/controllers/admin/designations_controller_spec.rb index 16db14429..3a6902505 100644 --- a/spec/controllers/admin/designations_controller_spec.rb +++ b/spec/controllers/admin/designations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'GET index' do - before(:each) do + before do @designation1 = create(:designation, name: 'BB', taxonomy: create(:taxonomy)) @designation2 = create(:designation, name: 'AA', taxonomy: create(:taxonomy)) end diff --git a/spec/controllers/admin/distributions_controller_spec.rb b/spec/controllers/admin/distributions_controller_spec.rb index e56800f9e..e77421367 100644 --- a/spec/controllers/admin/distributions_controller_spec.rb +++ b/spec/controllers/admin/distributions_controller_spec.rb @@ -6,12 +6,14 @@ before do @taxon_concept = create(:taxon_concept) end + describe "XHR GET 'new'" do it 'returns http success and renders the new template' do get :new, params: { taxon_concept_id: @taxon_concept.id }, xhr: true expect(response).to be_successful expect(response).to render_template('new') end + it 'assigns @geo_entities (country and territory) with two objects' do geo_entity_type_t = create(:geo_entity_type, name: 'TERRITORY') territory = create(:geo_entity, geo_entity_type_id: geo_entity_type_t.id) @@ -19,6 +21,7 @@ get :new, params: { taxon_concept_id: @taxon_concept.id }, xhr: true expect(assigns(:geo_entities).size).to eq(2) end + it 'assigns the distribution variable' do get :new, params: { taxon_concept_id: @taxon_concept.id }, xhr: true expect(assigns(:distribution)).not_to be_nil @@ -30,6 +33,7 @@ describe "XHR POST 'create'" do let(:geo_entity) { create(:geo_entity) } let(:reference) { create(:reference) } + it 'renders create when successful and has an existing reference' do post :create, xhr: true, params: { @@ -43,6 +47,7 @@ } expect(response).to render_template('create') end + it 'renders create when successful and is creating a reference' do post :create, xhr: true, params: { @@ -62,14 +67,17 @@ describe 'XHR GET edit' do let(:distribution) { create(:distribution, taxon_concept_id: @taxon_concept.id) } + it 'renders the new template' do get :edit, params: { taxon_concept_id: @taxon_concept.id, id: distribution.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the distribution variable' do get :edit, params: { taxon_concept_id: @taxon_concept.id, id: distribution.id }, xhr: true expect(assigns(:distribution)).not_to be_nil end + it 'assigns @geo_entities (country and territory) with two objects' do geo_entity_type_t = create(:geo_entity_type, name: 'TERRITORY') territory = create(:geo_entity, geo_entity_type_id: geo_entity_type_t.id) @@ -81,6 +89,7 @@ describe 'XHR PUT update' do let(:distribution) { create(:distribution, taxon_concept_id: @taxon_concept.id) } let(:geo_entity) { create(:geo_entity) } + it 'responds with 200 when successful' do put :update, format: 'json', xhr: true, params: { @@ -96,6 +105,7 @@ describe 'DELETE destroy' do let(:distribution) { create(:distribution, taxon_concept_id: @taxon_concept.id) } + it 'redirects after delete' do delete :destroy, params: { taxon_concept_id: @taxon_concept.id, id: distribution.id } expect(response).to redirect_to( diff --git a/spec/controllers/admin/ec_srgs_controller_spec.rb b/spec/controllers/admin/ec_srgs_controller_spec.rb index f3ba71cdd..cccd6b44e 100644 --- a/spec/controllers/admin/ec_srgs_controller_spec.rb +++ b/spec/controllers/admin/ec_srgs_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @cites_srg1 = create_ec_srg(name: 'S1') @cites_srg2 = create_ec_srg(name: 'S2') end @@ -14,6 +14,7 @@ get :index expect(assigns(:ec_srgs).sort).to eq([ @cites_srg1, @cites_srg2 ].sort) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/eu_council_regulations_controller_spec.rb b/spec/controllers/admin/eu_council_regulations_controller_spec.rb index dc87c4f8a..0f6ef9108 100644 --- a/spec/controllers/admin/eu_council_regulations_controller_spec.rb +++ b/spec/controllers/admin/eu_council_regulations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @eu_regulation1 = create_eu_council_regulation(name: 'BB') @eu_regulation2 = create_eu_council_regulation(name: 'AA') end @@ -14,6 +14,7 @@ get :index expect(assigns(:eu_council_regulations)).to eq([ @eu_regulation2, @eu_regulation1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/eu_hash_annotations_controller_spec.rb b/spec/controllers/admin/eu_hash_annotations_controller_spec.rb index f107e0554..6ab1a4322 100644 --- a/spec/controllers/admin/eu_hash_annotations_controller_spec.rb +++ b/spec/controllers/admin/eu_hash_annotations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do reg1 = create_eu_regulation(name: 'Regulation1') reg2 = create_eu_regulation(name: 'Regulation2') @annotation1 = create( @@ -22,6 +22,7 @@ get :index expect(assigns(:annotations)).to eq([ @annotation2, @annotation1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/eu_implementing_regulations_controller_spec.rb b/spec/controllers/admin/eu_implementing_regulations_controller_spec.rb index 2ff86a406..5376a60eb 100644 --- a/spec/controllers/admin/eu_implementing_regulations_controller_spec.rb +++ b/spec/controllers/admin/eu_implementing_regulations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @eu_regulation1 = create_eu_implementing_regulation(name: 'BB') @eu_regulation2 = create_eu_implementing_regulation(name: 'AA') end @@ -14,6 +14,7 @@ get :index expect(assigns(:eu_implementing_regulations)).to eq([ @eu_regulation2, @eu_regulation1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') diff --git a/spec/controllers/admin/eu_regulations_controller_spec.rb b/spec/controllers/admin/eu_regulations_controller_spec.rb index fc8848f68..0b08728c7 100644 --- a/spec/controllers/admin/eu_regulations_controller_spec.rb +++ b/spec/controllers/admin/eu_regulations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @eu_regulation1 = create_eu_regulation(name: 'BB') @eu_regulation2 = create_eu_regulation(name: 'AA') end @@ -14,6 +14,7 @@ get :index expect(assigns(:eu_regulations)).to eq([ @eu_regulation2, @eu_regulation1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') @@ -23,6 +24,7 @@ describe 'XHR POST activate' do let(:eu_regulation) { create_eu_regulation } + it 'renders create when successful' do post :activate, format: 'js', params: { id: eu_regulation.id }, xhr: true expect(response).to render_template('create') diff --git a/spec/controllers/admin/eu_suspension_regulations_controller_spec.rb b/spec/controllers/admin/eu_suspension_regulations_controller_spec.rb index f87fb495c..0a62406d3 100644 --- a/spec/controllers/admin/eu_suspension_regulations_controller_spec.rb +++ b/spec/controllers/admin/eu_suspension_regulations_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @eu_suspension_regulation1 = create_eu_suspension_regulation(name: 'BB', is_current: true) @eu_suspension_regulation2 = create_eu_suspension_regulation(name: 'AA', is_current: true) end @@ -14,6 +14,7 @@ get :index expect(assigns(:eu_suspension_regulations)).to eq([ @eu_suspension_regulation2, @eu_suspension_regulation1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') @@ -23,6 +24,7 @@ describe 'XHR POST activate' do let(:eu_suspension_regulation) { create_eu_suspension_regulation(is_current: true) } + it 'renders create when successful' do post :activate, format: 'js', params: { id: eu_suspension_regulation.id }, xhr: true expect(response).to render_template('create') diff --git a/spec/controllers/admin/eu_suspensions_controller_spec.rb b/spec/controllers/admin/eu_suspensions_controller_spec.rb index e4039d664..abd132a52 100644 --- a/spec/controllers/admin/eu_suspensions_controller_spec.rb +++ b/spec/controllers/admin/eu_suspensions_controller_spec.rb @@ -14,6 +14,7 @@ get :index, params: { eu_suspension_regulation_id: @eu_suspension_regulation } expect(response).to render_template('index') end + it 'renders the admin layout' do get :index, params: { eu_suspension_regulation_id: @eu_suspension_regulation } expect(response).to render_template('layouts/admin') @@ -21,13 +22,14 @@ end describe 'DELETE destroy' do - before(:each) do + before do @eu_suspension = create( :eu_suspension, taxon_concept_id: @taxon_concept.id, start_event_id: @eu_suspension_regulation.id ) end + it 'redirects after delete' do delete :destroy, params: { id: @eu_suspension.id, eu_suspension_regulation_id: @eu_suspension_regulation.id } expect(response).to redirect_to( diff --git a/spec/controllers/admin/event_documents_controller_spec.rb b/spec/controllers/admin/event_documents_controller_spec.rb index 00c63e750..73d5e570c 100644 --- a/spec/controllers/admin/event_documents_controller_spec.rb +++ b/spec/controllers/admin/event_documents_controller_spec.rb @@ -5,7 +5,7 @@ let(:event) { create(:event, published_at: DateTime.new(2014, 12, 25)) } describe 'ordering' do - before(:each) do + before do @document1 = create(:document, event: event, sort_index: 2) @document2 = create(:document, event: event, sort_index: 1) DocumentSearch.refresh_citations_and_documents diff --git a/spec/controllers/admin/events_controller_spec.rb b/spec/controllers/admin/events_controller_spec.rb index a92b3219e..9e8d538f7 100644 --- a/spec/controllers/admin/events_controller_spec.rb +++ b/spec/controllers/admin/events_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @event1 = create(:event, name: 'BB') @event2 = create(:event, name: 'AA', designation_id: @event1.designation_id) end @@ -14,6 +14,7 @@ get :index expect(assigns(:events)).to eq([ @event2, @event1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') @@ -26,6 +27,7 @@ get :new, xhr: true expect(response).to render_template('new') end + it 'assigns the event variable' do get :new, xhr: true expect(assigns(:event)).not_to be_nil @@ -37,6 +39,7 @@ post :create, params: { event: attributes_for(:event) }, xhr: true expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, params: { event: { name: nil } }, xhr: true expect(response).to render_template('new') @@ -45,10 +48,12 @@ describe 'XHR GET edit' do let(:event) { create(:event) } + it 'renders the edit template' do get :edit, params: { id: event.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the hybrid_relationship variable' do get :edit, params: { id: event.id }, xhr: true expect(assigns(:event)).not_to be_nil @@ -57,10 +62,12 @@ describe 'XHR PUT update JSON' do let(:event) { create(:event) } + it 'responds with 200 when successful' do put :update, format: 'json', params: { id: event.id, event: { name: 'ZZ' } }, xhr: true expect(response).to be_successful end + it 'responds with json when not successful' do put :update, format: 'json', params: { id: event.id, event: { name: nil } }, xhr: true expect(response.parsed_body).to include('errors') @@ -69,6 +76,7 @@ describe 'DELETE destroy' do let(:event) { create(:event) } + it 'redirects after delete' do delete :destroy, params: { id: event.id } expect(response).to redirect_to(admin_events_url) diff --git a/spec/controllers/admin/exports_controller_spec.rb b/spec/controllers/admin/exports_controller_spec.rb index ed784c219..09bb6c9c2 100644 --- a/spec/controllers/admin/exports_controller_spec.rb +++ b/spec/controllers/admin/exports_controller_spec.rb @@ -10,10 +10,12 @@ expect(response).to render_template('layouts/admin') end end + describe 'GET download with data_type=Names' do - after(:each) do + after do DownloadsCache.clear_taxon_concepts end + context 'all' do it 'returns taxon concepts names file' do create(:taxon_concept) @@ -22,11 +24,13 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"taxon_concepts_names.csv\"; filename*=UTF-8''taxon_concepts_names.csv") end + it 'redirects when no results' do get :download, params: { data_type: 'Names' } expect(response).to redirect_to(admin_exports_path) end end + context 'CITES_EU' do it 'returns CITES_EU taxon concepts names file' do create_cites_eu_species @@ -35,11 +39,13 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"taxon_concepts_names.csv\"; filename*=UTF-8''taxon_concepts_names.csv") end + it 'redirects when no results' do get :download, params: { data_type: 'Names', filters: { taxonomy: 'CITES_EU' } } expect(response).to redirect_to(admin_exports_path) end end + context 'CMS' do it 'returns CMS taxon concepts names file' do create_cms_species @@ -48,16 +54,19 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"taxon_concepts_names.csv\"; filename*=UTF-8''taxon_concepts_names.csv") end + it 'redirects when no results' do get :download, params: { data_type: 'Names', filters: { taxonomy: 'CMS' } } expect(response).to redirect_to(admin_exports_path) end end end + describe 'GET download with data_type=Distributions' do - after(:each) do + after do DownloadsCache.clear_distributions end + context 'all' do it 'returns taxon concepts distributions file' do tc = create(:taxon_concept) @@ -67,11 +76,13 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"taxon_concepts_distributions.csv\"; filename*=UTF-8''taxon_concepts_distributions.csv") end + it 'redirects when no results' do get :download, params: { data_type: 'Distributions' } expect(response).to redirect_to(admin_exports_path) end end + context 'CITES_EU' do it 'returns CITES_EU taxon concepts distributions file' do tc = create_cites_eu_species @@ -81,11 +92,13 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"taxon_concepts_distributions.csv\"; filename*=UTF-8''taxon_concepts_distributions.csv") end + it 'redirects when no results' do get :download, params: { data_type: 'Distributions', filters: { taxonomy: 'CITES_EU' } } expect(response).to redirect_to(admin_exports_path) end end + context 'CMS' do it 'returns CMS taxon concepts distributions file' do tc = create_cms_species @@ -95,6 +108,7 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"taxon_concepts_distributions.csv\"; filename*=UTF-8''taxon_concepts_distributions.csv") end + it 'redirects when no results' do get :download, params: { data_type: 'Distributions', filters: { taxonomy: 'CMS' } } expect(response).to redirect_to(admin_exports_path) diff --git a/spec/controllers/admin/geo_entities_controller_spec.rb b/spec/controllers/admin/geo_entities_controller_spec.rb index ae4c93918..7b60a73ce 100644 --- a/spec/controllers/admin/geo_entities_controller_spec.rb +++ b/spec/controllers/admin/geo_entities_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @geo_entity1 = create( :geo_entity, geo_entity_type: country_geo_entity_type, @@ -24,6 +24,7 @@ get :index expect(assigns(:geo_entities)).to eq([ @geo_entity2, @geo_entity1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') @@ -42,6 +43,7 @@ } expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, xhr: true, params: { geo_entity: { @@ -55,10 +57,12 @@ describe 'XHR PUT update JSON' do let(:geo_entity) { create(:geo_entity, geo_entity_type: country_geo_entity_type) } + it 'responds with 200 when successful' do put :update, format: 'json', params: { id: geo_entity.id, geo_entity: { iso_code2: 'ZZ' } }, xhr: true expect(response).to be_successful end + it 'responds with json when not successful' do put :update, format: 'json', params: { id: geo_entity.id, geo_entity: { iso_code2: nil } }, xhr: true expect(response.parsed_body).to include('errors') @@ -67,6 +71,7 @@ describe 'DELETE destroy' do let(:geo_entity) { create(:geo_entity) } + it 'redirects after delete' do delete :destroy, params: { id: geo_entity.id } expect(response).to redirect_to(admin_geo_entities_url) diff --git a/spec/controllers/admin/hybrid_relationships_controller_spec.rb b/spec/controllers/admin/hybrid_relationships_controller_spec.rb index 881134df3..a6fa96eec 100644 --- a/spec/controllers/admin/hybrid_relationships_controller_spec.rb +++ b/spec/controllers/admin/hybrid_relationships_controller_spec.rb @@ -3,7 +3,8 @@ describe Admin::HybridRelationshipsController do login_admin - before(:each) { hybrid_relationship_type } + before { hybrid_relationship_type } + let(:taxon_concept) { create(:taxon_concept) } let(:hybrid) { create(:taxon_concept, name_status: 'H') } let(:hybrid_relationship) do @@ -14,11 +15,13 @@ other_taxon_concept: hybrid ) end + describe 'XHR GET new' do it 'renders the new template' do get :new, params: { taxon_concept_id: taxon_concept.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the hybrid_relationship variable' do get :new, params: { taxon_concept_id: taxon_concept.id }, xhr: true expect(assigns(:hybrid_relationship)).not_to be_nil @@ -36,6 +39,7 @@ } expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, xhr: true, params: { taxon_concept_id: taxon_concept.id, @@ -52,6 +56,7 @@ get :edit, params: { taxon_concept_id: taxon_concept.id, id: hybrid_relationship.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the hybrid_relationship variable' do get :edit, params: { taxon_concept_id: taxon_concept.id, id: hybrid_relationship.id }, xhr: true expect(assigns(:hybrid_relationship)).not_to be_nil @@ -69,6 +74,7 @@ } expect(response).to render_template('create') end + it 'responds with json when not successful' do put :update, format: 'js', xhr: true, params: { taxon_concept_id: taxon_concept.id, diff --git a/spec/controllers/admin/instruments_controller_spec.rb b/spec/controllers/admin/instruments_controller_spec.rb index d1c38fa7f..8ebfeea3c 100644 --- a/spec/controllers/admin/instruments_controller_spec.rb +++ b/spec/controllers/admin/instruments_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'GET index' do - before(:each) do + before do @instrument1 = create(:instrument, name: 'BB', designation: create(:designation)) @instrument2 = create(:instrument, name: 'AA', designation: create(:designation)) end @@ -39,6 +39,7 @@ expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, params: { instrument: { name: nil } }, xhr: true @@ -64,6 +65,9 @@ describe 'DELETE destroy' do let(:instrument) { create(:instrument) } + let!(:taxon_instrument) { create(:taxon_instrument, instrument_id: instrument2.id) } + let(:instrument2) { create(:instrument) } + it 'redirects after delete' do delete :destroy, params: { id: instrument.id } @@ -72,8 +76,6 @@ expect(response).to redirect_to(admin_instruments_url) end - let(:instrument2) { create(:instrument) } - let!(:taxon_instrument) { create(:taxon_instrument, instrument_id: instrument2.id) } it 'fails to delete instrument because there are dependent objects' do delete :destroy, params: { id: instrument2.id } diff --git a/spec/controllers/admin/listing_changes_controller_spec.rb b/spec/controllers/admin/listing_changes_controller_spec.rb index 6fd34eb0c..7e814b9ad 100644 --- a/spec/controllers/admin/listing_changes_controller_spec.rb +++ b/spec/controllers/admin/listing_changes_controller_spec.rb @@ -47,10 +47,12 @@ expect(assigns(:listing_changes)).to eq([ listing_change2, listing_change1 ]) expect(assigns(:eu_regulation)).to eq @eu_regulation end + it 'renders the index template' do get :index, params: { eu_regulation_id: @eu_regulation.id } expect(response).to render_template('index') end + it 'renders the admin layout' do get :index, params: { eu_regulation_id: @eu_regulation.id } expect(response).to render_template('layouts/admin') @@ -58,7 +60,7 @@ end describe 'DELETE destroy' do - before(:each) do + before do @listing_change = create( :listing_change, taxon_concept_id: @taxon_concept.id, @@ -68,6 +70,7 @@ effective_at: 1.week.ago ) end + it 'redirects after delete' do delete :destroy, params: { id: @listing_change.id, eu_regulation_id: @eu_regulation.id } expect(response).to redirect_to( diff --git a/spec/controllers/admin/nomenclature_changes_controller_spec.rb b/spec/controllers/admin/nomenclature_changes_controller_spec.rb index 649296d76..0e430c2fa 100644 --- a/spec/controllers/admin/nomenclature_changes_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes_controller_spec.rb @@ -10,6 +10,7 @@ get :index expect(assigns(:collection)).to eq([ nomenclature_change2, nomenclature_change1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') @@ -18,6 +19,7 @@ describe 'DELETE destroy' do let(:nomenclature_change) { create(:nomenclature_change) } + it 'redirects after delete' do delete :destroy, params: { id: nomenclature_change.id } expect(response).to redirect_to(admin_nomenclature_changes_url) diff --git a/spec/controllers/admin/references_controller_spec.rb b/spec/controllers/admin/references_controller_spec.rb index bc1974732..e17e1babd 100644 --- a/spec/controllers/admin/references_controller_spec.rb +++ b/spec/controllers/admin/references_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @reference1 = create(:reference, citation: 'BB') @reference2 = create(:reference, citation: 'AA') end @@ -14,11 +14,13 @@ get :index expect(assigns(:references)).to eq([ @reference2, @reference1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') end end + describe 'XHR GET index JSON' do it 'renders json for dropdown' do get :index, format: 'json', xhr: true @@ -33,6 +35,7 @@ post :create, params: { reference: attributes_for(:reference) }, xhr: true expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, params: { reference: { citation: nil } }, xhr: true expect(response).to render_template('new') @@ -41,10 +44,12 @@ describe 'XHR PUT update JSON' do let(:reference) { create(:reference) } + it 'responds with 200 when successful' do put :update, format: 'json', params: { id: reference.id, reference: { citation: 'ZZ' } }, xhr: true expect(response).to be_successful end + it 'responds with json when not successful' do put :update, format: 'json', params: { id: reference.id, reference: { citation: nil } }, xhr: true expect(response.parsed_body).to include('errors') @@ -53,6 +58,7 @@ describe 'DELETE destroy' do let(:reference) { create(:reference) } + it 'redirects after delete' do delete :destroy, params: { id: reference.id } expect(response).to redirect_to(admin_references_url) diff --git a/spec/controllers/admin/synonym_relationships_controller_spec.rb b/spec/controllers/admin/synonym_relationships_controller_spec.rb index 4a5d57ac0..f572f8369 100644 --- a/spec/controllers/admin/synonym_relationships_controller_spec.rb +++ b/spec/controllers/admin/synonym_relationships_controller_spec.rb @@ -3,7 +3,8 @@ describe Admin::SynonymRelationshipsController do login_admin - before(:each) { synonym_relationship_type } + before { synonym_relationship_type } + let(:taxon_concept) { create(:taxon_concept) } let(:synonym) { create(:taxon_concept, name_status: 'S') } let(:synonym_relationship) do @@ -14,11 +15,13 @@ other_taxon_concept: synonym ) end + describe 'XHR GET new' do it 'renders the new template' do get :new, params: { taxon_concept_id: taxon_concept.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the synonym_relationship variable' do get :new, params: { taxon_concept_id: taxon_concept.id }, xhr: true expect(assigns(:synonym_relationship)).not_to be_nil @@ -35,6 +38,7 @@ }, xhr: true expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, xhr: true, params: { taxon_concept_id: taxon_concept.id, @@ -51,6 +55,7 @@ get :edit, params: { taxon_concept_id: taxon_concept.id, id: synonym_relationship.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the synonym_relationship variable' do get :edit, params: { taxon_concept_id: taxon_concept.id, id: synonym_relationship.id }, xhr: true expect(assigns(:synonym_relationship)).not_to be_nil @@ -69,6 +74,7 @@ } expect(response).to render_template('create') end + it 'responds with json when not successful' do put :update, format: 'js', xhr: true, params: { diff --git a/spec/controllers/admin/taxon_commons_controller_spec.rb b/spec/controllers/admin/taxon_commons_controller_spec.rb index 29c4cd8bf..f75d116de 100644 --- a/spec/controllers/admin/taxon_commons_controller_spec.rb +++ b/spec/controllers/admin/taxon_commons_controller_spec.rb @@ -59,7 +59,7 @@ expect(response).to render_template('new') end - it 'assigns the taxon common variable' do + it 'assigns the taxon common variable' do get :edit, params: { taxon_concept_id: @taxon_concept.id, id: @taxon_common.id }, xhr: true expect(assigns(:taxon_common)).not_to be_nil @@ -90,6 +90,7 @@ expect(response).to render_template('create') end + it 'renders new when not successful' do put :update, format: 'js', diff --git a/spec/controllers/admin/taxon_concept_comments_controller_spec.rb b/spec/controllers/admin/taxon_concept_comments_controller_spec.rb index cb0c2e1a0..38891131e 100644 --- a/spec/controllers/admin/taxon_concept_comments_controller_spec.rb +++ b/spec/controllers/admin/taxon_concept_comments_controller_spec.rb @@ -26,6 +26,7 @@ describe 'PUT update' do let(:comment) { @taxon_concept.comments.create({ note: 'bleh' }) } + it 'redirects to index with notice when success' do put :update, params: { id: comment.id, taxon_concept_id: @taxon_concept.id, comment: { note: 'blah' } } expect(response).to redirect_to( diff --git a/spec/controllers/admin/taxon_concept_references_controller_spec.rb b/spec/controllers/admin/taxon_concept_references_controller_spec.rb index 4f57323a9..61e44adee 100644 --- a/spec/controllers/admin/taxon_concept_references_controller_spec.rb +++ b/spec/controllers/admin/taxon_concept_references_controller_spec.rb @@ -53,7 +53,7 @@ expect(response).to render_template('new') end - it 'assigns the taxon concept reference variable' do + it 'assigns the taxon concept reference variable' do get :edit, params: { taxon_concept_id: @taxon_concept.id, id: @taxon_concept_reference.id }, xhr: true expect(assigns(:taxon_concept_reference)).not_to be_nil diff --git a/spec/controllers/admin/taxon_listing_changes_controller_spec.rb b/spec/controllers/admin/taxon_listing_changes_controller_spec.rb index 4021f7f8f..0cdf6cd50 100644 --- a/spec/controllers/admin/taxon_listing_changes_controller_spec.rb +++ b/spec/controllers/admin/taxon_listing_changes_controller_spec.rb @@ -111,7 +111,7 @@ end describe 'GET edit' do - before(:each) do + before do @listing_change = create( :listing_change, taxon_concept_id: @taxon_concept.id, @@ -135,7 +135,7 @@ end describe 'PUT update' do - before(:each) do + before do @annotation = create(:annotation) @listing_change = create( :listing_change, @@ -250,7 +250,7 @@ end describe 'DELETE destroy' do - before(:each) do + before do @listing_change = create( :listing_change, taxon_concept_id: @taxon_concept.id, @@ -273,6 +273,7 @@ ) end end + describe 'Authorization for contributors' do login_contributor @@ -299,6 +300,7 @@ expect(response).to render_template('layouts/taxon_concepts') end end + describe 'DELETE destroy' do it 'fails to delete and redirects' do @request.env['HTTP_REFERER'] = diff --git a/spec/controllers/admin/taxon_relationships_controller_spec.rb b/spec/controllers/admin/taxon_relationships_controller_spec.rb index 407b242de..5487ee1b9 100644 --- a/spec/controllers/admin/taxon_relationships_controller_spec.rb +++ b/spec/controllers/admin/taxon_relationships_controller_spec.rb @@ -3,21 +3,26 @@ describe Admin::TaxonRelationshipsController do login_admin - before(:each) { equal_relationship_type } + before { equal_relationship_type } + let(:taxon_concept) { create(:taxon_concept) } + describe 'GET index' do let(:taxon_relationship) do create(:taxon_relationship, taxon_concept_id: taxon_concept.id) end + it 'assigns @taxon_relationships' do get :index, params: { taxon_concept_id: taxon_concept.id, type: taxon_relationship.taxon_relationship_type.name } expect(assigns(:taxon_relationships)).to eq([ taxon_relationship ]) assigns(:taxon_concept) end + it 'renders the index template' do get :index, params: { taxon_concept_id: taxon_concept.id } expect(response).to render_template('index') end + it 'renders the taxon_concepts_layout' do get :index, params: { taxon_concept_id: taxon_concept.id } expect(response).to render_template('layouts/taxon_concepts') @@ -26,9 +31,11 @@ describe 'XHR POST create' do let(:taxon_relationship_attributes) { build_attributes(:taxon_relationship) } + before do allow(TaxonRelationshipType).to receive(:find).and_return(equal_relationship_type) end + it 'renders create when successful' do post :create, params: { taxon_relationship: taxon_relationship_attributes, @@ -36,6 +43,7 @@ }, xhr: true expect(response).to render_template('create') end + it 'renders new when not successful' do taxon_relationship = create(:taxon_relationship, taxon_relationship_attributes) post :create, params: { @@ -62,6 +70,7 @@ other_taxon_concept_id: other_taxon_concept.id ) end + context 'destroys relationship for taxon concept' do specify do expect do @@ -69,6 +78,7 @@ end.to change(TaxonRelationship, :count).by(-2) end end + context 'destroys relationship for other taxon concept' do specify do expect do @@ -77,6 +87,7 @@ end end end + context 'when relationship is not bidirectional' do let(:taxon_concept) do create_cites_eu_species @@ -92,6 +103,7 @@ other_taxon_concept_id: other_taxon_concept.id ) end + context 'destroys relationship for taxon concept' do specify do expect do @@ -99,6 +111,7 @@ end.to change(TaxonRelationship, :count).by(-1) end end + context 'destroys relationship for other taxon concept' do specify do expect do diff --git a/spec/controllers/admin/taxonomies_controller_spec.rb b/spec/controllers/admin/taxonomies_controller_spec.rb index be4cfef04..6b8ebdfb4 100644 --- a/spec/controllers/admin/taxonomies_controller_spec.rb +++ b/spec/controllers/admin/taxonomies_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'index' do - before(:each) do + before do @taxonomy1 = create(:taxonomy, name: 'BB') @taxonomy2 = create(:taxonomy, name: 'AA') end @@ -14,11 +14,13 @@ get :index expect(assigns(:taxonomies)).to eq([ @taxonomy2, @taxonomy1 ]) end + it 'renders the index template' do get :index expect(response).to render_template('index') end end + describe 'XHR GET index JSON' do it 'renders json for dropdown' do get :index, format: 'json', xhr: true @@ -33,6 +35,7 @@ post :create, params: { taxonomy: attributes_for(:taxonomy) }, xhr: true expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, params: { taxonomy: { name: nil } }, xhr: true expect(response).to render_template('new') @@ -41,10 +44,12 @@ describe 'XHR PUT update JSON' do let(:taxonomy) { create(:taxonomy) } + it 'responds with 200 when successful' do put :update, format: 'json', params: { id: taxonomy.id, taxonomy: { name: 'ZZ' } }, xhr: true expect(response).to be_successful end + it 'responds with json when not successful' do put :update, format: 'json', params: { id: taxonomy.id, taxonomy: { name: nil } }, xhr: true expect(response.parsed_body).to include('errors') @@ -53,6 +58,7 @@ describe 'DELETE destroy' do let(:taxonomy) { create(:taxonomy) } + it 'redirects after delete' do delete :destroy, params: { id: taxonomy.id } expect(response).to redirect_to(admin_taxonomies_url) @@ -67,8 +73,10 @@ expect(response).to redirect_to admin_root_path end end + describe 'DELETE destroy' do let(:taxonomy) { create(:taxonomy) } + it 'fails to delete and redirects to admin_root_path' do delete :destroy, params: { id: taxonomy.id } expect(response).to redirect_to(admin_root_path) diff --git a/spec/controllers/admin/trade_names_relationships_controller_spec.rb b/spec/controllers/admin/trade_names_relationships_controller_spec.rb index b45ca22a8..31ef0870e 100644 --- a/spec/controllers/admin/trade_names_relationships_controller_spec.rb +++ b/spec/controllers/admin/trade_names_relationships_controller_spec.rb @@ -3,7 +3,8 @@ describe Admin::TradeNameRelationshipsController do login_admin - before(:each) { trade_name_relationship_type } + before { trade_name_relationship_type } + let(:taxon_concept) { create(:taxon_concept) } let(:trade_name) { create(:taxon_concept, name_status: 'T') } let(:trade_name_relationship) do @@ -14,11 +15,13 @@ other_taxon_concept: trade_name ) end + describe 'XHR GET new' do it 'renders the new template' do get :new, params: { taxon_concept_id: taxon_concept.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the trade_name_relationship variable' do get :new, params: { taxon_concept_id: taxon_concept.id }, xhr: true expect(assigns(:trade_name_relationship)).not_to be_nil @@ -36,6 +39,7 @@ } expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, xhr: true, params: { @@ -56,6 +60,7 @@ }, xhr: true expect(response).to render_template('new') end + it 'assigns the trade_name_relationship variable' do get :edit, params: { taxon_concept_id: taxon_concept.id, @@ -77,6 +82,7 @@ } expect(response).to render_template('create') end + it 'responds with json when not successful' do put :update, format: 'js', xhr: true, params: { diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index e2e65fa1c..97de8a530 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -17,6 +17,7 @@ post :create, params: { user: attributes_for(:user) }, xhr: true expect(response).to render_template('create') end + it 'renders new when not successful' do post :create, params: { user: { name: nil } }, xhr: true expect(response).to render_template('new') @@ -25,10 +26,12 @@ describe 'XHR GET edit' do let(:user) { create(:user) } + it 'renders the edit template' do get :edit, params: { id: user.id }, xhr: true expect(response).to render_template('new') end + it 'assigns the hybrid_relationship variable' do get :edit, params: { id: user.id }, xhr: true expect(assigns(:user)).not_to be_nil @@ -37,11 +40,13 @@ describe 'XHR PUT update JS' do let(:user) { create(:user) } + it 'responds with 200 when successful' do put :update, format: 'js', params: { id: user.id, user: { name: 'ZZ' } }, xhr: true expect(response).to be_successful expect(response).to render_template('create') end + it 'responds with template new when not successful' do put :update, format: 'js', params: { id: user.id, user: { name: nil } }, xhr: true expect(response).to render_template('new') @@ -50,6 +55,7 @@ describe 'DELETE destroy' do let(:user) { create(:user) } + it 'redirects after delete' do delete :destroy, params: { id: user.id } expect(response).to redirect_to(admin_users_url) diff --git a/spec/controllers/api/document_tags_controller_spec.rb b/spec/controllers/api/document_tags_controller_spec.rb index 7c0371266..d3f5da4ef 100644 --- a/spec/controllers/api/document_tags_controller_spec.rb +++ b/spec/controllers/api/document_tags_controller_spec.rb @@ -2,9 +2,10 @@ describe Api::V1::DocumentTagsController do describe 'GET index' do - before(:each) do + before do create(:proposal_outcome) end + it 'returns document tags' do get :index expect(response.body).to have_json_size(1).at_path('document_tags') diff --git a/spec/controllers/api/documents_controller_spec.rb b/spec/controllers/api/documents_controller_spec.rb index 61332c94b..531d9df5a 100644 --- a/spec/controllers/api/documents_controller_spec.rb +++ b/spec/controllers/api/documents_controller_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Api::V1::DocumentsController do - before(:each) do + before do @taxon_concept = create_cites_eu_species @subspecies = create_cites_eu_subspecies(parent: @taxon_concept) @document = create(:proposal, is_public: true, event: create_cites_cop) @@ -61,13 +61,14 @@ def get_public_documents get :index, params: { taxon_concept_id: @taxon_concept.id } expect(response.body).to have_json_size(3).at_path('documents') end - context 'GET index api user ' do + context 'GET index api user' do login_api_user it 'returns only public documents' do get_public_documents end end + context 'GET index no user' do |variable| it 'returns only public documents' do get_public_documents @@ -80,7 +81,7 @@ def get_public_documents get :index, params: { taxon_concept_id: @taxon_concept.id } expect(response.body).to have_json_size(3).at_path('documents') end - context 'GET index api user ' do + context 'GET index api user' do login_secretariat_user it 'returns only public documents' do @@ -91,9 +92,9 @@ def get_public_documents context 'show action fails' do login_api_user - it 'should return 403 status when permission denied' do + it 'returns 403 status when permission denied' do get :show, params: { id: @document2.id } - expect(response).to have_http_status(403) + expect(response).to have_http_status(:forbidden) end end @@ -106,12 +107,13 @@ def get_public_documents context 'download documents' do context 'single document selected' do - it 'should return 404 if file is missing' do + it 'returns 404 if file is missing' do @document2.file.purge get :download_zip, params: { ids: @document2.id } - expect(response).to have_http_status(404) + expect(response).to have_http_status(:not_found) end - it 'should return zip file if file is found' do + + it 'returns zip file if file is found' do allow(controller).to receive(:render) get :download_zip, params: { ids: @document2.id } expect(response.headers['Content-Type']).to eq 'application/zip' @@ -119,14 +121,14 @@ def get_public_documents end context 'multiple documents selected' do - it 'should return 404 if all files are missing' do + it 'returns 404 if all files are missing' do @document.file.purge @document2.file.purge get :download_zip, params: { ids: "#{@document.id},#{@document2.id}" } - expect(response).to have_http_status(404) + expect(response).to have_http_status(:not_found) end - it 'should return zip file if at least a file is found' do + it 'returns zip file if at least a file is found' do @document.file.purge get :download_zip, params: { ids: "#{@document.id},#{@document2.id}" } expect(response.headers['Content-Type']).to eq 'application/zip' @@ -134,7 +136,7 @@ def get_public_documents end context 'cascading documents logic' do - it 'should get subspecies documents' do + it 'gets subspecies documents' do get :index, params: { taxon_concepts_ids: [ @taxon_concept.id ] } expect(response.body).to have_json_size(3).at_path('documents') end diff --git a/spec/controllers/api/events_controller_spec.rb b/spec/controllers/api/events_controller_spec.rb index ae2cd49bf..6d330543f 100644 --- a/spec/controllers/api/events_controller_spec.rb +++ b/spec/controllers/api/events_controller_spec.rb @@ -2,11 +2,12 @@ describe Api::V1::EventsController do describe 'GET index' do - before(:each) do + before do @copX = create(:cites_cop, designation: cites, name: 'CoPX', published_at: '2015-11-01') @copY = create(:cites_cop, designation: cites, name: 'CoPY', published_at: '2015-11-02') create(:eu_regulation, designation: eu) end + it 'returns only E-library events most recent first' do get :index expect(response.body).to have_json_size(2).at_path('events') diff --git a/spec/controllers/api/geo_entities_controller_spec.rb b/spec/controllers/api/geo_entities_controller_spec.rb index 22931ab95..bed3b896b 100644 --- a/spec/controllers/api/geo_entities_controller_spec.rb +++ b/spec/controllers/api/geo_entities_controller_spec.rb @@ -34,11 +34,13 @@ designations: [ cites ] ) end + describe 'GET index' do it 'returns regions' do get :index, params: { geo_entity_types_set: '1' } expect(response.body).to have_json_size(1).at_path('geo_entities') end + it 'returns countries & territories' do get :index, params: { geo_entity_types_set: '2' } expect(response.body).to have_json_size(3).at_path('geo_entities') diff --git a/spec/controllers/api/purposes_controller_spec.rb b/spec/controllers/api/purposes_controller_spec.rb index b15f2d695..8083b7992 100644 --- a/spec/controllers/api/purposes_controller_spec.rb +++ b/spec/controllers/api/purposes_controller_spec.rb @@ -2,9 +2,10 @@ describe Api::V1::PurposesController do describe 'GET index' do - before(:each) do + before do create(:purpose) end + it 'returns purposes' do get :index expect(response.body).to have_json_size(1).at_path('purposes') diff --git a/spec/controllers/api/sources_controller_spec.rb b/spec/controllers/api/sources_controller_spec.rb index 7c1cedb5c..9876a12a5 100644 --- a/spec/controllers/api/sources_controller_spec.rb +++ b/spec/controllers/api/sources_controller_spec.rb @@ -2,9 +2,10 @@ describe Api::V1::SourcesController do describe 'GET index' do - before(:each) do + before do create(:source) end + it 'returns sources' do get :index expect(response.body).to have_json_size(1).at_path('sources') diff --git a/spec/controllers/api/taxon_concepts_controller_spec.rb b/spec/controllers/api/taxon_concepts_controller_spec.rb index 7ba8bca1e..54e910579 100644 --- a/spec/controllers/api/taxon_concepts_controller_spec.rb +++ b/spec/controllers/api/taxon_concepts_controller_spec.rb @@ -8,7 +8,7 @@ expect do get :index, params: { taxonomy: 'cites_eu', taxon_concept_query: 'stork', geo_entity_scope: 'cites', page: 1 } end.to change { Ahoy::Event.count }.by(1) - expect(Ahoy::Event.last.visit_id).to_not be(nil) + expect(Ahoy::Event.last.visit_id).not_to be_nil expect do get :index, params: { taxonomy: 'cites_eu', taxon_concept_query: 'dolphin', geo_entity_scope: 'cites', page: 1 } diff --git a/spec/controllers/api/terms_controller_spec.rb b/spec/controllers/api/terms_controller_spec.rb index 8e1d24e8b..e42137b11 100644 --- a/spec/controllers/api/terms_controller_spec.rb +++ b/spec/controllers/api/terms_controller_spec.rb @@ -2,9 +2,10 @@ describe Api::V1::TermsController do describe 'GET index' do - before(:each) do + before do create(:term) end + it 'returns terms' do get :index expect(response.body).to have_json_size(1).at_path('terms') diff --git a/spec/controllers/api/units_controller_spec.rb b/spec/controllers/api/units_controller_spec.rb index 34dd8adbb..d6fd7457c 100644 --- a/spec/controllers/api/units_controller_spec.rb +++ b/spec/controllers/api/units_controller_spec.rb @@ -2,9 +2,10 @@ describe Api::V1::UnitsController do describe 'GET index' do - before(:each) do + before do create(:unit) end + it 'returns units' do get :index expect(response.body).to have_json_size(1).at_path('units') diff --git a/spec/controllers/checklist/geo_entities_controller_spec.rb b/spec/controllers/checklist/geo_entities_controller_spec.rb index ee4d98cdc..0c27341ae 100644 --- a/spec/controllers/checklist/geo_entities_controller_spec.rb +++ b/spec/controllers/checklist/geo_entities_controller_spec.rb @@ -34,11 +34,13 @@ designations: [ cites ] ) end + describe 'GET index' do it 'returns regions' do get :index, params: { geo_entity_types_set: '1' } expect(response.body).to have_json_size(1) end + it 'returns countries & territories' do get :index, params: { geo_entity_types_set: '2' } expect(response.body).to have_json_size(3) diff --git a/spec/controllers/checklist/taxon_concepts_controller_spec.rb b/spec/controllers/checklist/taxon_concepts_controller_spec.rb index 3cc56b72f..1ab4791ed 100644 --- a/spec/controllers/checklist/taxon_concepts_controller_spec.rb +++ b/spec/controllers/checklist/taxon_concepts_controller_spec.rb @@ -9,6 +9,7 @@ expect(response.body).to have_json_size(1) end end + context 'when query blank' do it 'returns 0 results' do get :autocomplete, format: 'json', xhr: true diff --git a/spec/controllers/cites_trade/exports_controller_spec.rb b/spec/controllers/cites_trade/exports_controller_spec.rb index c651571e9..751fa379d 100644 --- a/spec/controllers/cites_trade/exports_controller_spec.rb +++ b/spec/controllers/cites_trade/exports_controller_spec.rb @@ -11,6 +11,7 @@ expect(parse_json(response.body)['total']).to eq(1) end end + context 'comptab' do it 'returns comptab shipments file' do create(:shipment) @@ -21,6 +22,7 @@ expect(response.content_type).to eq('text/csv') expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"shipments.csv\"; filename*=UTF-8''shipments.csv") end + it 'logs download information from public interface to the TradeDataDownload model' do create(:shipment) allow_any_instance_of(Trade::ShipmentsExport).to receive(:public_file_name).and_return('shipments.csv') @@ -38,10 +40,12 @@ end.to change(Trade::TradeDataDownload, :count).by(1) end end + context 'when shipments cannot be retrieved' do - before(:each) do + before do allow_any_instance_of(Trade::ShipmentsExport).to receive(:export).and_return(false) end + it 'redirects to home page' do get :download, params: { filters: { report_type: :comptab } } expect(response).to redirect_to(cites_trade_root_url) diff --git a/spec/controllers/cites_trade/shipments_controller_spec.rb b/spec/controllers/cites_trade/shipments_controller_spec.rb index 7729bcb4f..e30856ebf 100644 --- a/spec/controllers/cites_trade/shipments_controller_spec.rb +++ b/spec/controllers/cites_trade/shipments_controller_spec.rb @@ -4,9 +4,10 @@ include_context 'Shipments' describe 'GET index' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + context 'serializer' do - it 'should return comptab export when report_type invalid' do + it 'returns comptab export when report_type invalid' do get :index, params: { filters: { report_type: 'raw' @@ -14,7 +15,8 @@ } expect(response.body).to have_json_path('shipment_comptab_export') end - it 'should return comptab export when report_type = comptab' do + + it 'returns comptab export when report_type = comptab' do get :index, params: { filters: { report_type: 'comptab' @@ -22,7 +24,8 @@ } expect(response.body).to have_json_path('shipment_comptab_export') end - it 'should return gross net export when report_type = gross_exports' do + + it 'returns gross net export when report_type = gross_exports' do get :index, params: { filters: { report_type: 'gross_exports' @@ -32,12 +35,12 @@ end end - it 'should return all comptab shipments' do + it 'returns all comptab shipments' do get :index, format: :json expect(response.body).to have_json_size(7).at_path('shipment_comptab_export/rows') end - it 'should return all gross_exports shipments' do + it 'returns all gross_exports shipments' do get :index, params: { filters: { report_type: 'gross_exports', @@ -48,7 +51,7 @@ expect(response.body).to have_json_size(5).at_path('shipment_gross_net_export/rows') end - it 'should treat params.$key as params.filters.$key' do + it 'treats params.$key as params.filters.$key' do get :index, params: { report_type: 'gross_exports', time_range_start: 2012, @@ -59,13 +62,13 @@ expect(response.body).to have_json_size(5).at_path('shipment_gross_net_export/rows') end - it 'should not throw an error if filters is the empty string' do + it 'does not throw an error if filters is the empty string' do get :index, params: { filters: '' }, format: :json expect(response.body).to have_json_size(7).at_path('shipment_comptab_export/rows') end - it 'should return genus & species shipments when searching by genus' do + it 'returns genus & species shipments when searching by genus' do get :index, params: { filters: { taxon_concepts_ids: [ @animal_genus.id ], @@ -75,7 +78,7 @@ expect(response.body).to have_json_size(2).at_path('shipment_comptab_export/rows') end - it 'should return family, genus & species shipments when searching by family' do + it 'returns family, genus & species shipments when searching by family' do get :index, params: { filters: { taxon_concepts_ids: [ @animal_family.id ], @@ -85,7 +88,7 @@ expect(response.body).to have_json_size(3).at_path('shipment_comptab_export/rows') end - it 'should return genus shipments when searching by taxon' do + it 'returns genus shipments when searching by taxon' do get :index, params: { filters: { taxon_concepts_ids: [ @animal_genus.id ], diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index 33c479832..15e823bcb 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -2,14 +2,16 @@ describe PagesController do describe 'GET eu_legislation' do - before(:each) do + before do @ar1 = create_eu_regulation(effective_at: '2014-09-01') @ar2 = create_eu_regulation(effective_at: '2014-09-02') end + it 'assigns annex regulations sorted by effective_at' do get :eu_legislation expect(assigns(:eu_annex_regulations)).to eq([ @ar2, @ar1 ]) end + it 'assigns suspension regulations' do get :eu_legislation expect(assigns(:eu_suspension_regulations)).not_to be_nil diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 467372373..dbaaa6734 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe RegistrationsController do - before(:each) do + before do @u1 = create( :user, password: '11111111', password_confirmation: '11111111' @@ -10,8 +10,9 @@ @u3 = build(:user) @request.env['devise.mapping'] = Devise.mappings[:user] end + context 'when editing own account' do - it 'should update name' do + it 'updates name' do sign_in(@u1) put :update, params: { id: @u1.id, user: { @@ -21,7 +22,8 @@ expect(response).to redirect_to(admin_root_url) expect(@u1.reload.name).to eq('ZZ') end - it 'should update password' do + + it 'updates password' do sign_in(@u1) put :update, params: { id: @u1.id, user: { @@ -33,7 +35,8 @@ expect(response).to redirect_to(admin_root_url) expect(@u1.reload.valid_password?('22222222')).to eq(true) end - it 'should not update that account if not valid' do + + it 'does not update that account if not valid' do sign_in(@u1) put :update, params: { id: @u1.id, user: { @@ -46,7 +49,7 @@ end context "when editing another user's account" do - it 'should not update that account' do + it 'does not update that account' do sign_in(@u1) put :update, params: { id: @u2.id, user: { @@ -58,7 +61,7 @@ end context 'when signing up' do - it 'should create an account with the role set to api' do + it 'creates an account with the role set to api' do expect do post :create, params: { user: { diff --git a/spec/controllers/species/exports_controller_spec.rb b/spec/controllers/species/exports_controller_spec.rb index cea68bc20..2dd5c53ce 100644 --- a/spec/controllers/species/exports_controller_spec.rb +++ b/spec/controllers/species/exports_controller_spec.rb @@ -4,9 +4,10 @@ context 'when data type and filters not given' do it 'returns unprocessable entity status' do get :download - expect(response).to have_http_status(422) + expect(response).to have_http_status(:unprocessable_entity) end end + context 'with ip address to csv separator conversion' do it 'sets separator to comma with local ip address' do allow_any_instance_of(ActionDispatch::Request).to receive(:remote_ip).and_return('127.0.0.1') @@ -16,7 +17,7 @@ } } - expect(response.cookies['speciesplus.csv_separator']).to_not be_nil + expect(response.cookies['speciesplus.csv_separator']).not_to be_nil expect(response.cookies['speciesplus.csv_separator']).to eq('comma') expect(assigns(:filters)[:csv_separator]).to eq(:comma) end @@ -29,7 +30,7 @@ 'set' => 'current', 'decision_types' => {}, :csv_separator => '' } } - expect(response.cookies['speciesplus.csv_separator']).to_not be_nil + expect(response.cookies['speciesplus.csv_separator']).not_to be_nil expect(response.cookies['speciesplus.csv_separator']).to eq('comma') expect(assigns(:filters)[:csv_separator]).to eq(:comma) end @@ -42,7 +43,7 @@ 'set' => 'current', 'decision_types' => {}, :csv_separator => '' } } - expect(response.cookies['speciesplus.csv_separator']).to_not be_nil + expect(response.cookies['speciesplus.csv_separator']).not_to be_nil expect(response.cookies['speciesplus.csv_separator']).to eq('semicolon') expect(assigns(:filters)[:csv_separator]).to eq(:semicolon) end @@ -54,7 +55,7 @@ 'set' => 'current', 'decision_types' => {}, :csv_separator => 'comma' } } - expect(response.cookies['speciesplus.csv_separator']).to_not be_nil + expect(response.cookies['speciesplus.csv_separator']).not_to be_nil expect(response.cookies['speciesplus.csv_separator']).to eq('comma') expect(assigns(:filters)[:csv_separator]).to eq(:comma) end @@ -66,7 +67,7 @@ 'set' => 'current', 'decision_types' => {}, :csv_separator => '' } } - expect(response.cookies['speciesplus.csv_separator']).to_not be_nil + expect(response.cookies['speciesplus.csv_separator']).not_to be_nil expect(response.cookies['speciesplus.csv_separator']).to eq('comma') expect(assigns(:filters)[:csv_separator]).to eq(:comma) end @@ -78,7 +79,7 @@ 'set' => 'current', 'decision_types' => {}, :csv_separator => '' } } - expect(response.cookies['speciesplus.csv_separator']).to_not be_nil + expect(response.cookies['speciesplus.csv_separator']).not_to be_nil expect(response.cookies['speciesplus.csv_separator']).to eq('comma') expect(assigns(:filters)[:csv_separator]).to eq(:comma) end diff --git a/spec/controllers/trade/annual_report_uploads_controller_spec.rb b/spec/controllers/trade/annual_report_uploads_controller_spec.rb index e28ff1bb7..40208c3d4 100644 --- a/spec/controllers/trade/annual_report_uploads_controller_spec.rb +++ b/spec/controllers/trade/annual_report_uploads_controller_spec.rb @@ -11,10 +11,6 @@ iso_code2: 'FR' ) end - def exporter_csv - test_document = Rails.root.join('spec/support/annual_report_upload_exporter.csv').to_s - Rack::Test::UploadedFile.new(test_document, 'text/csv') - end let(:annual_report_upload) do create( :annual_report_upload, @@ -23,8 +19,14 @@ def exporter_csv csv_source_file: exporter_csv ) end + + def exporter_csv + test_document = Rails.root.join('spec/support/annual_report_upload_exporter.csv').to_s + Rack::Test::UploadedFile.new(test_document, 'text/csv') + end + describe 'GET index' do - before(:each) do + before do cites_eu @aru = build(:annual_report_upload) @aru.save(validate: false) @@ -32,25 +34,27 @@ def exporter_csv @completed_aru.save(validate: false) @completed_aru.update(submitted_at: Time.now) end - it 'should return all annual report uploads' do + + it 'returns all annual report uploads' do get :index, format: :json expect(response.body).to have_json_size(2).at_path('annual_report_uploads') end - it 'should return annual report uploads in progress' do + + it 'returns annual report uploads in progress' do get :index, params: { is_done: 0, format: :json } expect(response.body).to have_json_size(1).at_path('annual_report_uploads') end end describe 'GET show' do - it 'should return success' do + it 'returns success' do get :show, params: { id: annual_report_upload.id, format: :json } expect(response.body).to have_json_path('annual_report_upload') end end describe 'POST create' do - it 'should return success in jQuery File Upload way' do + it 'returns success in jQuery File Upload way' do post :create, params: { annual_report_upload: { point_of_view: 'E', trading_country_id: france.id, @@ -59,7 +63,8 @@ def exporter_csv }, xhr: true, format: 'json' expect(parse_json(response.body, 'files/0')['id']).not_to be_blank end - it 'should return error in jQuery File Upload way' do + + it 'returns error in jQuery File Upload way' do post :create, params: { annual_report_upload: { point_of_view: 'I', trading_country_id: france.id, diff --git a/spec/controllers/trade/exports_controller_spec.rb b/spec/controllers/trade/exports_controller_spec.rb index 0e3956fe1..2afa69504 100644 --- a/spec/controllers/trade/exports_controller_spec.rb +++ b/spec/controllers/trade/exports_controller_spec.rb @@ -10,6 +10,7 @@ get :download, params: { filters: { report_type: 'raw' }, format: :json } expect(parse_json(response.body)['total']).to eq(1) end + it 'does not log download information from the admin interface' do create(:shipment) allow_any_instance_of(Trade::ShipmentsExport).to receive(:public_file_name).and_return('shipments.csv') @@ -25,10 +26,12 @@ end.not_to change(Trade::TradeDataDownload, :count) end end + context 'when shipments cannot be retrieved' do - before(:each) do + before do allow_any_instance_of(Trade::ShipmentsExport).to receive(:export).and_return(false) end + it 'redirects to home page' do get :download, params: { filters: { report_type: :comptab } } expect(response).to redirect_to(trade_root_url) diff --git a/spec/controllers/trade/shipments_controller_spec.rb b/spec/controllers/trade/shipments_controller_spec.rb index c44d579e6..2cc5be52f 100644 --- a/spec/controllers/trade/shipments_controller_spec.rb +++ b/spec/controllers/trade/shipments_controller_spec.rb @@ -6,25 +6,28 @@ include_context 'Shipments' describe 'GET index' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } - it 'should return all shipments' do + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + + it 'returns all shipments' do get :index, format: :json expect(response.body).to have_json_size(7).at_path('shipments') end - it 'should return genus & species shipments when searching by genus' do + + it 'returns genus & species shipments when searching by genus' do get :index, params: { taxon_concepts_ids: [ @animal_genus.id ], format: :json } expect(response.body).to have_json_size(2).at_path('shipments') end - it 'should return 1 shipment when searching for reporter_type I' do + it 'returns 1 shipment when searching for reporter_type I' do get :index, params: { time_range_start: @shipment1.year, time_range_end: @shipment2.year, reporter_type: 'E', exporters_ids: [ @portugal.id.to_s ], format: :json } expect(response.body).to have_json_size(1).at_path('shipments') end end describe 'PUT update' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } - it 'should auto resolve accepted taxon when blank' do + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + + it 'autoes resolve accepted taxon when blank' do put :update, params: { id: @shipment1.id, shipment: { reported_taxon_concept_id: @synonym_subspecies.id @@ -32,7 +35,8 @@ } expect(@shipment1.reload.taxon_concept_id).to eq(@plant_species.id) end - it 'should not auto resolve accepted taxon when given' do + + it 'does not auto resolve accepted taxon when given' do put :update, params: { id: @shipment1.id, shipment: { reported_taxon_concept_id: @synonym_subspecies.id, @@ -41,7 +45,8 @@ } expect(@shipment1.reload.taxon_concept_id).to eq(@animal_species.id) end - it 'should delete orphaned permits' do + + it 'deletes orphaned permits' do put :update, params: { id: @shipment1.id, shipment: { import_permit_number: 'YYY' @@ -52,8 +57,9 @@ end describe 'POST update_batch' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } - it 'should change reporter type from I to E' do + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + + it 'changes reporter type from I to E' do post :update_batch, params: { filters: { # shipment2 time_range_start: @shipment1.year, @@ -69,7 +75,8 @@ expect(@shipment1.reported_by_exporter).to be_truthy expect(@shipment2.reload.reported_by_exporter).to be_truthy end - it 'should change reporter type from E to I' do + + it 'changes reporter type from E to I' do post :update_batch, params: { filters: { # shipment1 time_range_start: @shipment1.year, @@ -86,7 +93,7 @@ expect(@shipment2.reported_by_exporter).to be_falsey end - it 'should update year' do + it 'updates year' do post :update_batch, params: { filters: { # shipment1 time_range_start: @shipment1.year, @@ -102,7 +109,7 @@ expect(Trade::Shipment.where(year: 2014).count).to be > 0 end - it 'should auto resolve accepted taxon when blank' do + it 'autoes resolve accepted taxon when blank' do post :update_batch, params: { filters: { # shipment1 time_range_start: @shipment1.year, @@ -117,7 +124,7 @@ expect(@shipment1.reload.taxon_concept_id).to eq(@plant_species.id) end - it 'should not auto resolve accepted taxon when given' do + it 'does not auto resolve accepted taxon when given' do post :update_batch, params: { filters: { # shipment1 time_range_start: @shipment1.year, @@ -133,7 +140,7 @@ expect(@shipment1.reload.taxon_concept_id).to eq(@animal_species.id) end - it 'should set permit number to blank and delete orphaned permits' do + it 'sets permit number to blank and delete orphaned permits' do post :update_batch, params: { filters: { # shipment1 time_range_start: @shipment1.year, @@ -152,57 +159,59 @@ end describe 'POST destroy_batch' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } - it 'should delete 1 shipment' do + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + + it 'deletes 1 shipment' do post :destroy_batch, params: { time_range_start: @shipment1.year, time_range_end: @shipment2.year, reporter_type: 'E', exporters_ids: [ @portugal.id.to_s, @argentina.id.to_s ], importers_ids: [ @portugal.id.to_s, @argentina.id.to_s ], taxon_concepts_ids: [ @animal_species.id ] } expect(Trade::Shipment.count).to eq(6) end - it 'should delete 5 shipment' do + + it 'deletes 5 shipment' do post :destroy_batch, params: { time_range_start: @shipment1.year, time_range_end: @shipment2.year, reporter_type: 'I', exporters_ids: [ @portugal.id.to_s, @argentina.id.to_s ], importers_ids: [ @portugal.id.to_s, @argentina.id.to_s ] } expect(Trade::Shipment.count).to eq(2) end - it 'should delete 2 shipments' do + it 'deletes 2 shipments' do post :destroy_batch, params: { importers_ids: [ @argentina.id.to_s ] } expect(Trade::Shipment.count).to eq(5) end - it 'should delete 1 shipments' do + it 'deletes 1 shipments' do post :destroy_batch, params: { exporters_ids: [ @portugal.id.to_s ] } expect(Trade::Shipment.count).to eq(5) end - it 'should delete all shipments' do + it 'deletes all shipments' do post :destroy_batch, params: { purposes_ids: [ @purpose.id.to_s ] } expect(Trade::Shipment.count).to eq(0) end - it "shouldn't delete any shipments" do + it 'does not delete any shipments' do post :destroy_batch, params: { purpose_blank: 'true' } expect(Trade::Shipment.count).to eq(7) end - it 'should delete 1 shipment' do + it 'deletes 1 shipment' do post :destroy_batch, params: { sources_ids: [ @source.id.to_s ] } expect(Trade::Shipment.count).to eq(5) end - it 'should delete 3 shipment' do + it 'deletes 3 shipment' do post :destroy_batch, params: { sources_ids: [ @source_wild.id.to_s ] } expect(Trade::Shipment.count).to eq(4) end - it 'should delete 0 shipments' do + it 'deletes 0 shipments' do post :destroy_batch, params: { sources_ids: [ @source_wild.id.to_s ], reporter_type: 'E' } expect(Trade::Shipment.count).to eq(7) end - it 'should delete 4 shipments' do + it 'deletes 4 shipments' do post :destroy_batch, params: { sources_ids: [ @source_wild.id.to_s ], reporter_type: 'I', source_blank: 'true' } expect(Trade::Shipment.count).to eq(3) end - it 'should delete orphaned permits' do + it 'deletes orphaned permits' do post :destroy_batch, params: { time_range_start: @shipment1.year, time_range_end: @shipment2.year, year: 2013, exporters_ids: [ @portugal.id.to_s, @argentina.id.to_s ], importers_ids: [ @portugal.id.to_s, @argentina.id.to_s ] } expect(Trade::Shipment.find_by(id: @shipment1.id)).to be_nil expect(Trade::Permit.find_by(id: @import_permit.id)).to be_nil @@ -210,12 +219,14 @@ end describe 'DELETE destroy' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } - it 'should delete 1 shipment' do + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + + it 'deletes 1 shipment' do delete :destroy, params: { id: @shipment1.id } expect(Trade::Shipment.where(id: @shipment1.id)).to be_empty end - it 'should delete orphaned permits' do + + it 'deletes orphaned permits' do delete :destroy, params: { id: @shipment1.id } expect(Trade::Permit.find_by(id: @import_permit.id)).to be_nil end diff --git a/spec/controllers/trade/validation_errors_controller_spec.rb b/spec/controllers/trade/validation_errors_controller_spec.rb index 6721c2d74..7a86af47e 100644 --- a/spec/controllers/trade/validation_errors_controller_spec.rb +++ b/spec/controllers/trade/validation_errors_controller_spec.rb @@ -31,7 +31,7 @@ end describe 'PUT update' do - it 'should update is_ignored' do + it 'updates is_ignored' do put :update, params: { id: validation_error.id, validation_error: { is_ignored: true @@ -42,7 +42,7 @@ end describe 'GET show' do - it 'should return success' do + it 'returns success' do get :show, params: { id: validation_error.id, format: :json } expect(response.body).to have_json_path('validation_error') end diff --git a/spec/controllers/trade/validation_rules_controller_spec.rb b/spec/controllers/trade/validation_rules_controller_spec.rb index e06a18562..103796c9b 100644 --- a/spec/controllers/trade/validation_rules_controller_spec.rb +++ b/spec/controllers/trade/validation_rules_controller_spec.rb @@ -4,7 +4,7 @@ login_admin describe 'GET index' do - it 'should return success' do + it 'returns success' do get :index, format: :json expect(response).to be_successful end diff --git a/spec/factories.rb b/spec/factories.rb index 3b063617b..ee7aef8c3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -34,19 +34,19 @@ published_at { '2011-02-01' } designation - factory :eu_regulation, class: EuRegulation do + factory :eu_regulation, class: 'EuRegulation' do end_date { '2012-01-01' } end - factory :eu_suspension_regulation, class: EuSuspensionRegulation - factory :eu_implementing_regulation, class: EuImplementingRegulation - factory :eu_council_regulation, class: EuCouncilRegulation - factory :cites_cop, class: CitesCop - factory :cites_ac, class: CitesAc - factory :cites_pc, class: CitesPc - factory :cites_tc, class: CitesTc - factory :cites_extraordinary_meeting, class: CitesExtraordinaryMeeting - factory :ec_srg, class: EcSrg - factory :cites_suspension_notification, class: CitesSuspensionNotification, + factory :eu_suspension_regulation, class: 'EuSuspensionRegulation' + factory :eu_implementing_regulation, class: 'EuImplementingRegulation' + factory :eu_council_regulation, class: 'EuCouncilRegulation' + factory :cites_cop, class: 'CitesCop' + factory :cites_ac, class: 'CitesAc' + factory :cites_pc, class: 'CitesPc' + factory :cites_tc, class: 'CitesTc' + factory :cites_extraordinary_meeting, class: 'CitesExtraordinaryMeeting' + factory :ec_srg, class: 'EcSrg' + factory :cites_suspension_notification, class: 'CitesSuspensionNotification', aliases: [ :start_notification ] do end_date { '2012-01-01' } end @@ -100,11 +100,11 @@ geo_entity eu_decision_type - factory :eu_opinion, class: EuOpinion do + factory :eu_opinion, class: 'EuOpinion' do start_date { Date.new(2013, 1, 1) } end - factory :eu_suspension, class: EuSuspension + factory :eu_suspension, class: 'EuSuspension' end factory :eu_decision_type do @@ -112,12 +112,12 @@ decision_type { 'NO_OPINION' } end - factory :ahoy_event, class: Ahoy::Event do + factory :ahoy_event, class: 'Ahoy::Event' do id { SecureRandom.uuid } user end - factory :ahoy_visit, class: Ahoy::Visit do + factory :ahoy_visit, class: 'Ahoy::Visit' do id { SecureRandom.uuid } user end diff --git a/spec/factories/document_tag.rb b/spec/factories/document_tag.rb index 34fc945b2..ce2ecccd3 100644 --- a/spec/factories/document_tag.rb +++ b/spec/factories/document_tag.rb @@ -1,13 +1,13 @@ FactoryBot.define do factory :document_tag do name { 'You taaaag' } - factory :review_phase, class: DocumentTag::ReviewPhase do + factory :review_phase, class: 'DocumentTag::ReviewPhase' do type { 'DocumentTag::ReviewPhase' } end - factory :process_stage, class: DocumentTag::ProcessStage do + factory :process_stage, class: 'DocumentTag::ProcessStage' do type { 'DocumentTag::ProcessStage' } end - factory :proposal_outcome, class: DocumentTag::ProposalOutcome do + factory :proposal_outcome, class: 'DocumentTag::ProposalOutcome' do type { 'DocumentTag::ProposalOutcome' } end end diff --git a/spec/factories/documents.rb b/spec/factories/documents.rb index 6bc56ffe3..28c5c96fa 100644 --- a/spec/factories/documents.rb +++ b/spec/factories/documents.rb @@ -7,13 +7,13 @@ type { 'Document' } is_public { false } - factory :review_of_significant_trade, class: Document::ReviewOfSignificantTrade do + factory :review_of_significant_trade, class: 'Document::ReviewOfSignificantTrade' do type { 'Document::ReviewOfSignificantTrade' } end - factory :proposal, class: Document::Proposal do + factory :proposal, class: 'Document::Proposal' do type { 'Document::Proposal' } end - factory :commission_note, class: Document::CommissionNotes do + factory :commission_note, class: 'Document::CommissionNotes' do type { 'Document::CommissionNotes' } end @@ -41,12 +41,12 @@ geo_entity end - factory :proposal_details, class: ProposalDetails do + factory :proposal_details, class: 'ProposalDetails' do document proposal_outcome end - factory :review_details, class: ReviewDetails do + factory :review_details, class: 'ReviewDetails' do document review_phase end diff --git a/spec/factories/nomenclature_changes.rb b/spec/factories/nomenclature_changes.rb index 9ff37f982..64601669e 100644 --- a/spec/factories/nomenclature_changes.rb +++ b/spec/factories/nomenclature_changes.rb @@ -4,36 +4,36 @@ status { 'new' } type { 'NomenclatureChange' } - factory :nomenclature_change_split, class: NomenclatureChange::Split do + factory :nomenclature_change_split, class: 'NomenclatureChange::Split' do type { 'NomenclatureChange::Split' } end - factory :nomenclature_change_lump, class: NomenclatureChange::Lump do + factory :nomenclature_change_lump, class: 'NomenclatureChange::Lump' do type { 'NomenclatureChange::Lump' } end - factory :nomenclature_change_status_swap, class: NomenclatureChange::StatusSwap do + factory :nomenclature_change_status_swap, class: 'NomenclatureChange::StatusSwap' do type { 'NomenclatureChange::StatusSwap' } end - factory :nomenclature_change_status_to_accepted, class: NomenclatureChange::StatusToAccepted do + factory :nomenclature_change_status_to_accepted, class: 'NomenclatureChange::StatusToAccepted' do type { 'NomenclatureChange::StatusToAccepted' } end - factory :nomenclature_change_status_to_synonym, class: NomenclatureChange::StatusToSynonym do + factory :nomenclature_change_status_to_synonym, class: 'NomenclatureChange::StatusToSynonym' do type { 'NomenclatureChange::StatusToSynonym' } end end - factory :nomenclature_change_input, class: NomenclatureChange::Input, + factory :nomenclature_change_input, class: 'NomenclatureChange::Input', aliases: [ :input ] do nomenclature_change taxon_concept end - factory :nomenclature_change_output, class: NomenclatureChange::Output, + factory :nomenclature_change_output, class: 'NomenclatureChange::Output', aliases: [ :output ] do nomenclature_change taxon_concept end - factory :nomenclature_change_reassignment, class: NomenclatureChange::Reassignment, + factory :nomenclature_change_reassignment, class: 'NomenclatureChange::Reassignment', aliases: [ :reassignment ] do input type { 'NomenclatureChange::Reassignment' } @@ -58,7 +58,7 @@ end end - factory :nomenclature_change_output_reassignment, class: NomenclatureChange::OutputReassignment, + factory :nomenclature_change_output_reassignment, class: 'NomenclatureChange::OutputReassignment', aliases: [ :output_reassignment ] do output type { 'NomenclatureChange::OutputReassignment' } @@ -80,7 +80,7 @@ end end - factory :nomenclature_change_reassignment_target, class: NomenclatureChange::ReassignmentTarget do + factory :nomenclature_change_reassignment_target, class: 'NomenclatureChange::ReassignmentTarget' do reassignment output end diff --git a/spec/factories/trade.rb b/spec/factories/trade.rb index aa629ab04..ec361adc8 100644 --- a/spec/factories/trade.rb +++ b/spec/factories/trade.rb @@ -1,61 +1,61 @@ FactoryBot.define do factory :trade_code do - factory :source, class: Source do + factory :source, class: 'Source' do sequence(:code) { |n| (97 + (n % 26)).chr } sequence(:name_en) { |n| 'Source @{n}' } end - factory :purpose, class: Purpose do + factory :purpose, class: 'Purpose' do sequence(:code) { |n| (97 + (n % 26)).chr } sequence(:name_en) { |n| 'Purpose @{n}' } end - factory :term, class: Term do + factory :term, class: 'Term' do sequence(:code) { |n| [ n, n + 1, n + 2 ].map { |i| (97 + (i % 26)).chr }.join } sequence(:name_en) { |n| 'Term @{n}' } end - factory :unit, class: Unit do + factory :unit, class: 'Unit' do sequence(:code) { |n| [ n, n + 1, n + 2 ].map { |i| (97 + (i % 26)).chr }.join } sequence(:name_en) { |n| 'Unit @{n}' } end end - factory :annual_report_upload, class: Trade::AnnualReportUpload do + factory :annual_report_upload, class: 'Trade::AnnualReportUpload' do trading_country point_of_view { 'E' } end - factory :validation_rule, class: Trade::ValidationRule do + factory :validation_rule, class: 'Trade::ValidationRule' do column_names { [ 'taxon_name' ] } run_order { 1 } - factory :presence_validation_rule, class: Trade::PresenceValidationRule - factory :numericality_validation_rule, class: Trade::NumericalityValidationRule - factory :format_validation_rule, class: Trade::FormatValidationRule do + factory :presence_validation_rule, class: 'Trade::PresenceValidationRule' + factory :numericality_validation_rule, class: 'Trade::NumericalityValidationRule' + factory :format_validation_rule, class: 'Trade::FormatValidationRule' do format_re { '^\w+$' } end - factory :inclusion_validation_rule, class: Trade::InclusionValidationRule do + factory :inclusion_validation_rule, class: 'Trade::InclusionValidationRule' do valid_values_view { 'valid_taxon_concept_view' } end factory :taxon_concept_appendix_year_validation_rule, - class: Trade::TaxonConceptAppendixYearValidationRule do + class: 'Trade::TaxonConceptAppendixYearValidationRule' do column_names { [ 'taxon_concept_id', 'appendix', 'year' ] } valid_values_view { 'valid_taxon_concept_appendix_year_mview' } end factory :distinct_values_validation_rule, - class: Trade::DistinctValuesValidationRule + class: 'Trade::DistinctValuesValidationRule' factory :taxon_concept_source_validation_rule, - class: Trade::TaxonConceptSourceValidationRule + class: 'Trade::TaxonConceptSourceValidationRule' end - factory :validation_error, class: Trade::ValidationError do + factory :validation_error, class: 'Trade::ValidationError' do annual_report_upload validation_rule matching_criteria { } is_ignored { false } end - factory :trade_taxon_concept_term_pair, class: Trade::TaxonConceptTermPair do + factory :trade_taxon_concept_term_pair, class: 'Trade::TaxonConceptTermPair' do taxon_concept term end @@ -65,7 +65,7 @@ trade_code end - factory :shipment, class: Trade::Shipment do + factory :shipment, class: 'Trade::Shipment' do taxon_concept term unit @@ -79,7 +79,7 @@ ignore_warnings { true } end - factory :permit, class: Trade::Permit do + factory :permit, class: 'Trade::Permit' do sequence(:number) { |n| "Permit #{n}" } end end diff --git a/spec/helpers/admin/nomenclature_changes_helper_spec.rb b/spec/helpers/admin/nomenclature_changes_helper_spec.rb index 0874cbe32..c1065961b 100644 --- a/spec/helpers/admin/nomenclature_changes_helper_spec.rb +++ b/spec/helpers/admin/nomenclature_changes_helper_spec.rb @@ -14,41 +14,56 @@ describe 'split_blurb' do include_context 'split_definitions' context 'split with input' do - before(:each) { @nomenclature_change = split_with_input } + before { @nomenclature_change = split_with_input } + specify { expect(helper.split_blurb).to match(@nomenclature_change.input.taxon_concept.full_name) } end + context 'split with outputs' do - before(:each) { @nomenclature_change = split_with_input_and_output } + before { @nomenclature_change = split_with_input_and_output } + specify { expect(helper.split_blurb).to match(@nomenclature_change.outputs.first.taxon_concept.full_name) } end + context 'split with output new taxon' do - before(:each) { @nomenclature_change = split_with_input_and_output_new_taxon } + before { @nomenclature_change = split_with_input_and_output_new_taxon } + specify { expect(helper.split_blurb).to match(@nomenclature_change.outputs.first.display_full_name) } end end + describe 'lump_blurb' do include_context 'lump_definitions' context 'lump with inputs' do - before(:each) { @nomenclature_change = lump_with_inputs } + before { @nomenclature_change = lump_with_inputs } + specify { expect(helper.lump_blurb).to match(@nomenclature_change.inputs.first.taxon_concept.full_name) } end + context 'lump with output' do - before(:each) { @nomenclature_change = lump_with_inputs_and_output } + before { @nomenclature_change = lump_with_inputs_and_output } + specify { expect(helper.lump_blurb).to match(@nomenclature_change.output.taxon_concept.full_name) } end + context 'lump with output new taxon' do - before(:each) { @nomenclature_change = lump_with_inputs_and_output_new_taxon } + before { @nomenclature_change = lump_with_inputs_and_output_new_taxon } + specify { expect(helper.lump_blurb).to match(@nomenclature_change.output.display_full_name) } end end + describe 'status_change_blurb' do include_context 'status_change_definitions' context 'status upgrade with primary output' do - before(:each) { @nomenclature_change = t_to_a_with_primary_output } + before { @nomenclature_change = t_to_a_with_primary_output } + specify { expect(helper.status_change_blurb).to match(@nomenclature_change.primary_output.taxon_concept.full_name) } end + context 'status upgrade with swap' do - before(:each) { @nomenclature_change = a_to_s_with_swap } + before { @nomenclature_change = a_to_s_with_swap } + specify { expect(helper.status_change_blurb).to match(@nomenclature_change.secondary_output.taxon_concept.full_name) } end end diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb index 0617597b2..fcd0a3234 100644 --- a/spec/helpers/admin_helper_spec.rb +++ b/spec/helpers/admin_helper_spec.rb @@ -16,15 +16,18 @@ expect(helper.edit_icon).to eq('') end end + describe 'delete_icon' do it 'ouputs bin icon for delete' do expect(helper.delete_icon).to eq('') end end + describe 'true_false_icon' do it 'outputs tick icon for true' do expect(helper.true_false_icon(true)).to eq('') end + it 'outputs blank for false' do expect(helper.true_false_icon(false)).to be_blank end diff --git a/spec/helpers/listing_changes_helper_spec.rb b/spec/helpers/listing_changes_helper_spec.rb index 3081f35c9..566125da8 100644 --- a/spec/helpers/listing_changes_helper_spec.rb +++ b/spec/helpers/listing_changes_helper_spec.rb @@ -51,10 +51,12 @@ is_party: false ) end + it 'outputs all geo entities comma separated' do expect(helper.geo_entities_tooltip(listing_change)).to eq('Poland') end end + describe 'annotation_tooltip' do it 'outputs the regular annotation in both short and long English form' do expect(helper.annotation_tooltip(listing_change)).to eq( @@ -62,6 +64,7 @@ ) end end + describe 'hash_annotation_tooltip' do it 'outputs the hash annotation in long English form' do expect(helper.hash_annotation_tooltip(listing_change)).to eq( @@ -69,9 +72,10 @@ ) end end + describe 'excluded_geo_entities_tooltip' do context 'no exclusions' do - it 'should output blank exception' do + it 'outputs blank exception' do expect(helper.excluded_geo_entities_tooltip(listing_change)).to be_blank end end @@ -91,11 +95,13 @@ is_party: false ) end - it 'should list geographic exception' do + + it 'lists geographic exception' do expect(helper.excluded_geo_entities_tooltip(listing_change)).to eq('Poland') end end end + describe 'excluded_taxon_concepts_tooltip' do let(:child_taxon_concept) do create_cites_eu_species( @@ -103,8 +109,9 @@ taxon_name: create(:taxon_name, scientific_name: 'cracovianus') ) end + context 'no exclusions' do - it 'should output blank exception' do + it 'outputs blank exception' do expect(helper.excluded_taxon_concepts_tooltip(listing_change)).to be_blank end end @@ -116,7 +123,8 @@ parent_id: listing_change.id ) end - it 'should list taxonomic exception' do + + it 'lists taxonomic exception' do expect(helper.excluded_taxon_concepts_tooltip(listing_change)).to eq('Foobarus cracovianus') end end diff --git a/spec/integration/login_spec.rb b/spec/integration/login_spec.rb index 9905524fc..e14b24392 100644 --- a/spec/integration/login_spec.rb +++ b/spec/integration/login_spec.rb @@ -6,16 +6,19 @@ post '/users/sign_in', params: { user: { email: user.email, password: user.password } } assert_redirected_to admin_root_path end + it 'redirects Data Contributor to admin root path' do user = create(:user, role: User::CONTRIBUTOR) post '/users/sign_in', params: { user: { email: user.email, password: user.password } } assert_redirected_to admin_root_path end + it 'redirects E-library Viewer to public root path' do user = create(:user, role: User::ELIBRARY_USER) post '/users/sign_in', params: { user: { email: user.email, password: user.password } } assert_redirected_to root_path end + it 'redirects API User to public root path' do user = create(:user, role: User::API_USER) post '/users/sign_in', params: { user: { email: user.email, password: user.password } } diff --git a/spec/models/annotation_spec.rb b/spec/models/annotation_spec.rb index 8c0052add..856fce472 100644 --- a/spec/models/annotation_spec.rb +++ b/spec/models/annotation_spec.rb @@ -9,6 +9,7 @@ :annotation, parent_symbol: 'CoP1', symbol: '#1a' ) end + specify { expect(annotation).to have(1).errors_on(:symbol) } end end @@ -19,28 +20,37 @@ let(:annotation) do create(:annotation, parent_symbol: 'CoP1', symbol: '#1') end + specify { annotation.full_symbol == 'CoP1#1' } end + context 'when event given' do let(:event) { create_cites_cop(name: 'CoP1') } let(:annotation) do create(:annotation, event_id: event.id, symbol: '#1') end + specify { annotation.full_symbol == 'CoP1#1' } end end + describe :destroy do let(:annotation) { create(:annotation) } + context 'when no dependent objects attached' do specify { expect(annotation.destroy).to be_truthy } end + context 'when dependent objects attached' do context 'when listing changes' do let!(:listing_change) { create_cites_I_addition(annotation_id: annotation.id) } + specify { expect(annotation.destroy).to be_falsey } end + context 'when hashed listing changes' do let!(:listing_change) { create_cites_I_addition(hash_annotation_id: annotation.id) } + specify { expect(annotation.destroy).to be_falsey } end end diff --git a/spec/models/api_request_spec.rb b/spec/models/api_request_spec.rb index 3e9c65862..640548bac 100644 --- a/spec/models/api_request_spec.rb +++ b/spec/models/api_request_spec.rb @@ -5,7 +5,7 @@ create(:user, role: 'api') end - before(:each) do + before do create( :api_request, user_id: api_user.id, @@ -34,6 +34,7 @@ subject do ApiRequest.top_50_most_active_users end + specify do expect(subject.first.user_id).to eq(api_user.id) end @@ -43,6 +44,7 @@ subject do ApiRequest.recent_requests end + specify do expect(subject).to eq( { @@ -59,6 +61,7 @@ subject do ApiRequest.requests_by_response_status end + specify do expect(subject).to eq( { @@ -77,6 +80,7 @@ subject do ApiRequest.requests_by_controller end + specify do expect(subject).to eq( { diff --git a/spec/models/change_type_spec.rb b/spec/models/change_type_spec.rb index cb4bc6381..9f01b996d 100644 --- a/spec/models/change_type_spec.rb +++ b/spec/models/change_type_spec.rb @@ -4,11 +4,13 @@ describe :abbreviation do context 'change type with single word name' do let(:change_type) { create(:change_type, name: 'Word') } + specify { expect(change_type.abbreviation).to eq('Wor') } end context 'change type with two words name' do let(:change_type) { create(:change_type, name: 'Word_Word') } + specify { expect(change_type.abbreviation).to eq('Wor-Wor') } end end diff --git a/spec/models/common_name_spec.rb b/spec/models/common_name_spec.rb index ab52c7bfa..cb509ea82 100644 --- a/spec/models/common_name_spec.rb +++ b/spec/models/common_name_spec.rb @@ -3,13 +3,15 @@ describe CommonName do context 'Generating PDF' do describe :english_to_pdf do - it 'should print last word before the first word, separated by comma' do + it 'prints last word before the first word, separated by comma' do expect(CommonName.english_to_pdf('Grey Wolf')).to eq('Wolf, Grey') end - it 'should print the last word before the other words, separated by comma' do + + it 'prints the last word before the other words, separated by comma' do expect(CommonName.english_to_pdf('Northern Rock Mountain Wolf')).to eq('Wolf, Northern Rock Mountain') end - it 'should print the single word, if the common name is composed of only one word' do + + it 'prints the single word, if the common name is composed of only one word' do expect(CommonName.english_to_pdf('Wolf')).to eq('Wolf') end end diff --git a/spec/models/designation_spec.rb b/spec/models/designation_spec.rb index 476a45afa..bed328181 100644 --- a/spec/models/designation_spec.rb +++ b/spec/models/designation_spec.rb @@ -4,23 +4,30 @@ describe :create do context 'when valid' do let(:designation) { build(:designation, name: 'GALACTIC REGULATIONS') } + specify { expect(designation).to be_valid } end + context 'when name missing' do let(:designation) { build(:designation, name: nil) } + specify { expect(designation).not_to be_valid } specify { expect(designation).to have(1).error_on(:name) } end + context 'when name duplicated' do let!(:designation1) { create(:designation) } let(:designation2) { build(:designation, name: designation1.name) } + specify { expect(designation2).not_to be_valid } specify { expect(designation2).to have(1).error_on(:name) } end end + describe :update do context 'when updating a non-protected name' do let(:designation) { create(:designation) } + specify do expect( designation.update( @@ -29,6 +36,7 @@ ).to be_truthy end end + context 'when updating a protected name' do specify do expect( @@ -38,28 +46,37 @@ ).to be_falsey end end + context 'when updating taxonomy with no dependent objects attached' do let(:designation) { create(:designation) } let(:taxonomy) { create(:taxonomy) } + specify { expect(designation.update(taxonomy_id: taxonomy.id)).to be_truthy } end + context 'when updating taxonomy with dependent objects attached' do let(:designation) { create(:designation) } let!(:change_type) { create(:change_type, designation: designation) } let(:taxonomy) { create(:taxonomy) } + specify { expect(designation.update(taxonomy_id: taxonomy.id)).to be_falsey } end end + describe :destroy do context 'when no dependent objects attached' do let(:designation) { create(:designation, name: 'GALACTIC REGULATIONS') } + specify { expect(designation.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:designation) { create(:designation, name: 'GALACTIC REGULATIONS') } let!(:change_type) { create(:change_type, designation: designation) } + specify { expect(designation.destroy).to be_falsey } end + context 'when protected name' do specify { expect(cites.destroy).to be_falsey } end diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb index 4a59620e2..b45453775 100644 --- a/spec/models/document_spec.rb +++ b/spec/models/document_spec.rb @@ -9,20 +9,26 @@ date: nil ) end + specify { expect(document).not_to be_valid } specify { expect(document).to have(1).error_on(:date) } end + context 'setting title from filename' do let(:document) { create(:document) } + specify { expect(document.title).to eq('Annual report upload exporter') } end + context 'when specified designation conflicts with event' do let(:cites_cop) { create_cites_cop } let(:document) do create(:document, event: cites_cop, designation: eu) end + specify { expect(document.designation).to eq(cites) } end + context 'when documents with same language and same primary document' do let(:language) { create(:language) } let(:primary_document) { create(:document) } @@ -56,12 +62,14 @@ primary_language_document_id: primary_document.id ) end + context 'when primary document sort_index_updated' do specify 'secondary document sort_index is in sync' do primary_document.update(sort_index: 3) expect(secondary_document.reload.sort_index).to eq(3) end end + context 'when secondary document sort_index_updated' do specify 'primary document sort_index is in sync' do secondary_document.update(sort_index: 3) @@ -77,6 +85,7 @@ let!(:secondary_document) do create(:proposal, primary_language_document_id: primary_document.id) end + context 'when secondary document destroyed' do specify 'document count decreases by 1' do expect do @@ -84,12 +93,14 @@ end.to change { Document.count }.by(-1) end end + context 'when primary document destroyed' do specify 'document count decreases by 1' do expect do primary_document.destroy end.to change { Document.count }.by(-1) end + specify 'secondary document becomes primary' do primary_document.destroy expect(secondary_document.primary_language_document).to be_nil diff --git a/spec/models/eu_decision_spec.rb b/spec/models/eu_decision_spec.rb index 733cb4c35..164d55ebc 100644 --- a/spec/models/eu_decision_spec.rb +++ b/spec/models/eu_decision_spec.rb @@ -35,7 +35,9 @@ describe :create do context 'downloads cache should be populated' do - before(:each) do + subject { Dir["#{DownloadsCache.eu_decisions_path}/*"] } + + before do DownloadsCache.clear_eu_decisions create( @@ -51,21 +53,23 @@ ).export end - subject { Dir["#{DownloadsCache.eu_decisions_path}/*"] } + specify { expect(subject).not_to be_empty } end end describe :save do context "Eu decision type and SRG history can't be blank at the same time" do - let(:eu_decision) { build(:eu_decision, srg_history_id: nil, eu_decision_type_id: nil) } subject { eu_decision.save } + let(:eu_decision) { build(:eu_decision, srg_history_id: nil, eu_decision_type_id: nil) } + + specify { expect(subject).to be_falsey } - it 'should have an error message' do + it 'has an error message' do subject - expect(eu_decision.errors[:base]).to_not be_empty + expect(eu_decision.errors[:base]).not_to be_empty end end @@ -90,7 +94,9 @@ describe :destroy do context 'downloads cache should be cleared' do - before(:each) do + subject { Dir["#{DownloadsCache.eu_decisions_path}/*"] } + + before do DownloadsCache.clear_eu_decisions d = create(:eu_decision, start_date: Time.utc(2013)) Species::EuDecisionsExport.new(set: 'current', decision_types: {}).export @@ -98,7 +104,7 @@ Species::EuDecisionsExport.new(set: 'current', decision_types: {}).export end - subject { Dir["#{DownloadsCache.eu_decisions_path}/*"] } + specify { expect(subject).to be_empty } end end diff --git a/spec/models/eu_decisions/eu_opinion_spec.rb b/spec/models/eu_decisions/eu_opinion_spec.rb index d98f05237..f150a546d 100644 --- a/spec/models/eu_decisions/eu_opinion_spec.rb +++ b/spec/models/eu_decisions/eu_opinion_spec.rb @@ -65,6 +65,7 @@ before do @eu_regulation = create(:ec_srg) end + let(:eu_opinion) { build(:eu_opinion, start_event: @eu_regulation) } specify { expect(eu_opinion).to be_valid } diff --git a/spec/models/eu_decisions/eu_suspension_spec.rb b/spec/models/eu_decisions/eu_suspension_spec.rb index 7b1584dd4..4dc44952d 100644 --- a/spec/models/eu_decisions/eu_suspension_spec.rb +++ b/spec/models/eu_decisions/eu_suspension_spec.rb @@ -135,7 +135,7 @@ specify { expect(eu_suspension.is_current).to be_falsey } end - context 'when start_event is set, and end_event is set with date in the future' do + context 'when start_event is set, and end_event is set with date in the future' do let(:end_event) do create(:event, effective_at: 1.day.from_now) end @@ -149,7 +149,7 @@ specify { expect(eu_suspension.is_current).to be_truthy } end - context 'when start_event is set, and end_event is set with date in the past' do + context 'when start_event is set, and end_event is set with date in the past' do let(:end_event) do create(:event, effective_at: 1.day.ago) end @@ -169,6 +169,7 @@ let(:eu_suspension) do create(:eu_suspension, start_event: nil) end + specify { expect(eu_suspension.start_date_formatted).to be_empty } end @@ -179,6 +180,7 @@ let(:start_event) do create(:event, effective_at: 2.days.ago) end + specify { expect(eu_suspension.start_date_formatted).to eq(2.days.ago.strftime('%d/%m/%Y')) } end end @@ -188,6 +190,7 @@ let(:eu_suspension) do create(:eu_suspension, end_event: nil) end + specify { expect(eu_suspension.end_date_formatted).to be_empty } end @@ -198,6 +201,7 @@ let(:end_event) do create(:event, effective_at: 2.days.ago) end + specify { expect(eu_suspension.end_date_formatted).to eq(2.days.ago.strftime('%d/%m/%Y')) } end end diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 875d7cd6d..add4e0169 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -4,21 +4,28 @@ describe :create do context 'when valid' do let(:event) { build(:event, name: 'CoPX') } + specify { expect(event).to be_valid } end + context 'when name missing' do let(:event) { build(:event, name: nil) } + specify { expect(event).not_to be_valid } specify { expect(event).to have(1).error_on(:name) } end + context 'when name duplicated' do let!(:event1) { create(:event) } let(:event2) { build(:event, name: event1.name) } + specify { expect(event2).not_to be_valid } specify { expect(event2).to have(1).error_on(:name) } end + context 'when url invalid' do let(:event) { build(:event, url: 'www.google.com') } + specify { expect(event).not_to be_valid } specify { expect(event).to have(1).error_on(:url) } end @@ -26,6 +33,7 @@ describe :effective_at_formatted do let(:event) { create(:event, effective_at: '2012-05-10') } + specify { expect(event.effective_at_formatted).to eq('10/05/2012') } end end diff --git a/spec/models/events/cites_cop_spec.rb b/spec/models/events/cites_cop_spec.rb index 6d98295e7..f1ff4cae6 100644 --- a/spec/models/events/cites_cop_spec.rb +++ b/spec/models/events/cites_cop_spec.rb @@ -34,9 +34,11 @@ designation: eu ) end + specify { expect(cites_cop).not_to be_valid } specify { expect(cites_cop).to have(1).error_on(:designation_id) } end + context 'when effective_at is blank' do let(:cites_cop) do build( @@ -44,6 +46,7 @@ effective_at: nil ) end + specify { expect(cites_cop).not_to be_valid } specify { expect(cites_cop).to have(1).error_on(:effective_at) } end @@ -63,6 +66,7 @@ # listing changes are deleted. context 'when listing changes exist' do let!(:listing_change) { create_cites_I_addition(event: cites_cop) } + specify { expect(cites_cop.destroy).to be_falsey } end diff --git a/spec/models/events/cites_suspension_notification_spec.rb b/spec/models/events/cites_suspension_notification_spec.rb index aae512439..56e802c84 100644 --- a/spec/models/events/cites_suspension_notification_spec.rb +++ b/spec/models/events/cites_suspension_notification_spec.rb @@ -34,9 +34,11 @@ designation: eu ) end + specify { expect(cites_suspension_notification).not_to be_valid } specify { expect(cites_suspension_notification).to have(1).error_on(:designation_id) } end + context 'when effective_at is blank' do let(:cites_suspension_notification) do build( @@ -44,6 +46,7 @@ effective_at: nil ) end + specify { expect(cites_suspension_notification).not_to be_valid } specify { expect(cites_suspension_notification).to have(1).error_on(:effective_at) } end @@ -51,9 +54,11 @@ describe :destroy do let(:cites_suspension_notification) { create_cites_suspension_notification } + context 'when no dependent objects attached' do specify { expect(cites_suspension_notification.destroy).to be_truthy } end + context 'when dependent objects attached' do context 'when start notification' do let!(:cites_suspension) do @@ -61,8 +66,10 @@ :cites_suspension, start_notification: cites_suspension_notification ) end + specify { expect(cites_suspension_notification.destroy).to be_falsey } end + context 'when end notification' do let!(:cites_suspension) do create( @@ -71,9 +78,13 @@ end_notification: cites_suspension_notification ) end + specify { expect(cites_suspension_notification.destroy).to be_falsey } end + context 'when confirmation notification, make sure it gets destroyed' do + subject { cites_suspension_notification.cites_suspension_confirmations } + let!(:cites_suspension) do # Ideally we would create this in a single statement but on upgrading # from rails 4.0 to 4.1 this started failing - the joining table @@ -92,7 +103,8 @@ suspension end - subject { cites_suspension_notification.cites_suspension_confirmations } + + specify do cites_suspension_notification.destroy expect(subject.reload).to be_empty @@ -103,14 +115,18 @@ describe :end_date_formatted do let(:cites_suspension_notification) { create_cites_suspension_notification(end_date: '2012-05-10') } + specify { expect(cites_suspension_notification.end_date_formatted).to eq('10/05/2012') } end describe :bases_for_suspension do + subject { CitesSuspensionNotification.bases_for_suspension } + let!(:cites_suspension_notification1) { create_cites_suspension_notification(subtype: 'A') } let!(:cites_suspension_notification2) { create_cites_suspension_notification(subtype: 'A') } let!(:cites_suspension_notification3) { create_cites_suspension_notification(subtype: 'B') } - subject { CitesSuspensionNotification.bases_for_suspension } + + specify { subject.length == 2 } end end diff --git a/spec/models/events/eu_regulation_spec.rb b/spec/models/events/eu_regulation_spec.rb index 7899b2d43..5f1bf890b 100644 --- a/spec/models/events/eu_regulation_spec.rb +++ b/spec/models/events/eu_regulation_spec.rb @@ -29,12 +29,15 @@ describe :create do context 'when eu_regulation to copy from given' do let(:eu_regulation1) { create_eu_regulation } + before do EventListingChangesCopyWorker.jobs.clear create_eu_regulation(listing_changes_event_id: eu_regulation1.id) end + specify { expect(EventListingChangesCopyWorker.jobs.size).to eq(1) } end + context 'when designation invalid' do let(:eu_regulation) do build( @@ -42,9 +45,11 @@ designation: cites ) end + specify { expect(eu_regulation).not_to be_valid } specify { expect(eu_regulation).to have(1).error_on(:designation_id) } end + context 'when effective_at is blank' do let(:eu_regulation) do build( @@ -52,26 +57,32 @@ effective_at: nil ) end + specify { expect(eu_regulation).not_to be_valid } specify { expect(eu_regulation).to have(1).error_on(:effective_at) } end end + describe :activate do let(:eu_regulation) { create_eu_regulation(name: 'REGULATION 2.0') } + before do EuRegulationActivationWorker.jobs.clear eu_regulation.activate! end + specify { expect(eu_regulation.is_current).to be_truthy } specify { expect(EuRegulationActivationWorker.jobs.size).to eq(1) } end describe :deactivate do let(:eu_regulation) { create_eu_regulation(name: 'REGULATION 2.0', is_current: true) } + before do EuRegulationActivationWorker.jobs.clear eu_regulation.deactivate! end + specify { expect(eu_regulation.is_current).to be_falsey } specify { expect(EuRegulationActivationWorker.jobs.size).to eq(1) } end @@ -90,6 +101,7 @@ # listing changes are deleted. context 'when listing changes' do let!(:listing_change) { create_eu_A_addition(event: eu_regulation) } + specify { expect(eu_regulation.destroy).to be_truthy } end diff --git a/spec/models/geo_entity_spec.rb b/spec/models/geo_entity_spec.rb index ae6ed4955..449519c8f 100644 --- a/spec/models/geo_entity_spec.rb +++ b/spec/models/geo_entity_spec.rb @@ -24,7 +24,10 @@ name: 'Wolin' ) end + context 'Europe should contain Europe, Poland and Wolin' do + subject { GeoEntity.nodes_and_descendants([ europe.id ]) } + let!(:poland_contains_wolin) do create( :geo_relationship, @@ -41,36 +44,49 @@ related_geo_entity: poland ) end - subject { GeoEntity.nodes_and_descendants([ europe.id ]) } + + specify { expect(subject.map(&:id)).to include(europe.id, poland.id, wolin.id) } specify { expect(subject.size).to eq(3) } end end + describe :destroy do let(:geo_entity) { create(:geo_entity) } + context 'when no dependent objects attached' do specify { expect(geo_entity.destroy).to be_truthy } end + context 'when dependent objects attached' do context 'when distributions' do - before(:each) { create(:distribution, geo_entity: geo_entity) } + before { create(:distribution, geo_entity: geo_entity) } + specify { expect(geo_entity.destroy).to be_falsey } end + context 'when exported shipments' do - before(:each) { create(:shipment, exporter: geo_entity) } + before { create(:shipment, exporter: geo_entity) } + specify { expect(geo_entity.destroy).to be_falsey } end + context 'when imported shipments' do - before(:each) { create(:shipment, importer: geo_entity) } + before { create(:shipment, importer: geo_entity) } + specify { expect(geo_entity.destroy).to be_falsey } end + context 'when originated shipments' do - before(:each) { create(:shipment, country_of_origin: geo_entity) } + before { create(:shipment, country_of_origin: geo_entity) } + specify { expect(geo_entity.destroy).to be_falsey } end + context 'when connected geo entities' do let(:child_geo_entity) { create(:geo_entity) } - before(:each) do + + before do create( :geo_relationship, geo_relationship_type: contains_geo_relationship_type, @@ -78,6 +94,7 @@ related_geo_entity: child_geo_entity ) end + specify { expect(geo_entity.destroy).to be_falsey } end end diff --git a/spec/models/html_to_latex_spec.rb b/spec/models/html_to_latex_spec.rb index fbcf1c821..f33ca2b1c 100644 --- a/spec/models/html_to_latex_spec.rb +++ b/spec/models/html_to_latex_spec.rb @@ -3,41 +3,53 @@ describe HtmlToLatex do describe :convert do subject { HtmlToLatex.convert(input_str) } + context 'when italics' do context 'when tag closed' do let(:input_str) { 'Text about Foobarus lolus and friends' } + specify do expect(subject).to eq('Text about \\textit{Foobarus lolus} and friends') end end + context 'when tag not closed' do let(:input_str) { 'Text about Foobarus lolus and friends' } + specify do expect(subject).to eq('Text about \\textit{Foobarus lolus and friends}') end end end + context 'when paragraph' do context 'when tag closed' do let(:input_str) { 'Text,

paragraph

and some more text' } + specify do expect(subject).to eq('Text, \\newline paragraph\\newline and some more text') end end + context 'when tag not closed' do let(:input_str) { 'Text,

paragraph and some more text' } + specify do expect(subject).to eq('Text, \\newline paragraph and some more text') end end end + context 'when latex special characters' do context 'within tags' do let(:input_str) { 'Lolus & friends' } + specify { expect(subject).to eq('\\textbf{Lolus \\& friends}') } end + context 'outside of tags' do let(:input_str) { 'Lolus & friends' } + specify { expect(subject).to eq('\\textbf{Lolus} \\& friends') } end end diff --git a/spec/models/hybrid_relationship_spec.rb b/spec/models/hybrid_relationship_spec.rb index c0dd66716..98b66eb85 100644 --- a/spec/models/hybrid_relationship_spec.rb +++ b/spec/models/hybrid_relationship_spec.rb @@ -50,10 +50,12 @@ other_taxon_concept_id: hybrid.id ) end + specify do hybrid_rel.save expect(tc.hybrids.map(&:full_name)).to include('Lolcatus lolatus x lolcatus') end + specify do hybrid_rel.save another_hybrid_rel.save diff --git a/spec/models/listing_change_spec.rb b/spec/models/listing_change_spec.rb index e8de5c4de..cc8fd8806 100644 --- a/spec/models/listing_change_spec.rb +++ b/spec/models/listing_change_spec.rb @@ -16,8 +16,10 @@ excluded_taxon_concepts_ids: "#{excluded_taxon_concept.id}" ) end + specify { expect(listing_change).to be_valid } end + context 'inclusion taxon concept is lower rank' do let(:inclusion) { create_cites_eu_subspecies } let(:taxon_concept) { create_cites_eu_species } @@ -28,8 +30,10 @@ inclusion_taxon_concept_id: inclusion.id ) end + specify { expect(listing_change.error_on(:inclusion_taxon_concept_id).size).to eq(1) } end + context 'species listing designation mismatch' do let(:designation1) { create(:designation) } let(:designation2) { create(:designation) } @@ -40,8 +44,10 @@ change_type: create(:change_type, designation: designation2) ) end + specify { expect(listing_change.error_on(:species_listing_id).size).to eq(1) } end + context 'event designation mismatch' do let(:designation1) { create(:designation) } let(:designation2) { create(:designation) } @@ -52,12 +58,15 @@ change_type: create(:change_type, designation: designation2) ) end + specify { expect(listing_change.error_on(:event_id).size).to eq(1) } end end end + describe :effective_at_formatted do let(:listing_change) { create_cites_I_addition(effective_at: '2012-05-10') } + specify { expect(listing_change.effective_at_formatted).to eq('10/05/2012') } end @@ -72,6 +81,7 @@ lc.annotation = create(:annotation, full_note_en: nil) lc end + specify { lc1.duplicates(taxon_concept_id: lc2.taxon_concept_id) } end end diff --git a/spec/models/nomenclature_change/input_spec.rb b/spec/models/nomenclature_change/input_spec.rb index 4dc3f0c92..b1e80320c 100644 --- a/spec/models/nomenclature_change/input_spec.rb +++ b/spec/models/nomenclature_change/input_spec.rb @@ -6,12 +6,15 @@ let(:input) do build(:nomenclature_change_input, nomenclature_change_id: nil) end + specify { expect(input).not_to be_valid } end + context 'when taxon concept not specified' do let(:input) do build(:nomenclature_change_input, taxon_concept_id: nil) end + specify { expect(input).not_to be_valid } end end diff --git a/spec/models/nomenclature_change/lump_spec.rb b/spec/models/nomenclature_change/lump_spec.rb index 9a9d966f0..8bfcce4f1 100644 --- a/spec/models/nomenclature_change/lump_spec.rb +++ b/spec/models/nomenclature_change/lump_spec.rb @@ -9,17 +9,21 @@ :nomenclature_change_lump, status: NomenclatureChange::Lump::INPUTS ) end + specify { expect(lump).to have(1).errors_on(:inputs) } end + context 'when submitting' do let(:lump) do build( :nomenclature_change_lump, status: NomenclatureChange::Lump::SUBMITTED ) end + specify { expect(lump).to have(1).errors_on(:inputs) } end end + context 'when required outputs missing' do context 'when outputs' do let(:lump) do @@ -27,16 +31,20 @@ :nomenclature_change_lump, status: NomenclatureChange::Lump::OUTPUTS ) end + specify { expect(lump).to have(1).errors_on(:output) } end + context 'when submitting' do let(:lump) do build( :nomenclature_change_lump, status: NomenclatureChange::Lump::SUBMITTED ) end + specify { expect(lump).to have(1).errors_on(:output) } end + context 'when only 1 input' do let(:lump) do build( @@ -44,10 +52,12 @@ inputs_attributes: { 0 => { taxon_concept_id: create_cites_eu_subspecies.id } } ) end + specify { expect(lump.errors_on(:inputs).size).to eq(1) } end end end + describe :new_output_rank do let(:lump) do build( @@ -59,6 +69,7 @@ status: NomenclatureChange::Lump::INPUTS ) end + specify { expect(lump.new_output_rank.name).to eq(Rank::SPECIES) } end end diff --git a/spec/models/nomenclature_change/output_reassignment_spec.rb b/spec/models/nomenclature_change/output_reassignment_spec.rb index 01adc84b8..64895f016 100644 --- a/spec/models/nomenclature_change/output_reassignment_spec.rb +++ b/spec/models/nomenclature_change/output_reassignment_spec.rb @@ -9,14 +9,17 @@ nomenclature_change_output_id: nil ) end + specify { expect(reassignment).not_to be_valid } end + context 'when reassignable_type not specified' do let(:reassignment) do build( :nomenclature_change_output_reassignment, reassignable_type: nil ) end + specify { expect(reassignment).not_to be_valid } end end diff --git a/spec/models/nomenclature_change/output_spec.rb b/spec/models/nomenclature_change/output_spec.rb index fa3d436d5..7888fbfed 100644 --- a/spec/models/nomenclature_change/output_spec.rb +++ b/spec/models/nomenclature_change/output_spec.rb @@ -1,14 +1,17 @@ require 'spec_helper' describe NomenclatureChange::Output do - before(:each) { cites_eu } + before { cites_eu } + describe :validate do context 'when nomenclature change not specified' do let(:output) do build(:nomenclature_change_output, nomenclature_change_id: nil) end + specify { expect(output).not_to be_valid } end + context 'when taxon concept not specified and new taxon concept attributes not specified' do let(:output) do build( @@ -19,12 +22,14 @@ new_name_status: nil ) end + specify { expect(output).to have(1).errors_on(:new_scientific_name) } specify { expect(output).to have(1).errors_on(:new_parent_id) } specify { expect(output).to have(1).errors_on(:new_rank) } specify { expect(output).to have(1).errors_on(:new_name_status) } specify { expect(output).to have(1).errors_on(:new_taxon_concept) } end + context 'when new taxon concept invalid' do let(:output) do build( @@ -35,13 +40,16 @@ new_name_status: 'A' ) end + specify { expect(output.error_on(:new_parent_id).size).to eq(1) } end + context 'when taxon concept specified' do let(:tc) { create_cites_eu_species } let(:output) do create(:nomenclature_change_output, taxon_concept_id: tc.id) end + specify { expect(output.parent_id).to eq(tc.parent_id) } specify { expect(output.rank_id).to eq(tc.rank_id) } specify { expect(output.scientific_name).to eq(tc.full_name) } @@ -49,6 +57,7 @@ specify { expect(output.name_status).to eq(tc.name_status) } end end + describe :expected_parent_name do let(:output) do create(:nomenclature_change_output, taxon_concept_id: tc.id) @@ -87,20 +96,28 @@ parent: magnolia_species ) end + context 'when genus' do let(:tc) { canis_genus } + specify { expect(output.expected_parent_name).to be_nil } end + context 'when species' do let(:tc) { canis_species } + specify { expect(output.expected_parent_name).to eq('Canis') } end + context 'when subspecies' do let(:tc) { canis_subspecies } + specify { expect(output.expected_parent_name).to eq('Canis lupus') } end + context 'when variety' do let(:tc) { magnolia_variety } + specify { expect(output.expected_parent_name).to eq('Magnolia liliifera') } end end diff --git a/spec/models/nomenclature_change/reassignment_spec.rb b/spec/models/nomenclature_change/reassignment_spec.rb index 1409d8b6e..0326a0d7d 100644 --- a/spec/models/nomenclature_change/reassignment_spec.rb +++ b/spec/models/nomenclature_change/reassignment_spec.rb @@ -9,14 +9,17 @@ nomenclature_change_input_id: nil ) end + specify { expect(reassignment).not_to be_valid } end + context 'when reassignable_type not specified' do let(:reassignment) do build( :nomenclature_change_reassignment, reassignable_type: nil ) end + specify { expect(reassignment).not_to be_valid } end end diff --git a/spec/models/nomenclature_change/reassignment_target_spec.rb b/spec/models/nomenclature_change/reassignment_target_spec.rb index 48cbc9426..ffac71e6b 100644 --- a/spec/models/nomenclature_change/reassignment_target_spec.rb +++ b/spec/models/nomenclature_change/reassignment_target_spec.rb @@ -9,8 +9,10 @@ nomenclature_change_reassignment_id: nil ) end + specify { expect(reassignment_target).not_to be_valid } end + context 'when output not specified' do let(:reassignment_target) do build( @@ -18,6 +20,7 @@ nomenclature_change_output_id: nil ) end + specify { expect(reassignment_target).not_to be_valid } end end diff --git a/spec/models/nomenclature_change/shared/common_name_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/common_name_reassignments_constructor_examples.rb index 5fd15cd9b..eaa7fc8d1 100644 --- a/spec/models/nomenclature_change/shared/common_name_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/common_name_reassignments_constructor_examples.rb @@ -3,21 +3,25 @@ context 'when no common names' do specify { expect(input.reassignments.size).to eq(0) } end + context 'when common names' do let(:input_species) do s = create_cites_eu_species 2.times { create(:taxon_common, taxon_concept: s) } s end + specify { expect(input.reassignments.size).to eq(1) } end end + context 'when previously reassignments in place' do let(:input) do i = create(:nomenclature_change_input, nomenclature_change: nc, taxon_concept: input_species) create(:nomenclature_change_reassignment, input: i) i end + specify { expect(input.reassignments).to eq(@old_reassignments) } end end diff --git a/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb index 8c3d2046e..155adcf63 100644 --- a/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb @@ -13,9 +13,10 @@ output: output ) end - before(:each) do + before do 2.times { create(:taxon_common, taxon_concept: input_species) } processor.run end + specify { expect(output_species1.common_names.count).to eq(2) } end diff --git a/spec/models/nomenclature_change/shared/distribution_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/distribution_reassignments_constructor_examples.rb index e122eeb38..393490065 100644 --- a/spec/models/nomenclature_change/shared/distribution_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/distribution_reassignments_constructor_examples.rb @@ -3,21 +3,25 @@ context 'when no distibutions' do specify { expect(input.distribution_reassignments.size).to eq(0) } end + context 'when distributions' do let(:input_species) do s = create_cites_eu_species 2.times { create(:distribution, taxon_concept: s) } s end + specify { expect(input.distribution_reassignments.size).to eq(2) } end end + context 'when previously reassignments in place' do let(:input) do i = create(:nomenclature_change_input, nomenclature_change: nc, taxon_concept: input_species) create(:nomenclature_change_distribution_reassignment, input: i) i end + specify { expect(input.distribution_reassignments).to eq(@old_reassignments) } end end diff --git a/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb index 2e650fc4b..4ec587ff3 100644 --- a/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb @@ -34,7 +34,7 @@ iso_code2: 'UK' ) end - before(:each) do + before do original_d = create( :distribution, taxon_concept: output_species1, @@ -75,10 +75,11 @@ create(:distribution, taxon_concept: input_species) processor.run end + specify { expect(output_species1.distributions.count).to eq(4) } specify { expect(output_species1.distributions.find_by(geo_entity_id: poland.id)).not_to be_nil } specify { expect(output_species1.distributions.find_by(geo_entity_id: poland.id).tag_list).to eq([]) } - specify { expect(output_species1.distributions.find_by(geo_entity_id: italy.id).tag_list).to match_array([ 'extinct', 'reintroduced' ]) } + specify { expect(output_species1.distributions.find_by(geo_entity_id: italy.id).tag_list).to contain_exactly('extinct', 'reintroduced') } specify { expect(output_species1.distributions.find_by(geo_entity_id: united_kingdom.id).tag_list).to eq([]) } specify { expect(output_species1.distributions.find_by(geo_entity_id: poland.id).distribution_references.count).to eq(2) } end diff --git a/spec/models/nomenclature_change/shared/document_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/document_reassignments_constructor_examples.rb index 5cd335b4f..d7d488f27 100644 --- a/spec/models/nomenclature_change/shared/document_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/document_reassignments_constructor_examples.rb @@ -3,6 +3,7 @@ context 'when no document citations' do specify { expect(input.document_citation_reassignments.size).to eq(0) } end + context 'when document citations' do let(:input_species) do s = create_cites_eu_species @@ -11,6 +12,7 @@ 2.times { create(:document_citation, taxon_concepts: [ s ], geo_entities: [ ge ]) } s end + specify { expect(input.document_citation_reassignments.size).to eq(2) } end end diff --git a/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb index df2ccf85b..ea49edc5e 100644 --- a/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb @@ -53,16 +53,17 @@ def create_citation(taxon_concepts_ary, geo_entities_ary, document = nil) end context 'when output species had no citations in place' do - before(:each) do + before do processor.run end + specify do expect(output_species1.document_citation_taxon_concepts.count).to eq(1) end end context 'when output species had an identical citation in place' do - before(:each) do + before do processor.run end diff --git a/spec/models/nomenclature_change/shared/legislation_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/legislation_reassignments_constructor_examples.rb index f7e9b4be3..e9f1787e0 100644 --- a/spec/models/nomenclature_change/shared/legislation_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/legislation_reassignments_constructor_examples.rb @@ -3,6 +3,7 @@ context 'when no CITES listings' do specify { expect(input.legislation_reassignments.size).to eq(0) } end + context 'when CITES listings' do let(:input_species) do s = create_cites_eu_species @@ -10,15 +11,18 @@ create_cites_II_addition(taxon_concept: s) s end + specify { expect(input.legislation_reassignments.size).to eq(1) } end end + context 'when previously reassignments in place' do let(:input) do i = create(:nomenclature_change_input, nomenclature_change: nc, taxon_concept: input_species) create(:nomenclature_change_legislation_reassignment, input: i) i end + specify { expect(input.legislation_reassignments).to eq(@old_reassignments) } end end diff --git a/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb index 554d5476d..7b5769e42 100644 --- a/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb @@ -13,7 +13,7 @@ iso_code2: 'PT' ) end - before(:each) do + before do lc1_annotation = create(:annotation) original_lc1 = create_cites_III_addition( taxon_concept: output_species1, @@ -101,13 +101,16 @@ ) processor.run end + specify { expect(output_species1.listing_changes.count).to eq(2) } + specify do expect( output_species1.listing_changes. find_by(effective_at: '2013-01-01', change_type_id: cites_addition.id) ).not_to be_nil end + specify do expect( output_species1.listing_changes. @@ -115,6 +118,7 @@ party_listing_distribution.geo_entity ).to eq(poland) end + specify do expect( output_species1.listing_changes. @@ -122,6 +126,7 @@ listing_distributions.count ).to eq(2) end + specify do expect( output_species1.listing_changes. @@ -129,6 +134,7 @@ annotation ).not_to be_nil end + specify do expect( output_species1.listing_changes. @@ -136,12 +142,14 @@ exclusions ).not_to be_empty end + specify do expect( output_species1.listing_changes. find_by(effective_at: '2013-01-02', change_type_id: cites_addition.id) ).not_to be_nil end + specify do expect( output_species1.listing_changes. @@ -149,13 +157,16 @@ party_listing_distribution.geo_entity ).to eq(portugal) end + specify { expect(output_species1.quotas.count).to eq(2) } + specify do expect( output_species1.quotas. find_by(geo_entity_id: poland.id) ).not_to be_nil end + specify do expect( output_species1.quotas. @@ -163,6 +174,7 @@ terms ).not_to be_empty end + specify do expect( output_species1.quotas. @@ -170,6 +182,7 @@ sources ).not_to be_empty end + specify do expect( output_species1.quotas. @@ -177,5 +190,6 @@ purposes ).not_to be_empty end + specify { expect(output_species1.cites_suspensions.count).to eq(2) } end diff --git a/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb index 0488fef7c..3c29cc5e4 100644 --- a/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb @@ -3,6 +3,7 @@ context 'when no names' do specify { expect(input.name_reassignments.size).to eq(0) } end + context 'when names' do let(:input_species) do s = create_cites_eu_species @@ -16,15 +17,18 @@ end s end + specify { expect(input.name_reassignments.size).to eq(2) } end end + context 'when previously reassignments in place' do let(:input) do i = create(:nomenclature_change_input, nomenclature_change: nc, taxon_concept: input_species) create(:nomenclature_change_name_reassignment, input: i) i end + specify { expect(input.name_reassignments).to eq(@old_reassignments) } end end diff --git a/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb index 30b3d6f39..153be994a 100644 --- a/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb @@ -24,8 +24,9 @@ output: output ) end - before(:each) do + before do processor.run end + specify { expect(output_species1.synonyms).to include(input_species_synonym) } end diff --git a/spec/models/nomenclature_change/shared/output_common_names_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_common_names_reassignments_processor_examples.rb index e8bde1193..f10d5b69f 100644 --- a/spec/models/nomenclature_change/shared/output_common_names_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_common_names_reassignments_processor_examples.rb @@ -1,5 +1,5 @@ shared_context 'output_common_name_reassignments_processor_examples' do - before(:each) do + before do create( :nomenclature_change_output_reassignment, output: output, @@ -9,6 +9,7 @@ output_processor.run processor.run end + specify { expect(new_output_species.common_names.count).to eq(2) } specify { expect(old_output_subspecies.common_names).to be_empty } end diff --git a/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb index a6145d0f2..53129eaa9 100644 --- a/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb @@ -6,7 +6,7 @@ iso_code2: 'PL' ) end - before(:each) do + before do create(:preset_tag, model: 'Distribution', name: 'extinct') d = create( :distribution, @@ -24,6 +24,7 @@ output_processor.run processor.run end + specify { expect(new_output_species.distributions.reload.count).to eq(2) } specify { expect(new_output_species.distributions.find_by(geo_entity_id: poland.id)).not_to be_nil } specify { expect(new_output_species.distributions.find_by(geo_entity_id: poland.id).tag_list).to eq([ 'extinct' ]) } diff --git a/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb index bacf49a20..76037cb13 100644 --- a/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb @@ -10,7 +10,7 @@ ) citation end - before(:each) do + before do create( :nomenclature_change_output_reassignment, output: output, @@ -20,6 +20,7 @@ output_processor.run processor.run end + specify { expect(new_output_species.document_citation_taxon_concepts.count).to eq(1) } specify { expect(old_output_subspecies.document_citation_taxon_concepts).to be_empty } end diff --git a/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb index 2af747ffc..72dd6b792 100644 --- a/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb @@ -13,7 +13,7 @@ iso_code2: 'PT' ) end - before(:each) do + before do lc1_annotation = create(:annotation) lc1 = create_cites_III_addition( taxon_concept: old_output_subspecies, @@ -67,13 +67,16 @@ output_processor.run processor.run end + specify { expect(new_output_species.listing_changes.count).to eq(2) } + specify do expect( new_output_species.listing_changes. find_by(effective_at: '2013-01-01', change_type_id: cites_addition.id) ).not_to be_nil end + specify do expect( new_output_species.listing_changes. @@ -81,13 +84,15 @@ party_listing_distribution.geo_entity ).to eq(poland) end + specify do expect( new_output_species.listing_changes. find_by(effective_at: '2013-01-01', change_type_id: cites_addition.id). listing_distributions - ).to_not be_empty + ).not_to be_empty end + specify do expect( new_output_species.listing_changes. @@ -95,12 +100,14 @@ annotation ).not_to be_nil end + specify do expect( new_output_species.listing_changes. find_by(effective_at: '2013-01-02', change_type_id: cites_addition.id) ).not_to be_nil end + specify do expect( new_output_species.listing_changes. @@ -108,13 +115,16 @@ party_listing_distribution.geo_entity ).to eq(portugal) end + specify { expect(new_output_species.quotas.count).to eq(2) } + specify do expect( new_output_species.quotas. find_by(geo_entity_id: poland.id) ).not_to be_nil end + specify do expect( new_output_species.quotas. @@ -122,6 +132,7 @@ terms ).not_to be_empty end + specify do expect( new_output_species.quotas. @@ -129,6 +140,7 @@ sources ).not_to be_empty end + specify do expect( new_output_species.quotas. @@ -136,6 +148,7 @@ purposes ).not_to be_empty end + specify { expect(new_output_species.cites_suspensions.count).to eq(2) } specify { expect(old_output_subspecies.listing_changes).to be_empty } specify { expect(old_output_subspecies.quotas).to be_empty } diff --git a/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb index 3915d7cc8..30081a2ba 100644 --- a/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb @@ -10,7 +10,7 @@ other_taxon_concept: output_subspecies2_synonym ) end - before(:each) do + before do create( :nomenclature_change_output_name_reassignment, output: output, @@ -19,6 +19,7 @@ output_processor.run processor.run end + specify { expect(new_output_species.synonyms).to include(output_subspecies2_synonym) } specify { expect(old_output_subspecies.synonyms).to be_empty } end diff --git a/spec/models/nomenclature_change/shared/output_reference_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_reference_reassignments_processor_examples.rb index b2dbfb25e..5f148d533 100644 --- a/spec/models/nomenclature_change/shared/output_reference_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_reference_reassignments_processor_examples.rb @@ -1,5 +1,5 @@ shared_context 'output_reference_reassignments_processor_examples' do - before(:each) do + before do create( :nomenclature_change_output_reassignment, output: output, @@ -9,6 +9,7 @@ output_processor.run processor.run end + specify { expect(new_output_species.taxon_concept_references.count).to eq(2) } specify { expect(old_output_subspecies.taxon_concept_references).to be_empty } end diff --git a/spec/models/nomenclature_change/shared/output_shipment_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_shipment_reassignments_processor_examples.rb index 080fa0624..d308e2505 100644 --- a/spec/models/nomenclature_change/shared/output_shipment_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_shipment_reassignments_processor_examples.rb @@ -1,5 +1,5 @@ shared_context 'output_shipment_reassignments_processor_examples' do - before(:each) do + before do create( :nomenclature_change_output_reassignment, output: output, @@ -9,6 +9,7 @@ output_processor.run processor.run end + specify { expect(new_output_species.shipments.count).to eq(2) } specify { expect(old_output_subspecies.shipments).to be_empty } end diff --git a/spec/models/nomenclature_change/shared/parent_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/parent_reassignments_constructor_examples.rb index 7f93d750c..8ad6a8153 100644 --- a/spec/models/nomenclature_change/shared/parent_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/parent_reassignments_constructor_examples.rb @@ -3,21 +3,25 @@ context 'when no children' do specify { expect(input.parent_reassignments.size).to eq(0) } end + context 'when children' do let(:input_species) do s = create_cites_eu_species 2.times { create_cites_eu_subspecies(parent: s) } s end + specify { expect(input.parent_reassignments.size).to eq(2) } end end + context 'when previously reassignments in place' do let(:input) do i = create(:nomenclature_change_input, nomenclature_change: nc, taxon_concept: input_species) create(:nomenclature_change_parent_reassignment, input: i) i end + specify { expect(input.parent_reassignments).to eq(@old_reassignments) } end end diff --git a/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb index d0e765168..11486576a 100644 --- a/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb @@ -16,14 +16,16 @@ output: output ) end - before(:each) do + before do synonym_relationship_type processor.run input_species_child.reload end + specify { expect(input_species_child.parent).to eq(input_species) } specify { expect(input_species_child.name_status).to eq('S') } specify { expect(input_species.children.count).to eq(0) } + specify do old_subspecies = input_species_child.reload new_subspecies = output.taxon_concept.children.first diff --git a/spec/models/nomenclature_change/shared/reference_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/reference_reassignments_constructor_examples.rb index b37bfdde2..436d2fa46 100644 --- a/spec/models/nomenclature_change/shared/reference_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/reference_reassignments_constructor_examples.rb @@ -3,21 +3,25 @@ context 'when no references' do specify { expect(input.reassignments.size).to eq(0) } end + context 'when references' do let(:input_species) do s = create_cites_eu_species 2.times { create(:taxon_concept_reference, taxon_concept: s) } s end + specify { expect(input.reassignments.size).to eq(1) } end end + context 'when previously reassignments in place' do let(:input) do i = create(:nomenclature_change_input, nomenclature_change: nc, taxon_concept: input_species) create(:nomenclature_change_reassignment, input: i) i end + specify { expect(input.reassignments).to eq(@old_reassignments) } end end diff --git a/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb index 7ce63d671..82c3b65a6 100644 --- a/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb @@ -13,9 +13,10 @@ output: output ) end - before(:each) do + before do 2.times { create(:taxon_concept_reference, taxon_concept: input_species) } processor.run end + specify { expect(output_species1.taxon_concept_references.count).to eq(2) } end diff --git a/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb index 9773a3899..2edff472a 100644 --- a/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb @@ -13,10 +13,11 @@ output: output ) end - before(:each) do + before do 2.times { create(:shipment, taxon_concept: input_species) } processor.run end + specify { expect(output_species1.shipments.count).to eq(2) } specify { expect(input_species.shipments).to be_empty } end diff --git a/spec/models/nomenclature_change/split_spec.rb b/spec/models/nomenclature_change/split_spec.rb index c1458d3be..625be911c 100644 --- a/spec/models/nomenclature_change/split_spec.rb +++ b/spec/models/nomenclature_change/split_spec.rb @@ -9,17 +9,21 @@ :nomenclature_change_split, status: NomenclatureChange::Split::INPUTS ) end + specify { expect(split).to have(1).errors_on(:input) } end + context 'when submitting' do let(:split) do build( :nomenclature_change_split, status: NomenclatureChange::Split::SUBMITTED ) end + specify { expect(split).to have(1).errors_on(:input) } end end + context 'when required outputs missing' do context 'when outputs' do let(:split) do @@ -27,17 +31,21 @@ :nomenclature_change_split, status: NomenclatureChange::Split::OUTPUTS ) end + specify { expect(split).to have(1).errors_on(:outputs) } end + context 'when submitting' do let(:split) do build( :nomenclature_change_split, status: NomenclatureChange::Split::SUBMITTED ) end + specify { expect(split).to have(1).errors_on(:outputs) } end end + context 'when output has different rank than input' do let(:split) do build( @@ -56,6 +64,7 @@ } ) end + specify { expect(split.errors_on(:outputs).size).to eq(1) } end end diff --git a/spec/models/nomenclature_change/status_to_accepted_spec.rb b/spec/models/nomenclature_change/status_to_accepted_spec.rb index bbcc9d7c8..d2a545731 100644 --- a/spec/models/nomenclature_change/status_to_accepted_spec.rb +++ b/spec/models/nomenclature_change/status_to_accepted_spec.rb @@ -10,8 +10,10 @@ status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ) end + specify { expect(status_change).to have(1).error_on(:primary_output) } end + context 'when submitting' do let(:status_change) do build( @@ -19,9 +21,11 @@ status: NomenclatureChange::StatusToAccepted::SUBMITTED ) end + specify { expect(status_change).to have(1).error_on(:primary_output) } end end + context 'when primary output has invalid name status' do context 'when primary_output' do let(:status_change) do @@ -33,9 +37,11 @@ status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ) end + specify { expect(status_change.error_on(:primary_output).size).to eq(1) } end end + context 'when primary output has valid name status' do context 'when primary_output' do let(:status_change) do @@ -47,6 +53,7 @@ status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ) end + specify { expect(status_change.errors_on(:primary_output).size).to eq(0) } end end diff --git a/spec/models/nomenclature_change/status_to_synonym_spec.rb b/spec/models/nomenclature_change/status_to_synonym_spec.rb index 753468988..bd2eb7b6d 100644 --- a/spec/models/nomenclature_change/status_to_synonym_spec.rb +++ b/spec/models/nomenclature_change/status_to_synonym_spec.rb @@ -10,8 +10,10 @@ status: NomenclatureChange::StatusToSynonym::PRIMARY_OUTPUT ) end + specify { expect(status_change).to have(1).error_on(:primary_output) } end + context 'when submitting' do let(:status_change) do build( @@ -19,9 +21,11 @@ status: NomenclatureChange::StatusToSynonym::SUBMITTED ) end + specify { expect(status_change).to have(1).error_on(:primary_output) } end end + context 'when primary output has invalid name status' do context 'when primary_output' do let(:status_change) do @@ -33,9 +37,11 @@ status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ) end + specify { expect(status_change.error_on(:primary_output).size).to eq(1) } end end + context 'when primary output has valid name status' do context 'when primary_output' do let(:status_change) do @@ -47,9 +53,11 @@ status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ) end + specify { expect(status_change.errors_on(:primary_output).size).to eq(0) } end end + context 'when required secondary output missing' do context 'when relay' do let(:status_change) do @@ -59,8 +67,10 @@ status: NomenclatureChange::StatusToSynonym::RELAY ) end + specify { expect(status_change.error_on(:secondary_output).size).to eq(1) } end + context 'when submitting' do let(:status_change) do build( @@ -69,6 +79,7 @@ status: NomenclatureChange::StatusToSynonym::SUBMITTED ) end + specify { expect(status_change.error_on(:secondary_output).size).to eq(1) } end end diff --git a/spec/models/nomenclature_change_spec.rb b/spec/models/nomenclature_change_spec.rb index 0e46adb35..6d37230f6 100644 --- a/spec/models/nomenclature_change_spec.rb +++ b/spec/models/nomenclature_change_spec.rb @@ -6,54 +6,67 @@ let(:nomenclature_change) do build(:nomenclature_change, status: nil) end + specify { expect(nomenclature_change).not_to be_valid } end + context 'when previous status=submitted' do let(:nomenclature_change) do nc = create(:nomenclature_change, status: NomenclatureChange::SUBMITTED) nc.status = NomenclatureChange::NEW nc end + specify { expect(nomenclature_change).not_to be_valid } end + context 'when previous status=closed' do let(:nomenclature_change) do nc = create(:nomenclature_change, status: NomenclatureChange::CLOSED) nc.status = NomenclatureChange::SUBMITTED nc end + specify { expect(nomenclature_change).not_to be_valid } end end + describe :submitting? do context 'when new object with status=submitted' do let(:nomenclature_change) do build(:nomenclature_change, status: NomenclatureChange::SUBMITTED) end + specify { expect(nomenclature_change).to be_submitting } end + context 'when updating object with status new -> submitted' do let(:nomenclature_change) do nc = create(:nomenclature_change, status: NomenclatureChange::NEW) nc.status = NomenclatureChange::SUBMITTED nc end + specify { expect(nomenclature_change).to be_submitting } end + context 'when updating object with status submitted -> closed' do let(:nomenclature_change) do nc = create(:nomenclature_change, status: NomenclatureChange::SUBMITTED) nc.status = NomenclatureChange::CLOSED nc end + specify { expect(nomenclature_change).not_to be_submitting } end + context 'when updating object with status closed -> submitted' do let(:nomenclature_change) do nc = create(:nomenclature_change, status: NomenclatureChange::CLOSED) nc.status = NomenclatureChange::SUBMITTED nc end + specify { expect(nomenclature_change).not_to be_submitting } end end diff --git a/spec/models/preset_tag_spec.rb b/spec/models/preset_tag_spec.rb index 6b0d248aa..eef80f84f 100644 --- a/spec/models/preset_tag_spec.rb +++ b/spec/models/preset_tag_spec.rb @@ -4,15 +4,20 @@ describe :create do context 'when valid' do let(:preset_tag) { build(:preset_tag, name: 'Test Tag', model: 'TaxonConcept') } + specify { expect(preset_tag).to be_valid } end + context 'when name missing' do let(:preset_tag) { build(:preset_tag, name: nil, model: 'TaxonConcept') } + specify { expect(preset_tag).not_to be_valid } specify { expect(preset_tag).to have(1).error_on(:name) } end + context 'when model (type) incorrect' do let(:preset_tag) { build(:preset_tag, name: 'Test Tag', model: 'Nope') } + specify { expect(preset_tag).not_to be_valid } specify { expect(preset_tag).to have(1).error_on(:model) } end diff --git a/spec/models/rank_spec.rb b/spec/models/rank_spec.rb index c48b8c70e..ef1cade35 100644 --- a/spec/models/rank_spec.rb +++ b/spec/models/rank_spec.rb @@ -4,19 +4,25 @@ describe :parent_rank_lower_bound do context 'obligatory rank' do let(:rank) { create(:rank, name: Rank::KINGDOM) } + specify { expect(rank.parent_rank_lower_bound).to eq('0') } end + context 'optional rank' do let(:rank) { create(:rank, name: Rank::SUBFAMILY) } + specify { expect(rank.parent_rank_lower_bound).to eq('5') } end end + describe :create do context 'when taxonomic position malformed' do let(:rank) { build(:rank, name: Rank::PHYLUM, taxonomic_position: '1.a.b') } + specify { expect(rank).to have(1).error_on(:taxonomic_position) } end end + describe :destroy do context 'when no dependent objects attached' do let(:rank) do @@ -24,29 +30,40 @@ r.update_attribute(:name, 'SUPER PHYLUM') r end + specify { expect(rank.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:rank) { create(:rank, name: Rank::PHYLUM, taxonomic_position: '1.1') } let!(:taxon_concept) { create(:taxon_concept, rank: rank) } + specify { expect(rank.destroy).to be_falsey } end + context 'when protected name' do let(:rank) { create(:rank, name: Rank::PHYLUM, taxonomic_position: '1.1') } + specify { expect(rank.destroy).to be_falsey } end end + describe :in_range do context 'when no bounds specified' do subject { Rank.in_range(nil, nil) } + specify { expect(subject).to eq(Rank.dict) } end + context 'when lower bound specified' do subject { Rank.in_range(Rank::CLASS, nil) } + specify { expect(subject).to eq([ Rank::KINGDOM, Rank::PHYLUM, Rank::CLASS ]) } end + context 'when lower and upper bound specified' do subject { Rank.in_range(Rank::GENUS, Rank::FAMILY) } + specify { expect(subject).to eq([ Rank::FAMILY, Rank::SUBFAMILY, Rank::GENUS ]) } end end diff --git a/spec/models/sapi/geoip_spec.rb b/spec/models/sapi/geoip_spec.rb index 65125af51..8c0433445 100644 --- a/spec/models/sapi/geoip_spec.rb +++ b/spec/models/sapi/geoip_spec.rb @@ -3,7 +3,8 @@ describe SapiModule::GeoIP do describe :resolve do subject { SapiModule::GeoIP.instance } - before(:each) do + + before do bogota_latin1 = 'Bogotá'.encode('ISO-8859-1', 'UTF-8') allow(subject).to receive(:country_and_city).and_return( { @@ -12,6 +13,7 @@ } ) end + specify { expect(subject.resolve('1.1.1.1')[:city]).to eq('Bogotá') } end end diff --git a/spec/models/synonym_relationship_spec.rb b/spec/models/synonym_relationship_spec.rb index 7e973c2a1..bc3b29b57 100644 --- a/spec/models/synonym_relationship_spec.rb +++ b/spec/models/synonym_relationship_spec.rb @@ -49,10 +49,12 @@ other_taxon_concept_id: synonym.id ) end + specify do synonymy_rel.save expect(tc.synonyms.map(&:full_name)).to include('Lolcatus lolus') end + specify do synonymy_rel.save another_synonymy_rel.save diff --git a/spec/models/taxon_common_spec.rb b/spec/models/taxon_common_spec.rb index a0829ca36..f11822d68 100644 --- a/spec/models/taxon_common_spec.rb +++ b/spec/models/taxon_common_spec.rb @@ -30,6 +30,7 @@ language_id: language.id ) end + context 'when common name changed' do let(:another_tc_common) do build( @@ -39,6 +40,7 @@ language_id: language.id ) end + specify do tc_common.save another_tc_common.save diff --git a/spec/models/taxon_concept/agalychnis_spec.rb b/spec/models/taxon_concept/agalychnis_spec.rb index 103fa5ad7..8db1440b3 100644 --- a/spec/models/taxon_concept/agalychnis_spec.rb +++ b/spec/models/taxon_concept/agalychnis_spec.rb @@ -9,25 +9,31 @@ context 'for class Amphibia' do specify { expect(@klass.cites_accepted).to be_truthy } end + context 'for family Hylidae' do specify { expect(@family.cites_accepted).to be_truthy } end + context 'for genus Agalychnis' do specify { expect(@genus.cites_accepted).to eq(false) } end end + describe :standard_taxon_concept_references do context 'for class Amphibia' do specify { expect(@klass.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref.id } end + context 'for family Hylidae' do specify { expect(@family.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref.id } end + context 'for genus Agalychnis' do specify { expect(@genus.taxon_concept.standard_taxon_concept_references).to be_empty } end end end + context 'LISTING' do describe :cites_listing do context 'for genus Agalychnis' do @@ -45,6 +51,7 @@ context 'for family Hylidae' do specify { expect(@family.cites_listed).to eq(false) } end + context 'for genus Agalychnis' do specify { expect(@genus.cites_listed).to be_truthy } end @@ -54,6 +61,7 @@ context 'for family Hylidae' do specify { expect(@family.eu_listed).to eq(false) } end + context 'for genus Agalychnis' do specify { expect(@genus.eu_listed).to be_truthy } end diff --git a/spec/models/taxon_concept/agave_spec.rb b/spec/models/taxon_concept/agave_spec.rb index 564d111a3..4216c38f4 100644 --- a/spec/models/taxon_concept/agave_spec.rb +++ b/spec/models/taxon_concept/agave_spec.rb @@ -9,6 +9,7 @@ context 'for species Agave parviflora' do specify { expect(@species2.cites_listing).to eq('I') } end + context 'for species Agave arizonica' do specify { expect(@species1.cites_listing).to eq('NC') } end @@ -18,6 +19,7 @@ context 'for species Agave parviflora' do specify { expect(@species2.cites_listed).to be_truthy } end + context 'for species Agave arizonica' do specify { expect(@species1.cites_listed).to be_nil } end @@ -27,6 +29,7 @@ context 'for species Agave parviflora' do specify { expect(@species2.cites_show).to be_truthy } end + context 'for species Agave arizonica' do specify { expect(@species1.cites_show).to be_falsey } end @@ -36,6 +39,7 @@ context 'for species Agave parviflora' do specify { expect(@species2.eu_listing).to eq('A') } end + context 'for species Agave arizonica' do specify { expect(@species1.eu_listing).to eq('NC') } end @@ -45,6 +49,7 @@ context 'for species Agave parviflora' do specify { expect(@species2.eu_listed).to be_truthy } end + context 'for species Agave arizonica' do specify { expect(@species1.eu_listed).to be_nil } end @@ -54,6 +59,7 @@ context 'for species Agave parviflora' do specify { expect(@species2.eu_show).to be_truthy } end + context 'for species Agave arizonica' do specify { expect(@species1.eu_show).to be_falsey } end diff --git a/spec/models/taxon_concept/ailuropoda_spec.rb b/spec/models/taxon_concept/ailuropoda_spec.rb index 4a7cd5fed..d9936a5fb 100644 --- a/spec/models/taxon_concept/ailuropoda_spec.rb +++ b/spec/models/taxon_concept/ailuropoda_spec.rb @@ -9,6 +9,7 @@ context 'for species Ailuropoda melanoleuca' do specify { expect(@species.cites_listing).to eq('I') } end + context 'for genus level Ailuropoda' do specify { expect(@genus.cites_listing).to eq('I') } end @@ -18,6 +19,7 @@ context 'for species Ailuropoda melanoleuca' do specify { expect(@species.eu_listing).to eq('A') } end + context 'for genus level Ailuropoda' do specify { expect(@genus.eu_listing).to eq('A') } end @@ -27,6 +29,7 @@ context 'for genus Ailuropoda' do specify { expect(@genus.cites_listed).to be_falsey } end + context 'for species Ailuropoda melanoleuca' do specify { expect(@species.cites_listed).to be_truthy } end @@ -36,6 +39,7 @@ context 'for genus Ailuropoda' do specify { expect(@genus.eu_listed).to be_falsey } end + context 'for species Ailuropoda melanoleuca' do specify { expect(@species.eu_listed).to be_truthy } end diff --git a/spec/models/taxon_concept/arctocephalus_spec.rb b/spec/models/taxon_concept/arctocephalus_spec.rb index 2786e718b..df22a72e8 100644 --- a/spec/models/taxon_concept/arctocephalus_spec.rb +++ b/spec/models/taxon_concept/arctocephalus_spec.rb @@ -6,37 +6,43 @@ context 'LISTING' do describe :cites_listing do - it 'should be II at species level Arctocephalus australis' do + it 'is II at species level Arctocephalus australis' do expect(@species1.cites_listing).to eq('II') end - it 'should be I at species level Arctocephalus townsendi' do + + it 'is I at species level Arctocephalus townsendi' do expect(@species2.cites_listing).to eq('I') end - it 'should be I/II at genus level Arctocephalus' do + + it 'is I/II at genus level Arctocephalus' do expect(@genus.cites_listing).to eq('I/II') end end describe :cites_listed do - it 'should be true for genus Arctocephalus' do + it 'is true for genus Arctocephalus' do expect(@genus.cites_listed).to be_truthy end - it 'should be true for species Arctocephalus townsendi' do + + it 'is true for species Arctocephalus townsendi' do expect(@species2.cites_listed).to be_truthy end - it 'should be false for species Arctocephalus australis (inclusion in higher taxa listing)' do + + it 'is false for species Arctocephalus australis (inclusion in higher taxa listing)' do expect(@species1.cites_listed).to eq(false) end end describe :eu_listed do - it 'should be true for genus Arctocephalus' do + it 'is true for genus Arctocephalus' do expect(@genus.eu_listed).to be_truthy end - it 'should be true for species Arctocephalus townsendi' do + + it 'is true for species Arctocephalus townsendi' do expect(@species2.eu_listed).to be_truthy end - it 'should be false for species Arctocephalus australis (inclusion in higher taxa listing)' do + + it 'is false for species Arctocephalus australis (inclusion in higher taxa listing)' do expect(@species1.eu_listed).to eq(false) end end diff --git a/spec/models/taxon_concept/boa_constrictor_spec.rb b/spec/models/taxon_concept/boa_constrictor_spec.rb index a505e7c76..1af07d903 100644 --- a/spec/models/taxon_concept/boa_constrictor_spec.rb +++ b/spec/models/taxon_concept/boa_constrictor_spec.rb @@ -8,9 +8,11 @@ context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.full_name).to eq('Boa constrictor occidentalis') } end + context 'for species Boa constrictor' do specify { expect(@species.full_name).to eq('Boa constrictor') } end + context 'for genus Boa' do specify { expect(@genus.full_name).to eq('Boa') } end @@ -20,9 +22,11 @@ context 'family' do specify { expect(@species.family_name).to eq('Boidae') } end + context 'order' do specify { expect(@species.order_name).to eq('Serpentes') } end + context 'class' do specify { expect(@species.class_name).to eq('Reptilia') } end @@ -34,9 +38,11 @@ context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.cites_listing).to eq('I') } end + context 'for subspecies Boa constrictor constrictor' do specify { expect(@subspecies2.cites_listing).to eq('II') } end + context 'for species Boa constrictor' do specify { expect(@species.cites_listing).to eq('I/II') } end @@ -46,9 +52,11 @@ context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.eu_listing).to eq('A') } end + context 'for subspecies Boa constrictor constrictor' do specify { expect(@subspecies2.eu_listing).to eq('B') } end + context 'for species Boa constrictor' do specify { expect(@species.eu_listing).to eq('A/B') } end @@ -58,15 +66,19 @@ context 'for family Boidae' do specify { expect(@family.cites_listed).to be_truthy } end + context 'for genus Boa' do specify { expect(@genus.cites_listed).to eq(false) } end + context 'for species Boa constrictor (inclusion in higher taxa listing)' do specify { expect(@species.cites_listed).to eq(false) } end + context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.cites_listed).to be_truthy } end + context 'for subspecies Boa constrictor constrictor' do specify { expect(@subspecies2.cites_listed).to be_falsey } end @@ -76,15 +88,19 @@ context 'for family Boidae' do specify { expect(@family.cites_show).to be_truthy } end + context 'for genus Boa' do specify { expect(@genus.cites_show).to be_truthy } end + context 'for species Boa constrictor (inclusion in higher taxa listing)' do specify { expect(@species.cites_show).to be_truthy } end + context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.cites_show).to be_truthy } end + context 'for subspecies Boa constrictor constrictor' do specify { expect(@subspecies2.cites_show).to be_falsey } end @@ -94,12 +110,15 @@ context 'for family Boidae' do specify { expect(@family.cites_listed_descendants).to be_truthy } end + context 'for genus Boa' do specify { expect(@genus.cites_listed_descendants).to be_truthy } end + context 'for species Boa constrictor (inclusion in higher taxa listing)' do specify { expect(@species.cites_listed_descendants).to be_truthy } end + context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.cites_listed_descendants).to be_falsey } end @@ -109,12 +128,15 @@ context 'for family Boidae' do specify { expect(@family.eu_listed).to be_truthy } end + context 'for genus Boa' do specify { expect(@genus.eu_listed).to eq(false) } end + context 'for species Boa constrictor (inclusion in higher taxa listing)' do specify { expect(@species.eu_listed).to eq(false) } end + context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1.eu_listed).to be_truthy } end @@ -124,15 +146,19 @@ context 'for family Boidae' do specify { expect(@family_ac.show_in_species_plus_ac).to be_truthy } end + context 'for genus Boa' do specify { expect(@genus_ac.show_in_species_plus_ac).to be_truthy } end + context 'for species Boa constrictor (inclusion in higher taxa listing)' do specify { expect(@species_ac.show_in_species_plus_ac).to be_truthy } end + context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1_ac.show_in_species_plus_ac).to be_truthy } end + context 'for subspecies Boa constrictor constrictor' do specify { expect(@subspecies2_ac.show_in_species_plus_ac).to be_falsey } end @@ -142,15 +168,19 @@ context 'for family Boidae' do specify { expect(@family_ac.show_in_checklist_ac).to be_truthy } end + context 'for genus Boa' do specify { expect(@genus_ac.show_in_checklist_ac).to be_truthy } end + context 'for species Boa constrictor (inclusion in higher taxa listing)' do specify { expect(@species_ac.show_in_checklist_ac).to be_truthy } end + context 'for subspecies Boa constrictor occidentalis' do specify { expect(@subspecies1_ac.show_in_checklist_ac).to be_truthy } end + context 'for subspecies Boa constrictor constrictor' do specify { expect(@subspecies2_ac.show_in_checklist_ac).to be_falsey } end diff --git a/spec/models/taxon_concept/caiman_latirostris_spec.rb b/spec/models/taxon_concept/caiman_latirostris_spec.rb index 5696656b3..5539bc7a9 100644 --- a/spec/models/taxon_concept/caiman_latirostris_spec.rb +++ b/spec/models/taxon_concept/caiman_latirostris_spec.rb @@ -10,6 +10,7 @@ specify { expect(@species1.full_name).to eq('Alligator cynocephalus') } end end + describe :rank_name do context 'for species synonym Alligator cynocephalus' do specify { expect(@species1.rank_name).to eq(Rank::SPECIES) } @@ -22,16 +23,19 @@ context 'for species Caiman latirostris' do specify { expect(@species.cites_accepted).to be_truthy } end + context 'for synonym species Alligator cynocephalus' do specify { expect(@species1.cites_accepted).to eq(false) } end end + describe :standard_taxon_concept_references do context 'for species Caiman latirostris' do specify { expect(@species.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref.id } end end end + context 'LISTING' do describe :cites_listing do context 'for species Caiman latirostris' do @@ -49,12 +53,15 @@ context 'for order Crocodylia' do specify { expect(@order.cites_listed).to be_truthy } end + context 'for family Alligatoridae' do specify { expect(@family.cites_listed).to eq(false) } end + context 'for genus Caiman' do specify { expect(@genus.cites_listed).to eq(false) } end + context 'for species Caiman latoristris' do specify { expect(@species.cites_listed).to be_truthy } end @@ -64,12 +71,15 @@ context 'for order Crocodylia' do specify { expect(@order.eu_listed).to be_truthy } end + context 'for family Alligatoridae' do specify { expect(@family.eu_listed).to eq(false) } end + context 'for genus Caiman' do specify { expect(@genus.eu_listed).to eq(false) } end + context 'for species Caiman latoristris' do specify { expect(@species.eu_listed).to be_truthy } end @@ -79,15 +89,19 @@ context 'for order Crocodylia' do specify { expect(@order.cites_show).to be_truthy } end + context 'for family Alligatoridae' do specify { expect(@family.cites_show).to be_truthy } end + context 'for genus Caiman' do specify { expect(@genus.cites_show).to be_truthy } end + context 'for species Caiman latoristris' do specify { expect(@species.cites_show).to be_truthy } end + context 'for synonym species Alligator cynocephalus' do specify { expect(@species1.cites_show).to be_falsey } end diff --git a/spec/models/taxon_concept/callback_spec.rb b/spec/models/taxon_concept/callback_spec.rb index 6cdc29f7e..1af8f6462 100644 --- a/spec/models/taxon_concept/callback_spec.rb +++ b/spec/models/taxon_concept/callback_spec.rb @@ -15,8 +15,10 @@ taxonomic_position: nil ) end + specify { expect(tc.taxonomic_position).to eq('1.1') } end + context 'taxonomic position given for fixed order rank' do let(:tc) do create_cites_eu_phylum( @@ -24,14 +26,17 @@ taxonomic_position: '1.2' ) end + specify { expect(tc.taxonomic_position).to eq('1.2') } end + context 'taxonomic position not given for fixed order root rank' do let(:tc) do create_cites_eu_kingdom( taxonomic_position: nil ) end + specify { expect(tc.taxonomic_position).to eq('1') } end end @@ -44,12 +49,14 @@ ) ) end + context 'data should be populated when creating a child' do let(:tc) do create_cites_eu_species( parent_id: genus_tc.id ) end + specify { expect(tc.data['family_name']).to eq('Derp') } specify { expect(tc.data['rank_name']).to eq(Rank::SPECIES) } end diff --git a/spec/models/taxon_concept/canis_lupus_spec.rb b/spec/models/taxon_concept/canis_lupus_spec.rb index d3d386289..dc67e5fd0 100644 --- a/spec/models/taxon_concept/canis_lupus_spec.rb +++ b/spec/models/taxon_concept/canis_lupus_spec.rb @@ -20,6 +20,7 @@ context 'for species Canis lupus' do specify { expect(@species.cites_listed).to be_truthy } end + context 'for subspecies Canis lupus crassodon' do specify { expect(@subspecies.cites_listed).to be_blank } end @@ -35,6 +36,7 @@ context 'for species Canis lupus' do specify { expect(@species_ac.show_in_species_plus_ac).to be_truthy } end + context 'for subspecies Canis lupus crassodon' do specify { expect(@subspecies_ac.show_in_species_plus_ac).to be_truthy } end @@ -44,6 +46,7 @@ context 'for species Canis lupus' do specify { expect(@species_ac.show_in_checklist_ac).to be_truthy } end + context 'for subspecies Canis lupus crassodon' do specify { expect(@subspecies_ac.show_in_checklist_ac).to be_falsey } end @@ -53,6 +56,7 @@ context 'for species Canis lupus' do specify { expect(@species.show_in_species_plus).to be_truthy } end + context 'for subspecies Canis lupus crassodon' do specify { expect(@subspecies.show_in_species_plus).to be_truthy } end diff --git a/spec/models/taxon_concept/caretta_caretta_cms_spec.rb b/spec/models/taxon_concept/caretta_caretta_cms_spec.rb index 5cd82b8f8..b765d490d 100644 --- a/spec/models/taxon_concept/caretta_caretta_cms_spec.rb +++ b/spec/models/taxon_concept/caretta_caretta_cms_spec.rb @@ -9,6 +9,7 @@ context 'for family Cheloniidae' do specify { expect(@family.cms_listing).to eq('I/II') } end + context 'for species Caretta caretta' do specify { expect(@species.cms_listing).to eq('I/II') } end @@ -18,6 +19,7 @@ context 'for family Cheloniidae' do specify { expect(@family.cms_listed).to be_truthy } end + context 'for species Caretta caretta' do specify { expect(@species.cms_listed).to be_truthy } end @@ -31,6 +33,7 @@ expect(@family.current_cms_additions.size).to eq(1) end end + context 'for species Caretta caretta' do specify do expect(@species.current_cms_additions.size).to eq(2) diff --git a/spec/models/taxon_concept/cervus_elaphus_cms_spec.rb b/spec/models/taxon_concept/cervus_elaphus_cms_spec.rb index 14509e5eb..b2ff17398 100644 --- a/spec/models/taxon_concept/cervus_elaphus_cms_spec.rb +++ b/spec/models/taxon_concept/cervus_elaphus_cms_spec.rb @@ -9,9 +9,11 @@ context 'for species Cervus elaphus' do specify { expect(@species.cms_listing).to eq('I/II') } end + context 'for subspecies Cervus elaphus bactrianus' do specify { expect(@subspecies1.cms_listing).to eq('I/II') } end + context 'for subspecies Cervus elaphus barbarus' do specify { expect(@subspecies2.cms_listing).to eq('I/II') } end @@ -21,6 +23,7 @@ context 'for subspecies Cervus elaphus bactrianus (instrument)' do specify { expect(@subspecies1_ac.show_in_species_plus_ac).to be_truthy } end + context 'for subspecies Cervus elaphus barbarus (listing)' do specify { expect(@subspecies2_ac.show_in_species_plus_ac).to be_truthy } end @@ -30,6 +33,7 @@ context 'for subspecies Cervus elaphus bactrianus (instrument)' do specify { expect(@subspecies1.show_in_species_plus).to be_truthy } end + context 'for subspecies Cervus elaphus barbarus (listing)' do specify { expect(@subspecies2.show_in_species_plus).to be_truthy } end diff --git a/spec/models/taxon_concept/cervus_elaphus_spec.rb b/spec/models/taxon_concept/cervus_elaphus_spec.rb index b3bca0de3..c82b2a954 100644 --- a/spec/models/taxon_concept/cervus_elaphus_spec.rb +++ b/spec/models/taxon_concept/cervus_elaphus_spec.rb @@ -9,9 +9,11 @@ context 'for subspecies Cervus elaphus bactrianus' do specify { expect(@subspecies1.full_name).to eq('Cervus elaphus bactrianus') } end + context 'for species Cervus elaphus' do specify { expect(@species.full_name).to eq('Cervus elaphus') } end + context 'for genus Cervus' do specify { expect(@genus.full_name).to eq('Cervus') } end @@ -23,15 +25,19 @@ context 'for species Cervus elaphus' do specify { expect(@species.cites_listing).to eq('I/II/III/NC') } end + context 'for subspecies Cervus elaphus bactrianus' do specify { expect(@subspecies1.cites_listing).to eq('II') } end + context 'for subspecies Cervus elaphus barbarus' do specify { expect(@subspecies2.cites_listing).to eq('III') } end + context 'for subspecies Cervus elaphus hanglu' do specify { expect(@subspecies3.cites_listing).to eq('I') } end + context 'for subspecies Cervus elaphus canadensis' do specify { expect(@subspecies4.cites_listing).to eq('NC') } end @@ -41,15 +47,19 @@ context 'for species Cervus elaphus' do specify { expect(@species.eu_listing).to eq('A/B/C/NC') } end + context 'for subspecies Cervus elaphus bactrianus' do specify { expect(@subspecies1.eu_listing).to eq('B') } end + context 'for subspecies Cervus elaphus barbarus' do specify { expect(@subspecies2.eu_listing).to eq('C') } end + context 'for subspecies Cervus elaphus hanglu' do specify { expect(@subspecies3.eu_listing).to eq('A') } end + context 'for subspecies Cervus elaphus canadensis' do specify { expect(@subspecies4.eu_listing).to eq('NC') } end @@ -59,24 +69,31 @@ context 'for order Artiodactyla' do specify { expect(@order.cites_listed).to eq(false) } end + context 'for family Cervidae' do specify { expect(@family.cites_listed).to eq(false) } end + context 'for genus Cervus' do specify { expect(@genus.cites_listed).to eq(false) } end + context 'for species Cervus elaphus' do specify { expect(@species.cites_listed).to eq(false) } end + context 'for subspecies Cervus elaphus bactrianus' do specify { expect(@subspecies1.cites_listed).to be_truthy } end + context 'for subspecies Cervus elaphus barbarus' do specify { expect(@subspecies2.cites_listed).to be_truthy } end + context 'for subspecies Cervus elaphus hanglu' do specify { expect(@subspecies3.cites_listed).to be_truthy } end + context 'for subspecies Cervus elaphus canadensis' do specify { expect(@subspecies4.cites_listed).to be_blank } end @@ -86,24 +103,31 @@ context 'for order Artiodactyla' do specify { expect(@order.eu_listed).to eq(false) } end + context 'for family Cervidae' do specify { expect(@family.eu_listed).to eq(false) } end + context 'for genus Cervus' do specify { expect(@genus.eu_listed).to eq(false) } end + context 'for species Cervus elaphus' do specify { expect(@species.eu_listed).to eq(false) } end + context 'for subspecies Cervus elaphus bactrianus' do specify { expect(@subspecies1.eu_listed).to be_truthy } end + context 'for subspecies Cervus elaphus barbarus' do specify { expect(@subspecies2.eu_listed).to be_truthy } end + context 'for subspecies Cervus elaphus hanglu' do specify { expect(@subspecies3.eu_listed).to be_truthy } end + context 'for subspecies Cervus elaphus canadensis' do specify { expect(@subspecies4.eu_listed).to be_blank } end @@ -113,6 +137,7 @@ context 'for subspecies Cervus elaphus hanglu' do specify { expect(@subspecies3.cites_show).to be_truthy } end + context 'for subspecies Cervus elaphus canadensis' do specify { expect(@subspecies4.cites_show).to be_falsey } end diff --git a/spec/models/taxon_concept/colophon_spec.rb b/spec/models/taxon_concept/colophon_spec.rb index 97a25f0cd..47d5067c5 100644 --- a/spec/models/taxon_concept/colophon_spec.rb +++ b/spec/models/taxon_concept/colophon_spec.rb @@ -9,6 +9,7 @@ context 'for genus Colophon' do specify { expect(@genus.cites_listing).to eq('III') } end + context 'for species Colophon barnardi' do specify { expect(@species.cites_listing).to eq('III') } end @@ -18,6 +19,7 @@ context 'for genus Colophon' do specify { expect(@genus.eu_listing).to eq('C') } end + context 'for species Colophon barnardi' do specify { expect(@species.eu_listing).to eq('C') } end @@ -27,6 +29,7 @@ context 'for genus Colophon' do specify { expect(@genus.cites_listed).to eq(true) } end + context 'for species Colophon barnardi' do specify { expect(@species.cites_listed).to eq(false) } end @@ -36,6 +39,7 @@ context 'for genus Colophon' do specify { expect(@genus.eu_listed).to eq(true) } end + context 'for species Colophon barnardi' do specify { expect(@species.eu_listed).to eq(false) } end @@ -45,6 +49,7 @@ context 'for order Coleoptera' do specify { expect(@order.cites_show).to be_falsey } end + context 'for family Lucanidae' do specify { expect(@family.cites_show).to be_falsey } end @@ -54,6 +59,7 @@ context 'for genus Colophon' do specify { expect(@genus.current_parties_ids).to eq([ GeoEntity.find_by(iso_code2: 'ZA').id ]) } end + context 'for species Colophon barnardi' do specify { expect(@species.current_parties_ids).to eq([ GeoEntity.find_by(iso_code2: 'ZA').id ]) } end diff --git a/spec/models/taxon_concept/dalbergia_spec.rb b/spec/models/taxon_concept/dalbergia_spec.rb index 88053b0c0..28a81da93 100644 --- a/spec/models/taxon_concept/dalbergia_spec.rb +++ b/spec/models/taxon_concept/dalbergia_spec.rb @@ -9,6 +9,7 @@ context 'for species Dalbergia abbreviata' do specify { expect(@species1.cites_listing).to eq('NC') } end + context 'for species Dalbergia abrahamii' do specify { expect(@species2.cites_listing).to eq('II') } end @@ -18,6 +19,7 @@ context 'for species Dalbergia abbreviata' do specify { expect(@species1.cites_listed).to be_nil } end + context 'for species Dalbergia abrahamii' do specify { expect(@species2.cites_listed).to eq(false) } end @@ -27,6 +29,7 @@ context 'for species Dalbergia abbreviata' do specify { expect(@species1.cites_show).to be_falsey } end + context 'for species Dalbergia abrahamii' do specify { expect(@species2.cites_show).to be_truthy } end diff --git a/spec/models/taxon_concept/destroy_spec.rb b/spec/models/taxon_concept/destroy_spec.rb index c9020cded..3061c5d15 100644 --- a/spec/models/taxon_concept/destroy_spec.rb +++ b/spec/models/taxon_concept/destroy_spec.rb @@ -3,64 +3,91 @@ describe TaxonConcept do describe :destroy do context 'general' do - before(:each) { @taxon_concept = create_cms_species } + before { @taxon_concept = create_cms_species } + context 'when no dependent objects attached' do specify { expect(@taxon_concept.destroy).to be_truthy } end + context 'when distributions' do - before(:each) { create(:distribution, taxon_concept: @taxon_concept) } + before { create(:distribution, taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_truthy } end + context 'when common names' do - before(:each) { create(:taxon_common, taxon_concept: @taxon_concept) } + before { create(:taxon_common, taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_truthy } end + context 'when references' do - before(:each) { create(:taxon_concept_reference, taxon_concept: @taxon_concept) } + before { create(:taxon_concept_reference, taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_truthy } end + context 'when document citations' do - before(:each) do + before do create(:document_citation_taxon_concept, taxon_concept: @taxon_concept) end + specify { expect(@taxon_concept.destroy).to be_falsey } end end + context 'CMS' do - before(:each) { @taxon_concept = create_cms_species } + before { @taxon_concept = create_cms_species } + context 'when taxon instruments' do - before(:each) { create(:taxon_instrument, taxon_concept: @taxon_concept) } + before { create(:taxon_instrument, taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_falsey } end end + context 'CITES / EU' do - before(:each) { @taxon_concept = create_cites_eu_species } + before { @taxon_concept = create_cites_eu_species } + context 'when listing changes' do - before(:each) { create_cites_I_addition(taxon_concept: @taxon_concept) } + before { create_cites_I_addition(taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_falsey } end + context 'when CITES quotas' do - before(:each) { create(:quota, taxon_concept: @taxon_concept, geo_entity: create(:geo_entity)) } + before { create(:quota, taxon_concept: @taxon_concept, geo_entity: create(:geo_entity)) } + specify { expect(@taxon_concept.destroy).to be_falsey } end + context 'when CITES suspensions' do - before(:each) { create(:cites_suspension, taxon_concept: @taxon_concept, start_notification: create(:cites_suspension_notification, designation: cites)) } + before { create(:cites_suspension, taxon_concept: @taxon_concept, start_notification: create(:cites_suspension_notification, designation: cites)) } + specify { expect(@taxon_concept.destroy).to be_falsey } end + context 'when EU opinions' do - before(:each) { create(:eu_opinion, taxon_concept: @taxon_concept, start_event: create(:ec_srg)) } + before { create(:eu_opinion, taxon_concept: @taxon_concept, start_event: create(:ec_srg)) } + specify { expect(@taxon_concept.destroy).to be_falsey } end + context 'when EU suspensions' do - before(:each) { create(:eu_suspension, taxon_concept: @taxon_concept) } + before { create(:eu_suspension, taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_falsey } end + context 'when shipments' do - before(:each) { create(:shipment, taxon_concept: @taxon_concept) } + before { create(:shipment, taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_falsey } end + context 'when reported shipments' do - before(:each) { create(:shipment, reported_taxon_concept: @taxon_concept) } + before { create(:shipment, reported_taxon_concept: @taxon_concept) } + specify { expect(@taxon_concept.destroy).to be_falsey } end end diff --git a/spec/models/taxon_concept/diospyros_spec.rb b/spec/models/taxon_concept/diospyros_spec.rb index ea7359130..fe115579e 100644 --- a/spec/models/taxon_concept/diospyros_spec.rb +++ b/spec/models/taxon_concept/diospyros_spec.rb @@ -9,6 +9,7 @@ context 'for species Diospyros aculeata' do specify { expect(@species1.cites_listing).to eq('II') } end + context 'for species Diospyros acuta' do specify { expect(@species2.cites_listing).to eq('NC') } end @@ -18,6 +19,7 @@ context 'for species Diospyros aculeata' do specify { expect(@species1.cites_listed).to eq(false) } end + context 'for species Diospyros acuta' do specify { expect(@species2.cites_listed).to be_nil } end @@ -27,6 +29,7 @@ context 'for species Diospyros aculeata' do specify { expect(@species1.cites_show).to be_truthy } end + context 'for species Diospyros acuta' do specify { expect(@species2.cites_show).to be_falsey } end @@ -36,6 +39,7 @@ context 'for species Diospyros aculeata' do specify { expect(@species1.eu_listing).to eq('B') } end + context 'for species Diospyros acuta' do specify { expect(@species2.eu_listing).to eq('NC') } end @@ -45,6 +49,7 @@ context 'for species Diospyros aculeata' do specify { expect(@species1.eu_listed).to eq(false) } end + context 'for species Diospyros acuta' do specify { expect(@species2.eu_listed).to be_nil } end @@ -54,6 +59,7 @@ context 'for species Diospyros aculeata' do specify { expect(@species1.eu_show).to be_truthy } end + context 'for species Diospyros acuta' do specify { expect(@species2.eu_show).to be_falsey } end diff --git a/spec/models/taxon_concept/falconiformes_spec.rb b/spec/models/taxon_concept/falconiformes_spec.rb index 80494bd5b..596f1fc7d 100644 --- a/spec/models/taxon_concept/falconiformes_spec.rb +++ b/spec/models/taxon_concept/falconiformes_spec.rb @@ -17,18 +17,23 @@ context 'for order Falconiformes' do specify { expect(@order.cites_listing).to eq('I/II/III/NC') } end + context 'for species Falco araea' do specify { expect(@species2_1.cites_listing).to eq('I') } end + context 'for species Falco alopex (H)' do specify { expect(@species2_2.cites_listing).to eq('II') } end + context 'for species Gymnogyps californianus' do specify { expect(@species1_1.cites_listing).to eq('I') } end + context 'for species Sarcoramphus papa' do specify { expect(@species1_2.cites_listing).to eq('III') } end + context 'for species Vultur atratus' do specify { expect(@species1_3.cites_listing).to eq('NC') } end @@ -38,18 +43,23 @@ context 'for order Falconiformes' do specify { expect(@order.eu_listing).to eq('A/B/C/NC') } end + context 'for species Falco araea' do specify { expect(@species2_1.eu_listing).to eq('A') } end + context 'for species Falco alopex (H)' do specify { expect(@species2_2.eu_listing).to eq('B') } end + context 'for species Gymnogyps californianus' do specify { expect(@species1_1.eu_listing).to eq('A') } end + context 'for species Sarcoramphus papa' do specify { expect(@species1_2.eu_listing).to eq('C') } end + context 'for species Vultur atratus' do specify { expect(@species1_3.eu_listing).to eq('NC') } end @@ -59,6 +69,7 @@ context 'for genus Vultur' do specify { expect(@genus1_3.cites_status).to eq('EXCLUDED') } end + context 'for species Vultur atratus' do specify { expect(@species1_3.cites_status).to eq('EXCLUDED') } end @@ -68,21 +79,27 @@ context 'for order Falconiformes' do specify { expect(@order.cites_listed).to be_truthy } end + context 'for family Falconidae (inclusion in higher taxa listing)' do specify { expect(@family2.cites_listed).to eq(false) } end + context 'for genus Falco' do specify { expect(@genus2_1.cites_listed).to eq(false) } end + context 'for species Falco araea' do specify { expect(@species2_1.cites_listed).to be_truthy } end + context 'for species Falco alopex' do specify { expect(@species2_2.cites_listed).to eq(false) } end + context 'for species Vultur atratus' do specify { expect(@species1_3.cites_listed).to be_blank } end + context 'for subspecies Falco peregrinus peregrinus' do specify { expect(@subspecies2_3_1.cites_listed).to eq(false) } end @@ -92,21 +109,27 @@ context 'for order Falconiformes' do specify { expect(@order.eu_listed).to be_truthy } end + context 'for family Falconidae (inclusion in higher taxa listing)' do specify { expect(@family2.eu_listed).to eq(false) } end + context 'for genus Falco' do specify { expect(@genus2_1.eu_listed).to eq(false) } end + context 'for species Falco araea' do specify { expect(@species2_1.eu_listed).to be_truthy } end + context 'for species Falco alopex' do specify { expect(@species2_2.eu_listed).to eq(false) } end + context 'for species Vultur atratus' do specify { expect(@species1_3.eu_listed).to be_blank } end + context 'for subspecies Falco peregrinus peregrinus' do specify { expect(@subspecies2_3_1.eu_listed).to eq(false) } end @@ -116,9 +139,11 @@ context 'for order Falconiformes' do specify { expect(@order.cites_show).to be_truthy } end + context 'for family Falconidae' do specify { expect(@family2.cites_show).to be_truthy } end + context 'for Falco hybrid' do specify { expect(@hybrid.cites_show).to be_falsey } end diff --git a/spec/models/taxon_concept/hybrids_spec.rb b/spec/models/taxon_concept/hybrids_spec.rb index 48d60194b..b70cc5df5 100644 --- a/spec/models/taxon_concept/hybrids_spec.rb +++ b/spec/models/taxon_concept/hybrids_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' describe TaxonConcept do - before(:each) { hybrid_relationship_type } + before { hybrid_relationship_type } + describe :create do let(:parent) do create_cites_eu_genus( @@ -29,36 +30,44 @@ other_taxon_concept_id: hybrid.id ) end + context 'when new' do specify do expect(tc.has_hybrids?).to be_truthy end + specify do expect(hybrid.is_hybrid?).to be_truthy end + specify do expect(hybrid.has_hybrid_parents?).to be_truthy end + specify do expect(hybrid.full_name).to eq('Lolcatus lolcatus x lolatus') end end + context 'when duplicate' do let(:duplicate) do hybrid.dup end + specify do expect do duplicate.save - end.to change(TaxonConcept, :count).by(0) + end.not_to change(TaxonConcept, :count) end end + context 'when duplicate but author name different' do let(:duplicate) do res = hybrid.dup res.author_year = 'Hemulen 2013' res end + specify do expect do duplicate.save diff --git a/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb b/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb index 135ad0184..c4902c400 100644 --- a/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb +++ b/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb @@ -8,22 +8,27 @@ context 'for species Loxodonta africana' do specify { expect(@species.full_name).to eq('Loxodonta africana') } end + context 'for genus Loxodonta' do specify { expect(@genus.full_name).to eq('Loxodonta') } end end + describe :rank do context 'for species Loxodonta africana' do specify { expect(@species.rank_name).to eq('SPECIES') } end end + describe :ancestors do context 'family' do specify { expect(@species.family_name).to eq('Elephantidae') } end + context 'order' do specify { expect(@species.order_name).to eq('Proboscidea') } end + context 'class' do specify { expect(@species.class_name).to eq('Mammalia') } end diff --git a/spec/models/taxon_concept/loxodonta_africana_spec.rb b/spec/models/taxon_concept/loxodonta_africana_spec.rb index 4a2033d23..ec129794d 100644 --- a/spec/models/taxon_concept/loxodonta_africana_spec.rb +++ b/spec/models/taxon_concept/loxodonta_africana_spec.rb @@ -8,22 +8,27 @@ context 'for species Loxodonta africana' do specify { expect(@species.full_name).to eq('Loxodonta africana') } end + context 'for genus Loxodonta' do specify { expect(@genus.full_name).to eq('Loxodonta') } end end + describe :rank do context 'for species Loxodonta africana' do specify { expect(@species.rank_name).to eq('SPECIES') } end end + describe :ancestors do context 'family' do specify { @species.family_name == 'Elephantidae' } end + context 'order' do specify { @species.order_name == 'Proboscidea' } end + context 'class' do specify { @species.class_name == 'Mammalia' } end @@ -47,6 +52,7 @@ context 'for species Loxodonta africana' do specify { expect(@species.cites_listed).to be_truthy } end + context 'for family Elephantidae' do specify { expect(@family.cites_listed).to eq(false) } end @@ -56,6 +62,7 @@ context 'for species Loxodonta africana' do specify { expect(@species.eu_listed).to be_truthy } end + context 'for family Elephantidae' do specify { expect(@family.eu_listed).to eq(false) } end diff --git a/spec/models/taxon_concept/mellivora_capensis_spec.rb b/spec/models/taxon_concept/mellivora_capensis_spec.rb index 4bf53fe27..2c193fe37 100644 --- a/spec/models/taxon_concept/mellivora_capensis_spec.rb +++ b/spec/models/taxon_concept/mellivora_capensis_spec.rb @@ -20,9 +20,11 @@ context 'for family Mustelinae' do specify { expect(@family.cites_listed).to eq(false) } end + context 'for genus Mellivora' do specify { expect(@genus.cites_listed).to eq(false) } end + context 'for species Mellivora capensis' do specify { expect(@species.cites_listed).to be_truthy } end @@ -32,9 +34,11 @@ context 'for family Mustelinae' do specify { expect(@family.eu_listed).to eq(false) } end + context 'for genus Mellivora' do specify { expect(@genus.eu_listed).to eq(false) } end + context 'for species Mellivora capensis' do specify { expect(@species.eu_listed).to be_truthy } end diff --git a/spec/models/taxon_concept/moschus_spec.rb b/spec/models/taxon_concept/moschus_spec.rb index ace9ff0fd..00606d5cc 100644 --- a/spec/models/taxon_concept/moschus_spec.rb +++ b/spec/models/taxon_concept/moschus_spec.rb @@ -9,12 +9,15 @@ context 'for genus Moschus' do specify { expect(@genus.cites_listing).to eq('I/II') } end + context 'for species Moschus leucogaster' do specify { expect(@species1.cites_listing).to eq('I') } end + context 'for species Moschus moschiferus' do specify { expect(@species2.cites_listing).to eq('II') } end + context 'for subspecies Moschus moschiferus moschiferus' do specify { expect(@subspecies.cites_listing).to eq('II') } end @@ -24,12 +27,15 @@ context 'for genus Moschus' do specify { expect(@genus.cites_listed).to be_truthy } end + context 'for species Moschus leucogaster' do specify { expect(@species1.cites_listed).to eq(false) } end + context 'for species Moschus moschiferus' do specify { expect(@species2.cites_listed).to eq(false) } end + context 'for subspecies Moschus moschiferus moschiferus' do specify { expect(@subspecies.cites_listed).to eq(false) } end @@ -47,6 +53,7 @@ expect(addition.species_listing_name).to eq('I') end end + context 'for species Moschus moschiferus' do specify do expect(@species2.current_cites_additions.size).to eq(1) @@ -56,6 +63,7 @@ expect(addition.species_listing_name).to eq('II') end end + context 'for subspecies Moschus moschiferus moschiferus' do specify do expect(@subspecies.current_cites_additions.size).to eq(1) diff --git a/spec/models/taxon_concept/natator_depressus_spec.rb b/spec/models/taxon_concept/natator_depressus_spec.rb index b23599b98..0a5f13d95 100644 --- a/spec/models/taxon_concept/natator_depressus_spec.rb +++ b/spec/models/taxon_concept/natator_depressus_spec.rb @@ -9,6 +9,7 @@ context 'for family Cheloniidae' do specify { expect(@family.cites_listing).to eq('I') } end + context 'for species Natator depressus' do specify { expect(@species.cites_listing).to eq('I') } end diff --git a/spec/models/taxon_concept/notomys_aquilo_spec.rb b/spec/models/taxon_concept/notomys_aquilo_spec.rb index 06d051acb..239a2cde1 100644 --- a/spec/models/taxon_concept/notomys_aquilo_spec.rb +++ b/spec/models/taxon_concept/notomys_aquilo_spec.rb @@ -9,6 +9,7 @@ context 'for genus Notomys' do specify { expect(@genus.cites_listing).to eq('NC') } end + context 'for species Notomys aquilo' do specify { expect(@species.cites_listing).to eq('NC') } end @@ -18,6 +19,7 @@ context 'for genus Notomys' do specify { expect(@genus.cites_show).to be_falsey } end + context 'for species Notomys aquilo' do specify { expect(@species.cites_show).to be_falsey } end diff --git a/spec/models/taxon_concept/panax_ginseng_spec.rb b/spec/models/taxon_concept/panax_ginseng_spec.rb index 0f554e2ca..c0007113e 100644 --- a/spec/models/taxon_concept/panax_ginseng_spec.rb +++ b/spec/models/taxon_concept/panax_ginseng_spec.rb @@ -9,6 +9,7 @@ context 'for species Panax ginseng' do specify { expect(@species.cites_listed).to be_truthy } end + context 'for genus Panax' do specify { expect(@genus.cites_listed).to eq(false) } end @@ -18,6 +19,7 @@ context 'for species Panax ginseng' do specify { expect(@species.eu_listed).to be_truthy } end + context 'for genus Panax' do specify { expect(@genus.eu_listed).to eq(false) } end diff --git a/spec/models/taxon_concept/pereskia_spec.rb b/spec/models/taxon_concept/pereskia_spec.rb index 6ef94b95b..f04907a6f 100644 --- a/spec/models/taxon_concept/pereskia_spec.rb +++ b/spec/models/taxon_concept/pereskia_spec.rb @@ -9,9 +9,11 @@ context 'for genus Pereskia (not listed, shown)' do specify { expect(@genus1.cites_listing).to eq('NC') } end + context 'for genus Ariocarpus' do specify { expect(@genus2.cites_listing).to eq('I') } end + context 'for family Cactaceae' do specify { expect(@family.cites_listing).to eq('I/II/NC') } end @@ -21,9 +23,11 @@ context 'for genus Pereskia (not listed, shown)' do specify { expect(@genus1.eu_listing).to eq('NC') } end + context 'for genus Ariocarpus' do specify { expect(@genus2.eu_listing).to eq('A') } end + context 'for family Cactaceae' do specify { expect(@family.eu_listing).to eq('A/B/NC') } end @@ -33,6 +37,7 @@ context 'for family Cactaceae' do specify { expect(@family.cites_listed).to be_truthy } end + context 'for genus Pereskia' do specify { expect(@genus1.cites_listed).to be_nil } end @@ -42,6 +47,7 @@ context 'for family Cactaceae' do specify { expect(@family.eu_listed).to be_truthy } end + context 'for genus Pereskia' do specify { expect(@genus1.eu_listed).to be_nil } end diff --git a/spec/models/taxon_concept/platysternon_megacephalum_spec.rb b/spec/models/taxon_concept/platysternon_megacephalum_spec.rb index 02e99ac6d..925eb3037 100644 --- a/spec/models/taxon_concept/platysternon_megacephalum_spec.rb +++ b/spec/models/taxon_concept/platysternon_megacephalum_spec.rb @@ -9,6 +9,7 @@ context 'for family Platysternidae' do specify { expect(@family.cites_listing).to eq('I') } end + context 'for species Platysternon megacephalum' do specify { expect(@species.cites_listing).to eq('I') } end @@ -30,6 +31,7 @@ context 'for family Platysternidae' do specify { expect(@family.eu_listing).to eq('A') } end + context 'for species Platysternon megacephalum' do specify { expect(@species.eu_listing).to eq('A') } end diff --git a/spec/models/taxon_concept/pristis_microdon_spec.rb b/spec/models/taxon_concept/pristis_microdon_spec.rb index 7da06ff5d..9b78b9696 100644 --- a/spec/models/taxon_concept/pristis_microdon_spec.rb +++ b/spec/models/taxon_concept/pristis_microdon_spec.rb @@ -9,6 +9,7 @@ context 'for family Pristidae' do specify { expect(@family.cites_listing).to eq('I') } end + context 'for species Pristis microdon' do specify { expect(@species.cites_listing).to eq('I') } end @@ -30,6 +31,7 @@ context 'for family Pristidae' do specify { expect(@family.eu_listing).to eq('A') } end + context 'for species Pristis microdon' do specify { expect(@species.eu_listing).to eq('A') } end diff --git a/spec/models/taxon_concept/pseudomys_fieldi_spec.rb b/spec/models/taxon_concept/pseudomys_fieldi_spec.rb index d7901dd57..f2a501237 100644 --- a/spec/models/taxon_concept/pseudomys_fieldi_spec.rb +++ b/spec/models/taxon_concept/pseudomys_fieldi_spec.rb @@ -9,6 +9,7 @@ context 'for subspecies Pseudomys fieldi preaconis' do specify { expect(@subspecies.cites_listing).to eq('I') } end + context 'for species Pseudomys fieldi' do specify { expect(@species.cites_listing).to eq('I/NC') } end @@ -18,6 +19,7 @@ context 'for subspecies Pseudomys fieldi preaconis' do specify { expect(@subspecies.eu_listing).to eq('A') } end + context 'for species Pseudomys fieldi' do specify { expect(@species.eu_listing).to eq('A/NC') } end @@ -27,6 +29,7 @@ context 'for subspecies Pseudomys fieldi preaconis' do specify { expect(@subspecies.cites_show).to be_truthy } end + context 'for species Pseudomys fieldi' do specify { expect(@species.cites_show).to be_truthy } end diff --git a/spec/models/taxon_concept/psittaciformes_spec.rb b/spec/models/taxon_concept/psittaciformes_spec.rb index d19783705..b5be6e272 100644 --- a/spec/models/taxon_concept/psittaciformes_spec.rb +++ b/spec/models/taxon_concept/psittaciformes_spec.rb @@ -9,24 +9,31 @@ context 'for order Psittaciformes' do specify { expect(@order.cites_listing).to eq('I/II/NC') } end + context 'for species Cacatua goffiniana' do specify { expect(@species1_2_1.cites_listing).to eq('I') } end + context 'for species Cacatua ducorpsi (H)' do specify { expect(@species1_2_2.cites_listing).to eq('II') } end + context 'for species Probosciger aterrimus' do specify { expect(@species1_1.cites_listing).to eq('I') } end + context 'for species Amazona aestiva' do specify { expect(@species2_2_1.cites_listing).to eq('II') } end + context 'for species Agapornis roseicollis (DEL II, not listed, not shown)' do specify { expect(@species2_1.cites_listing).to eq('NC') } end + context 'for species Psittacula krameri (DEL III, not listed, not shown)' do specify { expect(@species2_3.cites_listing).to eq('NC') } end + context 'for subspecies Amazona festiva festiva' do specify { expect(@subspecies2_2_2_1.cites_listing).to eq('II') } end @@ -36,24 +43,31 @@ context 'for order Psittaciformes' do specify { expect(@order.eu_listing).to eq('A/B/NC') } end + context 'for species Cacatua goffiniana' do specify { expect(@species1_2_1.eu_listing).to eq('A') } end + context 'for species Cacatua ducorpsi (H)' do specify { expect(@species1_2_2.eu_listing).to eq('B') } end + context 'for species Probosciger aterrimus' do specify { expect(@species1_1.eu_listing).to eq('A') } end + context 'for species Amazona aestiva' do specify { expect(@species2_2_1.eu_listing).to eq('B') } end + context 'for species Agapornis roseicollis (DEL II, not listed, not shown)' do specify { expect(@species2_1.eu_listing).to eq('NC') } end + context 'for species Psittacula krameri (DEL III, not listed, not shown)' do specify { expect(@species2_3.eu_listing).to eq('NC') } end + context 'for subspecies Amazona festiva festiva' do specify { expect(@subspecies2_2_2_1.eu_listing).to eq('B') } end @@ -63,18 +77,23 @@ context 'for order Psittaciformes' do specify { expect(@order.cites_listed).to be_truthy } end + context 'for family Cacatuidae' do specify { expect(@family1.cites_listed).to eq(false) } end + context 'for genus Cacatua' do specify { expect(@genus1_2.cites_listed).to eq(false) } end + context 'for species Cacatua goffiniana' do specify { expect(@species1_2_1.cites_listed).to be_truthy } end + context 'for species Cacatua ducorpsi' do specify { expect(@species1_2_2.cites_listed).to eq(false) } end + context 'for subspecies Amazona festiva festiva' do specify { expect(@subspecies2_2_2_1.cites_listed).to eq(false) } end @@ -84,18 +103,23 @@ context 'for order Psittaciformes' do specify { expect(@order.eu_listed).to be_truthy } end + context 'for family Cacatuidae' do specify { expect(@family1.eu_listed).to eq(false) } end + context 'for genus Cacatua' do specify { expect(@genus1_2.eu_listed).to eq(false) } end + context 'for species Cacatua goffiniana' do specify { expect(@species1_2_1.eu_listed).to be_truthy } end + context 'for species Cacatua ducorpsi' do specify { expect(@species1_2_2.eu_listed).to eq(false) } end + context 'for subspecies Amazona festiva festiva' do specify { expect(@subspecies2_2_2_1.eu_listed).to eq(false) } end @@ -105,9 +129,11 @@ context 'for species Agapornis roseicollis (DEL II)' do specify { expect(@species2_1.cites_show).to be_truthy } end + context 'for species Amazona aestiva' do specify { expect(@species2_2_1.cites_show).to be_truthy } end + context 'for species Psittacula krameri (DEL III)' do specify { expect(@species2_3.cites_show).to be_truthy } end @@ -117,6 +143,7 @@ context 'for species Agapornis roseicollis (DEL II)' do specify { expect(@species2_1.cites_status).to eq('EXCLUDED') } end + context 'for species Psittacula krameri (DEL III)' do specify { expect(@species2_3.cites_status).to eq('EXCLUDED') } end diff --git a/spec/models/taxon_concept/synonyms_spec.rb b/spec/models/taxon_concept/synonyms_spec.rb index c78bc1155..c9c48eb9b 100644 --- a/spec/models/taxon_concept/synonyms_spec.rb +++ b/spec/models/taxon_concept/synonyms_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' describe TaxonConcept do - before(:each) { synonym_relationship_type } + before { synonym_relationship_type } + describe :create do let(:parent) do create_cites_eu_genus( @@ -29,44 +30,53 @@ other_taxon_concept_id: synonym.id ) end + context 'when new' do specify do expect(tc.has_synonyms?).to be_truthy end + specify do expect(synonym.is_synonym?).to be_truthy end + specify do expect(synonym.has_accepted_names?).to be_truthy end + specify do expect(synonym.full_name).to eq('Lolcatus lolus') end end + context 'when duplicate' do let(:duplicate) do synonym.dup end + specify do expect do duplicate.save - end.to change(TaxonConcept, :count).by(0) + end.not_to change(TaxonConcept, :count) end end + context 'when duplicate but author name different' do let(:duplicate) do res = synonym.dup res.author_year = 'Hemulen 2013' res end + specify do expect do duplicate.save end.to change(TaxonConcept, :count).by(1) end end + context 'when has accepted parent' do - before(:each) do + before do @subspecies = create_cites_eu_subspecies( parent: tc, taxon_name: create(:taxon_name, scientific_name: 'perfidius') @@ -84,12 +94,15 @@ other_taxon_concept: @synonym ) end + # should not modify a synonym's full name when saving specify { expect(@synonym.full_name).to eq('Lolcatus lolus furiatus') } + context 'overnight calculations' do - before(:each) do + before do SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end + # should not modify a synonym's full name overnight specify { expect(@synonym.reload.full_name).to eq('Lolcatus lolus furiatus') } end diff --git a/spec/models/taxon_concept/tapiridae_spec.rb b/spec/models/taxon_concept/tapiridae_spec.rb index 817d4d1a2..164bd6a17 100644 --- a/spec/models/taxon_concept/tapiridae_spec.rb +++ b/spec/models/taxon_concept/tapiridae_spec.rb @@ -9,15 +9,18 @@ specify { expect(@family.full_name).to eq('Tapiridae') } end end + describe :rank do context 'for family Tapiridae' do specify { expect(@family.rank_name).to eq('FAMILY') } end end + describe :ancestors do context 'order' do specify { @species.order_name == 'Perissodactyla' } end + context 'class' do specify { @species.class_name == 'Mammalia' } end @@ -29,6 +32,7 @@ context 'for family Tapiridae' do specify { expect(@family.cites_listing).to eq('I/II') } end + context 'for species Tapirus terrestris' do specify { expect(@species.cites_listing).to eq('II') } end @@ -38,6 +42,7 @@ context 'for family Tapiridae' do specify { expect(@family.eu_listing).to eq('A/B') } end + context 'for species Tapirus terrestris' do specify { expect(@species.eu_listing).to eq('B') } end @@ -47,9 +52,11 @@ context 'for family Tapiridae' do specify { expect(@family.cites_listed).to be_truthy } end + context 'for genus Tapirus' do specify { expect(@genus.cites_listed).to eq(false) } end + context 'for species Tapirus terrestris' do specify { expect(@species.cites_listed).to be_truthy } end @@ -59,9 +66,11 @@ context 'for family Tapiridae' do specify { expect(@family.eu_listed).to be_truthy } end + context 'for genus Tapirus' do specify { expect(@genus.eu_listed).to eq(false) } end + context 'for species Tapirus terrestris' do specify { expect(@species.eu_listed).to be_truthy } end diff --git a/spec/models/taxon_concept/trade_names_spec.rb b/spec/models/taxon_concept/trade_names_spec.rb index e2efa1177..1a4e46a4d 100644 --- a/spec/models/taxon_concept/trade_names_spec.rb +++ b/spec/models/taxon_concept/trade_names_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' describe TaxonConcept do - before(:each) { trade_name_relationship_type } + before { trade_name_relationship_type } + describe :create do let(:parent) do create_cites_eu_genus( @@ -29,44 +30,53 @@ other_taxon_concept_id: trade_name.id ) end + context 'when new' do specify do expect(tc.has_trade_names?).to be_truthy end + specify do expect(trade_name.is_trade_name?).to be_truthy end + specify do expect(trade_name.has_accepted_names_for_trade_name?).to be_truthy end + specify do expect(trade_name.full_name).to eq('Lolcatus lolus') end end + context 'when duplicate' do let(:duplicate) do trade_name.dup end + specify do expect do duplicate.save - end.to change(TaxonConcept, :count).by(0) + end.not_to change(TaxonConcept, :count) end end + context 'when duplicate but author name different' do let(:duplicate) do res = trade_name.dup res.author_year = 'Hemulen 2013' res end + specify do expect do duplicate.save end.to change(TaxonConcept, :count).by(1) end end + context 'when has accepted parent' do - before(:each) do + before do @subspecies = create_cites_eu_subspecies( parent: tc, taxon_name: create(:taxon_name, scientific_name: 'perfidius') @@ -84,12 +94,15 @@ other_taxon_concept: @trade_name ) end + # should not modify a trade_name's full name when saving specify { expect(@trade_name.full_name).to eq('Lolcatus lolus furiatus') } + context 'overnight calculations' do - before(:each) do + before do SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end + # should not modify a trade_name's full name overnight specify { expect(@trade_name.reload.full_name).to eq('Lolcatus lolus furiatus') } end diff --git a/spec/models/taxon_concept/uroplatus_spec.rb b/spec/models/taxon_concept/uroplatus_spec.rb index 9cbf2183a..f1f5a41fa 100644 --- a/spec/models/taxon_concept/uroplatus_spec.rb +++ b/spec/models/taxon_concept/uroplatus_spec.rb @@ -9,33 +9,41 @@ context 'for genus Uroplatus' do specify { expect(@genus.cites_accepted).to eq(false) } end + context 'for species Uroplatus alluaudi' do specify { expect(@species1.cites_accepted).to eq(false) } end + context 'for species Uroplatus giganteus' do specify { expect(@species2.cites_accepted).to be_truthy } end end + describe :standard_taxon_concept_references do context 'for family Gekkonidae' do specify { expect(@family.taxon_concept.standard_taxon_concept_references).to be_empty } end + context 'for genus Uroplatus' do specify { expect(@genus.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to be_empty } end + context 'for species Uroplatus alluaudi' do specify { expect(@species1.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to be_empty } end + context 'for species Uroplatus giganteus' do specify { expect(@species2.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref.id } end end end + context 'LISTING' do describe :cites_listing do context 'for genus Uroplatus' do specify { expect(@genus.cites_listing).to eq('II') } end + context 'for species Uroplatus giganteus' do specify { expect(@species2.cites_listing).to eq('II') } end @@ -45,6 +53,7 @@ context 'for genus Uroplatus' do specify { expect(@genus.eu_listing).to eq('B') } end + context 'for species Uroplatus giganteus' do specify { expect(@species2.eu_listing).to eq('B') } end @@ -54,9 +63,11 @@ context 'for family Gekkonidae' do specify { expect(@family.cites_listed).to eq(false) } end + context 'for genus Uroplatus' do specify { expect(@genus.cites_listed).to be_truthy } end + context 'for species Uroplatus giganteus' do specify { expect(@species2.cites_listed).to eq(false) } end @@ -66,9 +77,11 @@ context 'for family Gekkonidae' do specify { expect(@family.eu_listed).to eq(false) } end + context 'for genus Uroplatus' do specify { expect(@genus.eu_listed).to be_truthy } end + context 'for species Uroplatus giganteus' do specify { expect(@species2.eu_listed).to eq(false) } end diff --git a/spec/models/taxon_concept/validation_spec.rb b/spec/models/taxon_concept/validation_spec.rb index 5069c0ff4..009c9f84c 100644 --- a/spec/models/taxon_concept/validation_spec.rb +++ b/spec/models/taxon_concept/validation_spec.rb @@ -9,6 +9,7 @@ taxon_name: build(:taxon_name, scientific_name: 'Foobaria') ) end + context 'all fine' do let(:tc) do create_phylum( @@ -16,8 +17,10 @@ parent_id: kingdom_tc.id ) end + specify { tc.valid? is_expected.to be_truthy } end + context 'taxonomy does not match parent' do let(:tc) do build_phylum( @@ -25,8 +28,10 @@ parent_id: kingdom_tc.id ) end + specify { expect(tc.error_on(:parent_id).size).to eq(1) } end + context 'parent is not an accepted name' do let(:genus_tc) do create_genus( @@ -40,8 +45,10 @@ parent_id: genus_tc.id ) end + specify { expect(tc.error_on(:parent_id).size).to eq(1) } end + context 'parent rank is too high above child rank' do let(:tc) do build_class( @@ -49,8 +56,10 @@ parent_id: kingdom_tc.id ) end + specify { expect(tc.error_on(:parent_id).size).to eq(1) } end + context 'parent rank is below child rank' do let(:parent) do create_phylum( @@ -64,8 +73,10 @@ parent_id: parent.id ) end + specify { expect(tc.error_on(:parent_id).size).to eq(1) } end + context 'scientific name is not given' do let(:tc) do build_phylum( @@ -74,8 +85,10 @@ taxon_name: build(:taxon_name, scientific_name: nil) ) end + specify { expect(tc.error_on(:taxon_name_id).size).to eq(1) } end + context 'when taxonomic position malformed' do let(:tc) do build_phylum( @@ -84,8 +97,10 @@ taxonomic_position: '1.a.b' ) end + specify { expect(tc.error_on(:taxonomic_position).size).to eq(1) } end + context 'when full name is already given' do let(:tc_parent) { create_cites_eu_species } let!(:tc1) do @@ -100,9 +115,11 @@ taxon_name: build(:taxon_name, scientific_name: 'duplicatus') ) end + specify { expect(tc2.error_on(:full_name).size).to eq(1) } end end + context 'update' do let(:family) do create_cites_eu_family( @@ -128,23 +145,28 @@ name_status: 'S' ) end + context 'taxonomy' do let!(:species_child) { create_cites_eu_subspecies(parent_id: species.id) } + specify 'cannot change taxonomy when dependents present' do species.taxonomy = cms expect(species.error_on(:taxonomy_id).size).to eq(1) end end + context 'scientific name' do specify 'cannot change species scientific name' do species.scientific_name = 'Vulgaris' expect(species.error_on(:full_name).size).to eq(1) end + specify 'cannot change genus scientific name' do genus.scientific_name = 'Felis' expect(genus.error_on(:full_name).size).to eq(1) end end + context 'parent' do let(:new_family) do create_cites_eu_family( @@ -157,29 +179,35 @@ taxon_name: create(:taxon_name, scientific_name: 'Felis') ) end + specify 'cannot change A species parent' do species.parent = new_genus expect(species.error_on(:full_name).size).to eq(1) end + specify 'can change S species parent' do s_species.parent = new_genus expect(s_species.error_on(:full_name).size).to eq(0) end + specify 'can change A genus parent' do genus.parent = new_family expect(genus.error_on(:full_name).size).to eq(0) end end + context 'rank' do specify 'cannot change A species rank' do species.rank = create(:rank, name: 'GENUS') expect(species.error_on(:full_name).size).to eq(1) end + specify 'can change S species rank' do s_species.rank = create(:rank, name: 'GENUS') expect(s_species.error_on(:full_name).size).to eq(0) end end + context 'author_year' do specify 'is valid with lots of non-ASCII PDF-safe characters' do species.author_year = 'Sigríður O’Brian–Żądło (2003)' diff --git a/spec/models/taxon_concept/varanidae_spec.rb b/spec/models/taxon_concept/varanidae_spec.rb index e873f24cc..3dfb12278 100644 --- a/spec/models/taxon_concept/varanidae_spec.rb +++ b/spec/models/taxon_concept/varanidae_spec.rb @@ -10,27 +10,33 @@ specify { expect(@species1.cites_accepted).to be_truthy } end end + describe :standard_taxon_concept_references do context 'for order Sauria' do specify { expect(@order.taxon_concept.standard_taxon_concept_references).to be_empty } end + context 'for family Varanidae' do specify { expect(@family.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref1.id } end + context 'for species Varanus bengalensis' do specify { expect(@species1.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref1.id } end + context 'for species Varanus bushi' do specify { expect(@species2.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref1.id } specify { expect(@species2.taxon_concept.standard_taxon_concept_references.map(&:reference_id)).to include @ref2.id } end end end + context 'LISTING' do describe :cites_listing do context 'for genus Varanus' do specify { expect(@genus.cites_listing).to eq('I/II') } end + context 'for species Varanus bengalensis' do specify { expect(@species1.cites_listing).to eq('I') } end @@ -40,6 +46,7 @@ context 'for genus Varanus' do specify { expect(@genus.eu_listing).to eq('A/B') } end + context 'for species Varanus bengalensis' do specify { expect(@species1.eu_listing).to eq('A') } end @@ -49,9 +56,11 @@ context 'for family Varanidae' do specify { expect(@family.cites_listed).to eq(false) } end + context 'for genus Varanus' do specify { expect(@genus.cites_listed).to be_truthy } end + context 'for species Varanus bengalensis' do specify { expect(@species1.cites_listed).to be_truthy } end @@ -61,9 +70,11 @@ context 'for family Varanidae' do specify { expect(@family.eu_listed).to eq(false) } end + context 'for genus Varanus' do specify { expect(@genus.eu_listed).to be_truthy } end + context 'for species Varanus bengalensis' do specify { expect(@species1.eu_listed).to be_truthy } end diff --git a/spec/models/taxon_relationship_spec.rb b/spec/models/taxon_relationship_spec.rb index 361cfe971..5d4c650e3 100644 --- a/spec/models/taxon_relationship_spec.rb +++ b/spec/models/taxon_relationship_spec.rb @@ -5,11 +5,14 @@ context 'a relationship with no opposite' do let(:taxon_relationship_type) { create(:taxon_relationship_type, is_bidirectional: false) } let!(:taxon_relationship) { create(:taxon_relationship, taxon_relationship_type_id: taxon_relationship_type.id) } + specify { expect(taxon_relationship.has_opposite?).to eq(false) } end + context 'with an opposite' do let(:taxon_relationship_type) { create(:taxon_relationship_type, is_bidirectional: true) } let(:taxon_relationship) { create(:taxon_relationship, taxon_relationship_type_id: taxon_relationship_type.id) } + specify { expect(taxon_relationship.has_opposite?).to eq(true) } end end @@ -18,12 +21,14 @@ context 'when creating a bidirectional relationship' do let(:taxon_relationship_type) { create(:taxon_relationship_type, is_bidirectional: true) } let!(:taxon_relationship) { create(:taxon_relationship, taxon_relationship_type_id: taxon_relationship_type.id) } + specify { expect(taxon_relationship.has_opposite?).to eq(true) } end context 'when creating a non bidirectional relationship' do let(:taxon_relationship_type) { create(:taxon_relationship_type, is_bidirectional: false) } let!(:taxon_relationship) { create(:taxon_relationship, taxon_relationship_type_id: taxon_relationship_type.id) } + specify { expect(taxon_relationship.has_opposite?).to eq(false) } end end @@ -51,6 +56,7 @@ taxon_relationship_type_id: taxon_relationship_type.id ) end + specify { taxon_relationship2.valid? == false } end end @@ -79,10 +85,12 @@ taxon_relationship_type_id: taxon_relationship_type2.id ) end + specify do expect(taxon_relationship2.valid?).to eq(false) end end + context 'adding an intertaxonomic relationship between taxon concepts that are already related in the opposite direction (B -> A)' do let(:taxonomy) { create(:taxonomy) } let(:taxonomy2) { create(:taxonomy) } @@ -107,10 +115,12 @@ taxon_relationship_type_id: taxon_relationship_type2.id ) end + specify do expect(taxon_relationship2.valid?).to eq(false) end end + context 'adding an intertaxonomic relationship between taxon concepts that are not already related' do let(:taxonomy) { create(:taxonomy) } let(:taxonomy2) { create(:taxonomy) } diff --git a/spec/models/taxonomy_spec.rb b/spec/models/taxonomy_spec.rb index 1de8f0e55..be3c03724 100644 --- a/spec/models/taxonomy_spec.rb +++ b/spec/models/taxonomy_spec.rb @@ -4,39 +4,52 @@ describe :create do context 'when valid' do let(:taxonomy) { build(:taxonomy, name: 'WILDLIFE') } + specify { expect(taxonomy).to be_valid } end + context 'when name missing' do let(:taxonomy) { build(:taxonomy, name: nil) } + specify { expect(taxonomy).not_to be_valid } specify { expect(taxonomy).to have(1).error_on(:name) } end + context 'when name duplicated' do let!(:taxonomy1) { create(:taxonomy) } let(:taxonomy2) { build(:taxonomy, name: taxonomy1.name) } + specify { expect(taxonomy2).not_to be_valid } specify { expect(taxonomy2).to have(1).error_on(:name) } end end + describe :update do context 'when updating a non-protected name' do let(:taxonomy) { create(:taxonomy) } + specify { expect(taxonomy.update({ name: 'WORLD OF LOLCATS' })).to be_truthy } end + context 'when updating a protected name' do specify { expect(cites_eu.update({ name: 'WORLD OF LOLCATS' })).to be_falsey } end end + describe :destroy do context 'when no dependent objects attached' do let(:taxonomy) { create(:taxonomy, name: 'WILDLIFE') } + specify { expect(taxonomy.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:taxonomy) { create(:taxonomy, name: 'WILDLIFE') } let!(:designation) { create(:designation, taxonomy: taxonomy) } + specify { expect(taxonomy.destroy).to be_falsey } end + context 'when protected name' do specify { expect(cites_eu.destroy).to be_falsey } end diff --git a/spec/models/trade/annual_report_upload_spec.rb b/spec/models/trade/annual_report_upload_spec.rb index 7834c33dc..a6b91e9f6 100644 --- a/spec/models/trade/annual_report_upload_spec.rb +++ b/spec/models/trade/annual_report_upload_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::AnnualReportUpload, drops_tables: true do +describe Trade::AnnualReportUpload, :drops_tables do def exporter_file Rack::Test::UploadedFile.new( Rails.root.join('spec/support/annual_report_upload_exporter.csv').to_s @@ -33,8 +33,10 @@ def invalid_file csv_source_file: exporter_file ) end + specify { expect(subject).to be_valid } end + context 'when uploaded file as importer with exporter column headers' do subject do build( @@ -43,8 +45,10 @@ def invalid_file csv_source_file: exporter_file ) end + specify { expect(subject).not_to be_valid } end + context 'when uploaded file as importer with importer column headers' do subject do build( @@ -53,8 +57,10 @@ def invalid_file csv_source_file: importer_file ) end + specify { expect(subject).to be_valid } end + context 'when uploaded file as exporter with importer column headers' do subject do build( @@ -63,14 +69,12 @@ def invalid_file csv_source_file: importer_file ) end + specify { expect(subject).not_to be_valid } end end describe :validation_errors do - let!(:format_validation_rule) do - create_year_format_validation - end subject do create( :annual_report_upload, @@ -78,11 +82,18 @@ def invalid_file csv_source_file: importer_file ) end + + let!(:format_validation_rule) do + create_year_format_validation + end + + specify { expect(subject.validation_errors).to be_empty } end describe :create do - before(:each) { Trade::CsvSourceFileUploader.enable_processing = true } + before { Trade::CsvSourceFileUploader.enable_processing = true } + context 'when blank lines in import file' do subject do create( @@ -91,6 +102,7 @@ def invalid_file csv_source_file: importer_file_w_blanks ) end + specify do sandbox_klass = Trade::SandboxTemplate.ar_klass(subject.sandbox.table_name) expect(sandbox_klass.count).to eq(10) @@ -106,6 +118,7 @@ def invalid_file csv_source_file: importer_file ) end + specify do expect(subject.sandbox).to receive(:destroy) subject.destroy @@ -113,7 +126,7 @@ def invalid_file end describe :submit do - before(:each) do + before do genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Acipenser') ) @@ -140,6 +153,7 @@ def invalid_file @submitter = create(:user, role: User::MANAGER) end + pending 'it calls submission worker' do # This has been disabled due to some issues with asynchronous reports submission" subject do # aru no primary errors @@ -160,6 +174,7 @@ def invalid_file create_year_format_validation aru end + specify do expect { subject.submit(@submitter) }.to change(SubmissionWorker.jobs, :size).by(1) end diff --git a/spec/models/trade/distinct_values_validation_rule_spec.rb b/spec/models/trade/distinct_values_validation_rule_spec.rb index 1ed16b452..378e432cb 100644 --- a/spec/models/trade/distinct_values_validation_rule_spec.rb +++ b/spec/models/trade/distinct_values_validation_rule_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::DistinctValuesValidationRule, drops_tables: true do +describe Trade::DistinctValuesValidationRule, :drops_tables do let(:canada) do create( :geo_entity, @@ -17,8 +17,9 @@ iso_code2: 'AR' ) end + describe :validation_errors_for_aru do - before(:each) do + before do @aru = build( :annual_report_upload, point_of_view: 'E', trading_country_id: canada.id @@ -26,21 +27,30 @@ @aru.save(validate: false) @sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) end + context 'exporter should not equal importer (E)' do - before(:each) do - @sandbox_klass.create(trading_partner: argentina.iso_code2) - @sandbox_klass.create(trading_partner: canada.iso_code2) - end subject do create_exporter_importer_validation end + + before do + @sandbox_klass.create(trading_partner: argentina.iso_code2) + @sandbox_klass.create(trading_partner: canada.iso_code2) + end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) end end + context 'exporter should not equal importer (I)' do - before(:each) do + subject do + create_exporter_importer_validation + end + + before do @aru = build( :annual_report_upload, point_of_view: 'I', trading_country_id: canada.id @@ -50,22 +60,25 @@ @sandbox_klass.create(trading_partner: argentina.iso_code2) @sandbox_klass.create(trading_partner: canada.iso_code2) end - subject do - create_exporter_importer_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) end end + context 'exporter should not equal country of origin' do - before(:each) do - @sandbox_klass.create(country_of_origin: argentina.iso_code2) - @sandbox_klass.create(country_of_origin: canada.iso_code2) - end subject do create_exporter_country_of_origin_validation end + + before do + @sandbox_klass.create(country_of_origin: argentina.iso_code2) + @sandbox_klass.create(country_of_origin: canada.iso_code2) + end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) diff --git a/spec/models/trade/inclusion_validation_rule_spec.rb b/spec/models/trade/inclusion_validation_rule_spec.rb index ed5ec6f1d..33a558242 100644 --- a/spec/models/trade/inclusion_validation_rule_spec.rb +++ b/spec/models/trade/inclusion_validation_rule_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::InclusionValidationRule, drops_tables: true do +describe Trade::InclusionValidationRule, :drops_tables do let(:annual_report_upload) do annual_report = build( :annual_report_upload, @@ -25,7 +25,8 @@ let(:validation_rule) do create_taxon_concept_validation end - before(:each) do + + before do @shipment1 = sandbox_klass.create( taxon_name: canis_lupus.full_name ) @@ -45,6 +46,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings validation_rule.refresh_errors_if_needed(annual_report_upload) end + specify do expect( validation_rule.matching_records_for_aru_and_error( @@ -59,7 +61,8 @@ let(:validation_rule) do create_taxon_concept_validation end - before(:each) do + + before do @shipment1 = sandbox_klass.create( taxon_name: canis_lupus.full_name ) @@ -117,7 +120,11 @@ describe :validation_errors_for_aru do context 'species name may have extra whitespace between name segments' do - before(:each) do + subject do + create_taxon_concept_validation + end + + before do genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Acipenser') ) @@ -126,20 +133,30 @@ parent: genus ) end - subject do - create_taxon_concept_validation - end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload)).to be_empty end end + context 'trading partner should be a valid iso code' do - before(:each) do + subject do + create( + :inclusion_validation_rule, + column_names: [ 'trading_partner' ], + valid_values_view: 'valid_trading_partner_view', + is_strict: true + ) + end + + before do sandbox_klass.create(trading_partner: 'Neverland') sandbox_klass.create(trading_partner: '') sandbox_klass.create(trading_partner: nil) end + let!(:france) do create( :geo_entity, @@ -148,19 +165,14 @@ iso_code2: 'FR' ) end - subject do - create( - :inclusion_validation_rule, - column_names: [ 'trading_partner' ], - valid_values_view: 'valid_trading_partner_view', - is_strict: true - ) - end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) end end + context 'term can only be paired with unit as defined by term_trade_codes_pairs table' do before do cap = create(:term, code: 'CAP') @@ -182,32 +194,45 @@ sandbox_klass.create(term_code: 'CAV', unit_code: 'KIL') sandbox_klass.create(term_code: 'CAV', unit_code: '') end + context 'when invalid combination' do - before(:each) do - sandbox_klass.create(term_code: 'CAP', unit_code: 'BAG') - end subject do create_term_unit_validation end + + before do + sandbox_klass.create(term_code: 'CAP', unit_code: 'BAG') + end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) end end + context 'when required unit blank' do - before(:each) do - sandbox_klass.create(term_code: 'CAP', unit_code: '') - end subject do create_term_unit_validation end + + before do + sandbox_klass.create(term_code: 'CAP', unit_code: '') + end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) end end end + context 'term can only be paired with purpose as defined by term_trade_codes_pairs table' do + subject do + create_term_purpose_validation + end + before do cav = create(:term, code: 'CAV') create(:purpose, code: 'B') @@ -220,37 +245,42 @@ sandbox_klass.create(term_code: 'CAV', purpose_code: 'P') sandbox_klass.create(term_code: 'CAV', purpose_code: '') end - subject do - create_term_purpose_validation - end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(2) end end + context 'taxon_concept_id can only be paired with term as defined by trade_taxon_concept_term_pairs table' do + subject do + create_taxon_concept_term_validation + end + before do @genus = create_cites_eu_genus cav = create(:term, code: 'CAV') create(:term, code: 'BAL') @pair = create(:trade_taxon_concept_term_pair, term_id: cav.id, taxon_concept_id: @genus.id) end - subject do - create_taxon_concept_term_validation - end + + context 'when accepted name' do - before(:each) do + before do @species = create_cites_eu_species(parent: @genus) sandbox_klass.create(term_code: 'CAV', taxon_name: @species.full_name) sandbox_klass.create(term_code: 'BAL', taxon_name: @species.full_name) end + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) end end + context 'when hybrid' do - before(:each) do + before do @hybrid = create_cites_eu_species(parent: @genus, name_status: 'H') create( :taxon_relationship, @@ -261,6 +291,7 @@ sandbox_klass.create(term_code: 'CAV', taxon_name: @hybrid.full_name) sandbox_klass.create(term_code: 'BAL', taxon_name: @hybrid.full_name) end + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) diff --git a/spec/models/trade/pov_inclusion_validation_rule_spec.rb b/spec/models/trade/pov_inclusion_validation_rule_spec.rb index 430595a2f..098a26451 100644 --- a/spec/models/trade/pov_inclusion_validation_rule_spec.rb +++ b/spec/models/trade/pov_inclusion_validation_rule_spec.rb @@ -16,7 +16,7 @@ require 'spec_helper' -describe Trade::InclusionValidationRule, drops_tables: true do +describe Trade::InclusionValidationRule, :drops_tables do let(:canada) do create( :geo_entity, @@ -41,7 +41,8 @@ iso_code2: 'XX' ) end - before(:each) do + + before do genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Pecari') ) @@ -55,9 +56,14 @@ geo_entity: argentina ) end + describe :validation_errors_for_aru do context "when W source and country of origin blank and exporter doesn't match distribution (E)" do - before(:each) do + subject do + create_taxon_concept_exporter_validation + end + + before do @aru = build(:annual_report_upload, point_of_view: 'E', trading_country_id: canada.id) @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -68,16 +74,20 @@ taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: argentina.iso_code2 ) end - subject do - create_taxon_concept_exporter_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) end end + context "when W source and country of origin blank and exporter doesn't match distribution (I)" do - before(:each) do + subject do + create_taxon_concept_exporter_validation + end + + before do @aru = build(:annual_report_upload, point_of_view: 'I', trading_country_id: argentina.id) @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -91,16 +101,20 @@ country_of_origin: argentina.iso_code2 ) end - subject do - create_taxon_concept_exporter_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) end end + context 'when W source and country XX' do - before(:each) do + subject do + create_taxon_concept_exporter_validation + end + + before do @aru = build(:annual_report_upload, point_of_view: 'I', trading_country_id: argentina.id) @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -114,16 +128,20 @@ country_of_origin: argentina.iso_code2 ) end - subject do - create_taxon_concept_exporter_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru)).to be_empty end end + context "when W source and country doesn't match distribution of higher taxa" do - before(:each) do + subject do + create_taxon_concept_exporter_validation + end + + before do @aru = build(:annual_report_upload, point_of_view: 'I', trading_country_id: argentina.id) @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -137,16 +155,20 @@ country_of_origin: canada.iso_code2 ) end - subject do - create_taxon_concept_exporter_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru)).to be_empty end end + context 'when invalid scope specified' do - before(:each) do + subject do + create_taxon_concept_exporter_validation + end + + before do @aru = build(:annual_report_upload, point_of_view: 'E', trading_country_id: canada.id) @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -154,11 +176,10 @@ taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: argentina.iso_code2 ) end - subject do - create_taxon_concept_exporter_validation - end + + specify do - expect { subject.validation_errors_for_aru(@aru) }.to_not raise_error + expect { subject.validation_errors_for_aru(@aru) }.not_to raise_error end end end diff --git a/spec/models/trade/sandbox_template_spec.rb b/spec/models/trade/sandbox_template_spec.rb index b7d266d03..266d3a1ba 100644 --- a/spec/models/trade/sandbox_template_spec.rb +++ b/spec/models/trade/sandbox_template_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::SandboxTemplate, drops_tables: true do +describe Trade::SandboxTemplate, :drops_tables do let(:annual_report_upload) do aru = build(:annual_report_upload) aru.save(validate: false) @@ -28,9 +28,10 @@ end describe :update do - before(:each) do + before do @shipment1 = sandbox_klass.create(taxon_name: canis_lupus.full_name) end + specify do @shipment1.update(taxon_name: canis_aureus.full_name) expect(@shipment1.reload.taxon_concept_id).to eq(canis_aureus.id) @@ -38,7 +39,7 @@ end describe :update_batch do - before(:each) do + before do canis_lupus @shipment = sandbox_klass.create(taxon_name: 'Caniis lupus') validation_rule = create_taxon_concept_validation @@ -53,6 +54,7 @@ error_count: 1 ) end + specify do expect(@shipment.reload.taxon_concept_id).to be_nil sandbox_klass.update_batch( diff --git a/spec/models/trade/scoped_inclusion_validation_rule_spec.rb b/spec/models/trade/scoped_inclusion_validation_rule_spec.rb index 9b05deb5f..4803a364d 100644 --- a/spec/models/trade/scoped_inclusion_validation_rule_spec.rb +++ b/spec/models/trade/scoped_inclusion_validation_rule_spec.rb @@ -1,50 +1,57 @@ require 'spec_helper' -describe Trade::InclusionValidationRule, drops_tables: true do +describe Trade::InclusionValidationRule, :drops_tables do describe :validation_errors do - before(:each) do + before do @aru = build(:annual_report_upload) @aru.save(validate: false) @sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) end context 'when W source and country of origin matches distribution' do + subject do + create_taxon_concept_country_of_origin_validation + end + include_context 'Pecari tajacu' - before(:each) do + before do @sandbox_klass.create( taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: 'AR' ) end - subject do - create_taxon_concept_country_of_origin_validation - end + + specify do expect(subject.validation_errors.reload.size).to eq(0) end end context "when W source and country of origin doesn't match distribution" do + subject do + create_taxon_concept_country_of_origin_validation + end + include_context 'Pecari tajacu' - before(:each) do + before do @sandbox_klass.create( taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: 'PL' ) end + end + + context 'when W source and country of origin blank' do subject do create_taxon_concept_country_of_origin_validation end - end - context 'when W source and country of origin blank' do include_context 'Pecari tajacu' - before(:each) do + before do @sandbox_klass.create( taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: nil ) end - subject do - create_taxon_concept_country_of_origin_validation - end + + specify do expect(subject.validation_errors.reload.size).to eq(0) end diff --git a/spec/models/trade/shipment_spec.rb b/spec/models/trade/shipment_spec.rb index 4b5c1938c..40811d2c5 100644 --- a/spec/models/trade/shipment_spec.rb +++ b/spec/models/trade/shipment_spec.rb @@ -4,21 +4,24 @@ describe :create do context 'when reporter_type not given' do subject { build(:shipment, reporter_type: nil) } + specify { expect(subject.error_on(:reporter_type).size).to eq(2) } end context 'when appendix valid' do subject { build(:shipment, appendix: 'N') } + specify { expect(subject).to be_valid } end context 'when appendix not valid' do subject { build(:shipment, appendix: 'I/II') } + specify { expect(subject.error_on(:appendix).size).to eq(1) } end context 'when permit numbers given' do - before(:each) do + before do @shipment = create( :shipment, export_permit_number: 'a', @@ -47,7 +50,7 @@ end describe 'secondary validations' do - before(:each) do + before do # an animal @genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Foobarus'), @@ -82,7 +85,7 @@ end context 'when species name + appendix + year' do - before(:each) do + before do create_cites_I_addition( taxon_concept: @taxon_concept, effective_at: '2013-01-01', @@ -100,6 +103,7 @@ taxon_concept: @taxon_concept, appendix: 'II', year: 2013 ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -110,6 +114,7 @@ taxon_concept: @taxon_concept, appendix: 'N', year: 2013 ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -120,12 +125,13 @@ taxon_concept: @taxon_concept, appendix: 'I', year: 2013 ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when species name + appendix N + year' do - before(:each) do + before do create_eu_B_addition( taxon_concept: @taxon_concept, effective_at: '2013-01-01', @@ -143,12 +149,13 @@ taxon_concept: @taxon_concept, appendix: 'N', year: 2013 ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when species name + appendix N + year' do - before(:each) do + before do @taxon_concept = create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'nonsignificatus'), parent: @genus @@ -165,12 +172,13 @@ taxon_concept: @taxon_concept, appendix: 'N', year: 2013 ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end end context 'when term + unit' do - before(:each) do + before do @cav = create(:term, code: 'CAV') @cap = create(:term, code: 'CAP') @bag = create(:unit, code: 'BAG') @@ -197,6 +205,7 @@ term: @cav, unit: @bag ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -207,6 +216,7 @@ term: @cav, unit: @kil ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end @@ -217,6 +227,7 @@ term: @cav, unit: nil ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end @@ -227,12 +238,13 @@ term: @cap, unit: nil ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end end context 'when term + purpose' do - before(:each) do + before do @cav = create(:term, code: 'CAV') @b = create(:purpose, code: 'B') @p = create(:purpose, code: 'P') @@ -250,6 +262,7 @@ term: @cav, purpose: @b ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -260,12 +273,13 @@ term: @cav, purpose: @p ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when species name + term' do - before(:each) do + before do @cav = create(:term, code: 'CAV') @bal = create(:term, code: 'BAL') create( @@ -282,6 +296,7 @@ taxon_concept: @taxon_concept, term: @cav ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -292,12 +307,13 @@ taxon_concept: @taxon_concept, term: @bal ) end + specify { expect(subject.warnings).to be_empty } end end context 'when species name + country of origin' do - before(:each) do + before do create_taxon_concept_country_of_origin_validation end @@ -310,6 +326,7 @@ country_of_origin: @poland ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -322,6 +339,7 @@ country_of_origin: @argentina ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end @@ -334,12 +352,13 @@ country_of_origin: nil ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when species name + exporter' do - before(:each) do + before do create_taxon_concept_exporter_validation end @@ -353,6 +372,7 @@ exporter: @poland ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -366,6 +386,7 @@ exporter: @argentina ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end @@ -379,12 +400,13 @@ exporter: @xx ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when exporter + country of origin' do - before(:each) do + before do create_exporter_country_of_origin_validation end @@ -397,6 +419,7 @@ country_of_origin: @argentina ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -409,12 +432,13 @@ country_of_origin: @argentina ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when exporter + importer' do - before(:each) do + before do create_exporter_importer_validation end @@ -427,6 +451,7 @@ exporter: @argentina ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -439,12 +464,13 @@ exporter: @argentina ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end context 'when species name + source code' do - before(:each) do + before do @artificial = create(:trade_code, type: 'Source', code: 'A', name_en: 'Artificially propagated') create_taxon_concept_source_validation cites @@ -461,6 +487,7 @@ source: @artificial ).tap(&:validate) end + specify { expect(subject.warnings).not_to be_empty } end @@ -472,6 +499,7 @@ source: @wild ).tap(&:validate) end + specify { expect(subject.warnings).to be_empty } end end diff --git a/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb b/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb index dae854ce3..a97a18925 100644 --- a/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb +++ b/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe Trade::TaxonConceptAppendixYearValidationRule, drops_tables: true do +describe Trade::TaxonConceptAppendixYearValidationRule, :drops_tables do describe :validation_errors_for_aru do - before(:each) do + before do @aru = build(:annual_report_upload) @aru.save(validate: false) @sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) end context 'when CITES listed' do - before(:each) do + before do genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Loxodonta') ) @@ -45,7 +45,11 @@ end context 'when split listing' do - before(:each) do + subject do + create_taxon_concept_appendix_year_validation + end + + before do @sandbox_klass.create( taxon_name: 'Loxodonta africana', appendix: 'I', year: '1997' ) @@ -53,16 +57,20 @@ taxon_name: 'Loxodonta africana', appendix: 'II', year: '1997' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) end end + context 'when old listing' do - before(:each) do + subject do + create_taxon_concept_appendix_year_validation + end + + before do @sandbox_klass.create( taxon_name: 'Loxodonta africana', appendix: 'II', year: '1996' ) @@ -70,54 +78,68 @@ taxon_name: 'Loxodonta africana', appendix: 'I', year: '1996' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) end + specify do subject.refresh_errors_if_needed(@aru) ve = subject.validation_errors_for_aru(@aru).first expect(ve.error_message).to eq('taxon_name Loxodonta africana with appendix II with year 1996 is invalid') end end + context 'when appendix N and CITES listed' do - before(:each) do + subject do + create_taxon_concept_appendix_year_validation + end + + before do @sandbox_klass.create( taxon_name: 'Loxodonta africana', appendix: 'N', year: '1996' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) end + specify do subject.refresh_errors_if_needed(@aru) ve = subject.validation_errors_for_aru(@aru).first expect(ve.error_message).to eq('taxon_name Loxodonta africana with appendix N with year 1996 is invalid') end end + context 'when reported under a synonym, but otherwise fine' do - before(:each) do + subject do + create_taxon_concept_appendix_year_validation + end + + before do @sandbox_klass.create( taxon_name: 'Loxodonta cyclotis', appendix: 'I', year: '2013' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) end end + context 'when hybrid' do - before(:each) do + subject do + create_taxon_concept_appendix_year_validation + end + + before do falconidae = create_cites_eu_family( taxon_name: create(:taxon_name, scientific_name: 'Falconidae') ) @@ -145,40 +167,47 @@ taxon_name: 'Falco hybrid', appendix: 'II', year: '2012' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) end end end + context 'when not CITES listed but EU listed' do + subject do + create_taxon_concept_appendix_year_validation + end + include_context 'Cedrela montana' - before(:each) do + before do @sandbox_klass.create( taxon_name: 'Cedrela montana', appendix: 'N', year: '2013' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) end end + context 'when not CITES listed and not EU listed' do + subject do + create_taxon_concept_appendix_year_validation + end + include_context 'Agave' - before(:each) do + before do @sandbox_klass.create( taxon_name: 'Agave arizonica', appendix: 'N', year: '2013' ) end - subject do - create_taxon_concept_appendix_year_validation - end + + specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) diff --git a/spec/models/trade/taxon_concept_source_validation_rule_spec.rb b/spec/models/trade/taxon_concept_source_validation_rule_spec.rb index 39e39ad14..4385b5669 100644 --- a/spec/models/trade/taxon_concept_source_validation_rule_spec.rb +++ b/spec/models/trade/taxon_concept_source_validation_rule_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::TaxonConceptSourceValidationRule, drops_tables: true do +describe Trade::TaxonConceptSourceValidationRule, :drops_tables do let(:annual_report_upload) do annual_report = build( :annual_report_upload, @@ -12,27 +12,37 @@ let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end + describe :validation_errors_for_aru do context "when species name is from Kingdom Animalia, source_code can't be A" do + subject do + create_taxon_concept_source_validation + end + before do @animal = create_cites_eu_animal_species sandbox_klass.create(source_code: 'A', taxon_name: @animal.full_name) sandbox_klass.create(source_code: 'B', taxon_name: @animal.full_name) end - subject do - create_taxon_concept_source_validation - end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) end + specify do subject.refresh_errors_if_needed(annual_report_upload) ve = subject.validation_errors_for_aru(annual_report_upload).first expect(ve.error_message).to eq("taxon_name #{@animal.full_name} with source_code A is invalid") end end + context "when species name is from Kingdom Plantae, source_code can't be C or R" do + subject do + create_taxon_concept_source_validation + end + before do @plant = create_cites_eu_plant_species sandbox_klass.create(source_code: 'C', taxon_name: @plant.full_name) @@ -40,9 +50,8 @@ sandbox_klass.create(source_code: 'A', taxon_name: @plant.full_name) sandbox_klass.create(source_code: 'B', taxon_name: @plant.full_name) end - subject do - create_taxon_concept_source_validation - end + + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(2) diff --git a/spec/models/trade/validation_rule_spec.rb b/spec/models/trade/validation_rule_spec.rb index afc5697f8..12a3b4253 100644 --- a/spec/models/trade/validation_rule_spec.rb +++ b/spec/models/trade/validation_rule_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Trade::ValidationRule, drops_tables: true do +describe Trade::ValidationRule, :drops_tables do let(:annual_report_upload) do annual_report = build( :annual_report_upload, @@ -17,7 +17,8 @@ let(:validation_rule) do create_taxon_name_presence_validation end - before(:each) do + + before do @shipment1 = sandbox_klass.create( taxon_name: 'Canis lupus' ) @@ -36,6 +37,7 @@ ) validation_rule.refresh_errors_if_needed(annual_report_upload) end + specify do expect( validation_rule.matching_records_for_aru_and_error( @@ -50,7 +52,8 @@ let(:validation_rule) do create_taxon_name_presence_validation end - before(:each) do + + before do @shipment1 = sandbox_klass.create( taxon_name: 'Canis lupus' ) @@ -107,9 +110,10 @@ describe Trade::PresenceValidationRule do describe :validation_errors_for_aru do - before(:each) do + before do sandbox_klass.create(trading_partner: nil) end + context 'trading_partner should not be blank' do subject do create( @@ -117,6 +121,7 @@ column_names: [ 'trading_partner' ] ) end + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) @@ -127,9 +132,10 @@ describe Trade::NumericalityValidationRule do describe :validation_errors_for_aru do - before(:each) do + before do sandbox_klass.create(quantity: 'www') end + context 'quantity should be a number' do subject do create( @@ -138,6 +144,7 @@ is_strict: true ) end + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) @@ -148,13 +155,15 @@ describe Trade::FormatValidationRule do describe :validation_errors_for_aru do - before(:each) do + before do sandbox_klass.create(year: '33333') end + context 'year should be a 4 digit value' do subject do create_year_format_validation end + specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) diff --git a/spec/models/trade_codes/purpose_spec.rb b/spec/models/trade_codes/purpose_spec.rb index 92b372de0..e61cb06ed 100644 --- a/spec/models/trade_codes/purpose_spec.rb +++ b/spec/models/trade_codes/purpose_spec.rb @@ -18,10 +18,13 @@ describe :destroy do context 'when no dependent objects attached' do let(:purpose) { create(:purpose) } + specify { expect(purpose.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:purpose) { create(:purpose) } + context 'when CITES suspension' do let!(:cites_suspension) do create( @@ -30,10 +33,13 @@ start_notification_id: create_cites_suspension_notification.id ) end + specify { expect(purpose.destroy).to be_falsey } end + context 'when shipments' do - before(:each) { create(:shipment, purpose: purpose) } + before { create(:shipment, purpose: purpose) } + specify { expect(purpose.destroy).to be_falsey } end end diff --git a/spec/models/trade_codes/source_spec.rb b/spec/models/trade_codes/source_spec.rb index 19a6ab9ca..e77609b6b 100644 --- a/spec/models/trade_codes/source_spec.rb +++ b/spec/models/trade_codes/source_spec.rb @@ -18,10 +18,13 @@ describe :destroy do context 'when no dependent objects attached' do let(:source) { create(:source) } + specify { expect(source.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:source) { create(:source) } + context 'when CITES suspension' do let!(:cites_suspension) do create( @@ -30,15 +33,20 @@ start_notification_id: create_cites_suspension_notification.id ) end + specify { expect(source.destroy).to be_falsey } end + context 'when CITES quota' do let(:geo_entity) { create(:geo_entity) } let!(:quota) { create(:quota, sources: [ source ], geo_entity_id: geo_entity.id) } + specify { expect(source.destroy).to be_falsey } end + context 'when shipments' do - before(:each) { create(:shipment, source: source) } + before { create(:shipment, source: source) } + specify { expect(source.destroy).to be_falsey } end end diff --git a/spec/models/trade_codes/term_spec.rb b/spec/models/trade_codes/term_spec.rb index 849b8902b..88ce722cf 100644 --- a/spec/models/trade_codes/term_spec.rb +++ b/spec/models/trade_codes/term_spec.rb @@ -18,10 +18,13 @@ describe :destroy do context 'when no dependent objects attached' do let(:term) { create(:term) } + specify { expect(term.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:term) { create(:term) } + context 'when CITES suspension' do let!(:cites_suspension) do create( @@ -30,15 +33,20 @@ start_notification_id: create_cites_suspension_notification.id ) end + specify { expect(term.destroy).to be_falsey } end + context 'when CITES quota' do let(:geo_entity) { create(:geo_entity) } let!(:quota) { create(:quota, terms: [ term ], geo_entity_id: geo_entity.id) } + specify { expect(term.destroy).to be_falsey } end + context 'when shipments' do - before(:each) { create(:shipment, term: term) } + before { create(:shipment, term: term) } + specify { expect(term.destroy).to be_falsey } end end diff --git a/spec/models/trade_codes/unit_spec.rb b/spec/models/trade_codes/unit_spec.rb index 726a2e42e..c820f89ac 100644 --- a/spec/models/trade_codes/unit_spec.rb +++ b/spec/models/trade_codes/unit_spec.rb @@ -18,17 +18,23 @@ describe :destroy do context 'when no dependent objects attached' do let(:unit) { create(:unit) } + specify { expect(unit.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:unit) { create(:unit) } + context 'when quotas' do let(:geo_entity) { create(:geo_entity) } let!(:quota) { create(:quota, unit: unit, geo_entity_id: geo_entity.id) } + specify { expect(unit.destroy).to be_falsey } end + context 'when shipments' do - before(:each) { create(:shipment, unit: unit) } + before { create(:shipment, unit: unit) } + specify { expect(unit.destroy).to be_falsey } end end diff --git a/spec/models/trade_restriction_spec.rb b/spec/models/trade_restriction_spec.rb index 21755eec5..2b767659a 100644 --- a/spec/models/trade_restriction_spec.rb +++ b/spec/models/trade_restriction_spec.rb @@ -6,18 +6,21 @@ @unit = create(:unit, code: 'ABC') @geo_entity = create(:geo_entity) end + describe 'filter_is_current' do before do @quota1 = create(:quota, is_current: true, unit_id: @unit.id, geo_entity_id: @geo_entity.id) @quota2 = create(:quota, is_current: false, unit_id: @unit.id, geo_entity_id: @geo_entity.id) end - it 'should return @quota1 if filter set to current' do + + it 'returns @quota1 if filter set to current' do result = Quota.filter_is_current('current') expect(result).to eq([ @quota1 ]) end - it 'should return both @quota1 and @quota2 if filter set to "all"' do + + it 'returns both @quota1 and @quota2 if filter set to "all"' do result = Quota.filter_is_current('all') - expect(result).to match_array([ @quota1, @quota2 ]) + expect(result).to contain_exactly(@quota1, @quota2) end end @@ -32,17 +35,20 @@ @quota3 = create(:quota, geo_entity_id: @geo_entity1.id, unit_id: @unit.id) @quota4 = create(:quota, geo_entity_id: @geo_entity3.id, unit_id: @unit.id) end - it 'should get all quotas if geo_entities filter not set' do + + it 'gets all quotas if geo_entities filter not set' do result = Quota.filter_geo_entities({}) - expect(result).to match_array([ @quota1, @quota2, @quota3, @quota4 ]) + expect(result).to contain_exactly(@quota1, @quota2, @quota3, @quota4) end - it 'should return quota1 and quota3 if geo_entities filter set to @geo_entity1' do + + it 'returns quota1 and quota3 if geo_entities filter set to @geo_entity1' do result = Quota.filter_geo_entities({ 'geo_entities_ids' => [ @geo_entity1.id ] }) - expect(result).to match_array([ @quota1, @quota3 ]) + expect(result).to contain_exactly(@quota1, @quota3) end - it 'should return quota1, quota3, and quota4 if geo_entities filter set to @geo_entity1 and @geo_entity3' do + + it 'returns quota1, quota3, and quota4 if geo_entities filter set to @geo_entity1 and @geo_entity3' do result = Quota.filter_geo_entities({ 'geo_entities_ids' => [ @geo_entity1.id, @geo_entity3.id ] }) - expect(result).to match_array([ @quota1, @quota3, @quota4 ]) + expect(result).to contain_exactly(@quota1, @quota3, @quota4) end end @@ -54,17 +60,20 @@ @quota3 = create(:quota, start_date: '01/09/2012', unit_id: @unit.id, geo_entity_id: @geo_entity.id) @quota4 = create(:quota, start_date: '01/06/2013', unit_id: @unit.id, geo_entity_id: @geo_entity.id) end - it 'should get all quotas if years filter not set' do + + it 'gets all quotas if years filter not set' do result = Quota.filter_years({}) - expect(result).to match_array([ @quota1, @quota2, @quota3, @quota4 ]) + expect(result).to contain_exactly(@quota1, @quota2, @quota3, @quota4) end - it 'should return quota1 and quota3 if years filter set to 2012' do + + it 'returns quota1 and quota3 if years filter set to 2012' do result = Quota.filter_years({ 'years' => [ 2012 ] }) - expect(result).to match_array([ @quota1, @quota3 ]) + expect(result).to contain_exactly(@quota1, @quota3) end - it 'should return quota1, quota3, and quota4 if years filter set to 2012 and 2013' do + + it 'returns quota1, quota3, and quota4 if years filter set to 2012 and 2013' do result = Quota.filter_years({ 'years' => [ 2012, 2013 ] }) - expect(result).to match_array([ @quota1, @quota3, @quota4 ]) + expect(result).to contain_exactly(@quota1, @quota3, @quota4) end end end diff --git a/spec/models/trade_restrictions/cites_suspension_spec.rb b/spec/models/trade_restrictions/cites_suspension_spec.rb index beef981b6..6b6f6dd8b 100644 --- a/spec/models/trade_restrictions/cites_suspension_spec.rb +++ b/spec/models/trade_restrictions/cites_suspension_spec.rb @@ -49,6 +49,7 @@ iso_code2: 'RW' ) end + before do travel -10.minutes @genus = create_cites_eu_genus @@ -77,10 +78,12 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.save }.to change { @taxon_concept.reload.dependents_updated_at } end end + context 'when global suspension' do subject do build( @@ -90,10 +93,12 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.save }.to change { @taxon_concept.reload.dependents_updated_at } end end + context 'when suspension at higher taxonomic level' do subject do create( @@ -102,11 +107,13 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.save }.to change { @taxon_concept.reload.dependents_updated_at } end end end + describe :update do context 'when taxon specific suspension' do subject do @@ -116,11 +123,13 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.update_attribute(:taxon_concept_id, @another_taxon_concept.id) }. to change { @taxon_concept.reload.dependents_updated_at } end end + context 'when global suspension' do subject do create( @@ -130,15 +139,18 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.update_attribute(:geo_entity_id, rwanda.id) }. to change { @taxon_concept.reload.dependents_updated_at } end + specify do expect { subject.update_attribute(:geo_entity_id, rwanda.id) }. to change { @another_taxon_concept.reload.dependents_updated_at } end end + context 'when suspension at higher taxonomic level' do subject do create( @@ -147,12 +159,14 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.update_attribute(:geo_entity_id, rwanda.id) }. to change { @taxon_concept.reload.dependents_updated_at } end end end + describe :destroy do context 'when taxon specific suspension' do subject do @@ -162,10 +176,12 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.destroy }.to change { @taxon_concept.reload.dependents_updated_at } end end + context 'when global suspension' do subject do create( @@ -175,11 +191,13 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.destroy }. to change { @taxon_concept.reload.dependents_updated_at } end end + context 'when suspension at higher taxonomic level' do subject do create( @@ -188,6 +206,7 @@ start_notification: create_cites_suspension_notification ) end + specify do expect { subject.destroy }. to change { @taxon_concept.reload.dependents_updated_at } @@ -241,7 +260,9 @@ describe :create do context 'downloads cache should be populated' do - before(:each) do + subject { Dir["#{DownloadsCache.cites_suspensions_path}/*"] } + + before do DownloadsCache.clear_cites_suspensions create( :cites_suspension, @@ -251,14 +272,17 @@ ) CitesSuspension.export('set' => 'current') end - subject { Dir["#{DownloadsCache.cites_suspensions_path}/*"] } + + specify { expect(subject).not_to be_empty } end end describe :destroy do context 'downloads cache should be cleared' do - before(:each) do + subject { Dir["#{DownloadsCache.cites_suspensions_path}/*"] } + + before do DownloadsCache.clear_cites_suspensions s = create( @@ -273,7 +297,7 @@ s.destroy end - subject { Dir["#{DownloadsCache.cites_suspensions_path}/*"] } + specify do # Currently fails because the clearing happens in an after_commit hook, # which does not run until the test is over. diff --git a/spec/models/trade_restrictions/quota_spec.rb b/spec/models/trade_restrictions/quota_spec.rb index 7c11d552c..ad8c8b945 100644 --- a/spec/models/trade_restrictions/quota_spec.rb +++ b/spec/models/trade_restrictions/quota_spec.rb @@ -39,19 +39,24 @@ describe :create do context 'downloads cache should be populated' do - before(:each) do + subject { Dir["#{DownloadsCache.quotas_path}/*"] } + + before do DownloadsCache.clear_quotas create(:quota, start_date: Time.utc(2013), geo_entity: create(:geo_entity)) Quota.export('set' => 'current') end - subject { Dir["#{DownloadsCache.quotas_path}/*"] } + + specify { expect(subject).not_to be_empty } end end describe :destroy do context 'downloads cache should be cleared' do - before(:each) do + subject { Dir["#{DownloadsCache.quotas_path}/*"] } + + before do DownloadsCache.clear_quotas q = create( @@ -64,7 +69,8 @@ q.destroy end - subject { Dir["#{DownloadsCache.quotas_path}/*"] } + + specify do # Currently fails because the clearing happens in an after_commit hook, # which does not run until the test is over. diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f42ba042e..66f8b7cc0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,26 +5,33 @@ describe :create do context 'when organisation not given' do let(:user) { build(:user, organisation: nil) } - specify { expect(user).to_not be_valid } + + specify { expect(user).not_to be_valid } end end + describe :destroy do context 'when no dependent objects attached' do let(:user) { create(:user) } + specify { expect(user.destroy).to be_truthy } end + context 'when dependent objects attached' do let(:user) { create(:user) } - before(:each) do + + before do RequestStore.store[:track_who_does_it_current_user] = user create(:shipment) end + specify { expect(user.destroy).to be_falsey } end end describe 'abilities' do subject(:ability) { Ability.new(user) } + let(:user) { nil } context 'when is a Data Manager' do @@ -42,16 +49,19 @@ context 'when is a E-library Viewer' do let(:user) { create(:user, role: User::ELIBRARY_USER) } + it { is_expected.not_to be_able_to(:manage, TaxonConcept) } end context 'when is an API User' do let(:user) { create(:user, role: User::API_USER) } + it { is_expected.not_to be_able_to(:manage, TaxonConcept) } end context 'when is a Secretariat' do let(:user) { create(:user, role: User::SECRETARIAT) } + it { is_expected.not_to be_able_to(:create, :all) } it { is_expected.not_to be_able_to(:update, :all) } it { is_expected.not_to be_able_to(:destroy, :all) } @@ -59,6 +69,7 @@ context 'when is not active' do let(:user) { create(:user, role: User::MANAGER, is_active: false) } + it { is_expected.not_to be_able_to(:create, :all) } it { is_expected.not_to be_able_to(:update, :all) } it { is_expected.not_to be_able_to(:destroy, :all) } diff --git a/spec/services/checklist/annotations_spec.rb b/spec/services/checklist/annotations_spec.rb index ff7f6b755..01305cac7 100644 --- a/spec/services/checklist/annotations_spec.rb +++ b/spec/services/checklist/annotations_spec.rb @@ -13,12 +13,16 @@ ) @taxon_concepts = @checklist.results end + context 'for species Caiman latirostris' do subject { @taxon_concepts.select { |e| e.full_name == 'Caiman latirostris' }.first } + specify { expect(subject.ann_symbol).to eq('1') } end + context 'for species Panax ginseng' do subject { @taxon_concepts.select { |e| e.full_name == 'Panax ginseng' }.first } + specify { expect(subject.ann_symbol).to eq('2') } end end diff --git a/spec/services/checklist/appendix_population_and_region_spec.rb b/spec/services/checklist/appendix_population_and_region_spec.rb index 275c1a53b..e8a690099 100644 --- a/spec/services/checklist/appendix_population_and_region_spec.rb +++ b/spec/services/checklist/appendix_population_and_region_spec.rb @@ -13,10 +13,12 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end + context 'when Mexico' do subject do checklist = Checklist::Checklist.new( @@ -26,10 +28,12 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end + context 'when Canada' do subject do checklist = Checklist::Checklist.new( @@ -39,10 +43,12 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end + context 'when Argentina' do subject do checklist = Checklist::Checklist.new( @@ -52,10 +58,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when South America' do subject do checklist = Checklist::Checklist.new( @@ -65,10 +73,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when North America' do subject do checklist = Checklist::Checklist.new( @@ -78,10 +88,12 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end + context 'when North America and Argentina' do subject do checklist = Checklist::Checklist.new( @@ -92,6 +104,7 @@ ) checklist.results end + specify do expect(subject).to include(@species) end diff --git a/spec/services/checklist/appendix_population_spec.rb b/spec/services/checklist/appendix_population_spec.rb index 8620cc82a..a48679d3d 100644 --- a/spec/services/checklist/appendix_population_spec.rb +++ b/spec/services/checklist/appendix_population_spec.rb @@ -4,7 +4,8 @@ include_context 'Canis lupus' context 'search by cites populations' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + context 'when Nepal' do subject do checklist = Checklist::Checklist.new( @@ -14,10 +15,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when Poland' do subject do checklist = Checklist::Checklist.new( @@ -27,13 +30,16 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end end + context 'search by cites appendices' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + context 'when App I' do subject do checklist = Checklist::Checklist.new( @@ -43,10 +49,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when App II' do subject do checklist = Checklist::Checklist.new( @@ -56,10 +64,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when App III' do subject do checklist = Checklist::Checklist.new( @@ -69,13 +79,16 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end end + context 'search by cites populations and appendices' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + context 'when Nepal' do context 'when App I' do subject do @@ -87,10 +100,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when App II' do subject do checklist = Checklist::Checklist.new( @@ -101,11 +116,13 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end end + context 'when Poland' do context 'when App I' do subject do @@ -117,10 +134,12 @@ ) checklist.results end + specify do expect(subject).not_to include(@species) end end + context 'when App II' do subject do checklist = Checklist::Checklist.new( @@ -131,11 +150,13 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end end + context 'when Poland or Nepal' do context 'when App I' do subject do @@ -147,10 +168,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when App II' do subject do checklist = Checklist::Checklist.new( @@ -161,11 +184,13 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end end + context 'when App I or II' do context 'when Poland' do subject do @@ -177,10 +202,12 @@ ) checklist.results end + specify do expect(subject).to include(@species) end end + context 'when Nepal' do subject do checklist = Checklist::Checklist.new( @@ -191,6 +218,7 @@ ) checklist.results end + specify do expect(subject).to include(@species) end diff --git a/spec/services/checklist/appendix_spec.rb b/spec/services/checklist/appendix_spec.rb index 549ffbe8a..aeeb9460f 100644 --- a/spec/services/checklist/appendix_spec.rb +++ b/spec/services/checklist/appendix_spec.rb @@ -13,11 +13,12 @@ ) @taxon_concepts = @checklist.results end - it 'should return Cacatua goffiniana' do + + it 'returns Cacatua goffiniana' do expect(@taxon_concepts.select { |e| e.full_name == @species1_2_1.full_name }.first).not_to be_nil end - it 'should not return Agapornis roseicollis' do + it 'does not return Agapornis roseicollis' do expect(@taxon_concepts.select { |e| e.full_name == @species2_1.full_name }.first).to be_nil end end diff --git a/spec/services/checklist/checklist_spec.rb b/spec/services/checklist/checklist_spec.rb index ce848d08d..98404978b 100644 --- a/spec/services/checklist/checklist_spec.rb +++ b/spec/services/checklist/checklist_spec.rb @@ -76,11 +76,13 @@ let(:summary) do Checklist::Checklist.summarise_filters({}) end + specify do expect(summary).to eq('All results') end end end + context 'when 1 region' do let(:region) do region_type = create( @@ -95,10 +97,12 @@ let(:summary) do Checklist::Checklist.summarise_filters({ cites_region_ids: [ region.id ] }) end + specify do expect(summary).to eq('Results from 1 region') end end + context 'when > 1 region' do let(:regions) do region_type = create( @@ -118,6 +122,7 @@ let(:summary) do Checklist::Checklist.summarise_filters({ cites_region_ids: regions }) end + specify do expect(summary).to eq('Results from 2 regions') end diff --git a/spec/services/checklist/common_names_spec.rb b/spec/services/checklist/common_names_spec.rb index de3889fbf..4204e8642 100644 --- a/spec/services/checklist/common_names_spec.rb +++ b/spec/services/checklist/common_names_spec.rb @@ -18,31 +18,31 @@ @arctocephalus = @taxon_concepts.select { |e| e.full_name == @genus.full_name }.first end - it "should return all English names for Arctocephalus australis: 'South American Fur Seal, Southern Fur Seal'" do + it "returns all English names for Arctocephalus australis: 'South American Fur Seal, Southern Fur Seal'" do expect(@australis.english_names).to eq([ 'South American Fur Seal', 'Southern Fur Seal' ]) end - it "should return all Spanish names for Arctocephalus australis: 'Lobo fino sudamericano, Oso marino austral'" do + it "returns all Spanish names for Arctocephalus australis: 'Lobo fino sudamericano, Oso marino austral'" do expect(@australis.spanish_names).to eq([ 'Lobo fino sudamericano', 'Oso marino austral' ]) end - it "should return all French names for Arctocephalus australis: 'Otarie à fourrure australe'" do + it "returns all French names for Arctocephalus australis: 'Otarie à fourrure australe'" do expect(@australis.french_names).to eq([ 'Otarie à fourrure australe' ]) end - it "should return all English names for Arctocephalus spp.: 'Fur seals, Southern fur seals'" do + it "returns all English names for Arctocephalus spp.: 'Fur seals, Southern fur seals'" do expect(@arctocephalus.english_names).to eq([ 'Fur seals 1', 'Southern fur seals' ]) end - it "should return all Spanish names for Arctocephalus spp.: 'Osos marinos'" do + it "returns all Spanish names for Arctocephalus spp.: 'Osos marinos'" do expect(@arctocephalus.spanish_names).to eq([ 'Osos marinos' ]) end - it "should return all French names for Arctocephalus spp.: 'Arctocéphales du sud, Otaries à fourrure, Otaries à fourrure du sud'" do + it "returns all French names for Arctocephalus spp.: 'Arctocéphales du sud, Otaries à fourrure, Otaries à fourrure du sud'" do expect(@arctocephalus.french_names).to eq([ 'Arctocéphales du sud', 'Otaries à fourrure', 'Otaries à fourrure du sud' ]) end - it 'should include a species without any common names defined' do + it 'includes a species without any common names defined' do @pusillus = @taxon_concepts.select { |e| e.full_name == @species3.full_name }.first expect(@pusillus).not_to be_nil end diff --git a/spec/services/checklist/higher_taxa_injector_spec.rb b/spec/services/checklist/higher_taxa_injector_spec.rb index 88cc630fb..c1955f67a 100644 --- a/spec/services/checklist/higher_taxa_injector_spec.rb +++ b/spec/services/checklist/higher_taxa_injector_spec.rb @@ -118,6 +118,7 @@ ] ) end + specify do headers = hti_different_class.higher_taxa_headers( @species1_1_1, @@ -126,6 +127,7 @@ expect(headers.map(&:full_name)).to eq([ 'Memaridae' ]) end end + context 'when two species from different classes and expand_headers set' do let(:hti_different_class) do Checklist::HigherTaxaInjector.new( @@ -135,6 +137,7 @@ ], { expand_headers: true } ) end + specify do headers = hti_different_class.higher_taxa_headers( @species1_1_1, @@ -144,6 +147,7 @@ end end end + context 'when same order' do context 'when two species from different families' do let(:hti_different_family) do @@ -154,10 +158,12 @@ ] ) end + specify do expect(hti_different_family.run.size).to eq(4) end end + context 'when two species from different families and skip family set' do let(:hti_different_family) do Checklist::HigherTaxaInjector.new( @@ -167,6 +173,7 @@ ], { skip_ancestor_ids: [ @family1.id ] } ) end + specify do expect(hti_different_family.run.size).to eq(3) end @@ -184,11 +191,13 @@ ] ) end + specify do headers = hti_one_species.higher_taxa_headers(nil, @species1_1_1) expect(headers.map(&:full_name)).to eq([ 'Lolcatidae' ]) end end + context 'when one species and skip family set' do let(:hti_one_species_skip_family) do Checklist::HigherTaxaInjector.new( @@ -197,10 +206,12 @@ ], { skip_ancestor_ids: [ @family1.id ] } ) end + specify do expect(hti_one_species_skip_family.higher_taxa_headers(nil, @species1_1_1)).to be_empty end end + context 'when one species and expand headers set' do let(:hti_one_species_expand_headers) do Checklist::HigherTaxaInjector.new( @@ -209,6 +220,7 @@ ], { expand_headers: true } ) end + specify do headers = hti_one_species_expand_headers.higher_taxa_headers(nil, @species1_1_1) expect(headers.map(&:full_name)).to eq( @@ -216,6 +228,7 @@ ) end end + context 'when two species' do let(:hti_same_genus) do Checklist::HigherTaxaInjector.new( @@ -225,10 +238,12 @@ ] ) end + specify do expect(hti_same_genus.higher_taxa_headers(@species1_1_1, @species1_1_2)).to be_empty end end + context 'when species and subspecies' do let(:hti_species_subspecies) do Checklist::HigherTaxaInjector.new( @@ -238,11 +253,13 @@ ] ) end + specify do expect(hti_species_subspecies.higher_taxa_headers(@species1_1_2, @subspecies1_1_1_1)).to be_empty end end end + context 'when same family' do context 'when two species from different genera' do let(:hti_same_family) do @@ -253,11 +270,13 @@ ] ) end + specify do expect(hti_same_family.higher_taxa_headers(@species1_1_1, @species1_2_1)).to be_empty end end end + context 'when same order' do context 'when two species from different families' do let(:hti_different_family) do @@ -268,6 +287,7 @@ ] ) end + specify do headers = hti_different_family.higher_taxa_headers(@species1_1_1, @species2_1_1) expect(headers.map(&:full_name)).to eq( @@ -275,6 +295,7 @@ ) end end + context 'when two species from different families and expand headers set' do let(:hti_different_family) do Checklist::HigherTaxaInjector.new( @@ -284,6 +305,7 @@ ], { expand_headers: true } ) end + specify do headers = hti_different_family.higher_taxa_headers(@species1_1_1, @species2_1_1) expect(headers.map(&:full_name)).to eq( @@ -291,6 +313,7 @@ ) end end + context 'when genus and different family' do let(:hti_genus_family) do Checklist::HigherTaxaInjector.new( @@ -300,6 +323,7 @@ ] ) end + specify do headers = hti_genus_family.higher_taxa_headers(@genus1_1, @family2) expect(headers.map(&:full_name)).to eq( @@ -307,6 +331,7 @@ ) end end + context 'when family and genus in different family' do let(:hti_family_genus) do Checklist::HigherTaxaInjector.new( @@ -316,6 +341,7 @@ ] ) end + specify do headers = hti_family_genus.higher_taxa_headers(@family1, @genus2_1) expect(headers.map(&:full_name)).to eq( @@ -324,6 +350,7 @@ end end end + context 'when same class' do context 'when order and genus from different order' do let(:hti_different_orders) do @@ -334,6 +361,7 @@ ] ) end + specify do headers = hti_different_orders.higher_taxa_headers(@order2, @genus2_1) expect(headers.map(&:full_name)).to eq( @@ -341,6 +369,7 @@ ) end end + context 'when order and genus from different order and expand headers set' do let(:hti_different_orders_expand) do Checklist::HigherTaxaInjector.new( @@ -350,6 +379,7 @@ ], { expand_headers: true } ) end + specify do headers = hti_different_orders_expand.higher_taxa_headers(@order2, @genus2_1) expect(headers.map(&:full_name)).to eq( diff --git a/spec/services/checklist/higher_taxa_item_spec.rb b/spec/services/checklist/higher_taxa_item_spec.rb index e72c0e2f8..720796ac6 100644 --- a/spec/services/checklist/higher_taxa_item_spec.rb +++ b/spec/services/checklist/higher_taxa_item_spec.rb @@ -3,6 +3,8 @@ describe Checklist::HigherTaxaItem do describe :ancestors_path do context 'when animal' do + subject { Checklist::HigherTaxaItem.new(taxon_concept) } + let(:taxon_concept) do obj = double( 'MTaxonConcept', @@ -14,10 +16,14 @@ family_name: 'Alligatoridae' ) end - subject { Checklist::HigherTaxaItem.new(taxon_concept) } + + specify { expect(subject.ancestors_path).to eq('Chordata,Reptilia,Crocodylia,Alligatoridae') } end + context 'when plant' do + subject { Checklist::HigherTaxaItem.new(taxon_concept) } + let(:taxon_concept) do obj = double( 'MTaxonConcept', @@ -29,7 +35,8 @@ family_name: 'Agavaceae' ) end - subject { Checklist::HigherTaxaItem.new(taxon_concept) } + + specify { expect(subject.ancestors_path).to eq('Agavaceae') } end end diff --git a/spec/services/checklist/order_spec.rb b/spec/services/checklist/order_spec.rb index 6dbabfa77..0581fca5c 100644 --- a/spec/services/checklist/order_spec.rb +++ b/spec/services/checklist/order_spec.rb @@ -14,64 +14,77 @@ @checklist.generate @taxon_concepts = @checklist.plantae end - it 'should include Agave (Agavaceae) before Panax (Araliaceae)' do + + it 'includes Agave (Agavaceae) before Panax (Araliaceae)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Agave parviflora' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Panax ginseng' } end end + context('Animalia') do before(:all) do @checklist = Checklist::Checklist.new({ output_layout: :taxonomic, per_page: 100 }) @checklist.generate @taxon_concepts = @checklist.animalia end - it 'should include birds after last mammal' do + + it 'includes birds after last mammal' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Tapirus terrestris' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Gymnogyps californianus' } end - it 'should include Falconiformes (Aves) before Psittaciformes (Aves)' do + + it 'includes Falconiformes (Aves) before Psittaciformes (Aves)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Falconiformes' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Psittaciformes' } end - it 'should include Cathartidae within Falconiformes' do + + it 'includes Cathartidae within Falconiformes' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be > @taxon_concepts.index { |tc| tc.full_name == 'Falconiformes' } expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Psittaciformes' } end - it 'should include Cathartidae (Falconiformes) before Falconidae (Falconiformes)' do + + it 'includes Cathartidae (Falconiformes) before Falconidae (Falconiformes)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Falconidae' } end - it 'should include Cathartidae (Falconiformes) before Cacatuidae (Psittaciformes)' do + + it 'includes Cathartidae (Falconiformes) before Cacatuidae (Psittaciformes)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Cacatuidae' } end - it 'should include Hirudo medicinalis at the very end (after all Chordata)' do + + it 'includes Hirudo medicinalis at the very end (after all Chordata)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Hirudo medicinalis' }).to eq( @taxon_concepts.length - 1 ) end end end + context 'when alphabetical order' do before(:all) do @checklist = Checklist::Checklist.new({ output_layout: :alphabetical, per_page: 100 }) @taxon_concepts = @checklist.results end - it 'should include Falconiformes (Aves) before Psittaciformes (Aves)' do + + it 'includes Falconiformes (Aves) before Psittaciformes (Aves)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Falconiformes' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Psittaciformes' } end - it 'should include Cathartidae before Falconiformes' do + + it 'includes Cathartidae before Falconiformes' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Falconiformes' } end - it 'should include Cathartidae (Falconiformes) before Falconidae (Falconiformes)' do + + it 'includes Cathartidae (Falconiformes) before Falconidae (Falconiformes)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be < @taxon_concepts.index { |tc| tc.full_name == 'Falconidae' } end - it 'should include Cathartidae (Falconiformes) after Cacatuidae (Psittaciformes)' do + + it 'includes Cathartidae (Falconiformes) after Cacatuidae (Psittaciformes)' do expect(@taxon_concepts.index { |tc| tc.full_name == 'Cathartidae' }).to be > @taxon_concepts.index { |tc| tc.full_name == 'Cacatuidae' } end diff --git a/spec/services/checklist/pdf/history_annotations_key_spec.rb b/spec/services/checklist/pdf/history_annotations_key_spec.rb index bcb90884a..d52afbd16 100644 --- a/spec/services/checklist/pdf/history_annotations_key_spec.rb +++ b/spec/services/checklist/pdf/history_annotations_key_spec.rb @@ -5,6 +5,7 @@ describe :annotations_key do subject { Checklist::Pdf::HistoryAnnotationsKey.new } + specify do allow(subject).to receive(:non_hash_annotations_key).and_return('x') allow(subject).to receive(:hash_annotations_key).and_return('x') @@ -13,7 +14,9 @@ end describe :hash_annotations_key do - before(:each) do + subject { Checklist::Pdf::HistoryAnnotationsKey.new } + + before do plant_genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Foobaria'), parent: create_cites_eu_family( @@ -55,7 +58,8 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - subject { Checklist::Pdf::HistoryAnnotationsKey.new } + + specify do expect(subject.hash_annotations_key).to eq("\\hashAnnotationsHistoryInfo\n\n\\hashannotationstable{\n\\rowcolor{pale_aqua}\nCoP1 & \\validFrom \\hspace{2 pt} 01/07/2012\\\\\n\\#1 & Only trunks \\\\\n\n}\n\\hashannotationstable{\n\\rowcolor{pale_aqua}\nCoP2 & \\validFrom \\hspace{2 pt} 01/07/2013\\\\\n\\#1 & Only bark \\\\\n\n}\n") end diff --git a/spec/services/checklist/pdf/history_spec.rb b/spec/services/checklist/pdf/history_spec.rb index dda02485a..695ae72d7 100644 --- a/spec/services/checklist/pdf/history_spec.rb +++ b/spec/services/checklist/pdf/history_spec.rb @@ -19,8 +19,11 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + describe :higher_taxon_name do context 'when family' do + subject { Checklist::Pdf::History.new(scientific_name: tc.full_name, show_english: true) } + let(:tc) { family_tc } let!(:taxon_common) do create( @@ -34,7 +37,8 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - subject { Checklist::Pdf::History.new(scientific_name: tc.full_name, show_english: true) } + + specify do expect(subject.higher_taxon_name(tc.reload)).to eq("\\subsection*{FOOBARIDAE (E) Foobars }\n") end @@ -43,6 +47,8 @@ describe :listed_taxon_name do context 'when family' do + subject { Checklist::Pdf::History.new(scientific_name: tc.full_name) } + let(:tc) { family_tc } let!(:lc) do lc = create_cites_I_addition( @@ -52,12 +58,16 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MCitesListingChange.find(lc.id) end - subject { Checklist::Pdf::History.new(scientific_name: tc.full_name) } + + specify do expect(subject.listed_taxon_name(tc)).to eq('FOOBARIDAE spp.') end end + context 'when genus' do + subject { Checklist::Pdf::History.new(scientific_name: tc.full_name) } + let(:tc) { genus_tc } let!(:lc) do lc = create_cites_I_addition( @@ -67,7 +77,8 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MCitesListingChange.find(lc.id) end - subject { Checklist::Pdf::History.new(scientific_name: tc.full_name) } + + specify do expect(subject.listed_taxon_name(tc)).to eq('\emph{Foobarus} spp.') end @@ -76,6 +87,8 @@ describe :annotation_for_language do context 'annotation with footnote' do + subject { Checklist::Pdf::History.new({}) } + let(:annotation) do create( :annotation, @@ -95,7 +108,8 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MCitesListingChange.find(lc.id) end - subject { Checklist::Pdf::History.new({}) } + + specify do expect(subject.annotation_for_language(lc, 'en')).to eq("Except \\textit{Foobarus cracoviensis}\n\nPreviously listed as \\textit{Foobarus polonicus}.\\footnote{...}") end diff --git a/spec/services/checklist/pdf/index_annotations_key_spec.rb b/spec/services/checklist/pdf/index_annotations_key_spec.rb index a2b4dd696..be496d33a 100644 --- a/spec/services/checklist/pdf/index_annotations_key_spec.rb +++ b/spec/services/checklist/pdf/index_annotations_key_spec.rb @@ -5,6 +5,7 @@ describe :annotations_key do subject { Checklist::Pdf::IndexAnnotationsKey.new } + specify do allow(subject).to receive(:non_hash_annotations_key).and_return('x') allow(subject).to receive(:hash_annotations_key).and_return('x') @@ -13,7 +14,9 @@ end describe :hash_annotations_key do - before(:each) do + subject { Checklist::Pdf::IndexAnnotationsKey.new } + + before do plant_genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Foobaria'), parent: create_cites_eu_family( @@ -42,14 +45,17 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - subject { Checklist::Pdf::IndexAnnotationsKey.new } + + specify do expect(subject.hash_annotations_key).to eq("\\newpage\n\\section*{\\hashAnnotations}\n\\hashAnnotationsIndexInfo\n\n\\hashannotationstable{\n\\rowcolor{pale_aqua}\nCoP2 & \\validFrom \\hspace{2 pt} 01/07/2013\\\\\n\\#1 & Only bark \\\\\n\n}\n") end end describe :non_hash_annotations_key do - before(:each) do + subject { Checklist::Pdf::IndexAnnotationsKey.new } + + before do animal_genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Foobarus'), parent: create_cites_eu_family( @@ -98,7 +104,8 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - subject { Checklist::Pdf::IndexAnnotationsKey.new } + + specify do allow(LatexToPdf).to receive(:html2latex).and_return('x') expect(subject.non_hash_annotations_key).to eq("\\section*{\\nonHashAnnotations}\n\\cfbox{orange}{\\superscript{1} \\textbf{\\textit{Foobarus bizarrus}}}\n\nx\n\n\\cfbox{green}{\\superscript{2} \\textbf{\\textit{Foobaria curiosa}}}\n\nx\n\n") diff --git a/spec/services/checklist/pdf/index_fetcher_spec.rb b/spec/services/checklist/pdf/index_fetcher_spec.rb index c42bbedbd..7a9e05b95 100644 --- a/spec/services/checklist/pdf/index_fetcher_spec.rb +++ b/spec/services/checklist/pdf/index_fetcher_spec.rb @@ -37,6 +37,8 @@ let(:rel) { MTaxonConcept.by_scientific_name('Lolcatus') } context 'with common names' do + subject { Checklist::Pdf::IndexFetcher.new(query) } + let(:query) do Checklist::Pdf::IndexQuery.new( rel, { @@ -45,10 +47,14 @@ } ) end - subject { Checklist::Pdf::IndexFetcher.new(query) } + + specify { expect(subject.next.first.sort_name).to eq('lolcat, Domestic') } end + context 'with synonyms and authors' do + subject { Checklist::Pdf::IndexFetcher.new(query) } + let!(:synonym) do create( :taxon_concept, @@ -73,7 +79,8 @@ } ) end - subject { Checklist::Pdf::IndexFetcher.new(query) } + + specify { expect(subject.next.first.sort_name).to eq('Catus fluffianus') } end end diff --git a/spec/services/checklist/scientific_name_spec.rb b/spec/services/checklist/scientific_name_spec.rb index 962e61945..998613ff3 100644 --- a/spec/services/checklist/scientific_name_spec.rb +++ b/spec/services/checklist/scientific_name_spec.rb @@ -14,11 +14,13 @@ ) checklist.results end + specify do expect(subject.first.full_name).to eq(@species2.full_name) expect(subject.size).to eq(1) end end + context 'by common name' do subject do checklist = Checklist::Checklist.new( @@ -29,6 +31,7 @@ ) checklist.results end + specify do expect(subject.first.full_name).to eq(@species2.full_name) expect(subject.size).to eq(1) diff --git a/spec/services/checklist/synonyms_spec.rb b/spec/services/checklist/synonyms_spec.rb index c45a4e437..d9c5e47cd 100644 --- a/spec/services/checklist/synonyms_spec.rb +++ b/spec/services/checklist/synonyms_spec.rb @@ -14,7 +14,7 @@ @taxon_concepts = @checklist.results end - it 'should return Alligator cynocephalus as synonym for Caiman latirostris' do + it 'returns Alligator cynocephalus as synonym for Caiman latirostris' do @caiman_latirostris = @taxon_concepts.select { |e| e.full_name == @species.full_name }.first expect(@caiman_latirostris.synonyms).to eq([ 'Alligator cynocephalus' ]) end diff --git a/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb b/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb index 817dfb5cc..ff62c5d0d 100644 --- a/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb +++ b/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb @@ -12,8 +12,10 @@ } ) end + specify { expect(subject.results.size).to eq(3) } end + context 'when match on accepted name' do subject do Species::TaxonConceptPrefixMatcher.new( @@ -23,8 +25,10 @@ } ) end + specify { expect(subject.results.size).to eq(3) } end + context 'when match on synonym' do subject do Species::TaxonConceptPrefixMatcher.new( @@ -34,8 +38,10 @@ } ) end + specify { expect(subject.results.size).to eq(2) } end + context 'when match on common name' do subject do Species::TaxonConceptPrefixMatcher.new( @@ -45,6 +51,7 @@ } ) end + specify { expect(subject.results.size).to eq(1) } end end diff --git a/spec/services/checklist/timeline_spec.rb b/spec/services/checklist/timeline_spec.rb index 36dcbbdb6..3fcdb335b 100644 --- a/spec/services/checklist/timeline_spec.rb +++ b/spec/services/checklist/timeline_spec.rb @@ -229,6 +229,7 @@ [ 'ADDITION', 'AMENDMENT' ] ) end + specify { expect(subject.timeline_intervals.count).to eq(2) } specify { expect(subject.timeline_intervals[1].end_pos).to eq(1) } end @@ -259,6 +260,7 @@ [ 'ADDITION', 'DELETION' ] ) end + specify { expect(subject.timeline_intervals.count).to eq(1) } specify { expect(subject.timeline_intervals[0].end_pos).to eq(subject.timeline_events[1].pos) } end diff --git a/spec/services/checklist/timelines_for_taxon_concept_spec.rb b/spec/services/checklist/timelines_for_taxon_concept_spec.rb index 8cca120b8..1f5862d0f 100644 --- a/spec/services/checklist/timelines_for_taxon_concept_spec.rb +++ b/spec/services/checklist/timelines_for_taxon_concept_spec.rb @@ -5,11 +5,10 @@ travel_to Time.local(1990) end - after do - end - describe :timelines do context 'when Appendix I' do + subject { Checklist::TimelinesForTaxonConcept.new(tc) } + let(:tc) do tc = create_cites_eu_species create_cites_I_addition( @@ -20,11 +19,15 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end - subject { Checklist::TimelinesForTaxonConcept.new(tc) } + + specify { expect(subject.raw_timelines['I'].timeline_events).not_to be_empty } specify { expect(subject.raw_timelines['II'].timeline_events).to be_empty } end + context 'when Appendix III' do + subject { Checklist::TimelinesForTaxonConcept.new(tc) } + let(:tc) do tc = create_cites_eu_species lc = create_cites_III_addition( @@ -41,11 +44,15 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end - subject { Checklist::TimelinesForTaxonConcept.new(tc) } + + specify { expect(subject.raw_timelines['III'].timeline_events).not_to be_empty } specify { expect(subject.raw_timelines['I'].timeline_events).to be_empty } end + context 'when Appendix III reservation' do + subject { Checklist::TimelinesForTaxonConcept.new(tc) } + let(:tc) do tc = create_cites_eu_species lc = create_cites_III_reservation( @@ -62,7 +69,8 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end - subject { Checklist::TimelinesForTaxonConcept.new(tc) } + + specify { expect(subject.raw_timelines['III'].timeline_events).to be_empty } specify { expect(subject.raw_timelines['III'].timelines.first.timeline_events).not_to be_empty } specify { expect(subject.raw_timelines['I'].timeline_events).to be_empty } @@ -71,12 +79,15 @@ describe :timeline_years do context 'when in 1990' do + subject { Checklist::TimelinesForTaxonConcept.new(tc).timeline_years } + let(:tc) do tc = create(:taxon_concept) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end - subject { Checklist::TimelinesForTaxonConcept.new(tc).timeline_years } + + specify { expect(subject.size).to eq(5) } specify { expect(subject.first.year).to eq(1975) } specify { expect(subject.last.year).to eq(1995) } diff --git a/spec/services/dashboard_stats_species_spec.rb b/spec/services/dashboard_stats_species_spec.rb index d4bfd72c5..27758ba02 100644 --- a/spec/services/dashboard_stats_species_spec.rb +++ b/spec/services/dashboard_stats_species_spec.rb @@ -35,6 +35,7 @@ it 'has one results for argentina' do expect(ds_ar.species[:cites_eu][0][:count]).to eq 1 end + it 'has no results for ghana' do expect(ds_gh.species[:cites_eu][0][:count]).to eq 0 end diff --git a/spec/services/dashboard_stats_trade_spec.rb b/spec/services/dashboard_stats_trade_spec.rb index aa6bc4e45..2f8388212 100644 --- a/spec/services/dashboard_stats_trade_spec.rb +++ b/spec/services/dashboard_stats_trade_spec.rb @@ -3,7 +3,7 @@ describe DashboardStats do include_context 'Shipments' describe '#trade' do - before(:each) do + before do SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings @shipment4_by_partner = create( :shipment, @@ -36,6 +36,7 @@ quantity: 1 ) end + context 'when no time range specified' do subject do DashboardStats.new( @@ -45,12 +46,14 @@ } ).trade end + it 'argentina should have 40 exported animals and no imports' do expect(subject[:exports][:top_traded].length).to eq(1) expect(subject[:exports][:top_traded][0][:count]).to eq 40 expect(subject[:imports][:top_traded].length).to eq 0 end end + context 'when time range specified' do subject do DashboardStats.new( @@ -61,6 +64,7 @@ } ).trade end + it 'argentina should have no exports in 2012-2012' do expect(subject[:exports][:top_traded].length).to eq(0) end diff --git a/spec/services/document_search_spec.rb b/spec/services/document_search_spec.rb index 10ddfbbb6..cf192b477 100644 --- a/spec/services/document_search_spec.rb +++ b/spec/services/document_search_spec.rb @@ -190,7 +190,7 @@ ) end - before(:each) do + before do document_on_swietenia document_on_swietenia_in_belize document_on_swietenia_in_brazil @@ -210,6 +210,7 @@ 'admin' ).results end + specify do expect(subject.pluck('id').sort).to eq( [ @@ -232,6 +233,7 @@ 'admin' ).results end + specify do expect(subject.pluck('id').sort).to eq( [ @@ -254,6 +256,7 @@ 'admin' ).results end + specify do expect(subject.pluck('id').sort).to eq( [ @@ -274,6 +277,7 @@ 'admin' ).results end + specify do expect(subject.pluck('id').sort).to eq( [ @@ -297,7 +301,7 @@ # In these tests we will check that making changes to @d 4 minutes ago # causes documents_need_refreshing to become true. - before(:each) do + before do @d = nil travel_to(Time.now - (DocumentSearch::REFRESH_INTERVAL + 1).minutes) do @@ -358,7 +362,7 @@ # cause documents_need_refreshing to become true, by amending the attribute # updated_at on @c and @d - before(:each) do + before do @refresh_threshold = Time.now - (DocumentSearch::REFRESH_INTERVAL).minutes @recent_time = Time.now - (DocumentSearch::REFRESH_INTERVAL - 1).minutes diff --git a/spec/services/geo_entity_search_spec.rb b/spec/services/geo_entity_search_spec.rb index f5c01cda7..8b39d03ad 100644 --- a/spec/services/geo_entity_search_spec.rb +++ b/spec/services/geo_entity_search_spec.rb @@ -2,7 +2,7 @@ describe GeoEntitySearch do describe :results do context 'when searching by geo entity types set' do - before(:each) do + before do @asia = create( :geo_entity, geo_entity_type: cites_region_geo_entity_type, @@ -44,29 +44,37 @@ iso_code2: 'ZZ' ) end + context 'default set' do context 'default locale' do subject { GeoEntitySearch.new({}).results } + specify { expect(subject).to include(@myanmar) } specify { expect(subject).not_to include(@burma) } end end + context 'Checklist regions (1)' do subject { GeoEntitySearch.new({ geo_entity_types_set: '1' }).results } + specify { expect(subject).to include(@asia) } specify { expect(subject.length).to eq(1) } end + context 'Checklist countries & territories (2)' do subject { GeoEntitySearch.new({ geo_entity_types_set: '2' }).results } + specify { expect(subject).not_to include(@asia) } specify { expect(subject).to include(@burma) } specify { expect(subject).to include(@myanmar) } specify { expect(subject).to include(@samoa) } specify { expect(subject).not_to include(@intro_from_the_sea) } end + context 'Species+ regions, countries & territories (3)' do context 'English locale' do subject { GeoEntitySearch.new({ geo_entity_types_set: '3', locale: 'EN' }).results } + specify { expect(subject).to include(@asia) } specify { expect(subject).not_to include(@burma) } specify { expect(subject).to include(@myanmar) } @@ -74,8 +82,10 @@ specify { expect(subject.index(@samoa)).to eq(1) } specify { expect(subject.index(@myanmar)).to eq(2) } end + context 'Spanish locale' do subject { GeoEntitySearch.new({ geo_entity_types_set: '3', locale: 'ES' }).results } + specify { expect(subject).to include(@asia) } specify { expect(subject).not_to include(@burma) } specify { expect(subject).to include(@myanmar) } @@ -84,8 +94,10 @@ specify { expect(subject.index(@myanmar)).to eq(1) } end end + context 'Trade countries, territories and trade entities (4)' do subject { GeoEntitySearch.new({ geo_entity_types_set: '4' }).results } + specify { expect(subject).not_to include(@asia) } specify { expect(subject).to include(@burma) } specify { expect(subject).to include(@myanmar) } @@ -96,7 +108,9 @@ end describe :cached_results do - before(:each) do + subject { GeoEntitySearch.new({ geo_entity_types_set: '3' }) } + + before do @burma = create( :geo_entity, geo_entity_type: country_geo_entity_type, @@ -104,7 +118,8 @@ iso_code2: 'BU' ) end - subject { GeoEntitySearch.new({ geo_entity_types_set: '3' }) } + + specify do subject.cached_results @burma.update({ is_current: false }) diff --git a/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb b/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb index 9d6941ef2..af4782439 100644 --- a/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb +++ b/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb @@ -3,7 +3,7 @@ describe NomenclatureChange::DeleteUnreassignedProcessor do include_context 'split_definitions' - before(:each) do + before do processor.run end diff --git a/spec/services/nomenclature_change/full_reassignment_spec.rb b/spec/services/nomenclature_change/full_reassignment_spec.rb index 26e4a363f..28a07c247 100644 --- a/spec/services/nomenclature_change/full_reassignment_spec.rb +++ b/spec/services/nomenclature_change/full_reassignment_spec.rb @@ -2,80 +2,90 @@ describe NomenclatureChange::FullReassignment do describe 'process' do + subject { NomenclatureChange::FullReassignment.new(old_tc, new_tc) } + let(:old_tc) { create_cites_eu_species } let(:new_tc) { create_cites_eu_species } - subject { NomenclatureChange::FullReassignment.new(old_tc, new_tc) } + context 'when distributions present' do - before(:each) do + before do create(:distribution, taxon_concept: old_tc) subject.process end + specify { expect(new_tc.distributions.count).to eq(1) } end context 'when references present' do - before(:each) do + before do create(:taxon_concept_reference, taxon_concept: old_tc) subject.process end + specify { expect(new_tc.taxon_concept_references.count).to eq(1) } end context 'when listing changes present' do - before(:each) do + before do create_cites_I_addition(taxon_concept: old_tc) subject.process end + specify { expect(new_tc.listing_changes.count).to eq(1) } end context 'when EU Opinions present' do - before(:each) do + before do @eu_regulation = create(:ec_srg) create(:eu_opinion, taxon_concept: old_tc, start_event: @eu_regulation) subject.process end + specify { expect(new_tc.eu_opinions.count).to eq(1) } end context 'when EU Suspensions present' do - before(:each) do + before do create(:eu_suspension, taxon_concept: old_tc) subject.process end + specify { expect(new_tc.eu_suspensions.count).to eq(1) } end context 'when CITES Quotas present' do - before(:each) do + before do create(:quota, taxon_concept: old_tc, geo_entity: create(:geo_entity)) subject.process end + specify { expect(new_tc.quotas.count).to eq(1) } end context 'when CITES Suspensions present' do - before(:each) do + before do create( :cites_suspension, taxon_concept: old_tc, start_notification: create(:cites_suspension_notification, designation: cites) ) subject.process end + specify { expect(new_tc.cites_suspensions.count).to eq(1) } end context 'when common names present' do - before(:each) do + before do create(:taxon_common, taxon_concept: old_tc) subject.process end + specify { expect(new_tc.taxon_commons.count).to eq(1) } end context 'when document citations present' do - before(:each) do + before do create( :document_citation_taxon_concept, taxon_concept: old_tc, @@ -86,6 +96,7 @@ ) subject.process end + specify { expect(new_tc.document_citation_taxon_concepts.count).to eq(1) } end end diff --git a/spec/services/nomenclature_change/lump/constructor_spec.rb b/spec/services/nomenclature_change/lump/constructor_spec.rb index 8e86032ab..e22f4cb17 100644 --- a/spec/services/nomenclature_change/lump/constructor_spec.rb +++ b/spec/services/nomenclature_change/lump/constructor_spec.rb @@ -4,49 +4,63 @@ include_context 'lump_definitions' let(:constructor) { NomenclatureChange::Lump::Constructor.new(lump) } + context :inputs do describe :build_inputs do let(:lump) { create(:nomenclature_change_lump) } - before(:each) do + + before do @old_inputs = lump.inputs constructor.build_inputs end + context 'when previously no inputs in place' do specify { expect(lump.inputs.size).not_to eq(0) } end + context 'when previously inputs in place' do let(:lump) { lump_with_inputs } + specify { expect(lump.inputs).to eq(@old_inputs) } end end end + context :outputs do describe :build_output do let(:lump) { lump_with_inputs } - before(:each) do + + before do @old_output = lump.output constructor.build_output end + context 'when previously no output in place' do specify { expect(lump.output).not_to be_nil } end + context 'when previously output in place' do let(:lump) { lump_with_inputs_and_output } + specify { expect(lump.output).to eq(@old_output) } end end end + context :reassignments do let(:lump) { lump_with_inputs_and_output } let(:nc) { lump } let(:input) { nc.inputs[0] } + describe :build_input_and_output_notes do let(:output) { lump.output } - before(:each) do + + before do @old_input_note = input.note_en @old_output_note = output.note_en constructor.build_input_and_output_notes end + context 'when previously no notes in place' do let(:lump) do create( @@ -58,8 +72,10 @@ output_attributes: { taxon_concept_id: output_species.id } ) end + specify { expect(input.note_en).not_to be_blank } specify { expect(output.note_en).not_to be_blank } + context 'when output = input' do let(:lump) do create( @@ -71,9 +87,11 @@ output_attributes: { taxon_concept_id: input_species1.id } ) end + specify { expect(input.note_en).to be_blank } end end + context 'when previously notes in place' do let(:input) do create(:nomenclature_change_input, nomenclature_change: lump, note_en: 'blah') @@ -81,15 +99,18 @@ let(:output) do create(:nomenclature_change_output, nomenclature_change: lump, note_en: 'blah') end + specify { expect(input.note_en).to eq(@old_input_note) } specify { expect(output.note_en).to eq(@old_output_note) } end end + describe :build_parent_reassignments do - before(:each) do + before do @old_reassignments = input.parent_reassignments constructor.build_parent_reassignments end + include_context 'parent_reassignments_constructor_examples' context 'when output = input' do @@ -101,6 +122,7 @@ let(:lump_with_inputs_and_output) { lump_with_inputs_and_same_output } let(:input) { lump.inputs_intersect_outputs.first } let(:default_output) { lump.output } + specify do reassignment_targets = input.parent_reassignments.map(&:reassignment_target) expect(reassignment_targets.map(&:output).uniq).to(eq([ default_output ])) @@ -113,14 +135,17 @@ create(:nomenclature_change_parent_reassignment, input: i) i end + specify { expect(input.parent_reassignments).to eq(@old_reassignments) } end end + describe :build_name_reassignments do - before(:each) do + before do @old_reassignments = input.name_reassignments constructor.build_name_reassignments end + include_context 'name_reassignments_constructor_examples' context 'when output = input' do @@ -139,6 +164,7 @@ let(:lump_with_inputs_and_output) { lump_with_inputs_and_same_output } let(:input) { lump.inputs_intersect_outputs.first } let(:default_output) { lump.output } + specify do reassignment_targets = input.name_reassignments.map do |reassignment| reassignment.reassignment_targets @@ -147,39 +173,49 @@ end end end + describe :build_distribution_reassignments do - before(:each) do + before do @old_reassignments = input.distribution_reassignments constructor.build_distribution_reassignments end + include_context 'distribution_reassignments_constructor_examples' end + describe :build_document_reassignments do - before(:each) do + before do constructor.build_distribution_reassignments constructor.build_document_reassignments end + include_context 'document_reassignments_constructor_examples' end + describe :build_legislation_reassignments do - before(:each) do + before do @old_reassignments = input.legislation_reassignments constructor.build_legislation_reassignments end + include_context 'legislation_reassignments_constructor_examples' end + describe :build_common_names_reassignments do - before(:each) do + before do @old_reassignments = input.reassignments constructor.build_common_names_reassignments end + include_context 'common_name_reassignments_constructor_examples' end + describe :build_references_reassignments do - before(:each) do + before do @old_reassignments = input.reassignments constructor.build_references_reassignments end + include_context 'reference_reassignments_constructor_examples' end end diff --git a/spec/services/nomenclature_change/lump/output_taxon_concept_processor_spec.rb b/spec/services/nomenclature_change/lump/output_taxon_concept_processor_spec.rb index 7c50464ca..68e520816 100644 --- a/spec/services/nomenclature_change/lump/output_taxon_concept_processor_spec.rb +++ b/spec/services/nomenclature_change/lump/output_taxon_concept_processor_spec.rb @@ -7,24 +7,33 @@ let(:processor) do NomenclatureChange::OutputTaxonConceptProcessor.new(output) end - before(:each) do + + before do processor.run end + context 'when output is existing taxon' do let(:output) { lump_with_inputs_and_output_existing_taxon.output } + specify { expect(output.new_taxon_concept).to be_nil } end + context 'when output is new taxon' do let(:output) { lump_with_inputs_and_output_new_taxon.output } + specify { expect(output.new_taxon_concept.full_name).to eq('Errorus fatalus') } end + context 'when output is existing taxon with new status' do let(:output) { lump_with_inputs_and_output_status_change.output } + specify { expect(output.new_taxon_concept).to be_nil } specify { expect(output.taxon_concept.name_status).to eq('A') } end + context 'when output is existing taxon with new name' do let(:output) { lump_with_inputs_and_output_name_change.output } + specify { expect(output.taxon_concept.full_name).to eq('Errorus fatalus fatalus') } specify { expect(output.new_taxon_concept.name_status).to eq('A') } specify { expect(output.new_taxon_concept.full_name).to eq('Errorus lolcatus') } diff --git a/spec/services/nomenclature_change/lump/processor_spec.rb b/spec/services/nomenclature_change/lump/processor_spec.rb index 6aa2fffc7..95e0b72df 100644 --- a/spec/services/nomenclature_change/lump/processor_spec.rb +++ b/spec/services/nomenclature_change/lump/processor_spec.rb @@ -3,7 +3,7 @@ describe NomenclatureChange::Lump::Processor do include_context 'lump_definitions' - before(:each) do + before do synonym_relationship_type @shipment = create( :shipment, @@ -11,14 +11,19 @@ reported_taxon_concept: input_species1 ) end + let(:processor) { NomenclatureChange::Lump::Processor.new(lump) } + describe :run do context 'when outputs are existing taxa' do let!(:lump) { lump_with_inputs_and_output_existing_taxon } + specify { expect { processor.run }.not_to change(TaxonConcept, :count) } specify { expect { processor.run }.not_to change(output_species, :full_name) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species1.reload).to be_is_synonym } specify { expect(input_species1.accepted_names).to include(output_species) } specify { expect(input_species1.shipments).to be_empty } @@ -26,37 +31,49 @@ specify { expect(output_species.shipments).to include(@shipment) } end end + context 'when output is new taxon' do let!(:lump) { lump_with_inputs_and_output_new_taxon } + specify { expect { processor.run }.to change(TaxonConcept, :count).by(1) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species1.reload).to be_is_synonym } specify { expect(input_species1.accepted_names).to include(lump.output.new_taxon_concept) } specify { expect(lump.output.new_taxon_concept.shipments).to include(@shipment) } end end + context 'when output is existing taxon with new status' do let(:output_species2) { create_cites_eu_species(name_status: 'S') } let!(:lump) { lump_with_inputs_and_output_status_change } + specify { expect { processor.run }.not_to change(TaxonConcept, :count) } specify { expect { processor.run }.not_to change(output_species, :full_name) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species1.reload).to be_is_synonym } specify { expect(input_species1.accepted_names).to include(output_species) } specify { expect(output_species.shipments).to include(@shipment) } end end + context 'when output is existing taxon with new name' do let(:input_genus1) { create_cites_eu_genus } let(:input_species1) { create_cites_eu_species(parent: input_genus1) } let(:output_species2) { create_cites_eu_subspecies } let!(:lump) { lump_with_inputs_and_output_name_change } + specify { expect { processor.run }.to change(TaxonConcept, :count).by(1) } specify { expect { processor.run }.not_to change(output_species, :full_name) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species1.reload).to be_is_synonym } specify { expect(input_species1.reload.parent).to eq(input_genus1) } specify { expect(input_species1.accepted_names).to include(lump.output.new_taxon_concept) } @@ -92,23 +109,29 @@ status: NomenclatureChange::Lump::LEGISLATION ) end - before(:each) { processor.run } + + before { processor.run } + specify 'input / output species has public nomenclature note set' do expect(input_species1.reload.nomenclature_note_en).to eq(' input species 1 was lumped from input species 1 and input species 2') end + specify 'child of input / output species does not inherit public nomenclature note' do expect( input_species1_child.reload.nomenclature_note_en ).to be_nil end + specify 'input / output species has internal nomenclature note set' do expect(input_species1.nomenclature_comment.note).to eq(' output internal note') end + specify 'child of input / output species does not inherit internal nomenclature note' do expect( input_species1_child.nomenclature_comment.try(:note) ).to be_nil end + specify 'child of input / output species does not have legislation nomenclature note' do expect( input_species1_child_listing.nomenclature_note_en @@ -120,6 +143,7 @@ let!(:input_species1_child) do create_cites_eu_subspecies(parent: input_species1) end + let(:output_species_genus_name) { output_species.parent.full_name } let!(:input_species1_child_listing) do create_cites_I_addition(taxon_concept: input_species1_child) end @@ -165,62 +189,79 @@ let(:output_species1_child) do output_species_children.where.not(id: output_species_child.id).first end - before(:each) { processor.run } + + before { processor.run } + + specify 'input species has public nomenclature note set' do expect(input_species1.reload.nomenclature_note_en).to eq(' input species 1 has been lumped into output species') end + specify 'child of input species inherits public nomenclature note' do expect( input_species1_child.reload.nomenclature_note_en ).to eq(input_species1.reload.nomenclature_note_en) end + specify 'input species has internal nomenclature note set' do expect(input_species1.nomenclature_comment.note).to eq(' input internal note') end + specify 'child of input species inherits internal nomenclature note' do expect( input_species1_child.nomenclature_comment.note ).to eq(input_species1.nomenclature_comment.note) end + specify 'output species has public nomenclature note set' do expect(output_species.reload.nomenclature_note_en).to eq(' output species was lumped from input species 1 and input species 2') end + specify 'child of output species inherits public nomenclature note from input' do expect( output_species1_child.reload.nomenclature_note_en ).to eq(input_species1.reload.nomenclature_note_en) end + specify 'output species has internal nomenclature note set' do expect(output_species.nomenclature_comment.note).to eq(' output internal note') end + specify 'child of output species inherits internal nomenclature note from input' do expect( output_species1_child.nomenclature_comment.note ).to eq(input_species1.nomenclature_comment.note) end + specify 'output species child has listing changes from input species child transferred' do expect(output_species1_child.listing_changes.count).to eq(1) end + specify 'child of output species has legislation nomenclature note copied from input species' do expect( output_species1_child.listing_changes.first.nomenclature_note_en ).to eq(input_species1.reload.nomenclature_note_en) end - let(:output_species_genus_name) { output_species.parent.full_name } + + specify 'original output species child retains higher taxa intact' do expect(output_species_child.data['genus_name']).to eq(output_species_genus_name) end + specify 'new output species child has higher taxa set correctly' do expect(output_species1_child.reload.data['genus_name']).to eq(output_species_genus_name) end + specify 'original input species child retains higher taxa intact' do expect(input_species1_child.data['genus_name']).to eq(input_species1.parent.full_name) end + specify 'original input species child is a synonym' do expect(input_species1_child.reload.name_status).to eq('S') end end end + context 'when input is genus and parent ressignments occur' do let(:input_genus) do create_cites_eu_genus( @@ -273,48 +314,61 @@ output: lump.output ) end - before(:each) { processor.run } + + before { processor.run } + specify 'input genus child is a synonym' do expect(input_genus_child.reload.name_status).to eq('S') end + specify 'input genus child is a synonym of output genus child' do output_genus_child = output_genus.children.first expect(input_genus_child.accepted_names).to include(output_genus_child) end + specify "input genus child's child is a synonym" do expect(input_genus_child_child.reload.name_status).to eq('S') end + specify "input genus child's child's name did not change" do expect(input_genus_child_child.reload.full_name).to eq('Crotalus durissus unicolor') end + specify 'output genus should have child with resolved name' do output_genus_child = output_genus.children.first expect(output_genus_child).not_to be_nil expect(output_genus_child.full_name).to eq('Paracrotalus durissus') end + specify 'output genus child should have child with resolved name' do output_genus_child = output_genus.children.first output_genus_child_child = output_genus_child.children.first expect(output_genus_child_child).not_to be_nil expect(output_genus_child_child.full_name).to eq('Paracrotalus durissus unicolor') end + specify 'output genus child should have input genus citations' do output_genus_child = output_genus.children.first expect(output_genus_child.document_citation_taxon_concepts.count).to eq(1) end + specify 'input genus child has no quotas' do expect(input_genus_child.quotas).to be_empty end + specify "input genus child's accepted name has 1 quota" do output_genus_child = output_genus.children.first expect(output_genus_child.quotas.size).to eq(1) end + specify "input genus child's document citations retained" do expect(input_genus_child.document_citation_taxon_concepts.count).to eq(1) end end + describe :summary do let(:lump) { lump_with_inputs_and_output_existing_taxon } - specify { expect(processor.summary).to be_kind_of(Array) } + + specify { expect(processor.summary).to be_a(Array) } end end diff --git a/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb b/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb index 0568af521..8cf76acdc 100644 --- a/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb +++ b/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb @@ -13,32 +13,39 @@ context 'when children' do include_context 'parent_reassignments_processor_examples' end + context 'when names' do include_context 'name_reassignments_processor_examples' specify { expect(input_species.synonyms).to include(input_species_synonym) } end + context 'when distribution' do include_context 'distribution_reassignments_processor_examples' specify { expect(input_species.distributions.count).to eq(4) } end + context 'when legislation' do include_context 'legislation_reassignments_processor_examples' specify { expect(input_species.listing_changes.count).to eq(2) } specify { expect(input_species.quotas.count).to eq(2) } specify { expect(input_species.cites_suspensions.count).to eq(2) } end + context 'when common names' do include_context 'common_name_reassignments_processor_examples' specify { expect(input_species.common_names.count).to eq(2) } end + context 'when references' do include_context 'reference_reassignments_processor_examples' specify { expect(input_species.taxon_concept_references.count).to eq(2) } end + context 'when document citations' do include_context 'document_reassignments_processor_examples' specify { expect(input_species.document_citation_taxon_concepts.count).to eq(1) } end + context 'when shipments' do include_context 'shipment_reassignments_processor_examples' end diff --git a/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb b/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb index b46468843..28053f640 100644 --- a/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb +++ b/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb @@ -10,35 +10,43 @@ let(:processor) do NomenclatureChange::ReassignmentTransferProcessor.new(input, output) end + context 'when children' do include_context 'parent_reassignments_processor_examples' end + context 'when names' do include_context 'name_reassignments_processor_examples' specify { expect(input_species.synonyms).to be_empty } end + context 'when distribution' do include_context 'distribution_reassignments_processor_examples' specify { expect(input_species.distributions).to be_empty } end + context 'when legislation' do include_context 'legislation_reassignments_processor_examples' specify { expect(input_species.listing_changes).to be_empty } specify { expect(input_species.quotas).to be_empty } specify { expect(input_species.cites_suspensions).to be_empty } end + context 'when common names' do include_context 'common_name_reassignments_processor_examples' specify { expect(input_species.common_names).to be_empty } end + context 'when references' do include_context 'reference_reassignments_processor_examples' specify { expect(input_species.taxon_concept_references).to be_empty } end + context 'when document citations' do include_context 'document_reassignments_processor_examples' pending { expect(input_species.document_citation_taxon_concepts).to be_empty } end + context 'when shipments' do include_context 'shipment_reassignments_processor_examples' end @@ -55,24 +63,31 @@ let(:processor) do NomenclatureChange::ReassignmentTransferProcessor.new(output, output) end + context 'when names' do include_context 'output_name_reassignments_processor_examples' end + context 'when distribution' do include_context 'output_distribution_reassignments_processor_examples' end + context 'when legislation' do include_context 'output_legislation_reassignments_processor_examples' end + context 'when common names' do include_context 'output_common_name_reassignments_processor_examples' end + context 'when references' do include_context 'output_reference_reassignments_processor_examples' end + context 'when document citations' do include_context 'output_document_reassignments_processor_examples' end + context 'when shipments' do include_context 'output_shipment_reassignments_processor_examples' end diff --git a/spec/services/nomenclature_change/split/constructor_spec.rb b/spec/services/nomenclature_change/split/constructor_spec.rb index d5eec140b..506a67e0e 100644 --- a/spec/services/nomenclature_change/split/constructor_spec.rb +++ b/spec/services/nomenclature_change/split/constructor_spec.rb @@ -4,49 +4,63 @@ include_context 'split_definitions' let(:constructor) { NomenclatureChange::Split::Constructor.new(split) } + context :inputs do describe :build_input do let(:split) { create(:nomenclature_change_split) } - before(:each) do + + before do @old_input = split.input constructor.build_input end + context 'when previously no input in place' do specify { expect(split.input).not_to be_nil } end + context 'when previously input in place' do let(:split) { split_with_input } + specify { expect(split.input).to eq(@old_input) } end end end + context :outputs do describe :build_outputs do let(:split) { split_with_input } - before(:each) do + + before do @old_outputs = split.outputs constructor.build_outputs end + context 'when previously no outputs in place' do specify { expect(split.outputs.size).not_to eq(0) } end + context 'when previously output in place' do let(:split) { split_with_input_and_output } + specify { expect(split.outputs).to eq(@old_outputs) } end end end + context :reassignments do let(:split) { split_with_input_and_output } let(:nc) { split } let(:input) { nc.input } + describe :build_input_and_output_notes do let(:output) { split.outputs[0] } - before(:each) do + + before do @old_input_note = input.note_en @old_output_note = output.note_en constructor.build_input_and_output_notes end + context 'when previously no notes in place' do let(:split) do s = create(:nomenclature_change_split) @@ -54,8 +68,10 @@ create(:nomenclature_change_output, nomenclature_change: s) s end + specify { expect(input.note_en).not_to be_blank } specify { expect(output.note_en).not_to be_blank } + context 'when output = input' do let(:split) do s = create(:nomenclature_change_split) @@ -63,9 +79,11 @@ create(:nomenclature_change_output, nomenclature_change: s, taxon_concept: input_species) s end + specify { expect(output.note_en).to be_blank } end end + context 'when previously notes in place' do let(:input) do create(:nomenclature_change_input, nomenclature_change: split, note_en: 'blah') @@ -73,15 +91,18 @@ let(:output) do create(:nomenclature_change_output, nomenclature_change: split, note_en: 'blah') end + specify { expect(input.note_en).to eq(@old_input_note) } specify { expect(output.note_en).to eq(@old_output_note) } end end + describe :build_parent_reassignments do - before(:each) do + before do @old_reassignments = input.parent_reassignments constructor.build_parent_reassignments end + include_context 'parent_reassignments_constructor_examples' context 'when output = input' do @@ -92,6 +113,7 @@ end let(:split_with_input_and_output) { split_with_input_and_same_output } let(:default_output) { split.outputs_intersect_inputs.first } + specify do reassignment_targets = input.parent_reassignments.map(&:reassignment_target) expect(reassignment_targets.map(&:output).uniq).to(eq([ default_output ])) @@ -104,14 +126,17 @@ create(:nomenclature_change_parent_reassignment, input: i) i end + specify { expect(input.parent_reassignments).to eq(@old_reassignments) } end end + describe :build_name_reassignments do - before(:each) do + before do @old_reassignments = input.name_reassignments constructor.build_name_reassignments end + include_context 'name_reassignments_constructor_examples' context 'when output = input' do @@ -129,6 +154,7 @@ end let(:split_with_input_and_output) { split_with_input_and_same_output } let(:default_output) { split.outputs_intersect_inputs.first } + specify do reassignment_targets = input.name_reassignments.map do |reassignment| reassignment.reassignment_targets @@ -137,18 +163,22 @@ end end end + describe :build_distribution_reassignments do - before(:each) do + before do @old_reassignments = input.distribution_reassignments constructor.build_distribution_reassignments end + include_context 'distribution_reassignments_constructor_examples' end + describe :build_documents_reassignments do - before(:each) do + before do constructor.build_distribution_reassignments constructor.build_document_reassignments end + include_context 'document_reassignments_constructor_examples' context 'when geo_entity citations mismatch distribution' do @@ -196,25 +226,31 @@ end end end + describe :build_legislation_reassignments do - before(:each) do + before do @old_reassignments = input.legislation_reassignments constructor.build_legislation_reassignments end + include_context 'legislation_reassignments_constructor_examples' end + describe :build_common_names_reassignments do - before(:each) do + before do @old_reassignments = input.reassignments constructor.build_common_names_reassignments end + include_context 'common_name_reassignments_constructor_examples' end + describe :build_references_reassignments do - before(:each) do + before do @old_reassignments = input.reassignments constructor.build_references_reassignments end + include_context 'reference_reassignments_constructor_examples' end end diff --git a/spec/services/nomenclature_change/split/output_taxon_concept_processor_spec.rb b/spec/services/nomenclature_change/split/output_taxon_concept_processor_spec.rb index 13fb83360..fda60e15e 100644 --- a/spec/services/nomenclature_change/split/output_taxon_concept_processor_spec.rb +++ b/spec/services/nomenclature_change/split/output_taxon_concept_processor_spec.rb @@ -3,29 +3,39 @@ describe NomenclatureChange::OutputTaxonConceptProcessor do include_context 'split_definitions' - before(:each) { synonym_relationship_type } + before { synonym_relationship_type } + describe :run do let(:processor) do NomenclatureChange::OutputTaxonConceptProcessor.new(output) end - before(:each) do + + before do processor.run end + context 'when output is existing taxon' do let(:output) { split_with_input_and_output_existing_taxon.outputs.last } + specify { expect(output.new_taxon_concept).to be_nil } end + context 'when output is new taxon' do let(:output) { split_with_input_and_output_new_taxon.outputs.last } + specify { expect(output.new_taxon_concept.full_name).to eq('Errorus fatalus') } end + context 'when output is existing taxon with new status' do let(:output) { split_with_input_and_outputs_status_change.outputs.last } + specify { expect(output.new_taxon_concept).to be_nil } specify { expect(output.taxon_concept.name_status).to eq('A') } end + context 'when output is existing taxon with new name' do let(:output) { split_with_input_and_outputs_name_change.outputs.last } + specify { expect(output.taxon_concept.full_name).to eq('Errorus fatalus fatalus') } specify { expect(output.new_taxon_concept.name_status).to eq('A') } specify { expect(output.new_taxon_concept.full_name).to eq('Errorus lolcatus') } diff --git a/spec/services/nomenclature_change/split/processor_spec.rb b/spec/services/nomenclature_change/split/processor_spec.rb index 158ee50be..3684b675d 100644 --- a/spec/services/nomenclature_change/split/processor_spec.rb +++ b/spec/services/nomenclature_change/split/processor_spec.rb @@ -3,7 +3,7 @@ describe NomenclatureChange::Split::Processor do include_context 'split_definitions' - before(:each) do + before do synonym_relationship_type @shipment = create( :shipment, @@ -11,15 +11,20 @@ reported_taxon_concept: input_species ) end + let(:processor) { NomenclatureChange::Split::Processor.new(split) } + describe :run do context 'when outputs are existing taxa' do let!(:split) { split_with_input_and_output_existing_taxon } + specify { expect { processor.run }.not_to change(TaxonConcept, :count) } specify { expect { processor.run }.not_to change(output_species1, :full_name) } specify { expect { processor.run }.not_to change(output_species2, :full_name) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species.reload).to be_is_synonym } specify { expect(input_species.accepted_names).to include(output_species1) } specify { expect(input_species.shipments).to be_empty } @@ -27,11 +32,15 @@ specify { expect(output_species1.shipments).to include(@shipment) } end end + context 'when output is new taxon' do let!(:split) { split_with_input_and_output_new_taxon } + specify { expect { processor.run }.to change(TaxonConcept, :count).by(1) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species.reload).to be_is_synonym } specify { expect(input_species.accepted_names).to include(split.outputs.last.new_taxon_concept) } specify { expect(input_species.shipments).to be_empty } @@ -39,6 +48,7 @@ specify { expect(output_species1.shipments).to include(@shipment) } end end + context 'when output is existing taxon with new status' do let(:output_species2) do create_cites_eu_species( @@ -52,24 +62,31 @@ ) end let!(:split) { split_with_input_and_outputs_status_change } + specify { expect { processor.run }.not_to change(TaxonConcept, :count) } specify { expect { processor.run }.not_to change(output_species1, :full_name) } specify { expect { processor.run }.not_to change(output_species2, :full_name) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species.reload).to be_is_synonym } specify { expect(input_species.accepted_names).to include(output_species1) } specify { expect(output_species1.shipments).to include(@shipment) } end end + context 'when output is existing taxon with new name' do let(:output_species2) { create_cites_eu_subspecies } let!(:split) { split_with_input_and_outputs_name_change } + specify { expect { processor.run }.to change(TaxonConcept, :count).by(1) } specify { expect { processor.run }.not_to change(output_species1, :full_name) } specify { expect { processor.run }.not_to change(output_species2, :full_name) } + context 'relationships and trade' do - before(:each) { processor.run } + before { processor.run } + specify { expect(input_species.reload).to be_is_synonym } specify { expect(input_species.reload.parent).to eq(genus1) } specify { expect(input_species.accepted_names).to include(split.outputs.last.new_taxon_concept) } @@ -105,23 +122,29 @@ status: NomenclatureChange::Split::LEGISLATION ) end - before(:each) { processor.run } + + before { processor.run } + specify 'input / output species has public nomenclature note set' do expect(input_species.reload.nomenclature_note_en).to eq(' input species was split into input species and output species 2') end + specify 'child of input / output species does not inherit public nomenclature note' do expect( input_species_child.reload.nomenclature_note_en ).to be_nil end + specify 'input / output species has internal nomenclature note set' do expect(input_species.nomenclature_comment.note).to eq(' input internal note') end + specify 'child of input / output species does not inherit internal nomenclature note' do expect( input_species_child.nomenclature_comment.try(:note) ).to be_nil end + specify 'child of input / output species does not have legislation nomenclature note' do expect( input_species_child.listing_changes.first.nomenclature_note_en @@ -133,6 +156,7 @@ let!(:input_species_child) do create_cites_eu_subspecies(parent: input_species) end + let(:output_species1_genus_name) { output_species1.parent.full_name } let!(:input_species_child_listing) do create_cites_I_addition(taxon_concept: input_species_child) end @@ -178,62 +202,79 @@ let(:output_species_child) do output.taxon_concept.children.where.not(id: output_species1_child.id).first end - before(:each) { processor.run } + + before { processor.run } + + specify 'input species has public nomenclature note set' do expect(input_species.reload.nomenclature_note_en).to eq(' input species was split into output species 1 and output species 2') end + specify 'child of input species inherits public nomenclature note' do expect( input_species_child.reload.nomenclature_note_en ).to eq(input_species.reload.nomenclature_note_en) end + specify 'input species has internal nomenclature note set' do expect(input_species.nomenclature_comment.note).to eq(' input internal note') end + specify 'child of input species inherits internal nomenclature note' do expect( input_species_child.nomenclature_comment.note ).to eq(input_species.nomenclature_comment.note) end + specify 'output species has public nomenclature note set' do expect(output_species.reload.nomenclature_note_en).to eq(' output species 1 was split from input species') end + specify 'child of output species inherits public nomenclature note from output' do expect( output_species_child.reload.nomenclature_note_en ).to eq(output_species.nomenclature_note_en) end + specify 'output species has internal nomenclature note set' do expect(output_species.nomenclature_comment.note).to eq(' output internal note') end + specify 'child of output species inherits internal nomenclature note from output' do expect( output_species_child.nomenclature_comment.note ).to eq(output_species.nomenclature_comment.note) end + specify 'output species child has listing changes from input species child transferred' do expect(output_species_child.listing_changes.count).to eq(1) end + specify 'output species child has legislation nomenclature note copied from output species' do expect( output_species_child.listing_changes.first.nomenclature_note_en ).to eq(output_species.nomenclature_note_en) end - let(:output_species1_genus_name) { output_species1.parent.full_name } + + specify 'original output species child retains higher taxa intact' do expect(output_species_child.data['genus_name']).to eq(output_species1_genus_name) end + specify 'new output species child has higher taxa set correctly' do expect(output_species1_child.data['genus_name']).to eq(output_species1_genus_name) end + specify 'original input species child retains higher taxa intact' do expect(input_species_child.data['genus_name']).to eq(input_species.parent.full_name) end + specify 'original input species child is a synonym' do expect(input_species_child.reload.name_status).to eq('S') end end end + context 'when input is genus and parent ressignments occur' do let(:input_genus) do create_cites_eu_genus( @@ -286,48 +327,61 @@ output: split.outputs.last ) end - before(:each) { processor.run } + + before { processor.run } + specify 'input genus child is a synonym' do expect(input_genus_child.reload.name_status).to eq('S') end + specify 'input genus child is a synonym of output genus child' do output_genus_child = output_genus.children.first expect(input_genus_child.accepted_names).to include(output_genus_child) end + specify "input genus child's child is a synonym" do expect(input_genus_child_child.reload.name_status).to eq('S') end + specify "input genus child's child's name did not change" do expect(input_genus_child_child.reload.full_name).to eq('Crotalus durissus unicolor') end + specify 'output genus should have child with resolved name' do output_genus_child = output_genus.children.first expect(output_genus_child).not_to be_nil expect(output_genus_child.full_name).to eq('Paracrotalus durissus') end + specify 'output genus child should have child with resolved name' do output_genus_child = output_genus.children.first output_genus_child_child = output_genus_child.children.first expect(output_genus_child_child).not_to be_nil expect(output_genus_child_child.full_name).to eq('Paracrotalus durissus unicolor') end + specify 'output genus child should have input genus citations' do output_genus_child = output_genus.children.first expect(output_genus_child.document_citation_taxon_concepts.count).to eq(1) end + specify 'input genus child has no quotas' do expect(input_genus_child.quotas).to be_empty end + specify "input genus child's accepted name has 1 quota" do output_genus_child = output_genus.children.first expect(output_genus_child.quotas.size).to eq(1) end + specify "input genus child's document citations retained" do expect(input_genus_child.document_citation_taxon_concepts.count).to eq(1) end end + describe :summary do let(:split) { split_with_input_and_output_existing_taxon } - specify { expect(processor.summary).to be_kind_of(Array) } + + specify { expect(processor.summary).to be_a(Array) } end end diff --git a/spec/services/nomenclature_change/status_swap/constructor_spec.rb b/spec/services/nomenclature_change/status_swap/constructor_spec.rb index d3a7d841c..365bb97bb 100644 --- a/spec/services/nomenclature_change/status_swap/constructor_spec.rb +++ b/spec/services/nomenclature_change/status_swap/constructor_spec.rb @@ -4,17 +4,22 @@ include_context 'status_change_definitions' let(:constructor) { NomenclatureChange::StatusSwap::Constructor.new(status_change) } + describe :build_primary_output do let(:status_change) { create(:nomenclature_change_status_swap) } - before(:each) do + + before do @old_output = status_change.primary_output constructor.build_primary_output end + context 'when previously no primary output in place' do specify { expect(status_change.primary_output).not_to be_nil } end + context 'when previously primary output in place' do let(:status_change) { a_to_s_with_swap } + specify { expect(status_change.primary_output).to eq(@old_output) } end end @@ -22,15 +27,19 @@ describe :build_secondary_output do context :downgrade do let(:status_change) { a_to_s_with_swap_with_primary_output } - before(:each) do + + before do @old_output = status_change.secondary_output constructor.build_secondary_output end + context 'when previously no secondary output in place' do specify { expect(status_change.secondary_output).not_to be_nil } end + context 'when previously secondary output in place' do let(:status_change) { a_to_s_with_swap } + specify { expect(status_change.secondary_output).to eq(@old_output) } end end @@ -38,17 +47,21 @@ describe :build_secondary_output_note do let(:primary_output) { status_change.primary_output } + let(:status_change) { a_to_s_with_swap } let(:secondary_output) { status_change.secondary_output } - before(:each) do + + before do @old_primary_output_note = primary_output.internal_note @old_secondary_output_note = secondary_output.note_en constructor.build_secondary_output_note end - let(:status_change) { a_to_s_with_swap } + + context 'when previously no notes in place' do specify { expect(primary_output.internal_note).to be_blank } specify { expect(secondary_output.note_en).not_to be_blank } end + context 'when previously notes in place' do let(:primary_output) do create(:nomenclature_change_output, nomenclature_change: status_change, internal_note: 'blah') @@ -56,6 +69,7 @@ let(:secondary_output) do create(:nomenclature_change_output, nomenclature_change: status_change, note_en: 'blah') end + specify { expect(primary_output.internal_note).to eq(@old_primary_output_note) } specify { expect(secondary_output.note_en).to eq(@old_secondary_output_note) } end diff --git a/spec/services/nomenclature_change/status_swap/processor_spec.rb b/spec/services/nomenclature_change/status_swap/processor_spec.rb index 08c7ec47c..dc772fd63 100644 --- a/spec/services/nomenclature_change/status_swap/processor_spec.rb +++ b/spec/services/nomenclature_change/status_swap/processor_spec.rb @@ -4,6 +4,9 @@ include_context 'status_change_definitions' let(:accepted_name) { create_cites_eu_species } + let(:processor) { NomenclatureChange::StatusSwap::Processor.new(status_change) } + let(:primary_output_taxon_concept) { status_change.primary_output.taxon_concept } + let(:secondary_output_taxon_concept) { status_change.secondary_output.taxon_concept } let(:synonym) do tc = create_cites_eu_species(name_status: 'S') @@ -16,17 +19,16 @@ tc end - before(:each) { synonym_relationship_type } - let(:processor) { NomenclatureChange::StatusSwap::Processor.new(status_change) } - let(:primary_output_taxon_concept) { status_change.primary_output.taxon_concept } - let(:secondary_output_taxon_concept) { status_change.secondary_output.taxon_concept } + before { synonym_relationship_type } + describe :run do context 'from accepted name' do let(:accepted_name_parent) { create_cites_eu_genus } let(:accepted_name) { create_cites_eu_species(parent: accepted_name_parent) } let(:status_change) { a_to_s_with_swap } - before(:each) do + + before do @shipment = create( :shipment, taxon_concept: primary_output_taxon_concept, @@ -35,13 +37,16 @@ secondary_output_taxon_concept.create_nomenclature_comment processor.run end + specify { expect(primary_output_taxon_concept).to be_is_synonym } specify { expect(primary_output_taxon_concept.parent).to eq(accepted_name_parent) } specify { expect(secondary_output_taxon_concept.name_status).to eq('A') } specify { expect(primary_output_taxon_concept.accepted_names).to include(secondary_output_taxon_concept) } + specify 'public nomenclature note is set' do expect(secondary_output_taxon_concept.nomenclature_note_en).to eq(' public') end + specify 'internal nomenclature note is set' do expect(secondary_output_taxon_concept.nomenclature_comment.try(:note)).to eq(' internal') end @@ -50,6 +55,7 @@ describe :summary do let(:status_change) { a_to_s_with_swap } - specify { expect(processor.summary).to be_kind_of(Array) } + + specify { expect(processor.summary).to be_a(Array) } end end diff --git a/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb b/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb index ef3dadca0..be9565ca1 100644 --- a/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb +++ b/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb @@ -4,6 +4,9 @@ include_context 'status_change_definitions' let(:accepted_name) { create_cites_eu_species } + let(:processor) { NomenclatureChange::StatusToAccepted::Processor.new(status_change) } + let(:primary_output_taxon_concept) { status_change.primary_output.taxon_concept } + let(:secondary_output_taxon_concept) { status_change.secondary_output.taxon_concept } let(:trade_name) do tc = create_cites_eu_species( @@ -41,16 +44,16 @@ taxon_name: create(:taxon_name, scientific_name: 'Foobarus') ) end - before(:each) { synonym_relationship_type } - let(:processor) { NomenclatureChange::StatusToAccepted::Processor.new(status_change) } - let(:primary_output_taxon_concept) { status_change.primary_output.taxon_concept } - let(:secondary_output_taxon_concept) { status_change.secondary_output.taxon_concept } + + before { synonym_relationship_type } + describe :run do context 'from trade name' do let(:output_species) { secondary_output_taxon_concept } let(:status_change) { t_to_a_with_input } - before(:each) do + + before do @shipment = create( :shipment, taxon_concept: accepted_name, @@ -58,6 +61,7 @@ ) processor.run end + specify { expect(primary_output_taxon_concept.name_status).to eq('A') } specify { expect(primary_output_taxon_concept.accepted_names_for_trade_name).to be_empty } specify { expect(primary_output_taxon_concept.shipments).to include(@shipment) } diff --git a/spec/services/nomenclature_change/status_to_synonym/constructor_spec.rb b/spec/services/nomenclature_change/status_to_synonym/constructor_spec.rb index 5843ef559..a722a85dc 100644 --- a/spec/services/nomenclature_change/status_to_synonym/constructor_spec.rb +++ b/spec/services/nomenclature_change/status_to_synonym/constructor_spec.rb @@ -8,15 +8,19 @@ describe :build_input do let(:status_change) { n_to_s_with_primary_output } - before(:each) do + + before do @old_input = status_change.input constructor.build_input end + context 'when previously no input in place' do specify { expect(status_change.input).not_to be_nil } end + context 'when previously input in place' do let(:status_change) { n_to_s_with_input_and_secondary_output } + specify { expect(status_change.input).to eq(@old_input) } end end diff --git a/spec/services/nomenclature_change/status_to_synonym/output_taxon_concept_processor_spec.rb b/spec/services/nomenclature_change/status_to_synonym/output_taxon_concept_processor_spec.rb index d82b535fb..7b3e564e1 100644 --- a/spec/services/nomenclature_change/status_to_synonym/output_taxon_concept_processor_spec.rb +++ b/spec/services/nomenclature_change/status_to_synonym/output_taxon_concept_processor_spec.rb @@ -3,18 +3,22 @@ describe NomenclatureChange::OutputTaxonConceptProcessor do include_context 'status_change_definitions' - before(:each) { synonym_relationship_type } + before { synonym_relationship_type } + let(:input_species) { create_cites_eu_species(name_status: 'N') } describe :run do let(:processor) do NomenclatureChange::OutputTaxonConceptProcessor.new(primary_output) end - before(:each) do + + before do processor.run end + context 'when output is existing taxon' do let(:primary_output) { n_to_s_with_input_and_secondary_output.primary_output } + specify { expect(primary_output.new_taxon_concept).to be_nil } end end diff --git a/spec/services/nomenclature_change/status_to_synonym/processor_spec.rb b/spec/services/nomenclature_change/status_to_synonym/processor_spec.rb index 69fa35641..d6d4097dc 100644 --- a/spec/services/nomenclature_change/status_to_synonym/processor_spec.rb +++ b/spec/services/nomenclature_change/status_to_synonym/processor_spec.rb @@ -3,7 +3,8 @@ describe NomenclatureChange::StatusToSynonym::Processor do include_context 'status_change_definitions' - before(:each) { synonym_relationship_type } + before { synonym_relationship_type } + let(:processor) { NomenclatureChange::StatusToSynonym::Processor.new(status_change) } let(:input_species) { create_cites_eu_species(name_status: 'N') } let(:primary_output_taxon_concept) { status_change.primary_output.taxon_concept } @@ -14,7 +15,8 @@ let(:input_species_parent) { create_cites_eu_genus } let(:input_species) { create_cites_eu_species(parent: input_species_parent) } let(:status_change) { n_to_s_with_input_and_secondary_output } - before(:each) do + + before do @shipment = create( :shipment, taxon_concept: primary_output_taxon_concept, @@ -22,6 +24,7 @@ ) processor.run end + specify { expect(primary_output_taxon_concept).to be_is_synonym } specify { expect(primary_output_taxon_concept.parent).to eq(input_species_parent) } specify { expect(primary_output_taxon_concept.accepted_names).to include(secondary_output_taxon_concept) } @@ -29,10 +32,12 @@ specify { expect(primary_output_taxon_concept.reported_shipments).to include(@shipment) } specify { expect(secondary_output_taxon_concept.shipments).to include(@shipment) } end + context 'from trade name' do let(:input_species) { trade_name } let(:status_change) { t_to_s_with_primary_and_secondary_output } - before(:each) do + + before do @shipment = create( :shipment, taxon_concept: accepted_name, @@ -40,6 +45,7 @@ ) processor.run end + specify { expect(primary_output_taxon_concept).to be_is_synonym } specify { expect(primary_output_taxon_concept.accepted_names).to include(secondary_output_taxon_concept) } specify { expect(primary_output_taxon_concept.reload.accepted_names_for_trade_name).to be_empty } diff --git a/spec/services/species/common_names_export_spec.rb b/spec/services/species/common_names_export_spec.rb index acb01d1d4..772dcdf8f 100644 --- a/spec/services/species/common_names_export_spec.rb +++ b/spec/services/species/common_names_export_spec.rb @@ -10,7 +10,7 @@ end end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::CommonNamesExport.new({}) @@ -22,7 +22,11 @@ end context 'when results' do - before(:each) do + subject do + Species::CommonNamesExport.new({}) + end + + before do create_cites_eu_species FileUtils.mkpath( @@ -33,13 +37,10 @@ and_return('spec/public/downloads/common_names/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/common_names', true) end - subject do - Species::CommonNamesExport.new({}) - end context 'when file not cached' do specify do diff --git a/spec/services/species/documents_export_spec.rb b/spec/services/species/documents_export_spec.rb index 2269105be..624daf036 100644 --- a/spec/services/species/documents_export_spec.rb +++ b/spec/services/species/documents_export_spec.rb @@ -12,8 +12,8 @@ SPEC_DOCUMENTS_DOWNLOAD_PATH = 'spec/public/downloads/documents' - describe :export, cache: true do - before(:each) do + describe :export, :cache do + before do FileUtils.mkpath( File.expand_path("#{SPEC_DOCUMENTS_DOWNLOAD_PATH}") ) @@ -21,19 +21,20 @@ and_return("#{SPEC_DOCUMENTS_DOWNLOAD_PATH}/") end - after(:each) do + after do FileUtils.remove_dir("#{SPEC_DOCUMENTS_DOWNLOAD_PATH}", true) end context 'when no results' do - before(:each) do - FileUtils.rm_rf(Dir.glob("#{SPEC_DOCUMENTS_DOWNLOAD_PATH}/*")) - end - subject do Species::DocumentsExport.new({}) end + before do + FileUtils.rm_rf(Dir.glob("#{SPEC_DOCUMENTS_DOWNLOAD_PATH}/*")) + end + + specify 'when file not cached it should not be generated' do expect(subject.export).to be_falsey end diff --git a/spec/services/species/invisible_subspecies_search_spec.rb b/spec/services/species/invisible_subspecies_search_spec.rb index a8d1a1164..983142ce8 100644 --- a/spec/services/species/invisible_subspecies_search_spec.rb +++ b/spec/services/species/invisible_subspecies_search_spec.rb @@ -5,6 +5,7 @@ context 'when searching by scientific name' do context 'when subspecies never listed' do subject { Species::Search.new({ taxon_concept_query: 'amazona festiva festiva' }).results } + specify { expect(subject).not_to include(@subspecies2_2_2_1) } specify { expect(subject).to include(@species2_2_2) } end diff --git a/spec/services/species/listings_export_spec.rb b/spec/services/species/listings_export_spec.rb index dc7ada10f..6b109e831 100644 --- a/spec/services/species/listings_export_spec.rb +++ b/spec/services/species/listings_export_spec.rb @@ -13,7 +13,7 @@ specify { expect(subject.path).to eq('public/downloads/cites_listings/') } end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::ListingsExportFactory.new( @@ -29,7 +29,17 @@ end context 'when results' do - before(:each) do + subject do + Species::ListingsExportFactory.new( + { + designation_id: cites.id, + species_listings_ids: [ cites_I.id ], + geo_entities_ids: [ nepal.id ] + } + ) + end + + before do FileUtils.mkpath( File.expand_path('spec/public/downloads/cites_listings') ) @@ -37,19 +47,10 @@ and_return('spec/public/downloads/cites_listings/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/cites_listings', true) end - subject do - Species::ListingsExportFactory.new( - { - designation_id: cites.id, - species_listings_ids: [ cites_I.id ], - geo_entities_ids: [ nepal.id ] - } - ) - end context 'when file not cached' do specify do @@ -125,13 +126,6 @@ end context 'when implicitly listed subspecies present' do - before(:each) do - create_cites_eu_subspecies( - parent_id: @species.id - ) - SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings - end - subject do Species::ListingsExportFactory.new( { @@ -141,6 +135,14 @@ ) end + before do + create_cites_eu_subspecies( + parent_id: @species.id + ) + SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + end + + specify { expect(subject.query.to_a.size).to eq(1) } end end diff --git a/spec/services/species/orphaned_taxon_concepts_export_spec.rb b/spec/services/species/orphaned_taxon_concepts_export_spec.rb index bf1f3833b..6cee3c733 100644 --- a/spec/services/species/orphaned_taxon_concepts_export_spec.rb +++ b/spec/services/species/orphaned_taxon_concepts_export_spec.rb @@ -8,7 +8,7 @@ specify { expect(subject.path).to eq('public/downloads/orphaned_taxon_concepts/') } end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::OrphanedTaxonConceptsExport.new({}) @@ -18,7 +18,11 @@ end context 'when results' do - before(:each) do + subject do + Species::OrphanedTaxonConceptsExport.new({}) + end + + before do tc = create(:taxon_concept) tc.update_attribute(:parent_id, nil) # skipping validations @@ -31,13 +35,10 @@ and_return('spec/public/downloads/orphaned_taxon_concepts/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/orphaned_taxon_concepts', true) end - subject do - Species::OrphanedTaxonConceptsExport.new({}) - end context 'when file not cached' do specify do diff --git a/spec/services/species/search_spec.rb b/spec/services/species/search_spec.rb index 94c9f21af..d7ea2a9ad 100644 --- a/spec/services/species/search_spec.rb +++ b/spec/services/species/search_spec.rb @@ -6,21 +6,25 @@ context 'when searching by scientific name' do context 'when regular query' do subject { Species::Search.new({ taxon_concept_query: 'canis' }).results } + specify { expect(subject).to include(@species) } end context 'when malicious query' do subject { Species::Search.new({ taxon_concept_query: 'canis\'' }).results } + specify { expect(subject).to be_empty } end context 'when leading whitespace' do subject { Species::Search.new({ taxon_concept_query: ' canis' }).results } + specify { expect(subject).to include(@species) } end context 'when trailing whitespace' do subject { Species::Search.new({ taxon_concept_query: 'canis ' }).results } + specify { expect(subject).to include(@species) } end end diff --git a/spec/services/species/species_reference_output_spec.rb b/spec/services/species/species_reference_output_spec.rb index 0a812a1e8..61b55f85e 100644 --- a/spec/services/species/species_reference_output_spec.rb +++ b/spec/services/species/species_reference_output_spec.rb @@ -8,7 +8,7 @@ specify { expect(subject.path).to eq('public/downloads/species_reference_output/') } end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::SpeciesReferenceOutputExport.new({}) @@ -18,7 +18,11 @@ end context 'when results' do - before(:each) do + subject do + Species::SpeciesReferenceOutputExport.new({}) + end + + before do create_cites_eu_species FileUtils.mkpath( @@ -29,13 +33,10 @@ and_return('spec/public/downloads/species_reference_output/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/species_reference_output', true) end - subject do - Species::SpeciesReferenceOutputExport.new({}) - end context 'when file not cached' do specify do diff --git a/spec/services/species/standard_reference_output_spec.rb b/spec/services/species/standard_reference_output_spec.rb index 1b916875f..aeda4d0f7 100644 --- a/spec/services/species/standard_reference_output_spec.rb +++ b/spec/services/species/standard_reference_output_spec.rb @@ -8,7 +8,7 @@ specify { expect(subject.path).to eq('public/downloads/standard_reference_output/') } end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::StandardReferenceOutputExport.new({}) @@ -18,7 +18,11 @@ end context 'when results' do - before(:each) do + subject do + Species::StandardReferenceOutputExport.new({}) + end + + before do create_cites_eu_species FileUtils.mkpath( @@ -29,13 +33,10 @@ and_return('spec/public/downloads/standard_reference_output/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/standard_reference_output', true) end - subject do - Species::StandardReferenceOutputExport.new({}) - end context 'when file not cached' do specify do diff --git a/spec/services/species/synonyms_and_trade_names_export_spec.rb b/spec/services/species/synonyms_and_trade_names_export_spec.rb index 5e815ab1c..ec673102e 100644 --- a/spec/services/species/synonyms_and_trade_names_export_spec.rb +++ b/spec/services/species/synonyms_and_trade_names_export_spec.rb @@ -8,7 +8,7 @@ specify { expect(subject.path).to eq('public/downloads/synonyms_and_trade_names/') } end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::SynonymsAndTradeNamesExport.new({}) @@ -18,7 +18,11 @@ end context 'when results' do - before(:each) do + subject do + Species::SynonymsAndTradeNamesExport.new({}) + end + + before do species = create_cites_eu_species synonym = create_cites_eu_species(name_status: 'S') create( @@ -34,13 +38,10 @@ and_return('spec/public/downloads/synonyms_and_trade_names/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/synonyms_and_trade_names', true) end - subject do - Species::SynonymsAndTradeNamesExport.new({}) - end context 'when file not cached' do specify do diff --git a/spec/services/species/taxon_concept_prefix_matcher_spec.rb b/spec/services/species/taxon_concept_prefix_matcher_spec.rb index 60f6f8765..9f10473bc 100644 --- a/spec/services/species/taxon_concept_prefix_matcher_spec.rb +++ b/spec/services/species/taxon_concept_prefix_matcher_spec.rb @@ -147,6 +147,7 @@ specify { expect(subject.results).to include(@family_ac) } end + # check ranks filtering context 'when explicitly listed higher taxon but ranks expected FAMILY' do subject do @@ -176,7 +177,7 @@ specify { expect(subject.results).to be_empty } end - context 'when searching for name that matches Species and Subspecies but ranks expected SUBSPECIES' do + context 'when searching for name that matches Species and Subspecies but ranks expected SUBSPECIES' do subject do Species::TaxonConceptPrefixMatcher.new( { diff --git a/spec/services/species/taxon_concepts_export_spec.rb b/spec/services/species/taxon_concepts_export_spec.rb index 7b1002e61..06cb44e89 100644 --- a/spec/services/species/taxon_concepts_export_spec.rb +++ b/spec/services/species/taxon_concepts_export_spec.rb @@ -8,7 +8,7 @@ specify { expect(subject.path).to eq('public/downloads/taxon_concepts_names/') } end - describe :export, cache: true do + describe :export, :cache do context 'when no results' do subject do Species::TaxonConceptsNamesExport.new({}) @@ -18,7 +18,11 @@ end context 'when results' do - before(:each) do + subject do + Species::TaxonConceptsNamesExport.new({}) + end + + before do create(:taxon_concept) FileUtils.mkpath( File.expand_path('spec/public/downloads/taxon_concepts_names') @@ -27,13 +31,10 @@ and_return('spec/public/downloads/taxon_concepts_names/') end - after(:each) do + after do FileUtils.remove_dir('spec/public/downloads/taxon_concepts_names', true) end - subject do - Species::TaxonConceptsNamesExport.new({}) - end context 'when file not cached' do specify do diff --git a/spec/services/species/trade_name_prefix_matcher_spec.rb b/spec/services/species/trade_name_prefix_matcher_spec.rb index ccbdefe2c..9b9455828 100644 --- a/spec/services/species/trade_name_prefix_matcher_spec.rb +++ b/spec/services/species/trade_name_prefix_matcher_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' describe Species::TaxonConceptPrefixMatcher do - before(:each) do + before do @accepted_name = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Pavona') ) diff --git a/spec/services/species/visible_subspecies_search_spec.rb b/spec/services/species/visible_subspecies_search_spec.rb index 33aa7bcda..6fbd7ef56 100644 --- a/spec/services/species/visible_subspecies_search_spec.rb +++ b/spec/services/species/visible_subspecies_search_spec.rb @@ -3,8 +3,9 @@ include_context 'Canis lupus' describe :results do context 'when searching by scientific name' do - context 'when subspecies previously listed ' do + context 'when subspecies previously listed' do subject { Species::Search.new({ taxon_concept_query: 'canis lupus' }).results } + specify { expect(subject).to include(@subspecies) } end end diff --git a/spec/services/taxon_concept_data_spec.rb b/spec/services/taxon_concept_data_spec.rb index 956e52059..a9bb4cf3c 100644 --- a/spec/services/taxon_concept_data_spec.rb +++ b/spec/services/taxon_concept_data_spec.rb @@ -17,18 +17,23 @@ create_cites_eu_species(parent: genus) end let(:tcd_to_h) { TaxonConceptData.new(taxon_concept).to_h } + context 'when regular accepted name' do let(:taxon_concept) do create_cites_eu_subspecies(parent: accepted_species) end + specify { expect(tcd_to_h['family_name']).to eq('Canidae') } end + context 'when N accepted name' do let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'N', parent: accepted_species) end + specify { expect(tcd_to_h['family_name']).to eq('Canidae') } end + context 'when hybrid' do let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'H') @@ -41,8 +46,10 @@ other_taxon_concept: taxon_concept ) end + specify { expect(tcd_to_h['family_name']).to eq('Canidae') } end + context 'when synonym' do let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'S') @@ -55,8 +62,10 @@ other_taxon_concept: taxon_concept ) end + specify { expect(tcd_to_h['family_name']).to eq('Canidae') } end + context 'when trade name' do let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'T') @@ -69,6 +78,7 @@ other_taxon_concept: taxon_concept ) end + specify { expect(tcd_to_h['family_name']).to eq('Canidae') } end end diff --git a/spec/services/taxon_concept_prefix_matcher_spec.rb b/spec/services/taxon_concept_prefix_matcher_spec.rb index 2ad678631..32f53b531 100644 --- a/spec/services/taxon_concept_prefix_matcher_spec.rb +++ b/spec/services/taxon_concept_prefix_matcher_spec.rb @@ -57,6 +57,7 @@ end let(:matcher) { TaxonConceptPrefixMatcher.new matcher_params } + specify { expect(matcher.taxon_concepts).to include(taxon_concept4) } specify { expect(matcher.taxon_concepts).not_to include(hybrid) } end @@ -85,12 +86,19 @@ TaxonConceptPrefixMatcher.new parent_matcher_params end - specify do - expect(parent_matcher.taxon_concepts.map(&:full_name)).to eq( - [ 'Aab', 'Aac' ] + let(:self_and_ancestor_matcher) do + TaxonConceptPrefixMatcher.new self_and_ancestor_matcher_params + end + let(:self_and_ancestor_matcher_params) do + SearchParams.new( + taxonomy: { id: taxonomy.id }, + rank: { id: taxon_concept4.rank_id, scope: :self_and_ancestors }, + scientific_name: 'AAA' ) end - + let(:ancestor_matcher) do + TaxonConceptPrefixMatcher.new ancestor_matcher_params + end let(:ancestor_matcher_params) do SearchParams.new( taxonomy: { id: taxonomy.id }, @@ -99,27 +107,21 @@ ) end - let(:ancestor_matcher) do - TaxonConceptPrefixMatcher.new ancestor_matcher_params + specify do + expect(parent_matcher.taxon_concepts.map(&:full_name)).to eq( + [ 'Aab', 'Aac' ] + ) end + + specify do expect(ancestor_matcher.taxon_concepts.map(&:full_name)).to eq( [ 'Aaa' ] ) end - let(:self_and_ancestor_matcher_params) do - SearchParams.new( - taxonomy: { id: taxonomy.id }, - rank: { id: taxon_concept4.rank_id, scope: :self_and_ancestors }, - scientific_name: 'AAA' - ) - end - let(:self_and_ancestor_matcher) do - TaxonConceptPrefixMatcher.new self_and_ancestor_matcher_params - end specify do expect(self_and_ancestor_matcher.taxon_concepts.map(&:full_name)).to eq( @@ -127,6 +129,7 @@ ) end end + context 'when taxon concept scope applied' do let(:ancestor_matcher_params) do SearchParams.new( @@ -139,12 +142,9 @@ TaxonConceptPrefixMatcher.new ancestor_matcher_params end - specify do - expect(ancestor_matcher.taxon_concepts.map(&:full_name)).to eq( - [ 'Aaa', 'Aab', 'Aac' ] - ) + let(:descendant_matcher) do + TaxonConceptPrefixMatcher.new descendant_matcher_params end - let(:descendant_matcher_params) do SearchParams.new( taxonomy: { id: taxonomy.id }, @@ -153,10 +153,14 @@ ) end - let(:descendant_matcher) do - TaxonConceptPrefixMatcher.new descendant_matcher_params + specify do + expect(ancestor_matcher.taxon_concepts.map(&:full_name)).to eq( + [ 'Aaa', 'Aab', 'Aac' ] + ) end + + specify do expect(descendant_matcher.taxon_concepts.map(&:full_name)).to eq( [ 'Aaab', 'Aab', 'Abb' ] diff --git a/spec/services/trade/filter_spec.rb b/spec/services/trade/filter_spec.rb index 2a64056c6..146204e22 100644 --- a/spec/services/trade/filter_spec.rb +++ b/spec/services/trade/filter_spec.rb @@ -4,7 +4,8 @@ describe :results do context 'when searching by taxon concepts ids' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + context 'in the public interface' do context 'at GENUS rank' do subject do Trade::Filter.new( @@ -14,10 +15,12 @@ taxon_with_descendants: true } ).results end + specify { expect(subject).to include(@shipment1) } specify { expect(subject).not_to include(@shipment2) } specify { expect(subject.length).to eq(2) } end + context 'at FAMILY rank' do subject do Trade::Filter.new( { @@ -26,9 +29,11 @@ taxon_with_descendants: false } ).results end + specify { expect(subject.length).to eq(0) } end end + context 'in the admin interface' do context 'at GENUS rank' do subject do Trade::Filter.new( @@ -37,10 +42,12 @@ internal: true } ).results end + specify { expect(subject).to include(@shipment1) } specify { expect(subject).not_to include(@shipment2) } specify { expect(subject.length).to eq(2) } end + context 'at FAMILY rank' do subject do Trade::Filter.new( { @@ -48,10 +55,12 @@ internal: true } ).results end + specify { expect(subject).to include(@shipment2) } specify { expect(subject).not_to include(@shipment1) } specify { expect(subject.length).to eq(4) } end + context 'at mixed ranks' do subject do Trade::Filter.new( @@ -61,15 +70,14 @@ } ).results end + specify { expect(subject).to include(@shipment1) } specify { expect(subject).to include(@shipment2) } specify { expect(subject.length).to eq(6) } end end + context 'when status N shipments present' do - before(:each) do - @shipment_of_status_N = create(:shipment, taxon_concept_id: @status_N_species.id) - end subject do Trade::Filter.new( { @@ -77,12 +85,16 @@ } ).results end + + before do + @shipment_of_status_N = create(:shipment, taxon_concept_id: @status_N_species.id) + end + + specify { expect(subject).to include(@shipment_of_status_N) } end + context 'when subspecies shipments present' do - before(:each) do - @shipment_of_subspecies = create(:shipment, taxon_concept_id: @subspecies.id) - end subject do Trade::Filter.new( { @@ -90,16 +102,24 @@ } ).results end + + before do + @shipment_of_subspecies = create(:shipment, taxon_concept_id: @subspecies.id) + end + + specify { expect(subject).to include(@shipment_of_subspecies) } end + context 'when synonym subspecies shipments present' do - before(:each) do + before do @shipment_of_synonym_subspecies = create( :shipment, reported_taxon_concept_id: @synonym_subspecies.id, taxon_concept_id: @plant_species.id ) end + context 'when searching by taxonomic parent' do subject do Trade::Filter.new( @@ -108,8 +128,10 @@ } ).results end + specify { expect(subject).not_to include(@shipment_of_synonym_subspecies) } end + context 'when searching by accepted name' do subject do Trade::Filter.new( @@ -118,20 +140,16 @@ } ).results end + specify { expect(subject).to include(@shipment_of_synonym_subspecies) } end end end + context 'when searching by reported taxon concepts ids' do - before(:each) { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + before { SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings } + context 'when trade names shipments present' do - before(:each) do - @shipment_of_trade_name = create( - :shipment, - reported_taxon_concept_id: @trade_name.id, - taxon_concept_id: @plant_species.id - ) - end subject do Trade::Filter.new( { @@ -139,29 +157,44 @@ } ).results end + + before do + @shipment_of_trade_name = create( + :shipment, + reported_taxon_concept_id: @trade_name.id, + taxon_concept_id: @plant_species.id + ) + end + + specify { expect(subject).to include(@shipment_of_trade_name) } end end + context 'when searching by appendices' do subject { Trade::Filter.new({ appendices: [ 'I' ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(1) } end context 'when searching for terms_ids' do subject { Trade::Filter.new({ terms_ids: [ @term_cav.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(3) } end context 'when searching for units_ids' do subject { Trade::Filter.new({ units_ids: [ @unit.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(3) } end context 'when searching for purposes_ids' do subject { Trade::Filter.new({ purposes_ids: [ @purpose.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(7) } end @@ -169,30 +202,39 @@ context 'when searching for sources_ids' do context 'when code' do subject { Trade::Filter.new({ sources_ids: [ @source.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(2) } end + context 'when blank' do subject { Trade::Filter.new({ source_blank: true }).results } + specify { expect(subject).to include(@shipment6) } specify { expect(subject.length).to eq(1) } end + context 'when both code and blank' do subject { Trade::Filter.new({ sources_ids: [ @source.id ], source_blank: true }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(3) } end + context 'when wild' do subject { Trade::Filter.new({ sources_ids: [ @source_wild.id ], source_blank: true }).results } + specify { expect(subject).to include(@shipment3) } specify { expect(subject.length).to eq(5) } end + context 'when wild and internal' do subject do Trade::Filter.new( { sources_ids: [ @source_wild.id ], source_blank: true, internal: true } ).results end + specify { expect(subject).to include(@shipment3) } specify { expect(subject.length).to eq(4) } end @@ -200,18 +242,21 @@ context 'when searching for importers_ids' do subject { Trade::Filter.new({ importers_ids: [ @argentina.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(2) } end context 'when searching for exporters_ids' do subject { Trade::Filter.new({ exporters_ids: [ @argentina.id ] }).results } + specify { expect(subject).to include(@shipment2) } specify { expect(subject.length).to eq(5) } end context 'when searching for countries_of_origin_ids' do subject { Trade::Filter.new({ countries_of_origin_ids: [ @argentina.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(2) } end @@ -219,20 +264,27 @@ context 'when searching by year' do context 'when time range specified' do subject { Trade::Filter.new({ time_range_start: 2013, time_range_end: 2015 }).results } + specify { expect(subject).to include(@shipment2) } specify { expect(subject.length).to eq(6) } end + context 'when time range specified incorrectly' do subject { Trade::Filter.new({ time_range_start: 2013, time_range_end: 2012 }).results } + specify { expect(subject.length).to eq(0) } end + context 'when time range start specified' do subject { Trade::Filter.new({ time_range_start: 2012 }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(7) } end + context 'when time range end specified' do subject { Trade::Filter.new({ time_range_end: 2012 }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(1) } end @@ -241,17 +293,20 @@ context 'when searching by reporter_type' do context 'when reporter type is not I or E' do subject { Trade::Filter.new({ internal: true, reporter_type: 'K' }).results } + specify { expect(subject.length).to eq(7) } end context 'when reporter type is I' do subject { Trade::Filter.new({ internal: true, reporter_type: 'I' }).results } + specify { expect(subject).to include(@shipment2) } specify { expect(subject.length).to eq(5) } end context 'when reporter type is E' do subject { Trade::Filter.new({ internal: true, reporter_type: 'E' }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(2) } end @@ -260,22 +315,28 @@ context 'when searching by permit' do context 'when permit number' do subject { Trade::Filter.new({ internal: true, permits_ids: [ @export_permit1.id ] }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(1) } end + context 'when blank' do subject { Trade::Filter.new({ internal: true, permit_blank: true }).results } + specify { expect(subject).to include(@shipment2) } specify { expect(subject.length).to eq(5) } end + context 'when both permit number and blank' do subject { Trade::Filter.new({ internal: true, permits_ids: [ @export_permit1.id ], permit_blank: true }).results } + specify { expect(subject.length).to eq(6) } end end context 'when searching by quantity' do subject { Trade::Filter.new({ internal: true, quantity: 20 }).results } + specify { expect(subject).to include(@shipment1) } specify { expect(subject.length).to eq(1) } end @@ -284,16 +345,19 @@ describe :total_cnt do context 'when none matches' do subject { Trade::Filter.new({ appendices: [ 'III' ] }) } + specify { expect(subject.total_cnt).to eq(0) } end context 'when one matches' do subject { Trade::Filter.new({ appendices: [ 'I' ] }) } + specify { expect(subject.total_cnt).to eq(1) } end context 'when two match' do subject { Trade::Filter.new({ purposes_ids: [ @purpose.id ] }) } + specify { expect(subject.total_cnt).to eq(7) } end end diff --git a/spec/services/trade/permit_matcher_spec.rb b/spec/services/trade/permit_matcher_spec.rb index 672099d49..e70840c26 100644 --- a/spec/services/trade/permit_matcher_spec.rb +++ b/spec/services/trade/permit_matcher_spec.rb @@ -2,36 +2,50 @@ describe Trade::PermitMatcher do describe :results do context 'when searching by permit number' do - before(:each) do + before do @permit = create(:permit, number: '006AAA') @permit_percent = create(:permit, number: '100%') end + context 'when regular query' do subject { Trade::PermitMatcher.new({ permit_query: '006' }).results } + specify { expect(subject).to include(@permit) } end + context 'when wildcard in query, do not inject as wildcard' do subject { Trade::PermitMatcher.new({ permit_query: '%AA' }).results } + specify { expect(subject).to be_empty } end + context 'when wildcard in query, treat as literal instead' do subject { Trade::PermitMatcher.new({ permit_query: '100%' }).results } + specify { expect(subject).to include(@permit_percent) } end + context 'when case mismatch in query' do subject { Trade::PermitMatcher.new({ permit_query: '006aa' }).results } + specify { expect(subject).to include(@permit) } end + context 'when malicious query' do subject { Trade::PermitMatcher.new({ permit_query: '006\'' }).results } + specify { expect(subject).to be_empty } end + context 'when leading whitespace' do subject { Trade::PermitMatcher.new({ permit_query: ' 006' }).results } + specify { expect(subject).to include(@permit) } end + context 'when trailing whitespace' do subject { Trade::PermitMatcher.new({ permit_query: '006AAA ' }).results } + specify { expect(subject).to include(@permit) } end end diff --git a/spec/services/trade/reported_taxon_concept_resolver_spec.rb b/spec/services/trade/reported_taxon_concept_resolver_spec.rb index 1808af06d..40cae245e 100644 --- a/spec/services/trade/reported_taxon_concept_resolver_spec.rb +++ b/spec/services/trade/reported_taxon_concept_resolver_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Trade::ReportedTaxonConceptResolver do context 'resolving trade names' do - before(:each) do + before do @accepted_name = create_cites_eu_species @trade_name = create_cites_eu_species( name_status: 'T' @@ -13,14 +13,16 @@ taxon_relationship_type: trade_name_relationship_type ) end + let(:resolver) do Trade::ReportedTaxonConceptResolver.new(@trade_name.id) end + specify { expect(resolver.accepted_taxa).to include(@accepted_name) } end context 'resolving synonyms' do - before(:each) do + before do @accepted_name = create_cites_eu_species @synonym = create_cites_eu_species( name_status: 'S' @@ -32,19 +34,23 @@ taxon_relationship_type: synonym_relationship_type ) end + let(:resolver) do Trade::ReportedTaxonConceptResolver.new(@synonym.id) end + specify { expect(resolver.accepted_taxa).to include(@accepted_name) } end context 'resolving accepted names' do - before(:each) do + before do @accepted_name = create_cites_eu_species end + let(:resolver) do Trade::ReportedTaxonConceptResolver.new(@accepted_name.id) end + specify { expect(resolver.accepted_taxa).to include(@accepted_name) } end end diff --git a/spec/services/trade/sandbox_filter_spec.rb b/spec/services/trade/sandbox_filter_spec.rb index a9da244c6..b3060d662 100644 --- a/spec/services/trade/sandbox_filter_spec.rb +++ b/spec/services/trade/sandbox_filter_spec.rb @@ -19,7 +19,8 @@ let(:validation_rule) do create_taxon_concept_appendix_year_validation end - before(:each) do + + before do @shipment1 = sandbox_klass.create( taxon_name: canis_lupus.full_name, appendix: 'I', @@ -61,6 +62,7 @@ validation_error_id: @validation_error.id ).results end + specify { expect(subject).to include(@shipment2) } specify { expect(subject).not_to include(@shipment1) } end diff --git a/spec/services/trade/sandbox_spec.rb b/spec/services/trade/sandbox_spec.rb index 286675cfe..73d1a9738 100644 --- a/spec/services/trade/sandbox_spec.rb +++ b/spec/services/trade/sandbox_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe Trade::Sandbox, drops_tables: true do - before(:each) do +describe Trade::Sandbox, :drops_tables do + before do genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Acipenser') ) @@ -26,6 +26,7 @@ iso_code2: 'PT' ) end + let(:annual_report_upload) do aru = build(:annual_report_upload, trading_country_id: @argentina.id, point_of_view: 'I') aru.save(validate: false) @@ -44,8 +45,10 @@ create_year_format_validation aru end + describe :destroy do subject { annual_report_upload.sandbox } + specify do sandbox_klass = Trade::SandboxTemplate.ar_klass(subject.table_name) subject.destroy diff --git a/spec/services/trade/shipments_comptab_export_spec.rb b/spec/services/trade/shipments_comptab_export_spec.rb index 16b9c479a..3ffc01e70 100644 --- a/spec/services/trade/shipments_comptab_export_spec.rb +++ b/spec/services/trade/shipments_comptab_export_spec.rb @@ -1,17 +1,20 @@ require 'spec_helper' describe Trade::ShipmentsComptabExport do - before(:each) do + before do 4.times { create(:shipment) } end describe :total_cnt do context 'when internal' do subject { Trade::ShipmentsComptabExport.new(internal: true, per_page: 4) } + specify { expect(subject.total_cnt).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsComptabExport.new(internal: false, per_page: 3) } + specify { expect(subject.total_cnt).to eq(4) } end end @@ -19,10 +22,13 @@ describe :query do context 'when internal' do subject { Trade::ShipmentsComptabExport.new(internal: true, per_page: 4) } + specify { expect(subject.query.ntuples).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsComptabExport.new(internal: false, per_page: 3) } + specify { expect(subject.query.ntuples).to eq(3) } end end diff --git a/spec/services/trade/shipments_export_spec.rb b/spec/services/trade/shipments_export_spec.rb index e9d8c95cf..2fcacb071 100644 --- a/spec/services/trade/shipments_export_spec.rb +++ b/spec/services/trade/shipments_export_spec.rb @@ -1,17 +1,20 @@ require 'spec_helper' describe Trade::ShipmentsExport do - before(:each) do + before do 4.times { create(:shipment) } end describe :total_cnt do context 'when internal' do subject { Trade::ShipmentsExport.new(internal: true, per_page: 4) } + specify { expect(subject.total_cnt).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsExport.new(internal: false, per_page: 3) } + specify { expect(subject.total_cnt).to eq(4) } end end @@ -19,10 +22,13 @@ describe :query do context 'when internal' do subject { Trade::ShipmentsExport.new(internal: true, per_page: 4) } + specify { expect(subject.query.ntuples).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsExport.new(internal: false, per_page: 3) } + specify { expect(subject.query.ntuples).to eq(3) } end end diff --git a/spec/services/trade/shipments_gross_exports_export_spec.rb b/spec/services/trade/shipments_gross_exports_export_spec.rb index 5558abd0f..fe04274b8 100644 --- a/spec/services/trade/shipments_gross_exports_export_spec.rb +++ b/spec/services/trade/shipments_gross_exports_export_spec.rb @@ -1,17 +1,20 @@ require 'spec_helper' describe Trade::ShipmentsGrossExportsExport do - before(:each) do + before do 4.times { create(:shipment) } end describe :total_cnt do context 'when internal' do subject { Trade::ShipmentsGrossExportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.total_cnt).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsGrossExportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.total_cnt).to eq(4) } end end @@ -19,12 +22,16 @@ describe :query do context 'when internal' do subject { Trade::ShipmentsGrossExportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.query.ntuples).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsGrossExportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.query.ntuples).to eq(3) } end + # TODO Temporarily disabling this test. # No changes to the code seem responsible for this to fail. # Comparing the last succesful build and the first failed one, the issue seems to be related @@ -32,6 +39,7 @@ context 'when invalid date range' do pending('This fails on Travis. It started failing after new version of some packages (like PG) have been installed') do subject { Trade::ShipmentsGrossExportsExport.new(internal: false, time_range_start: 2015, time_range_end: 2014) } + specify { subject.query.ntuples.should == 0 } end end diff --git a/spec/services/trade/shipments_gross_imports_export_spec.rb b/spec/services/trade/shipments_gross_imports_export_spec.rb index 22891ec14..88ba4bc0c 100644 --- a/spec/services/trade/shipments_gross_imports_export_spec.rb +++ b/spec/services/trade/shipments_gross_imports_export_spec.rb @@ -1,17 +1,20 @@ require 'spec_helper' describe Trade::ShipmentsGrossImportsExport do - before(:each) do + before do 4.times { create(:shipment) } end describe :total_cnt do context 'when internal' do subject { Trade::ShipmentsGrossImportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.total_cnt).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsGrossImportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.total_cnt).to eq(4) } end end @@ -19,12 +22,16 @@ describe :query do context 'when internal' do subject { Trade::ShipmentsGrossImportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.query.ntuples).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsGrossImportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.query.ntuples).to eq(3) } end + # TODO Temporarily disabling this test. # No changes to the code seem responsible for this to fail. # Comparing the last succesful build and the first failed one, the issue seems to be related @@ -32,6 +39,7 @@ context 'when invalid date range' do pending('This fails on Travis. It started failing after new version of some packages (like PG) have been installed') do subject { Trade::ShipmentsGrossImportsExport.new(internal: false, time_range_start: 2015, time_range_end: 2014) } + specify { subject.query.ntuples.should == 0 } end end diff --git a/spec/services/trade/shipments_net_exports_export_spec.rb b/spec/services/trade/shipments_net_exports_export_spec.rb index 69ec8de87..006e155b4 100644 --- a/spec/services/trade/shipments_net_exports_export_spec.rb +++ b/spec/services/trade/shipments_net_exports_export_spec.rb @@ -1,17 +1,20 @@ require 'spec_helper' describe Trade::ShipmentsNetExportsExport do - before(:each) do + before do 4.times { create(:shipment) } end describe :total_cnt do context 'when internal' do subject { Trade::ShipmentsNetExportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.total_cnt).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsNetExportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.total_cnt).to eq(4) } end end @@ -19,12 +22,16 @@ describe :query do context 'when internal' do subject { Trade::ShipmentsNetExportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.query.ntuples).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsNetExportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.query.ntuples).to eq(3) } end + # TODO Temporarily disabling this test. # No changes to the code seem responsible for this to fail. # Comparing the last succesful build and the first failed one, the issue seems to be related @@ -32,6 +39,7 @@ context 'when invalid date range' do pending('This fails on Travis. It started failing after new version of some packages (like PG) have been installed') do subject { Trade::ShipmentsNetExportsExport.new(internal: false, time_range_start: 2015, time_range_end: 2014) } + specify { subject.query.ntuples.should == 0 } end end diff --git a/spec/services/trade/shipments_net_imports_export_spec.rb b/spec/services/trade/shipments_net_imports_export_spec.rb index b7426dbf2..05aa4ffe3 100644 --- a/spec/services/trade/shipments_net_imports_export_spec.rb +++ b/spec/services/trade/shipments_net_imports_export_spec.rb @@ -1,17 +1,20 @@ require 'spec_helper' describe Trade::ShipmentsNetImportsExport do - before(:each) do + before do 4.times { create(:shipment) } end describe :total_cnt do context 'when internal' do subject { Trade::ShipmentsNetImportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.total_cnt).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsNetImportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.total_cnt).to eq(4) } end end @@ -19,12 +22,16 @@ describe :query do context 'when internal' do subject { Trade::ShipmentsNetImportsExport.new(internal: true, per_page: 4) } + specify { expect(subject.query.ntuples).to eq(4) } end + context 'when public' do subject { Trade::ShipmentsNetImportsExport.new(internal: false, per_page: 3) } + specify { expect(subject.query.ntuples).to eq(3) } end + # TODO Temporarily disabling this test. # No changes to the code seem responsible for this to fail. # Comparing the last succesful build and the first failed one, the issue seems to be related @@ -32,6 +39,7 @@ context 'when invalid date range' do pending('This fails on Travis. It started failing after new version of some packages (like PG) have been installed') do subject { Trade::ShipmentsNetImportsExport.new(internal: false, time_range_start: 2015, time_range_end: 2014) } + specify { subject.query.ntuples.should == 0 } end end diff --git a/spec/shared/shipments.rb b/spec/shared/shipments.rb index 391b604f4..cfae4a11a 100644 --- a/spec/shared/shipments.rb +++ b/spec/shared/shipments.rb @@ -1,5 +1,5 @@ shared_context 'Shipments' do - before(:each) do + before do @animal_family = create_cites_eu_family( parent: create_cites_eu_order( parent: cites_eu_mammalia diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4c283c747..44ff527cc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -71,27 +71,27 @@ RequestStore.store[:track_who_does_it_current_user] = @user end - config.before(:each) do + config.before do DatabaseCleaner.strategy = :transaction end - config.before(:each, drops_tables: true) do + config.before(:each, :drops_tables) do DatabaseCleaner.strategy = :deletion, { cache_tables: false } ApplicationRecord.connection.execute('SELECT * FROM drop_trade_sandboxes()') end - config.before(:each) do + config.before do DatabaseCleaner.start end - config.after(:each) do + config.after do DatabaseCleaner.clean # this is duplicated here because of the :drops_tables specs @user = create(:user) RequestStore.store[:track_who_does_it_current_user] = @user end - config.before(:each) do |example| + config.before do |example| # Clears out the jobs for tests using the fake testing Sidekiq::Worker.clear_all # Get the current example from the example_method object @@ -107,7 +107,7 @@ end end - config.before(:each) do |example| + config.before do |example| if example.metadata[:cache] memory_store = ActiveSupport::Cache.lookup_store(:memory_store) diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index b0c3b8ff9..b3ccc7de1 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -1,34 +1,34 @@ module ControllerMacros def login_admin - before(:each) do + before do @request.env['devise.mapping'] = Devise.mappings[:user] sign_in @user || FactoryBot.create(:user, role: User::MANAGER) end end def login_contributor - before(:each) do + before do @request.env['devise.mapping'] = Devise.mappings[:user] sign_in FactoryBot.create(:user, role: User::CONTRIBUTOR) end end def login_elibrary_viewer - before(:each) do + before do @request.env['devise.mapping'] = Devise.mappings[:user] sign_in FactoryBot.create(:user, role: User::ELIBRARY_USER) end end def login_api_user - before(:each) do + before do @request.env['devise.mapping'] = Devise.mappings[:user] sign_in FactoryBot.create(:user, role: User::API_USER) end end def login_secretariat_user - before(:each) do + before do @request.env['devise.mapping'] = Devise.mappings[:user] sign_in FactoryBot.create(:user, role: User::SECRETARIAT) end diff --git a/spec/support/sapi_helpers.rb b/spec/support/sapi_helpers.rb index 9f4c468c6..55b85dcf8 100644 --- a/spec/support/sapi_helpers.rb +++ b/spec/support/sapi_helpers.rb @@ -1,4 +1,4 @@ -shared_context :sapi do +shared_context :sapi do # rubocop:disable RSpec/SharedExamples # too many changes def cites_eu @_cites_eu ||= create(:taxonomy, name: Taxonomy::CITES_EU) end @@ -11,13 +11,17 @@ def cites return @_cites if @_cites d = Designation.find_by(taxonomy_id: cites_eu.id, name: Designation::CITES) + unless d d = create(:designation, name: Designation::CITES, taxonomy: cites_eu) + %w[ADDITION DELETION RESERVATION RESERVATION_WITHDRAWAL EXCEPTION].each do |ch| ch_type = ChangeType.find_by(designation_id: d.id, name: ch) + unless ch_type create(:change_type, name: ch, designation: d) end + %w[I II III].each do |app| unless SpeciesListing.find_by(designation_id: d.id, abbreviation: app) create( @@ -28,6 +32,7 @@ def cites end end end + @_cites = d end @@ -35,12 +40,15 @@ def eu return @_eu if @_eu d = Designation.find_by(taxonomy_id: cites_eu.id, name: Designation::EU) + unless d d = create(:designation, name: Designation::EU, taxonomy: cites_eu) + %w[ADDITION DELETION RESERVATION RESERVATION_WITHDRAWAL EXCEPTION].each do |ch| unless ChangeType.find_by(designation_id: d.id, name: ch) create(:change_type, name: ch, designation: d) end + %w[A B C D].each do |app| unless SpeciesListing.find_by(designation_id: d.id, abbreviation: app) create( @@ -51,6 +59,7 @@ def eu end end end + @_eu ||= d end @@ -58,12 +67,15 @@ def cms_designation return @_cms_designation if @_cms_designation d = Designation.find_by(taxonomy_id: cms.id, name: Designation::CMS) + unless d d = create(:designation, name: Designation::CMS, taxonomy: cms) + %w[ADDITION DELETION EXCEPTION].each do |ch| unless ChangeType.find_by(designation_id: d.id, name: ch) create(:change_type, name: ch, designation: d) end + %w[I II].each do |app| unless SpeciesListing.find_by(designation_id: d.id, abbreviation: app) create( @@ -74,6 +86,7 @@ def cms_designation end end end + @_cms_designation = d end @@ -90,6 +103,7 @@ def cms_designation define_method "cites_#{app}" do SpeciesListing.find_by(designation_id: cites.id, abbreviation: app) end + define_method "create_cites_#{app}_#{ch.downcase}" do |options = {}| create( :listing_change, @@ -102,10 +116,12 @@ def cms_designation ) end end + %w[A B C D].each do |app| define_method "eu_#{app}" do SpeciesListing.find_by(designation_id: eu.id, abbreviation: app) end + define_method "create_eu_#{app}_#{ch.downcase}" do |options = {}| create( :listing_change, @@ -129,6 +145,7 @@ def cms_designation define_method "cms_#{app}" do SpeciesListing.find_by(designation_id: cms_designation.id, abbreviation: app) end + define_method "create_cms_#{app}_#{ch.downcase}" do |options = {}| create( :listing_change, @@ -150,6 +167,7 @@ def cms_animalia taxon_name: create(:taxon_name, scientific_name: 'Animalia') ) end + def cms_chordata @_cms_chordata ||= create_cms_phylum( @@ -158,6 +176,7 @@ def cms_chordata parent: cms_animalia ) end + def cites_eu_mammalia @_cites_eu_mammalia ||= create_cites_eu_class( taxonomic_position: '1.1.1', @@ -165,6 +184,7 @@ def cites_eu_mammalia parent: cites_eu_chordata ) end + def cms_mammalia @_cms_mammalia ||= create_cms_class( @@ -173,6 +193,7 @@ def cms_mammalia parent: cms_chordata ) end + def cites_eu_aves @_cites_eu_aves ||= create_cites_eu_class( @@ -181,6 +202,7 @@ def cites_eu_aves parent: cites_eu_chordata ) end + def cms_reptilia @_cms_reptilia ||= create_cms_class( @@ -189,6 +211,7 @@ def cms_reptilia parent: cms_chordata ) end + def cites_eu_amphibia @_cites_eu_amphibia ||= create_cites_eu_class( @@ -197,6 +220,7 @@ def cites_eu_amphibia parent: cites_eu_chordata ) end + def cites_eu_elasmobranchii @_cites_eu_elasmobranchii ||= create_cites_eu_class( @@ -205,6 +229,7 @@ def cites_eu_elasmobranchii parent: cites_eu_chordata ) end + def cites_eu_arthropoda @_cites_eu_arthropoda ||= create_cites_eu_phylum( @@ -213,6 +238,7 @@ def cites_eu_arthropoda parent: cites_eu_animalia ) end + def cites_eu_insecta @_cites_eu_insecta ||= create_cites_eu_class( @@ -221,6 +247,7 @@ def cites_eu_insecta parent: cites_eu_arthropoda ) end + def cites_eu_annelida @_cites_eu_annelida ||= create_cites_eu_phylum( @@ -229,6 +256,7 @@ def cites_eu_annelida parent: cites_eu_animalia ) end + def cites_eu_hirudinoidea @_cites_eu_hirudinoidea ||= create_cites_eu_class( @@ -237,6 +265,7 @@ def cites_eu_hirudinoidea parent: cites_eu_annelida ) end + def cites_eu_plantae @_cites_eu_plantae ||= create_cites_eu_kingdom( @@ -295,12 +324,14 @@ def create_cites_eu_plant_species(options = {}) options.merge({ rank: create(:rank, name: rank) }) ) end + define_method "build_#{rank.downcase}" do |options = {}| build( :taxon_concept, options.merge({ rank: create(:rank, name: rank) }) ) end + define_method "create_cites_eu_#{rank.downcase}" do |options = {}| create( :taxon_concept, @@ -312,6 +343,7 @@ def create_cites_eu_plant_species(options = {}) ) ) end + define_method "build_cites_eu_#{rank.downcase}" do |options = {}| build( :taxon_concept, @@ -323,6 +355,7 @@ def create_cites_eu_plant_species(options = {}) ) ) end + define_method "create_cms_#{rank.downcase}" do |options = {}| create( :taxon_concept, @@ -334,6 +367,7 @@ def create_cites_eu_plant_species(options = {}) ) ) end + define_method "build_cms_#{rank.downcase}" do |options = {}| build( :taxon_concept, @@ -357,6 +391,7 @@ def create_cites_eu_plant_species(options = {}) options.merge({ designation: cites }) ) end + define_method "build_#{cites_event_type}" do |options = {}| build( cites_event_type, @@ -364,6 +399,7 @@ def create_cites_eu_plant_species(options = {}) ) end end + [ :eu_regulation, :eu_suspension_regulation, :eu_implementing_regulation, :eu_council_regulation, :ec_srg @@ -374,6 +410,7 @@ def create_cites_eu_plant_species(options = {}) options.merge({ designation: eu }) ) end + define_method "build_#{eu_event_type}" do |options = {}| build( eu_event_type, @@ -508,6 +545,7 @@ def reg1997 effective_at: '1997-06-01', end_date: '2000-12-18' ) end + def reg2005 @_reg2005 ||= create( @@ -515,6 +553,7 @@ def reg2005 effective_at: '2005-08-22', end_date: '2008-04-11' ) end + def reg2008 @_reg2008 ||= create( @@ -522,6 +561,7 @@ def reg2008 effective_at: '2008-04-11', end_date: '2009-05-22' ) end + def reg2012 @_reg2012 ||= create( @@ -529,6 +569,7 @@ def reg2012 effective_at: '2012-12-15', end_date: '2013-08-10' ) end + def reg2013 @_reg2013 ||= create( @@ -579,6 +620,7 @@ def contains_geo_relationship_type instance_variable_set("@_#{met_name}", relationship) end end + def equal_relationship_type @_equal_relationship_type ||= create( diff --git a/spec/workers/eu_regulation_activation_worker_spec.rb b/spec/workers/eu_regulation_activation_worker_spec.rb index bf76cde10..d29385930 100644 --- a/spec/workers/eu_regulation_activation_worker_spec.rb +++ b/spec/workers/eu_regulation_activation_worker_spec.rb @@ -23,6 +23,7 @@ is_current: false ) end + describe 'Set new EU regulation to true' do before do EventListingChangesCopyWorker.drain diff --git a/spec/workers/event_listing_changes_copy_worker_spec.rb b/spec/workers/event_listing_changes_copy_worker_spec.rb index b39b9e605..a4c2ae8c1 100644 --- a/spec/workers/event_listing_changes_copy_worker_spec.rb +++ b/spec/workers/event_listing_changes_copy_worker_spec.rb @@ -38,13 +38,16 @@ is_current: false ) end + before { EventListingChangesCopyWorker.new.perform(prev_eu_regulation.id, eu_regulation.id) } + specify { expect(eu_regulation.listing_changes.reload.count).to eq(1) } specify { expect(eu_regulation.listing_changes.first.is_current).to be_falsey } end context 'when copy into current regulation' do before { EventListingChangesCopyWorker.new.perform(prev_eu_regulation.id, eu_regulation.id) } + specify { expect(eu_regulation.listing_changes.reload.count).to eq(1) } specify { expect(eu_regulation.listing_changes.first.is_current).to be_truthy } end @@ -67,6 +70,7 @@ end before { EventListingChangesCopyWorker.new.perform(prev_eu_regulation.id, eu_regulation.id) } + specify { expect(eu_regulation.listing_changes.reload.count).to eq(1) } specify { expect(eu_regulation.listing_changes.first.exclusions.count).to eq(2) } specify { expect(eu_regulation.listing_changes.first.taxonomic_exclusions.count).to eq(1) } diff --git a/spec/workers/quotas_copy_worker_spec.rb b/spec/workers/quotas_copy_worker_spec.rb index ffee75375..657cdc9e0 100644 --- a/spec/workers/quotas_copy_worker_spec.rb +++ b/spec/workers/quotas_copy_worker_spec.rb @@ -48,9 +48,10 @@ end describe 'Copy single quota, for a given year' do - before(:each) do + before do QuotasCopyWorker.new.perform(job_defaults) end + specify { expect(Quota.count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).count(true)).to eq(1) } specify { expect(Quota.where(is_current: false).count(true)).to eq(1) } @@ -58,7 +59,7 @@ end describe 'Try to copy quota from wrong year' do - before(:each) do + before do QuotasCopyWorker.new.perform( job_defaults.merge( { @@ -67,24 +68,26 @@ ) ) end + specify { expect(Quota.count(true)).to eq(1) } specify { expect(Quota.where(is_current: true).count(true)).to eq(1) } specify { expect(Quota.where(is_current: false).count(true)).to eq(0) } end describe 'Copy quota when there are no current quotas' do - before(:each) do + before do quota.is_current = false quota.save QuotasCopyWorker.new.perform(job_defaults) end + specify { expect(Quota.count(true)).to eq(1) } specify { expect(Quota.where(is_current: true).count(true)).to eq(0) } specify { expect(Quota.where(is_current: false).count(true)).to eq(1) } end describe 'When multiple quotas copy quota for given country' do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc2 = create( :taxon_concept, @@ -106,6 +109,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(3) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).to include(@quota2.id) } @@ -114,7 +118,7 @@ end describe 'When multiple quotas copy quota for both countries' do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc2 = create( :taxon_concept, @@ -136,6 +140,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(4) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: false).count(true)).to eq(2) } @@ -144,7 +149,7 @@ end describe "When multiple quotas don't copy quota for given country" do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc2 = create( :taxon_concept, @@ -166,6 +171,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(3) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).to include(@quota2.id) } @@ -174,7 +180,7 @@ end describe 'When multiple quotas copy quota for given taxon_concept' do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc = create(:taxon_concept) @quota2 = create( @@ -193,6 +199,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(3) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).to include(@quota2.id) } @@ -201,7 +208,7 @@ end describe 'When multiple quotas copy quota for both taxon_concepts' do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc = create( :taxon_concept, @@ -223,6 +230,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(4) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).not_to include(@quota2.id) } @@ -231,7 +239,7 @@ end describe "When multiple quotas don't copy quota for given taxon_concept" do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc = create(:taxon_concept, taxonomy_id: taxonomy.id) @quota2 = create( @@ -250,6 +258,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(3) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).to include(@quota2.id) } @@ -258,7 +267,7 @@ end describe 'When text to replace passed, should be replaced' do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc = create(:taxon_concept, taxonomy_id: taxonomy.id) @quota2 = create( @@ -279,6 +288,7 @@ ) ) end + specify { expect(Quota.count(true)).to eq(4) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).not_to include(@quota2.id) } @@ -290,7 +300,7 @@ end describe 'When url passed, should be replaced' do - before(:each) do + before do geo_entity2 = create(:geo_entity) tc = create(:taxon_concept, taxonomy_id: taxonomy.id) @quota2 = create( @@ -304,6 +314,7 @@ ) QuotasCopyWorker.new.perform(job_defaults.merge({ 'url' => 'http://myurl.co.uk' })) end + specify { expect(Quota.count(true)).to eq(4) } specify { expect(Quota.where(is_current: true).count(true)).to eq(2) } specify { expect(Quota.where(is_current: true).map(&:id)).not_to include(@quota2.id) } diff --git a/spec/workers/submission_worker_spec.rb b/spec/workers/submission_worker_spec.rb index 71540882a..0c0705a99 100644 --- a/spec/workers/submission_worker_spec.rb +++ b/spec/workers/submission_worker_spec.rb @@ -9,7 +9,7 @@ def deliver end describe SubmissionWorker do - before(:each) do + before do genus = create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Acipenser') ) @@ -43,10 +43,11 @@ def deliver allow_any_instance_of(SubmissionWorker).to receive(:upload_on_S3) allow_any_instance_of(NotificationMailer).to receive(:mail).and_return(EmailMessageStub.new()) end + context 'when no primary errors' do pending(PENDING_REASON) if PENDING_REASON - before(:each) do + before do @aru = build(:annual_report_upload, trading_country_id: @argentina.id, point_of_view: 'I') @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -65,27 +66,33 @@ def deliver ) create_year_format_validation end + specify do expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.to change { Trade::Shipment.count }.by(1) end + specify do expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.to change { Trade::Permit.count }.by(5) end + specify 'leading space is stripped' do SubmissionWorker.new.perform(@aru.id, @submitter.id) expect(Trade::Permit.find_by(number: 'BBB')).not_to be_nil end + context 'when permit previously reported' do - before(:each) { create(:permit, number: 'xxx') } + before { create(:permit, number: 'xxx') } + specify do expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.to change { Trade::Permit.count }.by(4) end end end + context 'when primary errors present' do pending(PENDING_REASON) if PENDING_REASON - before(:each) do + before do @aru = build(:annual_report_upload) @aru.save(validate: false) sandbox_klass = Trade::SandboxTemplate.ar_klass(@aru.sandbox.table_name) @@ -98,14 +105,16 @@ def deliver ) create_year_format_validation end + specify do expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.not_to change { Trade::Shipment.count } end end + context 'when reported under a synonym' do pending(PENDING_REASON) if PENDING_REASON - before(:each) do + before do @synonym = create_cites_eu_species( name_status: 'S', scientific_name: 'Acipenser stenorrhynchus' @@ -132,13 +141,16 @@ def deliver ) create_year_format_validation end + specify do expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.to change { Trade::Shipment.count }.by(1) end + specify do SubmissionWorker.new.perform(@aru.id, @submitter.id) expect(Trade::Shipment.first.taxon_concept_id).to eq(@species.id) end + specify do SubmissionWorker.new.perform(@aru.id, @submitter.id) expect(Trade::Shipment.first.reported_taxon_concept_id).to eq(@synonym.id) From 90365c5b10b1f61ac3600be74ecd2b42f2fc1fa2 Mon Sep 17 00:00:00 2001 From: Daniel Perrett Date: Mon, 20 Apr 2026 23:00:46 +0100 Subject: [PATCH 8/8] chore: insert new lines around blocks Replace: \bend\n(?!$|\n|\s*(?:end\b|elsif\b|else\b|\]|\)|\})) With: end\n\n In: app/**/*.rb,lib/**/*.rb,lib/**/*.rake,spec/**/*.rb Replace: \n(\x20+)([^\x20\n#].*)(? a } end + index! end diff --git a/app/controllers/admin/simple_crud_controller.rb b/app/controllers/admin/simple_crud_controller.rb index e3f710441..291689e56 100644 --- a/app/controllers/admin/simple_crud_controller.rb +++ b/app/controllers/admin/simple_crud_controller.rb @@ -11,6 +11,7 @@ def index def create create! do |success, failure| success.js { render 'create' } + failure.js do load_associations @@ -24,6 +25,7 @@ def create def update update! do |success, failure| success.js { render 'create' } + failure.js do load_associations @@ -40,6 +42,7 @@ def destroy destroy! do |success, failure| success.html { redirect_to collection_url, notice: 'Operation succeeded' } + failure.html do redirect_to collection_url, alert: diff --git a/app/controllers/admin/synonym_relationships_controller.rb b/app/controllers/admin/synonym_relationships_controller.rb index 2e1bfb3c1..9d6c74d51 100644 --- a/app/controllers/admin/synonym_relationships_controller.rb +++ b/app/controllers/admin/synonym_relationships_controller.rb @@ -17,6 +17,7 @@ def edit format.js { render 'new' } end end + def create params[:taxon_relationship][:taxon_relationship_type_id] = @synonym_relationship_type.id @@ -26,13 +27,13 @@ def create includes(:other_taxon_concept).order('taxon_concepts.full_name') render 'create' end + failure.js do render 'new' end end end - def update params[:taxon_relationship][:taxon_relationship_type_id] = @synonym_relationship_type.id @@ -42,6 +43,7 @@ def update includes(:other_taxon_concept).order('taxon_concepts.full_name') render 'create' end + failure.js do render 'new' end diff --git a/app/controllers/admin/taxon_commons_controller.rb b/app/controllers/admin/taxon_commons_controller.rb index ab3591040..8086405da 100644 --- a/app/controllers/admin/taxon_commons_controller.rb +++ b/app/controllers/admin/taxon_commons_controller.rb @@ -23,6 +23,7 @@ def create success.js do @taxon_commons = @taxon_concept.taxon_commons end + failure.js do load_associations render 'new' @@ -30,13 +31,13 @@ def create end end - def update update! do |success, failure| success.js do @taxon_commons = @taxon_concept.taxon_commons render 'create' end + failure.js do load_associations render 'new' @@ -50,6 +51,7 @@ def destroy redirect_to admin_taxon_concept_names_url(@taxon_concept), notice: 'Operation succeeded' end + failure.html do redirect_to admin_taxon_concept_names_url(@taxon_concept), notice: 'Operation failed' diff --git a/app/controllers/admin/taxon_concept_associated_types_controller.rb b/app/controllers/admin/taxon_concept_associated_types_controller.rb index 2557ad232..ea42a5565 100644 --- a/app/controllers/admin/taxon_concept_associated_types_controller.rb +++ b/app/controllers/admin/taxon_concept_associated_types_controller.rb @@ -9,6 +9,7 @@ def destroy redirect_to edit_admin_taxon_concept_url(params[:taxon_concept_id]), notice: 'Operation successful' end + failure.html do redirect_to edit_admin_taxon_concept_url(params[:taxon_concept_id]), notice: 'Operation failed' diff --git a/app/controllers/admin/taxon_concept_references_controller.rb b/app/controllers/admin/taxon_concept_references_controller.rb index 1a98de50b..f6150f6c1 100644 --- a/app/controllers/admin/taxon_concept_references_controller.rb +++ b/app/controllers/admin/taxon_concept_references_controller.rb @@ -22,6 +22,7 @@ def edit format.js { render 'new' } end end + def create @references = TaxonConceptReference.where(taxon_concept_id: params['taxon_concept_id']) @@ -42,11 +43,11 @@ def create @taxon_concept_reference.reference = Reference.new render 'create' end + failure.js { render 'new' } end end - def update update! do |success, failure| success.js do @@ -54,6 +55,7 @@ def update @taxon_concept_reference.reference = Reference.new render 'create' end + failure.js { render 'new' } end end @@ -64,6 +66,7 @@ def destroy redirect_to admin_taxon_concept_taxon_concept_references_path(@taxon_concept), notice: 'Operation successful' end + failure.html do redirect_to admin_taxon_concept_taxon_concept_references_path(@taxon_concept), notice: 'Operation failed' diff --git a/app/controllers/admin/taxon_concepts_controller.rb b/app/controllers/admin/taxon_concepts_controller.rb index 2a480b74c..938f5891d 100644 --- a/app/controllers/admin/taxon_concepts_controller.rb +++ b/app/controllers/admin/taxon_concepts_controller.rb @@ -29,6 +29,7 @@ def edit def create create! do |success, failure| success.js { render('create') } + failure.js do load_taxonomies load_ranks @@ -41,6 +42,7 @@ def create def update @taxon_concept = TaxonConcept.find(params[:id]) rebuild_taxonomy = @taxon_concept.rebuild_taxonomy?(params) + update! do |success, failure| success.js do UpdateTaxonomyWorker.perform_async if rebuild_taxonomy @@ -129,6 +131,7 @@ def split_stringified_ids_lists when 'T' then :accepted_names_for_trade_name_ids when 'H' then :hybrid_parents_ids end + if ids_list_key && params[:taxon_concept].key?(ids_list_key) && (stringified_ids_list = params[:taxon_concept][ids_list_key]) && diff --git a/app/controllers/admin/taxon_eu_suspensions_controller.rb b/app/controllers/admin/taxon_eu_suspensions_controller.rb index fdffd5bc9..26b08a133 100644 --- a/app/controllers/admin/taxon_eu_suspensions_controller.rb +++ b/app/controllers/admin/taxon_eu_suspensions_controller.rb @@ -17,12 +17,14 @@ def create ), notice: 'Operation successful' end + failure.html do load_search render 'create' end end end + def update update! do |success, failure| success.html do @@ -53,7 +55,6 @@ def update end end - def destroy destroy! do |success, failure| success.html do diff --git a/app/controllers/admin/taxon_instruments_controller.rb b/app/controllers/admin/taxon_instruments_controller.rb index 5b307af53..0b8c84880 100644 --- a/app/controllers/admin/taxon_instruments_controller.rb +++ b/app/controllers/admin/taxon_instruments_controller.rb @@ -33,6 +33,7 @@ def update success.html do redirect_to admin_taxon_concept_taxon_instruments_url(@taxon_concept) end + failure.html do load_instruments render 'edit' diff --git a/app/controllers/admin/taxon_listing_changes_controller.rb b/app/controllers/admin/taxon_listing_changes_controller.rb index 24971f2e9..8c54224eb 100644 --- a/app/controllers/admin/taxon_listing_changes_controller.rb +++ b/app/controllers/admin/taxon_listing_changes_controller.rb @@ -31,6 +31,7 @@ def edit build_dependants end end + def create @taxon_concept = TaxonConcept.find(params[:taxon_concept_id]) @designation = Designation.find(params[:designation_id]) @@ -46,7 +47,6 @@ def create end end - def update update! do |success, failure| success.html do @@ -56,6 +56,7 @@ def update redirect_to admin_taxon_concept_designation_listing_changes_url(@taxon_concept, @designation) end end + failure.html do load_change_types build_dependants @@ -82,6 +83,7 @@ def build_dependants listing_change_params[:party_listing_distribution_attributes] ) end + unless @listing_change.annotation @listing_change.build_annotation( params[:listing_change] && @@ -106,6 +108,7 @@ def load_change_types else [] end + @events = if @designation.is_eu? EuRegulation.order(effective_at: :desc) diff --git a/app/controllers/admin/taxon_quotas_controller.rb b/app/controllers/admin/taxon_quotas_controller.rb index 2902559f5..6d934f14a 100644 --- a/app/controllers/admin/taxon_quotas_controller.rb +++ b/app/controllers/admin/taxon_quotas_controller.rb @@ -15,21 +15,25 @@ def create redirect_to admin_taxon_concept_quotas_url(params[:taxon_concept_id]), notice: 'Operation successful' end + failure.html { render 'create' } end end + def update update! do |success, failure| success.html do redirect_to admin_taxon_concept_quotas_url(params[:taxon_concept_id]), notice: 'Operation successful' end + failure.html do load_lib_objects render 'new' end success.js { render 'create' } + failure.js do load_lib_objects render 'new' @@ -37,7 +41,6 @@ def update end end - def destroy destroy! do |success, failure| success.html do diff --git a/app/controllers/admin/taxon_relationships_controller.rb b/app/controllers/admin/taxon_relationships_controller.rb index e66211690..092626b42 100644 --- a/app/controllers/admin/taxon_relationships_controller.rb +++ b/app/controllers/admin/taxon_relationships_controller.rb @@ -34,6 +34,7 @@ def create create! do |success, failure| success.js { render 'create' } + failure.js do # for Inter-taxonomic relationships @taxonomies = Taxonomy.order(:name).where.not( @@ -56,6 +57,7 @@ def destroy # the *taxon_concept_id*. @taxon_relationship = TaxonRelationship.find(params[:id]) type = @taxon_relationship.taxon_relationship_type.name + destroy! do |success, failure| success.html { redirect_to collection_url(type: type), notice: 'Operation succeeded' } end @@ -70,6 +72,7 @@ def load_taxon_relationship_types else TaxonRelationshipType.find_by(name: params[:type] || TaxonRelationshipType::EQUAL_TO) end + @taxon_relationship_types = TaxonRelationshipType.order(:name). intertaxonomic end diff --git a/app/controllers/admin/term_trade_codes_pairs_controller.rb b/app/controllers/admin/term_trade_codes_pairs_controller.rb index 719897484..5187bb685 100644 --- a/app/controllers/admin/term_trade_codes_pairs_controller.rb +++ b/app/controllers/admin/term_trade_codes_pairs_controller.rb @@ -11,6 +11,7 @@ def index def destroy @term_trade_codes_pair = TermTradeCodesPair.find params[:id] + destroy! do |format| format.html do redirect_to admin_term_trade_codes_pairs_path(type: @term_trade_codes_pair.trade_code_type) diff --git a/app/controllers/admin/trade_name_relationships_controller.rb b/app/controllers/admin/trade_name_relationships_controller.rb index 8858cdc7c..ca9ae3a75 100644 --- a/app/controllers/admin/trade_name_relationships_controller.rb +++ b/app/controllers/admin/trade_name_relationships_controller.rb @@ -17,6 +17,7 @@ def edit format.js { render 'new' } end end + def create params[:taxon_relationship][:taxon_relationship_type_id] = @trade_name_relationship_type.id @@ -26,13 +27,13 @@ def create includes(:other_taxon_concept).order('taxon_concepts.full_name') render 'create' end + failure.js do render 'new' end end end - def update params[:taxon_relationship][:taxon_relationship_type_id] = @trade_name_relationship_type.id @@ -42,6 +43,7 @@ def update includes(:other_taxon_concept).order('taxon_concepts.full_name') render 'create' end + failure.js do render 'new' end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 9497c9337..d82668376 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -23,6 +23,7 @@ def update else @user.update(user_params) end + respond_to do |format| format.js do if update_result diff --git a/app/controllers/api/trade_downloads_cache_cleanup_controller.rb b/app/controllers/api/trade_downloads_cache_cleanup_controller.rb index ea156e050..036c4ccdb 100644 --- a/app/controllers/api/trade_downloads_cache_cleanup_controller.rb +++ b/app/controllers/api/trade_downloads_cache_cleanup_controller.rb @@ -8,6 +8,7 @@ def index rescue message = 'Something went wrong' end + message = 'Shipments downloads successfully cleared' if message.blank? render json: { message: message diff --git a/app/controllers/api/v1/documents_controller.rb b/app/controllers/api/v1/documents_controller.rb index 0da6ec02d..b75a0dacd 100644 --- a/app/controllers/api/v1/documents_controller.rb +++ b/app/controllers/api/v1/documents_controller.rb @@ -111,6 +111,7 @@ def download_zip "{\n title: #{document.title},\n filename: #{document.filename}\n}" else zos.put_next_entry(document.file.filename) + ActiveStorage::Blob.service.download(document.file.blob.key) do |chunk| zos.print(chunk) end diff --git a/app/controllers/api/v1/eu_decisions_controller.rb b/app/controllers/api/v1/eu_decisions_controller.rb index 8bebd348a..f6842058e 100644 --- a/app/controllers/api/v1/eu_decisions_controller.rb +++ b/app/controllers/api/v1/eu_decisions_controller.rb @@ -73,6 +73,7 @@ def sanitized_params h end + filters end end diff --git a/app/controllers/api/v1/shipments_controller.rb b/app/controllers/api/v1/shipments_controller.rb index 77aadc0d6..6adc872fe 100644 --- a/app/controllers/api/v1/shipments_controller.rb +++ b/app/controllers/api/v1/shipments_controller.rb @@ -3,6 +3,7 @@ class Api::V1::ShipmentsController < ApplicationController before_action :authenticate before_action :load_grouping_type + after_action only: [ :grouped_query, :country_query ] do set_pagination_headers(:data, :grouped_params) end @@ -130,6 +131,7 @@ def download_data ) do Trade::DownloadDataRetriever.dashboard_download(download_params).to_a end + render json: @download_data end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f6951d02d..de553bd3f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -67,6 +67,7 @@ def access_denied_error(exception) end flash.now[:error] = message + respond_to do |format| format.html { redirect_to rescue_path } format.js { render inline: 'location.reload();' } diff --git a/app/controllers/checklist/downloads_controller.rb b/app/controllers/checklist/downloads_controller.rb index 0f497e705..b285b2a7f 100644 --- a/app/controllers/checklist/downloads_controller.rb +++ b/app/controllers/checklist/downloads_controller.rb @@ -8,6 +8,7 @@ def index ids = params[:ids] || '' @downloads = Download.where(id: ids).order(updated_at: :desc).limit(5) @downloads = @downloads.map { |v| v.attributes.except('filename', 'path') } + @downloads.each do |v| v['updated_at'] = v['updated_at'].strftime('%A, %e %b %Y %H:%M') end @@ -42,7 +43,6 @@ def create render json: @download.to_json end - # GET downloads/:id/download def download @download = Download.find(params[:id]) diff --git a/app/controllers/checklist/timelines_controller.rb b/app/controllers/checklist/timelines_controller.rb index af59ad4cd..132a45933 100644 --- a/app/controllers/checklist/timelines_controller.rb +++ b/app/controllers/checklist/timelines_controller.rb @@ -9,6 +9,7 @@ def index Checklist::TimelinesForTaxonConcept.new(tc) unless tc.nil? end + render json: res, each_serializer: Checklist::TimelinesForTaxonConceptSerializer end diff --git a/app/controllers/cites_trade_controller.rb b/app/controllers/cites_trade_controller.rb index fb599d7d2..b9de64a3a 100644 --- a/app/controllers/cites_trade_controller.rb +++ b/app/controllers/cites_trade_controller.rb @@ -8,7 +8,6 @@ def set_db_download_config @db_download_size ||= db_download_config[:size] end - private def search_params diff --git a/app/controllers/concerns/trade/trade_data_download_logger.rb b/app/controllers/concerns/trade/trade_data_download_logger.rb index 0a7112e5a..7341ba902 100644 --- a/app/controllers/concerns/trade/trade_data_download_logger.rb +++ b/app/controllers/concerns/trade/trade_data_download_logger.rb @@ -18,9 +18,11 @@ def log_download(request, search_params, rows) data['importer'] = self.get_field_values(search_params[:importers_ids], GeoEntity) data['exporter'] = self.get_field_values(search_params[:exporters_ids], GeoEntity) geo_ip_data = SapiModule::GeoIP.instance.resolve(request.ip) + [ :country, :city, :organization ].each do |col| data[col] = geo_ip_data[col] end + w = Trade::TradeDataDownload.new(data) w.save end @@ -29,6 +31,7 @@ def log_download(request, search_params, rows) def self.get_field_values(param, model) if param == '' then return 'All' end + if param == nil then return '' end if model.to_s == 'GeoEntity' diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 7609d2a8d..fecf14d20 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -29,6 +29,7 @@ def create def invalid_login_attempt @user = User.new set_flash_message(:error, :invalid) + respond_to do |format| format.html { render :new, status: :unauthorized } format.json { render json: flash[:error], status: :unauthorized } diff --git a/app/controllers/species/exports_controller.rb b/app/controllers/species/exports_controller.rb index f5c54fc45..9f6362caf 100644 --- a/app/controllers/species/exports_controller.rb +++ b/app/controllers/species/exports_controller.rb @@ -21,6 +21,7 @@ def download when 'Processes' result = Species::CitesProcessesExport.new(@filters).export end + respond_to do |format| format.html do if result.is_a?(Array) @@ -33,6 +34,7 @@ def download redirect_to species_exports_path, notice: "There are no #{params[:data_type]} to download." end end + format.json do render json: { total: result.is_a?(Array) ? 1 : 0 } end diff --git a/app/controllers/trade/annual_report_uploads_controller.rb b/app/controllers/trade/annual_report_uploads_controller.rb index 4e160ed7f..25dbd23e4 100644 --- a/app/controllers/trade/annual_report_uploads_controller.rb +++ b/app/controllers/trade/annual_report_uploads_controller.rb @@ -15,6 +15,7 @@ def index null_cond ) end + render json: @annual_report_uploads, each_serializer: Trade::AnnualReportUploadSerializer end diff --git a/app/controllers/trade/shipments_controller.rb b/app/controllers/trade/shipments_controller.rb index ecfef1832..23a7d06e7 100644 --- a/app/controllers/trade/shipments_controller.rb +++ b/app/controllers/trade/shipments_controller.rb @@ -44,6 +44,7 @@ def destroy def destroy_batch @search = Trade::Filter.new(search_params) cnt = @search.query.count + disconnected_permits_ids = @search.query.map do |s| s.permits_ids end.flatten.uniq @@ -97,15 +98,19 @@ def batch_update_params if reporter_type.present? res[:reported_by_exporter] = Trade::Shipment.reporter_type_to_reported_by_exporter(reporter_type) end + if res.key?(:import_permit_number) && res[:import_permit_number].nil? res[:import_permits_ids] = nil end + if res.key?(:export_permit_number) && res[:export_permit_number].nil? res[:export_permits_ids] = nil end + if res.key?(:origin_permit_number) && res[:origin_permit_number].nil? res[:origin_permits_ids] = nil end + res end @@ -117,6 +122,7 @@ def populate_accepted_taxon_concept(update_params) ).accepted_taxa.first update_params[:taxon_concept_id] = accepted_tc && accepted_tc.id end + update_params end end diff --git a/app/controllers/trade_controller.rb b/app/controllers/trade_controller.rb index 727ae3adc..ed0ac6bcf 100644 --- a/app/controllers/trade_controller.rb +++ b/app/controllers/trade_controller.rb @@ -10,11 +10,11 @@ def user_can_edit def create raise NoMethodError end + def update raise NoMethodError end - def submit raise NoMethodError end diff --git a/app/helpers/admin/api_usage_helper.rb b/app/helpers/admin/api_usage_helper.rb index 00f17d8e1..1ea1defb3 100644 --- a/app/helpers/admin/api_usage_helper.rb +++ b/app/helpers/admin/api_usage_helper.rb @@ -11,10 +11,12 @@ def controller_colours # and anything else with 'Failed' and return newly constructed hash def sanitise_hash_for_line_graph(hash) new_hash = {} + hash.map do |k, v| n = k[0] == 200 ? 'Successful' : 'Failed' new_hash[[ n, k[1] ]] = v end + new_hash end end diff --git a/app/helpers/admin/nomenclature_changes_helper.rb b/app/helpers/admin/nomenclature_changes_helper.rb index b264c5e82..279fd21f1 100644 --- a/app/helpers/admin/nomenclature_changes_helper.rb +++ b/app/helpers/admin/nomenclature_changes_helper.rb @@ -63,6 +63,7 @@ def split_outputs_blurb html = ' into ' total = @nomenclature_change.outputs.size + @nomenclature_change.outputs.each_with_index do |output, idx| if output.taxon_concept && !output.new_full_name html += link_to( @@ -72,8 +73,10 @@ def split_outputs_blurb else html += content_tag(:span, output.display_full_name) end + html += ', ' if idx < (total - 1) end + html.html_safe end @@ -81,6 +84,7 @@ def lump_blurb content_tag(:div, class: 'well well-small') do concat 'Lumping ' total = @nomenclature_change.inputs.size + @nomenclature_change.inputs.each_with_index do |input, idx| if input.taxon_concept concat link_to( @@ -88,8 +92,10 @@ def lump_blurb admin_taxon_concept_names_path(input.taxon_concept) ) end + concat ', ' if idx < (total - 1) end + concat lump_outputs_blurb end end @@ -107,6 +113,7 @@ def lump_outputs_blurb else html += content_tag(:span, @nomenclature_change.output.display_full_name) end + html.html_safe end @@ -141,6 +148,7 @@ def global_selection(checked = true) :p, content_tag(:i, nil, class: 'icon-info-sign') + 'Select a taxon below to populate all fields with that taxon.' ) + @nomenclature_change.outputs.map do |output| html += content_tag(:div, class: 'species-checkbox') do @@ -148,6 +156,7 @@ def global_selection(checked = true) content_tag(:span, output.display_full_name, class: 'species-name') end end + html.html_safe end @@ -164,6 +173,7 @@ def outputs_selection(ff) else 'existing_taxon' end + content_tag(:div, class: 'outputs_selection') do [ 'New taxon', 'Existing subspecies', 'Existing taxon' ].each do |opt| opt_val = opt.downcase.gsub(/\s+/, '_') @@ -176,6 +186,7 @@ def outputs_selection(ff) ) + ' ' + opt ) end + concat ff.link_to_remove 'Remove output' end end @@ -265,6 +276,7 @@ def lump_inputs_tags def lump_output_content tc = @nc.output.new_taxon_concept || @nc.output.taxon_concept + content_tag(:div, class: 'tab-content') do content_tag( :div, inner_content(@nc.output, tc), @@ -275,6 +287,7 @@ def lump_output_content def lump_output_tag tc = @nc.output.new_taxon_concept || @nc.output.taxon_concept + content_tag(:ul, class: 'nav nav-tabs') do content_tag(:li, class: 'active') do concat link_to( @@ -310,6 +323,7 @@ def split_input_content def outputs_tags outputs = Array.wrap(select_outputs) + content_tag(:ul, class: 'nav nav-tabs') do outputs.each_with_index do |output, idx| tc = output.new_taxon_concept || output.taxon_concept @@ -320,6 +334,7 @@ def outputs_tags def outputs_content outputs = Array.wrap(select_outputs) + content_tag(:div, class: 'tab-content') do outputs.each_with_index do |output, idx| tc = output.new_taxon_concept || output.taxon_concept @@ -370,6 +385,7 @@ def sorted_parent_reassignments(ff) def name_reassignment_label(reassignment) taxon_relationship = reassignment.reassignable other_taxon_concept = taxon_relationship.other_taxon_concept + content_tag(:label, class: 'control-label') do content_tag(:span, taxon_relationship.taxon_relationship_type.name) + tag.br() + @@ -377,6 +393,7 @@ def name_reassignment_label(reassignment) other_taxon_concept.full_name, admin_taxon_concept_names_path(other_taxon_concept) ) + + content_tag(:span) do ' (' + (other_taxon_concept.name_status || '--') + ')' end + diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 2711d6eab..c294f495a 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -46,6 +46,7 @@ def internal_notes(record) content_tag(:b, 'Internal notes:') + content_tag(:p, record.internal_notes) end + comment_icon_with_tooltip(info) end @@ -94,6 +95,7 @@ def error_messages_for(resource) "#{pluralize(resource.errors.count, "error")} " + 'prohibited this record from being saved:' ) + + content_tag(:ul) do resource.errors.full_messages.collect do |item| concat(content_tag(:li, item)) @@ -165,6 +167,7 @@ def admin_new_modal(options = {}) render partial: 'form' end end + + content_tag(:div, class: 'modal-footer') do button_tag( type: 'button', class: 'btn', 'data-dismiss': 'modal', @@ -223,9 +226,11 @@ def traco_locale_columns(column_name) result << "#{column_name}_#{I18n.default_locale}" # default locale 2nd. remaining_locales -= I18n.default_locale end + remaining_locales.sort.each do |locale| # alphabetically all remaining locales. result << "#{column_name}_#{locale}" end + result.map(&:to_sym) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bd69e51ab..a467f0b2c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,6 +21,7 @@ def error_message_for(field) message = if field == :password_confirmation field = :password + resource.errors.messages[:password].select do |message| message.include? 'confirmation' end diff --git a/app/helpers/taxon_concept_helper.rb b/app/helpers/taxon_concept_helper.rb index 50aa3f499..ea748f17e 100644 --- a/app/helpers/taxon_concept_helper.rb +++ b/app/helpers/taxon_concept_helper.rb @@ -10,6 +10,7 @@ def admin_taxon_concept_title end ) + ( content_tag(:div, class: 'action-buttons' + ) do admin_add_new_taxon_concept_multi end @@ -21,16 +22,20 @@ def admin_add_new_taxon_concept_multi content_tag(:div, class: 'btn-group', style: 'float:right') do link_to(' Add new Taxon Concept'.html_safe, '#', class: 'btn') + link_to(''.html_safe, '#', class: 'btn dropdown-toggle', 'data-toggle': 'dropdown') + + content_tag(:ul, class: 'dropdown-menu') do content_tag(:li) do link_to('Accepted name', '#new-taxon_concept', 'data-toggle': 'modal') end + + content_tag(:li) do link_to('Synonym', '#new-taxon_concept_synonym', 'data-toggle': 'modal') end + + content_tag(:li) do link_to('Hybrid', '#new-taxon_concept_hybrid', 'data-toggle': 'modal') end + + content_tag(:li) do link_to('N name', '#new-taxon_concept_n_name', 'data-toggle': 'modal') end @@ -211,6 +216,7 @@ def taxon_concept_internal_note_label(comment) content_tag(:p, class: 'internal-notes-type') do comment.comment_type + ' note' end + + content_tag(:div, class: 'internal-notes-meta') do updater = comment.try(:updater) if updater @@ -219,6 +225,7 @@ def taxon_concept_internal_note_label(comment) '' end end + + content_tag(:div, class: 'internal-notes-meta') do updated_at = comment.try(:updated_at).try(:strftime, '%d/%m/%y %H:%M') @@ -238,6 +245,7 @@ def taxon_concept_internal_note_form(comment) content_tag(:td, style: 'width:30%') do taxon_concept_internal_note_label(comment) end + + content_tag(:td) do f.text_area( :note, diff --git a/app/jobs/elibrary_refresh_document_search_job.rb b/app/jobs/elibrary_refresh_document_search_job.rb index 6352d38d5..b8405fd49 100644 --- a/app/jobs/elibrary_refresh_document_search_job.rb +++ b/app/jobs/elibrary_refresh_document_search_job.rb @@ -7,12 +7,14 @@ def perform(*args) Benchmark.realtime do DocumentSearch.refresh_citations_and_documents end + Rails.logger.debug { "#{Time.now} Citations & documents refreshed in #{elapsed_time}s" } elsif DocumentSearch.documents_need_refreshing? elapsed_time = Benchmark.realtime do DocumentSearch.refresh_documents end + Rails.logger.debug { "#{Time.now} Documents refreshed in #{elapsed_time}s" } end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 92474729c..a5126d1a5 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -10,6 +10,7 @@ def initialize(user) # else # can :read, :all # end + # # The first argument to `can` is the action you are giving the user # permission to do. @@ -39,9 +40,11 @@ def initialize(user) can [ :autocomplete, :read ], :all can :update, :all can :create, :all + cannot :update, User do |u| u.id != user.id end + cannot :manage, [ Taxonomy, Rank, Designation, Instrument, SpeciesListing, diff --git a/app/models/concerns/changeable.rb b/app/models/concerns/changeable.rb index 5fcb46369..8fb160e22 100644 --- a/app/models/concerns/changeable.rb +++ b/app/models/concerns/changeable.rb @@ -44,6 +44,7 @@ def changeable_after_save_callback if taxon_concept changeable_bump_dependents_timestamp_part_one(taxon_concept, updated_by_id) end + # Rails 5.1 to 5.2 # DEPRECATION WARNING: The behavior of `attribute_was` inside of after callbacks will be changing in the next version of Rails. # The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). @@ -64,7 +65,9 @@ def changeable_after_save_callback # if previous_taxon_concept # bump_dependents_timestamp(previous_taxon_concept, updated_by_id) # end + # end + # == Changed to fix deprecation warnings == if (taxon_concept.nil? && taxon_concept_id_before_last_save) || (taxon_concept && taxon_concept_id_before_last_save && taxon_concept_id != taxon_concept_id_before_last_save) @@ -95,6 +98,7 @@ def changeable_after_save_callback_on_commit if taxon_concept changeable_bump_dependents_timestamp_part_two end + # Rails 5.1 to 5.2 # DEPRECATION WARNING: The behavior of `attribute_was` inside of after callbacks will be changing in the next version of Rails. # The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). @@ -115,7 +119,9 @@ def changeable_after_save_callback_on_commit # if previous_taxon_concept # bump_dependents_timestamp(previous_taxon_concept, updated_by_id) # end + # end + # == Changed to fix deprecation warnings == if (taxon_concept.nil? && taxon_concept_id_before_last_save) || (taxon_concept && taxon_concept_id_before_last_save && taxon_concept_id != taxon_concept_id_before_last_save) diff --git a/app/models/concerns/comparison_attributes.rb b/app/models/concerns/comparison_attributes.rb index 8aaee91c7..2a42bb9ad 100644 --- a/app/models/concerns/comparison_attributes.rb +++ b/app/models/concerns/comparison_attributes.rb @@ -75,6 +75,7 @@ def comparison_conditions(comparison_attributes = nil) a.table[attr_name].eq(attr_val).to_sql end end + arel_nodes.join(' AND ') end @@ -90,6 +91,7 @@ def comparison_conditions(comparison_attributes = nil) # if row.duplicates({ parent_id: new_parent_id }) # raise "Cannot reassign row #{row.id} from parent #{row.parent_id} to #{new_parent_id} - duplicate exists" # end + # ``` # # This is used heavily in code relating to nomenclature changes. diff --git a/app/models/concerns/dictionary.rb b/app/models/concerns/dictionary.rb index d22d092fd..4c28f8eec 100644 --- a/app/models/concerns/dictionary.rb +++ b/app/models/concerns/dictionary.rb @@ -10,6 +10,7 @@ def build_dictionary(*keys) # keys.each do |key| # const_set key.to_s.upcase, key.to_s.upcase # end + # define_singleton_method("dict") { keys.map{|k| k.to_s.upcase } } build_basic_dictionary(*keys) { |key| key.to_s.upcase } end @@ -23,6 +24,7 @@ def build_basic_dictionary(*keys) key end end + define_singleton_method('dict') { keys.map { |k| k.to_s.upcase } } end end diff --git a/app/models/concerns/status_dictionary.rb b/app/models/concerns/status_dictionary.rb index d32561d8c..7dd31cd57 100644 --- a/app/models/concerns/status_dictionary.rb +++ b/app/models/concerns/status_dictionary.rb @@ -8,9 +8,11 @@ def build_steps(*steps) statuses = ([ :new, :submitted, :closed ] + steps).map(&:to_s) const_set(:STEPS, steps) build_basic_dictionary(*statuses) + define_singleton_method :status_dict do statuses end + steps.each do |status| define_dynamic_status_check(status) define_dynamic_status_or_submitting_check(status) @@ -24,9 +26,11 @@ def define_dynamic_status_check(status) # def inputs? # status == self.INPUTS # end + def #{status}? status == self.class::#{status.upcase} end + RUBY end @@ -35,9 +39,11 @@ def define_dynamic_status_or_submitting_check(status) # def inputs_or_submitting? # status == self.INPUTS || submitting? # end + def #{status}_or_submitting? status == self.class::#{status.upcase} || submitting? end + RUBY end end diff --git a/app/models/document.rb b/app/models/document.rb index 3c5960f2d..0c8518996 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -128,6 +128,7 @@ class Document < ApplicationRecord def is_link? self.type == 'Document::VirtualCollege' && !is_pdf? end + alias_method :is_link, :is_link? # Used by Serializer. def self.display_name diff --git a/app/models/document_citation.rb b/app/models/document_citation.rb index 5ad812cd9..0c45927d7 100644 --- a/app/models/document_citation.rb +++ b/app/models/document_citation.rb @@ -73,6 +73,7 @@ def duplicates(comparison_attributes_override = {}) ) ) end + relation end end diff --git a/app/models/events/cites_suspension_notification.rb b/app/models/events/cites_suspension_notification.rb index f8aaf0376..ac3097f20 100644 --- a/app/models/events/cites_suspension_notification.rb +++ b/app/models/events/cites_suspension_notification.rb @@ -53,6 +53,7 @@ class CitesSuspensionNotification < Event validates :effective_at, presence: true before_save :handle_new_subtype + before_validation do cites = Designation.find_by(name: 'CITES') self.designation_id = cites && cites.id diff --git a/app/models/listing_change.rb b/app/models/listing_change.rb index f2239f369..2df7b67a5 100644 --- a/app/models/listing_change.rb +++ b/app/models/listing_change.rb @@ -170,11 +170,13 @@ def duplicates(comparison_attributes_override = {}) ) ) end + if annotation relation = relation.includes(:annotation).references(:annotation).where( annotation.comparison_conditions ) end + relation end diff --git a/app/models/m_taxon_concept.rb b/app/models/m_taxon_concept.rb index 4452ff76a..2104d58ba 100644 --- a/app/models/m_taxon_concept.rb +++ b/app/models/m_taxon_concept.rb @@ -135,7 +135,8 @@ class MTaxonConcept < ApplicationRecord WHEN change_type_name = 'RESERVATION' THEN 1 WHEN change_type_name = 'RESERVATION_WITHDRAWAL' THEN 2 WHEN change_type_name = 'DELETION' THEN 3 - END + end + SQL ) ) diff --git a/app/models/nomenclature_change/constructor_helpers.rb b/app/models/nomenclature_change/constructor_helpers.rb index 2771ce22e..588ebd196 100644 --- a/app/models/nomenclature_change/constructor_helpers.rb +++ b/app/models/nomenclature_change/constructor_helpers.rb @@ -44,6 +44,7 @@ def _build_parent_reassignment(child, input, output) reassignment.build_reassignment_target(nomenclature_change_output_id: output.id) end end + reassignment end @@ -60,6 +61,7 @@ def _build_names_reassignments(input, outputs, all_outputs = nil) taxon_concepts_ids.include?(relationship.other_taxon_concept_id) end end + input.name_reassignments = relationships.map do |relationship| _build_name_reassignment(relationship, input, outputs) @@ -84,6 +86,7 @@ def _build_name_reassignment(relationship, input, outputs) end ) end + reassignment end @@ -114,6 +117,7 @@ def _build_distribution_reassignment(distribution, input, outputs) end end end + reassignment end @@ -124,10 +128,12 @@ def _build_legislation_reassignments(input, outputs) ].map do |legislation_collection_name| _build_legislation_type_reassignment(legislation_collection_name, input) end.compact + input.legislation_reassignments.each do |reassignment| if input.is_a?(NomenclatureChange::Input) _build_multiple_targets(reassignment, outputs) end + input.reassignments << reassignment end end @@ -164,6 +170,7 @@ def _build_document_reassignment(document_citation, input, outputs) tc_distributions = input.taxon_concept.distributions input_tc_ge_ids = tc_distributions.map(&:geo_entity_id) distribution_reassignments = input.distribution_reassignments + outputs.each do |output| reassigned_distributions = distribution_reassignments.select do |dr| dr.reassignment_targets. @@ -186,6 +193,7 @@ def _build_document_reassignment(document_citation, input, outputs) end end end + reassignment end @@ -206,6 +214,7 @@ def _build_common_names_reassignments(input, outputs) if input.is_a?(NomenclatureChange::Input) _build_multiple_targets(reassignment, outputs) end + input.reassignments << reassignment end end @@ -216,6 +225,7 @@ def _build_references_reassignments(input, outputs) if input.is_a?(NomenclatureChange::Input) _build_multiple_targets(reassignment, outputs) end + input.reassignments << reassignment end end @@ -242,6 +252,7 @@ def in_year(event, lng) def multi_lingual_legislation_note(note_type) result = {} + [ :en, :es, :fr ].each do |lng| result[lng] = legislation_note(lng) do |input_html, output_html| @@ -254,6 +265,7 @@ def multi_lingual_legislation_note(note_type) end end end + result end diff --git a/app/models/nomenclature_change/lump.rb b/app/models/nomenclature_change/lump.rb index 28b70989b..d020008fe 100644 --- a/app/models/nomenclature_change/lump.rb +++ b/app/models/nomenclature_change/lump.rb @@ -56,6 +56,7 @@ def build_auto_reassignments builder.build_common_names_reassignments builder.build_references_reassignments end + true end diff --git a/app/models/nomenclature_change/split.rb b/app/models/nomenclature_change/split.rb index 806d1011c..7e628b16f 100644 --- a/app/models/nomenclature_change/split.rb +++ b/app/models/nomenclature_change/split.rb @@ -59,6 +59,7 @@ def build_auto_reassignments builder.build_common_names_reassignments builder.build_references_reassignments end + true end diff --git a/app/models/nomenclature_change/status_change_helpers.rb b/app/models/nomenclature_change/status_change_helpers.rb index c35573b05..cebad4d4d 100644 --- a/app/models/nomenclature_change/status_change_helpers.rb +++ b/app/models/nomenclature_change/status_change_helpers.rb @@ -29,6 +29,7 @@ def required_primary_output errors.add(:primary_output, 'Must have a primary output') return false end + true end end diff --git a/app/models/nomenclature_change/status_swap.rb b/app/models/nomenclature_change/status_swap.rb index ef75c176c..059088fa7 100644 --- a/app/models/nomenclature_change/status_swap.rb +++ b/app/models/nomenclature_change/status_swap.rb @@ -52,6 +52,7 @@ def required_secondary_output errors.add(:secondary_output, 'Must have a secondary output') return false end + true end @@ -60,6 +61,7 @@ def required_primary_output_name_status errors.add(:primary_output, 'Must be A taxon') return false end + true end @@ -68,6 +70,7 @@ def required_secondary_output_name_status errors.add(:secondary_output, 'Must be S taxon') return false end + true end @@ -104,6 +107,7 @@ def build_auto_reassignments builder.build_references_reassignments builder.build_documents_reassignments end + true end diff --git a/app/models/nomenclature_change/status_to_synonym.rb b/app/models/nomenclature_change/status_to_synonym.rb index c5a3f2f16..be3262e7a 100644 --- a/app/models/nomenclature_change/status_to_synonym.rb +++ b/app/models/nomenclature_change/status_to_synonym.rb @@ -56,6 +56,7 @@ def required_primary_output_name_status errors.add(:primary_output, 'Must be N or T taxon') return false end + true end @@ -68,6 +69,7 @@ def required_secondary_output errors.add(:secondary_output, 'Must have a secondary output') return false end + true end @@ -105,6 +107,7 @@ def build_auto_reassignments builder.build_common_names_reassignments builder.build_references_reassignments end + true end end diff --git a/app/models/taxon_concept.rb b/app/models/taxon_concept.rb index 47a5714bc..87d65d42a 100644 --- a/app/models/taxon_concept.rb +++ b/app/models/taxon_concept.rb @@ -212,6 +212,7 @@ class TaxonConcept < ApplicationRecord } before_validation :ensure_taxonomic_position + before_validation do before_validate_scientific_name before_validate_full_name @@ -223,6 +224,7 @@ class TaxonConcept < ApplicationRecord Species::TaxonConceptPrefixMatcher.increment_cache_iterator Checklist::Checklist.increment_cache_iterator end + after_update do ensure_species_touched if saved_change_to_rank_id? || @@ -235,6 +237,7 @@ class TaxonConcept < ApplicationRecord Checklist::Checklist.increment_cache_iterator end end + after_save do if [ 'A', 'N' ].include? name_status tcd = TaxonConceptData.new(self) @@ -242,22 +245,27 @@ class TaxonConcept < ApplicationRecord update_column(:data, data) self.data = data end + if name_status == 'S' rebuild_relationships(accepted_names_ids) end + if name_status == 'T' rebuild_relationships(accepted_names_for_trade_name_ids) end + if name_status == 'H' rebuild_relationships(hybrid_parents_ids) end end + after_destroy do ensure_species_touched Species::Search.increment_cache_iterator Species::TaxonConceptPrefixMatcher.increment_cache_iterator Checklist::Checklist.increment_cache_iterator end + after_commit :cache_cleanup after_touch :ensure_species_touched @@ -467,6 +475,7 @@ def before_validate_scientific_name else @scientific_name || scientific_name end + tn = TaxonName.where([ 'UPPER(scientific_name) = UPPER(?)', sanitized_scientific_name ]).first if tn self.taxon_name = tn @@ -606,6 +615,7 @@ def maximum_2_hybrid_parents errors.add(:hybrid_parents_ids, 'maximum 2 hybrid parents') return false end + true end @@ -626,6 +636,7 @@ def ensure_taxonomic_position prev_taxonomic_position_parts << ((prev_taxonomic_position_parts.pop || 0).to_i + 1) self.taxonomic_position = prev_taxonomic_position_parts.join('.') end + true end diff --git a/app/models/taxon_relationship.rb b/app/models/taxon_relationship.rb index 924d664bf..069364dcf 100644 --- a/app/models/taxon_relationship.rb +++ b/app/models/taxon_relationship.rb @@ -78,7 +78,6 @@ class TaxonRelationship < ApplicationRecord ) } - def update_higher_taxa_for_hybrid_child if other_taxon_concept && taxon_relationship_type && taxon_relationship_type.name == TaxonRelationshipType::HAS_HYBRID diff --git a/app/models/trade/annual_report_upload.rb b/app/models/trade/annual_report_upload.rb index e5aafc408..c9ec017f8 100644 --- a/app/models/trade/annual_report_upload.rb +++ b/app/models/trade/annual_report_upload.rb @@ -66,6 +66,7 @@ class Trade::AnnualReportUpload < ApplicationRecord } after_create :copy_to_sandbox + before_destroy do success = sandbox && sandbox.destroy throw(:abort) unless success @@ -98,6 +99,7 @@ def validation_errors if @validation_errors.count == 0 run_secondary_validations end + @validation_errors end @@ -123,6 +125,7 @@ def submit(submitter) self.errors[:base] << 'Submit failed, primary validation errors present.' return false end + return false unless sandbox.copy_from_sandbox_to_shipments(submitter) records_submitted = sandbox.moved_rows_cnt @@ -160,10 +163,12 @@ def is_submitted? # Expects a relation object def run_validations(validation_rules) validation_errors = [] + validation_rules.order(:run_order).each do |vr| vr.refresh_errors_if_needed(self) validation_errors << vr.validation_errors_for_aru(self) end + validation_errors.flatten end diff --git a/app/models/trade/distinct_values_validation_rule.rb b/app/models/trade/distinct_values_validation_rule.rb index f77d421a8..79f8e9989 100644 --- a/app/models/trade/distinct_values_validation_rule.rb +++ b/app/models/trade/distinct_values_validation_rule.rb @@ -23,11 +23,13 @@ def validation_errors_for_shipment(shipment) # if it is, check if validated columns are not equal distinct_values = true + shipments_columns.each do |c1| shipments_columns.each do |c2| distinct_values = false if c1 != c2 && shipment.send(c1) == shipment.send(c2) end end + return nil if distinct_values error_message diff --git a/app/models/trade/inclusion_validation_rule.rb b/app/models/trade/inclusion_validation_rule.rb index a204e97ea..821b0502c 100644 --- a/app/models/trade/inclusion_validation_rule.rb +++ b/app/models/trade/inclusion_validation_rule.rb @@ -168,6 +168,7 @@ def jsonb_matching_criteria_for_comparison(values_hash = nil) '"' || COALESCE("#{column_reference}"::TEXT, '') || '"' EOT end + <<-EOT '"' || '#{c}' || '": ' || #{value_or_column_reference_quoted} EOT @@ -222,9 +223,11 @@ def scoped_records_arel(s) required_column_names.map do |c| s[c].not_eq(nil) end + not_null_conds = not_null_nodes.shift not_null_nodes.each { |n| not_null_conds = not_null_conds.and(n) } result = s.project(Arel.star).where(not_null_conds) + scope_nodes = sanitized_sandbox_scope.map do |scope_column, scope_def| tmp = [] diff --git a/app/models/trade/numericality_validation_rule.rb b/app/models/trade/numericality_validation_rule.rb index 6f4f309d3..40b609d6f 100644 --- a/app/models/trade/numericality_validation_rule.rb +++ b/app/models/trade/numericality_validation_rule.rb @@ -33,6 +33,7 @@ def matching_records(annual_report_upload) arel_columns.map do |a| Arel::Nodes::NamedFunction.new 'isnumeric', [ a ] end + arel_nodes = isnumeric_columns.map { |c| c.eq(false) } sandbox_klass.select('*').where(arel_nodes.inject(&:or)) end diff --git a/app/models/trade/presence_validation_rule.rb b/app/models/trade/presence_validation_rule.rb index 04da0b6a3..8fde07a39 100644 --- a/app/models/trade/presence_validation_rule.rb +++ b/app/models/trade/presence_validation_rule.rb @@ -31,6 +31,7 @@ def matching_records(annual_report_upload) column_names.map do |c| s[c].eq(nil) end + sandbox_klass.select(Arel.star).where(arel_nodes.inject(&:and)) end end diff --git a/app/models/trade/shipment.rb b/app/models/trade/shipment.rb index 325b54d4a..76126572f 100644 --- a/app/models/trade/shipment.rb +++ b/app/models/trade/shipment.rb @@ -119,13 +119,16 @@ class Trade::Shipment < ApplicationRecord ].each do |permits_ids| @old_permits_ids += permits_ids ? permits_ids.dup : [] end + unless reported_taxon_concept_id self.reported_taxon_concept_id = taxon_concept_id end end + before_destroy do @old_permits_ids = permits_ids.dup end + after_commit :async_tasks_after_save, on: [ :create, :update ] after_commit :async_tasks_for_destroy, on: :destroy diff --git a/app/models/trade/taxon_concept_appendix_year_validation_rule.rb b/app/models/trade/taxon_concept_appendix_year_validation_rule.rb index fb639ac49..405af5ee0 100644 --- a/app/models/trade/taxon_concept_appendix_year_validation_rule.rb +++ b/app/models/trade/taxon_concept_appendix_year_validation_rule.rb @@ -62,6 +62,7 @@ def matching_records_arel(table_name) column_names.map do |c| s[c].not_eq(nil) end + not_null_conds = not_null_nodes.shift not_null_nodes.each { |n| not_null_conds = not_null_conds.and(n) } s.project(Arel.star).where(not_null_conds).except(valid_values) diff --git a/app/models/trade/validation_rule.rb b/app/models/trade/validation_rule.rb index c77c9f3b7..a73d6a028 100644 --- a/app/models/trade/validation_rule.rb +++ b/app/models/trade/validation_rule.rb @@ -89,6 +89,7 @@ def validation_errors_for_shipment(shipment) # This method is public, because it is exposed in the serializer def sanitized_sandbox_scope res = {} + scope && scope.each do |scope_column, scope_def| if ( Trade::SandboxTemplate.column_names + @@ -98,6 +99,7 @@ def sanitized_sandbox_scope res[scope_column] = scope_def end end + res end @@ -135,6 +137,7 @@ def refresh_needed?(annual_report_upload) # scope needs to be :source_code => { :inclusion => [ID of W] } def sanitized_shipments_scope res = {} + sanitized_sandbox_scope.each do |scope_column, scope_def| case scope_column when 'taxon_name', 'rank' @@ -143,26 +146,33 @@ def sanitized_shipments_scope res[scope_column] = scope_def when 'exporter', 'importer', 'country_of_origin' tmp_def = {} + (scope_def.keys & [ 'inclusion', 'exclusion' ]).each do |k| tmp_def[k] = scope_def[k].map { |value| GeoEntity.find_by(iso_code2: value).id } end + tmp_def['blank'] = scope_def['blank'] if scope_def.key?('blank') res[scope_column + '_id'] = tmp_def when /(.+)_code$/ tmp_def = {} + (scope_def.keys & [ 'inclusion', 'exclusion' ]).each do |k| tmp_def[k] = scope_def[k].map { |value| TradeCode.find_by(type: $1.capitalize, code: value).id } end + tmp_def['blank'] = scope_def['blank'] if scope_def.key?('blank') res[$1 + '_id'] = tmp_def else tmp_def = {} + (scope_def.keys & [ 'inclusion', 'exclusion', 'blank' ]).each do |k| tmp_def[k] = scope_def[k] end + res[scope_column + '_id'] = tmp_def end end + res end @@ -174,17 +184,21 @@ def shipment_in_scope?(shipment) if scope_def['inclusion'] shipment_in_scope = false unless scope_def['inclusion'].include?(value) end + if scope_def['exclusion'] shipment_in_scope = false if scope_def['exclusion'].include?(value) end + if scope_def['blank'] shipment_in_scope = false if shipment.send(scope_column).present? end end + # make sure the validated fields are not blank required_shipments_columns.each do |column| shipment_in_scope = false if shipment.send(column).blank? end + shipment_in_scope end diff --git a/app/models/trade_restriction.rb b/app/models/trade_restriction.rb index bcec927de..4cd4fcc8c 100644 --- a/app/models/trade_restriction.rb +++ b/app/models/trade_restriction.rb @@ -153,6 +153,7 @@ def self.export(filters) if !File.file?(path + file_name) self.to_csv(path + file_name, filters) end + [ path + file_name, { filename: public_file_name, type: 'text/csv' } @@ -198,6 +199,7 @@ def self.to_csv(file_path, filters) when :semicolon then ';' else ',' end + CSV.open(file_path, 'wb', col_sep: csv_separator_char) do |csv| csv << ( Species::RestrictionsExport::TAXONOMY_COLUMN_NAMES + diff --git a/app/models/user.rb b/app/models/user.rb index 7ee96bb0d..e4f9a037c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -117,6 +117,7 @@ def can_be_deleted? return false end end + true end @@ -159,6 +160,7 @@ def sync_with_captive_breeding_db else :none end + return if action == :none email_was = previous_changes['email']&.first diff --git a/app/serializers/species/cites_listing_change_serializer.rb b/app/serializers/species/cites_listing_change_serializer.rb index 21dd00508..6cbf49ab5 100644 --- a/app/serializers/species/cites_listing_change_serializer.rb +++ b/app/serializers/species/cites_listing_change_serializer.rb @@ -35,7 +35,6 @@ def is_addition object.change_type_name == ChangeType::ADDITION end - def excluded_geo_entities if object.party_full_name.blank? object.excluded_geo_entities_ids diff --git a/app/services/checklist/checklist.rb b/app/services/checklist/checklist.rb index 149962aaa..6d00aada4 100644 --- a/app/services/checklist/checklist.rb +++ b/app/services/checklist/checklist.rb @@ -90,6 +90,7 @@ def generate injector = Checklist::HigherTaxaInjector.new(@plantae) @plantae = injector.run end + [ self ] # TODO: just for compatibility with frontend, no sensible reason for this end diff --git a/app/services/checklist/csv/history.rb b/app/services/checklist/csv/history.rb index cddd5e3d4..8f71913a8 100644 --- a/app/services/checklist/csv/history.rb +++ b/app/services/checklist/csv/history.rb @@ -23,7 +23,8 @@ def prepare_main_query WHEN change_type_name = 'RESERVATION' THEN 1 WHEN change_type_name = 'RESERVATION_WITHDRAWAL' THEN 2 WHEN change_type_name = 'DELETION' THEN 3 - END + end + SQL ) ) diff --git a/app/services/checklist/csv/history_content.rb b/app/services/checklist/csv/history_content.rb index 838a8d56b..23ab22e5a 100644 --- a/app/services/checklist/csv/history_content.rb +++ b/app/services/checklist/csv/history_content.rb @@ -10,6 +10,7 @@ def content(csv) def kingdom(csv, fetcher) begin kingdom = fetcher.next + kingdom.each do |tc| csv << (taxon_concepts_csv_columns.map { |c| tc.send(c) } + listing_changes_csv_columns.map { |c| tc[c] }) diff --git a/app/services/checklist/higher_taxa_injector.rb b/app/services/checklist/higher_taxa_injector.rb index 88d74e6a7..3760df815 100644 --- a/app/services/checklist/higher_taxa_injector.rb +++ b/app/services/checklist/higher_taxa_injector.rb @@ -24,14 +24,17 @@ def initialize(taxon_concepts, options = {}) def run res = [] + @taxon_concepts.each_with_index do |tc, i| prev_item = (i > 0 ? @taxon_concepts[i - 1] : nil) res += higher_taxa_headers(prev_item, tc).map do |ht| Checklist::HigherTaxaItem.new(ht) end + res << tc end + res end @@ -41,6 +44,7 @@ def run_summary res = [] current_higher_taxon = nil current_higher_taxon_children_ids = [] + @taxon_concepts.each_with_index do |tc, i| prev_item = (i > 0 ? @taxon_concepts[i - 1] : nil) higher_taxon = higher_taxa_headers(prev_item, tc).first @@ -54,8 +58,10 @@ def run_summary current_higher_taxon = higher_taxon current_higher_taxon_children_ids = [] end + current_higher_taxon_children_ids << tc.id end + # push the last one res.push( { @@ -84,6 +90,7 @@ def higher_taxa_headers(prev_item, curr_item) tmp << rank end end + tmp.reverse end @@ -91,6 +98,7 @@ def higher_taxa_headers(prev_item, curr_item) res = [] @last_ancestor_ids = @header_ranks.map { |rank| curr_item.send("#{rank.downcase}_id") } + ranks.each_with_index do |rank, idx| higher_taxon_id = curr_item.send("#{rank.downcase}_id") @@ -101,6 +109,7 @@ def higher_taxa_headers(prev_item, curr_item) end end end + res end end diff --git a/app/services/checklist/higher_taxa_item.rb b/app/services/checklist/higher_taxa_item.rb index 96d5fd13f..33a32c42f 100644 --- a/app/services/checklist/higher_taxa_item.rb +++ b/app/services/checklist/higher_taxa_item.rb @@ -12,7 +12,9 @@ def ancestors_ranks else [ 'PHYLUM', 'CLASS', 'ORDER', 'FAMILY', 'SUBFAMILY' ] end + current_idx = taxa.index(rank_name) || 0 + 0.upto(current_idx).map do |i| taxa[i] end diff --git a/app/services/checklist/history.rb b/app/services/checklist/history.rb index c9c22946f..2df44497f 100644 --- a/app/services/checklist/history.rb +++ b/app/services/checklist/history.rb @@ -48,10 +48,12 @@ def prepare_main_query def generate if !File.exist?(@download_path) prepare_queries + document do |doc| content(doc) end end + ctime = File.ctime(@download_path).strftime('%Y-%m-%d %H:%M') doc_name = I18n.t('history_title').split.join('_') @download_name = "#{doc_name}_#{has_full_options? ? '' : '[CUSTOM]_'}#{ctime}.#{ext}" diff --git a/app/services/checklist/index.rb b/app/services/checklist/index.rb index fdfede828..49e0bd5c1 100644 --- a/app/services/checklist/index.rb +++ b/app/services/checklist/index.rb @@ -29,10 +29,12 @@ def prepare_kingdom_queries def generate if !File.exist?(@download_path) prepare_queries + document do |doc| content(doc) end end + ctime = File.ctime(@download_path).strftime('%Y-%m-%d %H:%M') doc_name = I18n.t('index_title').split.join('_') @download_name = "#{doc_name}_#{has_full_options? ? '' : '[CUSTOM]_'}#{ctime}.#{ext}" diff --git a/app/services/checklist/pdf/document.rb b/app/services/checklist/pdf/document.rb index f005a5443..3cb30c5ae 100644 --- a/app/services/checklist/pdf/document.rb +++ b/app/services/checklist/pdf/document.rb @@ -35,6 +35,7 @@ def document [ tmp_dir_path, '/_dict.tex' ].join # set flags for latex flags_tex = [ tmp_dir_path, '/_flags.tex' ].join + File.open(flags_tex, 'wb') do |tex| tex << (@intro ? "\\introtrue\n" : "\\introfalse\n") end @@ -45,6 +46,7 @@ def document File.open(@tmp_tex, 'wb') do |tex| yield tex end + output = LatexToPdf.generate_pdf_from_file(tmp_dir_path, @input_name) # save output at download path FileUtils.cp output, @download_path diff --git a/app/services/checklist/pdf/helpers.rb b/app/services/checklist/pdf/helpers.rb index ecf3082f2..f1e2f97ab 100644 --- a/app/services/checklist/pdf/helpers.rb +++ b/app/services/checklist/pdf/helpers.rb @@ -4,12 +4,15 @@ def common_names_with_lng_initials(taxon_concept) unless !@english_common_names || taxon_concept.english_names.empty? res += " (E) #{LatexToPdf.escape_latex(taxon_concept.english_names.join(', '))} " end + unless !@spanish_common_names || taxon_concept.spanish_names.empty? res += " (S) #{LatexToPdf.escape_latex(taxon_concept.spanish_names.join(', '))} " end + unless !@french_common_names || taxon_concept.french_names.empty? res += " (F) #{LatexToPdf.escape_latex(taxon_concept.french_names.join(', '))} " end + res end @@ -24,6 +27,7 @@ def taxon_name_at_rank(taxon_concept) LatexToPdf.escape_latex(taxon_concept.full_name) end end + res += " #{LatexToPdf.escape_latex(taxon_concept.spp)}" if taxon_concept.spp res end diff --git a/app/services/checklist/pdf/history_annotations_key.rb b/app/services/checklist/pdf/history_annotations_key.rb index eea7fc0f8..0668be9a6 100644 --- a/app/services/checklist/pdf/history_annotations_key.rb +++ b/app/services/checklist/pdf/history_annotations_key.rb @@ -13,6 +13,7 @@ def annotations_key def hash_annotations_key tex = '\\hashAnnotationsHistoryInfo' + "\n\n" cops = CitesCop.order(:effective_at) + cops.each do |cop| annotations = cop.hash_annotations.order(Arel.sql('SUBSTRING(symbol FROM 2)::INT')) if annotations.empty? @@ -21,11 +22,14 @@ def hash_annotations_key tex << "\\hashannotationstable{\n\\rowcolor{pale_aqua}\n" tex << "#{LatexToPdf.escape_latex(cop.name)} & \\validFrom \\hspace{2 pt} #{cop.effective_at_formatted}\\\\\n" + annotations.each do |a| tex << "#{LatexToPdf.escape_latex(a.symbol)} & #{LatexToPdf.html2latex(a.full_note)} \\\\\n\n" end + tex << "}\n" end + tex end end diff --git a/app/services/checklist/pdf/history_content.rb b/app/services/checklist/pdf/history_content.rb index b10d94e32..6b819af9f 100644 --- a/app/services/checklist/pdf/history_content.rb +++ b/app/services/checklist/pdf/history_content.rb @@ -29,21 +29,25 @@ def kingdom(tex, fetcher, kingdom_name) @skip_ancestor_ids = injector.last_ancestor_ids listed_taxa_ary = [] + kingdom.each do |tc| if tc.kind_of? Checklist::HigherTaxaItem unless listed_taxa_ary.empty? listed_taxa(tex, listed_taxa_ary, kingdom_name) listed_taxa_ary = [] end + tex << higher_taxon_name(tc) else listed_taxa_ary << tc end end + unless listed_taxa_ary.empty? listed_taxa(tex, listed_taxa_ary, kingdom_name) listed_taxa_ary = [] end + kingdom = fetcher.next end while !kingdom.empty? end @@ -51,9 +55,11 @@ def kingdom(tex, fetcher, kingdom_name) def listed_taxa(tex, listed_taxa_ary, kingdom_name = 'FAUNA') tex << "\\listingtable#{kingdom_name.downcase}{" rows = [] + listed_taxa_ary.each do |tc| listed_taxon_name = listed_taxon_name(tc) is_tc_row = true # it is the first row per taxon concept + tc.historic_cites_listing_changes_for_downloads.each do |lc| is_lc_row = true # it is the first row per listing change ann = annotation_for_language(lc, I18n.locale) @@ -68,12 +74,14 @@ def listed_taxa(tex, listed_taxa_ary, kingdom_name = 'FAUNA') if kingdom_name == 'FLORA' row << (is_lc_row ? "#{LatexToPdf.escape_latex(lc.full_hash_ann_symbol)}" : '') end + is_lc_row = false # ann fields row << ann rows << row.join(' & ') end end + tex << rows.join("\\\\\n") tex << '}' end @@ -85,6 +93,7 @@ def listing_with_change_type(listing_change) else listing_change.species_listing_name end + change_type = if listing_change.change_type_name == ChangeType::RESERVATION '/r' @@ -95,6 +104,7 @@ def listing_with_change_type(listing_change) else nil end + "#{appendix}#{change_type}" end @@ -122,9 +132,11 @@ def listed_taxon_name(taxon_concept) else taxon_concept.full_name end + if [ 'SPECIES', 'SUBSPECIES', 'GENUS' ].include? taxon_concept.rank_name res = "\\emph{#{res}}" end + res += " #{taxon_concept.spp}" if taxon_concept.spp res end diff --git a/app/services/checklist/pdf/index_annotations_key.rb b/app/services/checklist/pdf/index_annotations_key.rb index 14d030b54..7f67ff5ca 100644 --- a/app/services/checklist/pdf/index_annotations_key.rb +++ b/app/services/checklist/pdf/index_annotations_key.rb @@ -13,11 +13,13 @@ def annotations_key def non_hash_annotations_key tex = "\\section*{\\nonHashAnnotations}\n" + non_hash_annotations.each do |a| box_colour = (a[:taxon_concept].kingdom_name == 'Animalia' ? 'orange' : 'green') tex << "\\cfbox{#{box_colour}}{\\superscript{#{a[:symbol]}} \\textbf{#{taxon_name_at_rank(a[:taxon_concept])}}}\n\n" tex << "#{LatexToPdf.html2latex(a[:note])}\n\n" end + tex end @@ -34,9 +36,11 @@ def hash_annotations_key tex << "\\hashannotationstable{\n\\rowcolor{pale_aqua}\n" tex << "#{LatexToPdf.escape_latex(cop.name)} & \\validFrom \\hspace{2 pt} #{cop.effective_at_formatted}\\\\\n" + annotations.each do |a| tex << "#{LatexToPdf.escape_latex(a.symbol)} & #{LatexToPdf.html2latex(a.full_note)} \\\\\n\n" end + tex << "}\n" tex end @@ -53,6 +57,7 @@ def non_hash_annotations ). where('taxon_concept_id = original_taxon_concept_id'). where.not(cites_listing_changes_mview: { ann_symbol: nil }). + order(Arel.sql('cites_listing_changes_mview.ann_symbol::INT')).map do |lc| { taxon_concept: lc.taxon_concept, diff --git a/app/services/checklist/pdf/index_content.rb b/app/services/checklist/pdf/index_content.rb index 0660032d3..0ff8c3f22 100644 --- a/app/services/checklist/pdf/index_content.rb +++ b/app/services/checklist/pdf/index_content.rb @@ -28,6 +28,7 @@ def kingdom(tex, fetcher, kingdom_name) main_entry(tc) end end + tex << entries.join("\n\n") kingdom = fetcher.next end while !kingdom.empty? @@ -52,6 +53,7 @@ def main_entry(tc) res += " #{"#{tc.family_name}".upcase}" if tc.rank_name != 'FAMILY' res += " (#{tc.class_name})" if tc.class_name.present? end + res += common_names_with_lng_initials(tc) res end @@ -68,9 +70,11 @@ def current_listing_with_annotations(taxon_concept) symbol = LatexToPdf.escape_latex(taxon_concept.hash_ann_symbol) res = " #{symbol}#{res}" end + if taxon_concept.ann_symbol.present? res += "\\superscript{#{taxon_concept.ann_symbol}}" end + res end end diff --git a/app/services/checklist/pdf/index_query.rb b/app/services/checklist/pdf/index_query.rb index d4908f3ac..844f6e22c 100644 --- a/app/services/checklist/pdf/index_query.rb +++ b/app/services/checklist/pdf/index_query.rb @@ -39,7 +39,8 @@ def initialize(rel, options) WHEN author_year IS NOT NULL THEN ' ' || author_year ELSE '' - END + end + FROM ( (SELECT synonym, ROW_NUMBER() OVER() AS id FROM (SELECT * FROM UNNEST(synonyms_ary) AS synonym) q) synonyms LEFT JOIN diff --git a/app/services/checklist/timeline.rb b/app/services/checklist/timeline.rb index 3853751ea..ab0264c40 100644 --- a/app/services/checklist/timeline.rb +++ b/app/services/checklist/timeline.rb @@ -50,6 +50,7 @@ def add_reservation_event(event) def change_consecutive_additions_to_amendments (@timelines + [ self ]).flatten.each do |timeline| prev_event = nil + timeline.timeline_events.each_with_index do |event, idx| if prev_event && ( prev_event.is_addition? || @@ -60,6 +61,7 @@ def change_consecutive_additions_to_amendments event.change_type_name = 'AMENDMENT' end + prev_event = event end end @@ -99,6 +101,7 @@ def add_intervals ) end end + timeline.timeline_intervals << interval if interval end end diff --git a/app/services/checklist/timelines_for_taxon_concept.rb b/app/services/checklist/timelines_for_taxon_concept.rb index cfb50b343..430203b63 100644 --- a/app/services/checklist/timelines_for_taxon_concept.rb +++ b/app/services/checklist/timelines_for_taxon_concept.rb @@ -41,6 +41,7 @@ def initialize(taxon_concept) def generate_timelines @raw_timelines = {} + [ 'I', 'II', 'III' ].each do |species_listing_name| @raw_timelines[species_listing_name] = Checklist::Timeline.new( taxon_concept_id: @taxon_concept_id, @@ -50,6 +51,7 @@ def generate_timelines current: @current_appendices.include?(species_listing_name) ) end + @timeline_events.each do |timeline_event| species_listing_name = timeline_event.species_listing_name || ( @@ -60,11 +62,13 @@ def generate_timelines @raw_timelines[species_listing_name] && @raw_timelines[species_listing_name].add_event(timeline_event) end + @raw_timelines.values.each do |t| t.change_consecutive_additions_to_amendments t.add_intervals @has_reservations = true if t.has_nested_timelines end + @timelines = [ @raw_timelines['I'], @raw_timelines['II'], @raw_timelines['III'] ] end diff --git a/app/services/cms_mapping_manager.rb b/app/services/cms_mapping_manager.rb index 045368fdd..404a9e7f5 100644 --- a/app/services/cms_mapping_manager.rb +++ b/app/services/cms_mapping_manager.rb @@ -19,6 +19,7 @@ class CmsMappingManager # analyse mapping # end + # end # def analyse(mapping) @@ -46,9 +47,11 @@ class CmsMappingManager # else # nil # end + # } # mapping.save # end + # end # # Finds CITES' taxon concepts that match the CMS Species or Subspecies and @@ -76,12 +79,16 @@ class CmsMappingManager # DistributionReference.find_or_create_by( # distribution_id: distribution.id, reference_id: reference.reference_id) # end + # end + # puts "creating taxon relationship" # TaxonRelationship.create(:taxon_concept_id => matching_cites_taxon.id, # :other_taxon_concept_id => taxon.id, # :taxon_relationship_type_id => equal_to.id) # end + # end + # end end diff --git a/app/services/dashboard_stats.rb b/app/services/dashboard_stats.rb index 5a2b202fe..2b3f33edc 100644 --- a/app/services/dashboard_stats.rb +++ b/app/services/dashboard_stats.rb @@ -36,6 +36,7 @@ def species_stats_per_taxonomy(taxonomy_name) kingdom_name: @kingdom ) designation_name = (taxonomy_name == Taxonomy::CMS ? :cms : :cites) + (classes && classes.map do |klass| cnt = MTaxonConcept.where(class_id: klass.id). where("countries_ids_ary && ARRAY[#{@geo_entity.id}]"). diff --git a/app/services/document_search.rb b/app/services/document_search.rb index e45188701..e97218b6f 100644 --- a/app/services/document_search.rb +++ b/app/services/document_search.rb @@ -266,7 +266,8 @@ def locale_document THEN 'default' ELSE 'false' END - END + end + SQL end diff --git a/app/services/geo_entity_search.rb b/app/services/geo_entity_search.rb index be38c1a0c..e4e435c8f 100644 --- a/app/services/geo_entity_search.rb +++ b/app/services/geo_entity_search.rb @@ -27,6 +27,7 @@ def initialize_params(options) else I18n.locale end + @options = { geo_entity_types_set: @geo_entity_types_set, locale: @locale @@ -44,10 +45,12 @@ def initialize_query if GeoEntityType::CURRENT_ONLY_SETS.include?(@geo_entity_types_set) @query = @query.current end + unless geo_entity_types.empty? @query = @query. where('geo_entity_types.name' => geo_entity_types) end + if @query_string.present? @query = @query.where("unaccent(name_#{@locale}) ILIKE unaccent(:q)", q: "%#{@query_string}%") end diff --git a/app/services/iucn_mapping_manager.rb b/app/services/iucn_mapping_manager.rb index 150e9b0fb..208216a6f 100644 --- a/app/services/iucn_mapping_manager.rb +++ b/app/services/iucn_mapping_manager.rb @@ -11,6 +11,7 @@ class IucnMappingManager # :taxonomy_id => taxonomy.id).each do |taxon_concept| # sync_taxon_concept taxon_concept # end + # end # def sync_taxon_concept(taxon_concept) @@ -20,12 +21,14 @@ class IucnMappingManager # else # taxon_concept.full_name # end + # data = fetch_data_for_name full_name # if !data || !data["result"] || data["result"].empty? # puts "#{taxon_concept.full_name} NO MATCH" # else # map_taxon_concept taxon_concept, mapping, data # end + # end # def fetch_data_for_name(full_name) @@ -58,6 +61,7 @@ class IucnMappingManager # puts "########################## EXCEPTION Taxon Concept #{taxon_concept.id} ###########" # puts e.message # end + # end # def type_of_match(tc, match) @@ -69,7 +73,9 @@ class IucnMappingManager # puts "NAME_MATCH" # "NAME_MATCH" # end + # end + # end # def strip_authors(author) @@ -78,5 +84,6 @@ class IucnMappingManager # reject { |p| ["and", "&", "&", ","].include?(p) }. # join(" ") # end + # end end diff --git a/app/services/m_taxon_concept_filter_by_appendix_query.rb b/app/services/m_taxon_concept_filter_by_appendix_query.rb index 7246b1706..566f16fab 100644 --- a/app/services/m_taxon_concept_filter_by_appendix_query.rb +++ b/app/services/m_taxon_concept_filter_by_appendix_query.rb @@ -15,6 +15,7 @@ def initialize_species_listings_conditions(designation_name = 'CITES') ARRAY[#{@appendix_abbreviations.map { |e| "'#{e}'" }.join(',')}]::TEXT[] SQL end + @species_listings_ids = SpeciesListing.where(abbreviation: @appendix_abbreviations).map(&:id) @species_listings_in_clause = @species_listings_ids.compact.join(',') end diff --git a/app/services/nomenclature_change/lump/constructor.rb b/app/services/nomenclature_change/lump/constructor.rb index 8c7edf1d4..a35a3f65b 100644 --- a/app/services/nomenclature_change/lump/constructor.rb +++ b/app/services/nomenclature_change/lump/constructor.rb @@ -15,6 +15,7 @@ def build_output def build_parent_reassignments output = @nomenclature_change.output + @nomenclature_change.inputs.each do |input| children = input.taxon_concept.children - [ output.taxon_concept ] _build_parent_reassignments(input, output, children) @@ -60,6 +61,7 @@ def build_references_reassignments def input_lumped_into(input, output, lng) input_html = taxon_concept_html(input.taxon_concept.full_name, input.taxon_concept.rank.name) output_html = taxon_concept_html(output.display_full_name, output.display_rank_name) + I18n.with_locale(lng) do I18n.t( 'lump.input_lumped_into', @@ -72,9 +74,11 @@ def input_lumped_into(input, output, lng) def output_lumped_from(output, inputs, lng) output_html = taxon_concept_html(output.display_full_name, output.display_rank_name) + inputs_html = @nomenclature_change.inputs.map do |input| taxon_concept_html(input.taxon_concept.full_name, input.taxon_concept.rank.name) end.join(', ') + I18n.with_locale(lng) do I18n.t( 'lump.output_lumped_from', @@ -87,6 +91,7 @@ def output_lumped_from(output, inputs, lng) def multi_lingual_input_note(input, output, event) result = {} + [ :en, :es, :fr ].each do |lng| note = '

' note << input_lumped_into(input, output, lng) @@ -95,11 +100,13 @@ def multi_lingual_input_note(input, output, event) note << '.

' result[lng] = note end + result end def multi_lingual_output_note(output, inputs, event) result = {} + [ :en, :es, :fr ].each do |lng| note = '

' note << output_lumped_from(output, @nomenclature_change.inputs, lng) @@ -108,18 +115,21 @@ def multi_lingual_output_note(output, inputs, event) note << '.

' result[lng] = note end + result end def build_input_and_output_notes output = @nomenclature_change.output event = @nomenclature_change.event + @nomenclature_change.inputs_except_outputs.each do |input| note = multi_lingual_input_note(input, output, event) input.note_en = note[:en] input.note_es = note[:es] input.note_fr = note[:fr] end + note = multi_lingual_output_note(output, @nomenclature_change.inputs, event) output.note_en = note[:en] output.note_es = note[:es] @@ -136,6 +146,7 @@ def legislation_note(lng) if @nomenclature_change.event note << following_taxonomic_changes(@nomenclature_change.event, lng) end + note = "

#{note}.

" if note.present? end diff --git a/app/services/nomenclature_change/lump/processor.rb b/app/services/nomenclature_change/lump/processor.rb index f2521742f..529c0711f 100644 --- a/app/services/nomenclature_change/lump/processor.rb +++ b/app/services/nomenclature_change/lump/processor.rb @@ -22,17 +22,21 @@ def prepare_chain @inputs.select do |input| input.taxon_concept_id != @output.taxon_concept_id || @output.will_create_taxon? end + inputs_that_are_not_output.each do |input| chain << NomenclatureChange::InputTaxonConceptProcessor.new(input) chain << NomenclatureChange::CascadingNotesProcessor.new(input) end + if !@output.will_create_taxon? && @nc.inputs_intersect_outputs.empty? chain << NomenclatureChange::CascadingNotesProcessor.new(@output) end + inputs_that_are_not_output.each do |input| chain << NomenclatureChange::ReassignmentTransferProcessor.new(input, @output) chain << NomenclatureChange::StatusDowngradeProcessor.new(input, [ @output ]) end + chain end diff --git a/app/services/nomenclature_change/output_taxon_concept_processor.rb b/app/services/nomenclature_change/output_taxon_concept_processor.rb index e42fa59b8..823926d85 100644 --- a/app/services/nomenclature_change/output_taxon_concept_processor.rb +++ b/app/services/nomenclature_change/output_taxon_concept_processor.rb @@ -45,6 +45,7 @@ def summary if @output.new_rank && @output.new_rank_id != @output.rank_id res << "#{@output.taxon_concept.full_name} rank changed from #{@output.taxon_concept.rank.name} to #{@output.new_rank.name}" end + if @output.new_parent res << if @output.taxon_concept.parent @@ -53,13 +54,16 @@ def summary "#{@output.taxon_concept.full_name} parent set to #{@output.new_parent.full_name}" end end + if @output.new_name_status.present? res << "#{@output.taxon_concept.full_name} name status changed from #{@output.taxon_concept.name_status} to #{@output.new_name_status}" end + if @output.new_author_year.present? res << "#{@output.taxon_concept.full_name} author year changed from #{@output.taxon_concept.author_year} to #{@output.new_author_year}" end end + res end end diff --git a/app/services/nomenclature_change/reassignment_copy_processor.rb b/app/services/nomenclature_change/reassignment_copy_processor.rb index ad1b660a3..f8fae63de 100644 --- a/app/services/nomenclature_change/reassignment_copy_processor.rb +++ b/app/services/nomenclature_change/reassignment_copy_processor.rb @@ -115,6 +115,7 @@ def build_distribution_associations(reassignable, copied_object) distr_ref.comparison_attributes ) end + # taggings copy_distribution_taggings(reassignable, copied_object) end diff --git a/app/services/nomenclature_change/split/constructor.rb b/app/services/nomenclature_change/split/constructor.rb index 5df57ac8c..e31804250 100644 --- a/app/services/nomenclature_change/split/constructor.rb +++ b/app/services/nomenclature_change/split/constructor.rb @@ -26,6 +26,7 @@ def build_parent_reassignments children = input.taxon_concept.children - @nomenclature_change.outputs.map(&:taxon_concept).compact _build_parent_reassignments(input, default_output, children) + outputs_for_reassignments.each do |output| _build_parent_reassignments(output, output) end @@ -36,6 +37,7 @@ def build_name_reassignments default_output = @nomenclature_change.outputs_intersect_inputs.first default_output ||= @nomenclature_change.outputs.first _build_names_reassignments(input, [ default_output ], @nomenclature_change.outputs) + outputs_for_reassignments.each do |output| _build_names_reassignments(output, [ output ], @nomenclature_change.outputs) end @@ -45,6 +47,7 @@ def build_distribution_reassignments input = @nomenclature_change.input default_outputs = @nomenclature_change.outputs _build_distribution_reassignments(input, default_outputs) + outputs_for_reassignments.each do |output| _build_distribution_reassignments(output, [ output ]) end @@ -53,6 +56,7 @@ def build_distribution_reassignments def build_legislation_reassignments input = @nomenclature_change.input _build_legislation_reassignments(@nomenclature_change.input, @nomenclature_change.outputs) + outputs_for_reassignments.each do |output| _build_legislation_reassignments(output, [ output ]) end @@ -62,6 +66,7 @@ def build_document_reassignments input = @nomenclature_change.input outputs = @nomenclature_change.outputs _build_document_reassignments(input, outputs) + outputs_for_reassignments.each do |output| _build_document_reassignments(output, [ output ]) end @@ -70,6 +75,7 @@ def build_document_reassignments def build_common_names_reassignments input = @nomenclature_change.input _build_common_names_reassignments(@nomenclature_change.input, @nomenclature_change.outputs) + outputs_for_reassignments.each do |output| _build_common_names_reassignments(output, [ output ]) end @@ -78,6 +84,7 @@ def build_common_names_reassignments def build_references_reassignments input = @nomenclature_change.input _build_references_reassignments(@nomenclature_change.input, @nomenclature_change.outputs) + outputs_for_reassignments.each do |output| _build_references_reassignments(output, [ output ]) end @@ -85,6 +92,7 @@ def build_references_reassignments def input_split_into(input, outputs, lng) input_html = taxon_concept_html(input.taxon_concept.full_name, input.taxon_concept.rank.name) + outputs_html = @nomenclature_change.outputs.map do |output| if output.scientific_name.present? && output.new_scientific_name.present? taxon_concept_html( @@ -95,6 +103,7 @@ def input_split_into(input, outputs, lng) taxon_concept_html(output.display_full_name, output.display_rank_name) end end.join(', ') + I18n.with_locale(lng) do I18n.t( 'split.input_split_into', @@ -123,7 +132,9 @@ def output_split_from(output, input, lng) else taxon_concept_html(output.display_full_name, output.display_rank_name) end + input_html = taxon_concept_html(input.taxon_concept.full_name, input.taxon_concept.rank.name) + I18n.with_locale(lng) do I18n.t( 'split.output_split_from', @@ -136,6 +147,7 @@ def output_split_from(output, input, lng) def multi_lingual_input_note(input, outputs, event) result = {} + [ :en, :es, :fr ].each do |lng| note = '

' note << input_split_into(input, @nomenclature_change.outputs, lng) @@ -144,11 +156,13 @@ def multi_lingual_input_note(input, outputs, event) note << '.

' result[lng] = note end + result end def multi_lingual_output_note(output, input, event) result = {} + [ :en, :es, :fr ].each do |lng| note = '

' note << output_split_from(output, input, lng) @@ -157,6 +171,7 @@ def multi_lingual_output_note(output, input, event) note << '.

' result[lng] = note end + result end @@ -167,6 +182,7 @@ def build_input_and_output_notes input.note_en = note[:en] input.note_es = note[:es] input.note_fr = note[:fr] + @nomenclature_change.outputs_except_inputs.each do |output| note = multi_lingual_output_note(output, input, event) output.note_en = note[:en] @@ -185,6 +201,7 @@ def legislation_note(lng) if @nomenclature_change.event note << following_taxonomic_changes(@nomenclature_change.event, lng) end + note = "

#{note}.

" if note.present? end diff --git a/app/services/nomenclature_change/split/processor.rb b/app/services/nomenclature_change/split/processor.rb index 19c8a1172..b055365be 100644 --- a/app/services/nomenclature_change/split/processor.rb +++ b/app/services/nomenclature_change/split/processor.rb @@ -21,10 +21,12 @@ def prepare_chain map(&:taxon_concept_id).include?(@input.taxon_concept_id) chain << NomenclatureChange::InputTaxonConceptProcessor.new(@input) + @outputs.each_with_index do |output, idx| if @input.taxon_concept_id != output.taxon_concept_id chain << NomenclatureChange::OutputTaxonConceptProcessor.new(output) end + if output.will_create_taxon? # for the case when an existing accepted subspecies is turned into a species if output.name_status == 'A' @@ -38,6 +40,7 @@ def prepare_chain elsif !output.will_create_taxon? && output.name_status == 'S' chain << NomenclatureChange::StatusUpgradeProcessor.new(output) end + if @input.taxon_concept_id != output.taxon_concept_id || output.will_create_taxon? # if input is not one of outputs and this is the last output # transfer the associations rather than copy them @@ -48,18 +51,22 @@ def prepare_chain chain << NomenclatureChange::ReassignmentCopyProcessor.new(@input, output) end end + if @input.taxon_concept_id != output.taxon_concept_id chain << NomenclatureChange::CascadingNotesProcessor.new(output) end end + unless input_is_one_of_outputs chain << NomenclatureChange::CascadingNotesProcessor.new(@input) end + unless input_is_one_of_outputs chain << NomenclatureChange::StatusDowngradeProcessor.new(@input, @outputs) else chain << NomenclatureChange::DeleteUnreassignedProcessor.new(@input) end + chain end diff --git a/app/services/nomenclature_change/status_change/constructor_helpers.rb b/app/services/nomenclature_change/status_change/constructor_helpers.rb index 52bf007d6..64c0d892e 100644 --- a/app/services/nomenclature_change/status_change/constructor_helpers.rb +++ b/app/services/nomenclature_change/status_change/constructor_helpers.rb @@ -83,6 +83,7 @@ def status_elevated_to_accepted_name(output_new, output_old, lng) output_old.display_full_name, output_old.display_rank_name ) + I18n.with_locale(lng) do I18n.t( 'status_change.status_elevated_to_accepted_name', @@ -95,9 +96,11 @@ def status_elevated_to_accepted_name(output_new, output_old, lng) def multi_lingual_public_output_note(output_new, output_old, event) result = {} + [ :en, :es, :fr ].each do |lng| result[lng] = public_output_note(output_new, output_old, event, lng) end + result end @@ -139,6 +142,7 @@ def input_output_for_reassignment elsif @nomenclature_change.needs_to_receive_associations? @nomenclature_change.primary_output end + return false unless input && output yield(input, output) diff --git a/app/services/nomenclature_change/status_swap/constructor.rb b/app/services/nomenclature_change/status_swap/constructor.rb index 61cae4b7a..3e748044a 100644 --- a/app/services/nomenclature_change/status_swap/constructor.rb +++ b/app/services/nomenclature_change/status_swap/constructor.rb @@ -31,6 +31,7 @@ def legislation_note(lng) if @event note << following_taxonomic_changes(@event, lng) end + note + '.

' end end diff --git a/app/services/nomenclature_change/status_swap/processor.rb b/app/services/nomenclature_change/status_swap/processor.rb index 8d8519e6f..3644c6aa3 100644 --- a/app/services/nomenclature_change/status_swap/processor.rb +++ b/app/services/nomenclature_change/status_swap/processor.rb @@ -20,6 +20,7 @@ def prepare_chain accepted_names = @secondary_output ? [ @secondary_output ] : [] NomenclatureChange::StatusDowngradeProcessor.new(@primary_output, accepted_names) end + chain.compact end diff --git a/app/services/nomenclature_change/status_to_synonym/constructor.rb b/app/services/nomenclature_change/status_to_synonym/constructor.rb index 08732f353..4c3e0e847 100644 --- a/app/services/nomenclature_change/status_to_synonym/constructor.rb +++ b/app/services/nomenclature_change/status_to_synonym/constructor.rb @@ -14,6 +14,7 @@ def build_secondary_output primary_output_tc = @nomenclature_change.primary_output.try(:taxon_concept) primary_output_tc && primary_output_tc.accepted_names_for_trade_name.first end + @nomenclature_change.build_secondary_output( is_primary_output: false, taxon_concept_id: secondary_output_tc.try(:id) diff --git a/app/services/species/csv_copy_export.rb b/app/services/species/csv_copy_export.rb index 2da863b68..46a469e9d 100644 --- a/app/services/species/csv_copy_export.rb +++ b/app/services/species/csv_copy_export.rb @@ -58,6 +58,7 @@ def initialize_file_name else @filters.to_hash.symbolize_keys!.sort.to_s end + digest = Digest::SHA1.hexdigest(value) # Include locale string to differentiate cached files. locale_string = I18n.locale&.to_s diff --git a/app/services/species/eu_listings_export.rb b/app/services/species/eu_listings_export.rb index 214e0ac0a..0ea58d898 100644 --- a/app/services/species/eu_listings_export.rb +++ b/app/services/species/eu_listings_export.rb @@ -19,6 +19,7 @@ def sql_columns if @include_cites columns << :cites_listing_original end + columns + [ :original_taxon_concept_party_iso_code, :original_taxon_concept_full_name_with_spp, :original_taxon_concept_full_note_en, :original_taxon_concept_hash_full_note_en, @@ -39,6 +40,7 @@ def csv_column_headers if @include_cites headers << 'CITES' end + headers + [ 'Party', 'Listed under', 'Full note', '# Full note', 'All_DistributionFullNames', 'All_DistributionISOCodes', diff --git a/app/services/species/id_manual_documents_export.rb b/app/services/species/id_manual_documents_export.rb index 71a19a743..848d85d13 100644 --- a/app/services/species/id_manual_documents_export.rb +++ b/app/services/species/id_manual_documents_export.rb @@ -23,6 +23,7 @@ def sql_columns then 'Whole animals/plants' else 'Parts and derivatives' end + SQL [ diff --git a/app/services/species/listings_export_factory.rb b/app/services/species/listings_export_factory.rb index 9ff4f6fdc..adc0fbe0c 100644 --- a/app/services/species/listings_export_factory.rb +++ b/app/services/species/listings_export_factory.rb @@ -6,6 +6,7 @@ def self.new(filters = {}) elsif filters[:designation] Designation.find_by(name: filters[:designation].upcase) end + if @designation && @designation.name == 'CMS' Species::CmsListingsExport.new(@designation, filters) elsif @designation && @designation.name == 'EU' diff --git a/app/services/species/restrictions_export.rb b/app/services/species/restrictions_export.rb index 0e2711af8..88f18ec36 100644 --- a/app/services/species/restrictions_export.rb +++ b/app/services/species/restrictions_export.rb @@ -33,12 +33,14 @@ def self.fill_taxon_columns(restriction) else taxon = nil end + return [ '' ] * (TAXONOMY_COLUMNS.size + 1) unless taxon # return array with empty strings columns = TAXONOMY_COLUMNS.map do |c| taxon.send(c) end + columns << remark columns end diff --git a/app/services/species/search.rb b/app/services/species/search.rb index bceb23930..ad8e29f0b 100644 --- a/app/services/species/search.rb +++ b/app/services/species/search.rb @@ -58,6 +58,7 @@ def initialize_query 'taxon_concepts_mview.*, matching_names.matched_names_ary AS synonyms_ary' ) end + @query = @query end diff --git a/app/services/species/taxon_concept_prefix_matcher.rb b/app/services/species/taxon_concept_prefix_matcher.rb index efe3b67fd..be8e7dfd4 100644 --- a/app/services/species/taxon_concept_prefix_matcher.rb +++ b/app/services/species/taxon_concept_prefix_matcher.rb @@ -94,7 +94,8 @@ def initialize_query ARRAY_AGG_NOTNULL( DISTINCT CASE WHEN matched_name != full_name THEN matched_name ELSE NULL - END + end + ORDER BY CASE WHEN matched_name != full_name THEN matched_name ELSE NULL END diff --git a/app/services/taxon_concept_data.rb b/app/services/taxon_concept_data.rb index 92cd34d6e..93ac15109 100644 --- a/app/services/taxon_concept_data.rb +++ b/app/services/taxon_concept_data.rb @@ -49,8 +49,10 @@ def higher_taxa_from_parent when 'T' @taxon_concept.accepted_names_for_trade_name.first end + fake_parent && fake_parent.data end + return nil unless data data.slice(*field_names) @@ -65,6 +67,7 @@ def higher_taxa_field_names # all ranks Rank.in_range(nil, nil) end + higher_taxa_ranks.map do |r| [ "#{r.downcase}_id", "#{r.downcase}_name" ] end.flatten diff --git a/app/services/trade/batch_update.rb b/app/services/trade/batch_update.rb index fe6902df7..693d593f1 100644 --- a/app/services/trade/batch_update.rb +++ b/app/services/trade/batch_update.rb @@ -18,11 +18,13 @@ def execute(update_params) s.permits_ids end.flatten.uniq affected_shipments = nil + Trade::Shipment.transaction do affected_shipments = @shipments.count @shipments.update_all(update_params.to_h) DownloadsCacheCleanupWorker.perform_async('shipments') end + PermitCleanupWorker.perform_async(disconnected_permits_ids) affected_shipments end diff --git a/app/services/trade/permit_matcher.rb b/app/services/trade/permit_matcher.rb index cd90fd592..69fc19b77 100644 --- a/app/services/trade/permit_matcher.rb +++ b/app/services/trade/permit_matcher.rb @@ -47,6 +47,7 @@ def sanitize_permit_query(query) ApplicationRecord.connection.quote_string(qp) end end + query_parts.join end end diff --git a/app/services/trade/sandbox.rb b/app/services/trade/sandbox.rb index 91c359beb..cf55d6d1f 100644 --- a/app/services/trade/sandbox.rb +++ b/app/services/trade/sandbox.rb @@ -16,6 +16,7 @@ def copy def copy_from_sandbox_to_shipments(submitter) success = true + Trade::Shipment.transaction do pg_result = Trade::SandboxTemplate.connection.execute( Trade::SandboxTemplate.send( @@ -35,6 +36,7 @@ def copy_from_sandbox_to_shipments(submitter) raise ActiveRecord::Rollback end end + success end diff --git a/app/services/trade/shipments_export.rb b/app/services/trade/shipments_export.rb index 3b5e394e0..bacd76016 100644 --- a/app/services/trade/shipments_export.rb +++ b/app/services/trade/shipments_export.rb @@ -21,10 +21,12 @@ def export unless csv_cached? to_csv end + unless csv_created? Rails.logger.error('Unable to generate output') return false end + ctime = File.ctime(@file_name).strftime('%Y-%m-%d %H:%M') @public_file_name = "#{resource_name}_#{ctime}_#{@csv_separator}_separated.csv" [ diff --git a/app/services/trade/shipments_export_factory.rb b/app/services/trade/shipments_export_factory.rb index f2d4d6e37..629059f4f 100644 --- a/app/services/trade/shipments_export_factory.rb +++ b/app/services/trade/shipments_export_factory.rb @@ -6,6 +6,7 @@ def self.new(filters) unless report_types.include? @report_type @report_type = :comptab end + case @report_type when :comptab Trade::ShipmentsComptabExport.new(filters) diff --git a/app/services/trade/shipments_gross_exports_export.rb b/app/services/trade/shipments_gross_exports_export.rb index 4d9aa0764..9e2b1ecdd 100644 --- a/app/services/trade/shipments_gross_exports_export.rb +++ b/app/services/trade/shipments_gross_exports_export.rb @@ -11,6 +11,7 @@ def full_csv_column_headers def query_sql(options) headers = csv_column_headers + select_columns = sql_columns.each_with_index.map do |c, i| "#{c} AS \"#{headers[i]}\"" end + years_columns diff --git a/app/uploaders/trade/csv_source_file_uploader.rb b/app/uploaders/trade/csv_source_file_uploader.rb index 19accc128..50390eaa4 100644 --- a/app/uploaders/trade/csv_source_file_uploader.rb +++ b/app/uploaders/trade/csv_source_file_uploader.rb @@ -60,11 +60,13 @@ def convert_to_utf8 unless cleaned.valid_encoding? cleaned = content.encode('UTF-8', 'iso-8859-1') end + content = cleaned rescue EncodingError # Force it to UTF-8, throwing out invalid bits content.encode!('UTF-8', invalid: :replace, undef: :replace) end + File.write(current_path, content) end diff --git a/app/workers/manual_download_worker.rb b/app/workers/manual_download_worker.rb index 26dbe402e..60d393494 100644 --- a/app/workers/manual_download_worker.rb +++ b/app/workers/manual_download_worker.rb @@ -81,6 +81,7 @@ def zip_file_generator else # Download the file from S3, put in temp folder. path_to_file = Rails.root.join(tmp_dir_path, document.file.filename.to_s).to_s + File.open(path_to_file, 'wb') do |out| # stream download in chunks document.file.blob.service.download(document.file.blob.key) do |chunk| @@ -105,11 +106,13 @@ def zip_file_generator zip.add('missing_files.txt', missing_file_name) end end + ensure FileUtils.rm_rf(tmp_dir_path) FileUtils.rm_rf(@cover_path) FileUtils.rm(@download_path) end + rescue => exception Appsignal.add_exception(exception) if defined? Appsignal @download.status = 'failed' diff --git a/app/workers/refresh_documents_worker.rb b/app/workers/refresh_documents_worker.rb index 2eb298596..6758a2a6f 100644 --- a/app/workers/refresh_documents_worker.rb +++ b/app/workers/refresh_documents_worker.rb @@ -9,6 +9,7 @@ def perform else DocumentSearch.refresh_documents end + DocumentSearch.increment_cache_iterator end end diff --git a/lib/capistrano/tasks/rsync.rake b/lib/capistrano/tasks/rsync.rake index a3ed53397..f5c300450 100644 --- a/lib/capistrano/tasks/rsync.rake +++ b/lib/capistrano/tasks/rsync.rake @@ -1,5 +1,6 @@ namespace :rsync do desc 'Rsync of existing directories' + task :sync do on roles(:app) do execute "rsync -av --ignore-existing #{release_path}/public/downloads/ #{shared_path}/public/downloads/" diff --git a/lib/csv_column_headers_validator.rb b/lib/csv_column_headers_validator.rb index 5f24c1c4e..aedbc85f2 100644 --- a/lib/csv_column_headers_validator.rb +++ b/lib/csv_column_headers_validator.rb @@ -31,6 +31,7 @@ def validate_each(record, attribute, value) record.errors.add(attribute, error_msg) end end + rescue => e Rails.logger.error e.inspect record.errors.add(attribute, 'file cannot be processed') diff --git a/lib/modules/downloads_cache.rb b/lib/modules/downloads_cache.rb index ed357a2a1..18b5303c8 100644 --- a/lib/modules/downloads_cache.rb +++ b/lib/modules/downloads_cache.rb @@ -138,6 +138,7 @@ def self.update_checklist_downloads Checklist::Csv, Checklist::Json ] + [ 'en', 'es', 'fr' ].each do |locale| # full download parameters params = { @@ -155,11 +156,13 @@ def self.update_checklist_downloads Benchmark.realtime do Rails.logger.debug m::Index.new(params).generate end + Rails.logger.debug { "#{Time.now} #{m}::Index download #{locale} generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do Rails.logger.debug m::History.new(params).generate end + Rails.logger.debug { "#{Time.now} #{m}::History download #{locale} generated in #{elapsed_time}s" } end end @@ -167,11 +170,13 @@ def self.update_checklist_downloads def self.update_species_downloads Rails.logger.debug 'Updating Species+ downloads' + Designation.dict.each do |d| elapsed_time = Benchmark.realtime do Species::ListingsExportFactory.new(designation: d).export end + Rails.logger.debug { "#{Time.now} #{d} Listings download generated in #{elapsed_time}s" } end @@ -179,56 +184,66 @@ def self.update_species_downloads Benchmark.realtime do CitesSuspension.export('set' => 'current') end + Rails.logger.debug { "#{Time.now} current CITES Suspensions download generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do CitesSuspension.export('set' => 'all') end + Rails.logger.debug { "#{Time.now} all CITES Suspensions download generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do Quota.export('set' => 'current') end + Rails.logger.debug { "#{Time.now} current CITES Quotas download generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do Quota.export('set' => 'all') end + Rails.logger.debug { "#{Time.now} all CITES Quotas download generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do Species::EuDecisionsExport.new(set: 'current', decision_types: {}).export end + Rails.logger.debug { "#{Time.now} current EU Decisions download generated in #{elapsed_time}s" } elapsed_time = Benchmark.realtime do Species::EuDecisionsExport.new(set: 'all', decision_types: {}).export end + Rails.logger.debug { "#{Time.now} all EU Decisions download generated in #{elapsed_time}s" } end def self.update_admin_downloads Rails.logger.debug 'Updating admin downloads' + [ Taxonomy::CITES_EU, Taxonomy::CMS ].each do |taxonomy_name| Rails.logger.debug { "#{taxonomy_name} Names" } elapsed_time = Benchmark.realtime do Species::TaxonConceptsNamesExport.new(taxonomy: taxonomy_name).export end + Rails.logger.debug { "#{Time.now} Taxon Concepts Names #{taxonomy_name} download generated in #{elapsed_time}s" } Rails.logger.debug { "#{taxonomy_name} Synonyms and Trade Names" } elapsed_time = Benchmark.realtime do Species::SynonymsAndTradeNamesExport.new(taxonomy: taxonomy_name).export end + Rails.logger.debug { "#{Time.now} Synonyms & Trade Names #{taxonomy_name} download generated in #{elapsed_time}s" } Rails.logger.debug { "#{taxonomy_name} Distributions" } elapsed_time = Benchmark.realtime do Species::TaxonConceptsDistributionsExport.new(taxonomy: taxonomy_name).export end + Rails.logger.debug { "#{Time.now} Distributions #{taxonomy_name} download generated in #{elapsed_time}s" } Rails.logger.debug { "#{Time.now} Common Names #{taxonomy_name} download generated in #{elapsed_time}s" } Rails.logger.debug { "#{taxonomy_name} Common Names" } @@ -236,6 +251,7 @@ def self.update_admin_downloads Benchmark.realtime do Species::CommonNamesExport.new(taxonomy: taxonomy_name).export end + Rails.logger.debug { "#{Time.now} Common Names #{taxonomy_name} download generated in #{elapsed_time}s" } end end diff --git a/lib/modules/html_to_latex.rb b/lib/modules/html_to_latex.rb index 46ed8f73c..8312daacc 100644 --- a/lib/modules/html_to_latex.rb +++ b/lib/modules/html_to_latex.rb @@ -5,6 +5,7 @@ class HtmlToLatex def self.convert(input_str) doc = Nokogiri::HTML(input_str) output_str = '' + doc.at_css('body').traverse do |n| if n.text? n_content = LatexToPdf.escape_latex(n.content) @@ -16,10 +17,12 @@ def self.convert(input_str) output_str << n_content end end + if n.next_sibling && (n.next_sibling.name == 'p' || n.name == 'p') output_str << '\\newline ' end end + output_str end end diff --git a/lib/modules/import/rst/importer.rb b/lib/modules/import/rst/importer.rb index 9811dd7cc..79217ce97 100644 --- a/lib/modules/import/rst/importer.rb +++ b/lib/modules/import/rst/importer.rb @@ -4,6 +4,7 @@ def import(data) # Array of CitesRstProcesses in current import we can use to # destroy records no longer being returned from the RST API. active_ids = [] + data.map do |item| taxon_concept = map_taxon_concept(item) unless taxon_concept diff --git a/lib/modules/latex_to_pdf.rb b/lib/modules/latex_to_pdf.rb index df67e325e..b6b1540bf 100644 --- a/lib/modules/latex_to_pdf.rb +++ b/lib/modules/latex_to_pdf.rb @@ -25,6 +25,7 @@ def self.generate_pdf_from_file(dir, input) File.open("#{input}.log", 'a') do |io| io.write("#{$!.message}:\n#{$!.backtrace.join("\n")}\n") end + ensure $stdout, $stderr = original_stdout, original_stderr Process.exit! 1 @@ -71,6 +72,7 @@ def latex_esc(text) # :nodoc: end end end + # :startdoc: end diff --git a/lib/modules/pdf_merger.rb b/lib/modules/pdf_merger.rb index fe8322cde..87c598add 100644 --- a/lib/modules/pdf_merger.rb +++ b/lib/modules/pdf_merger.rb @@ -6,13 +6,16 @@ def initialize(files, destination) def merge pdf_file_paths = @file_paths + Prawn::Document.generate(@destination, { page_size: 'A4', skip_page_creation: true }) do |pdf| n = 0 + pdf_file_paths.each_slice(50) do |pdf_files| pdf_files.each do |pdf_file| n += 1 Rails.logger.debug { "processing file n #{n} of #{pdf_file_paths.count} #{pdf_file.split('/').last}" } pdf_temp_nb_pages = Prawn::Document.new(template: pdf_file).page_count + (1..pdf_temp_nb_pages).each do |i| pdf.start_new_page(template: pdf_file, template_page: i) end diff --git a/lib/modules/pg_copy.rb b/lib/modules/pg_copy.rb index f7b553668..3d5a4d0be 100644 --- a/lib/modules/pg_copy.rb +++ b/lib/modules/pg_copy.rb @@ -23,7 +23,9 @@ def self.copy_model_to_db(model, column_names = model.column_names) # [row_hash['taxon_id'], row_hash['name']] # ) # end + # end + # ``` def self.copy_to_db( table_name, diff --git a/lib/modules/sapi_module/geo_i_p.rb b/lib/modules/sapi_module/geo_i_p.rb index 0746ed74f..375576059 100644 --- a/lib/modules/sapi_module/geo_i_p.rb +++ b/lib/modules/sapi_module/geo_i_p.rb @@ -9,6 +9,7 @@ def initialize rescue Errno::ENOENT @city_db = nil end + begin @org_db = GEO_IP_CONFIG['org_db'] && ::GeoIP.new(GEO_IP_CONFIG['org_db']) rescue Errno::ENOENT @@ -18,6 +19,7 @@ def initialize def resolve(ip) result = country_and_city(ip).merge(organisation(ip)) + result.each do |k, v| result[k] = if v.nil? diff --git a/lib/modules/sapi_module/summary.rb b/lib/modules/sapi_module/summary.rb index 3d234b12a..a251d0e1c 100644 --- a/lib/modules/sapi_module/summary.rb +++ b/lib/modules/sapi_module/summary.rb @@ -193,6 +193,7 @@ def self.kingdom_summary(t, k) print_count_for 'TaxonCommons', stats[:common_names] Rails.logger.debug '' + Rank.order(:taxonomic_position).each do |r| Rails.logger.debug { "############## Rank: #{r.name} ####################" } ranked_taxon_concept_ids = TaxonConcept. @@ -204,6 +205,7 @@ def self.kingdom_summary(t, k) taxon_concept_id: ranked_taxon_concept_ids ).count end + Rails.logger.debug '#####################################################' Rails.logger.debug '' end diff --git a/lib/modules/search_param_sanitiser.rb b/lib/modules/search_param_sanitiser.rb index 58f3ad6f1..9d637a949 100644 --- a/lib/modules/search_param_sanitiser.rb +++ b/lib/modules/search_param_sanitiser.rb @@ -28,6 +28,7 @@ def sanitise_positive_integer(i, default = nil) else i end + new_i && new_i > 0 ? new_i : default end @@ -38,6 +39,7 @@ def sanitise_float(f, default = nil) else f end + new_f || default end diff --git a/lib/modules/statistics.rb b/lib/modules/statistics.rb index acdbeb054..32e738fb6 100644 --- a/lib/modules/statistics.rb +++ b/lib/modules/statistics.rb @@ -2,6 +2,7 @@ module Statistics def self.get_total_transactions_per_year trade_transactions = {} years = Trade::Shipment.where.not(year: nil).uniq.pluck(:year) + years.each do |y| unless y.nil? reported_by_exporter = Trade::Shipment.where( @@ -20,6 +21,7 @@ def self.get_total_transactions_per_year } end end + trade_transactions[:total] = {} trade_transactions[:total][:by_exporter] = Trade::Shipment. where(reported_by_exporter: true). diff --git a/lib/modules/trade/appendix_i_reservations_shipments.rb b/lib/modules/trade/appendix_i_reservations_shipments.rb index 2f544b71c..af23931c8 100644 --- a/lib/modules/trade/appendix_i_reservations_shipments.rb +++ b/lib/modules/trade/appendix_i_reservations_shipments.rb @@ -99,10 +99,12 @@ def exceptions_query def except where = [] + CSV.foreach(RESERVATIONS_PATH, headers: true) do |row| @row = row where << "\n (#{ATTRIBUTES.map { |a| send("parse_#{a}", row[a.to_s]) }.join(' AND ')})\n" end + where.join("\n OR\n") end end diff --git a/lib/modules/trade/changelog_csv_generator.rb b/lib/modules/trade/changelog_csv_generator.rb index 78f7f6306..57219a7c1 100644 --- a/lib/modules/trade/changelog_csv_generator.rb +++ b/lib/modules/trade/changelog_csv_generator.rb @@ -31,6 +31,7 @@ def self.call(aru, requester, duplicates = nil) data_columns.map do |dc| shipment[dc] end + values = values + [ duplicate ] if duplicates csv << values @@ -52,6 +53,7 @@ def self.call(aru, requester, duplicates = nil) data_columns.map do |dc| reified[dc] end + values = values + [ '' ] if duplicates csv << values end @@ -61,6 +63,7 @@ def self.call(aru, requester, duplicates = nil) end end end + tempfile end end diff --git a/lib/modules/trade/cites_suspensions_shipments.rb b/lib/modules/trade/cites_suspensions_shipments.rb index 22f35efb1..b8e55f86a 100644 --- a/lib/modules/trade/cites_suspensions_shipments.rb +++ b/lib/modules/trade/cites_suspensions_shipments.rb @@ -229,6 +229,7 @@ def except @row = row where << "\n (#{ATTRIBUTES.map { |a| send("parse_#{a}", row[a.to_s]) }.join(' AND ')})\n" end + where.join("\n OR\n") end diff --git a/lib/modules/trade/download_data_retriever.rb b/lib/modules/trade/download_data_retriever.rb index ab683bf04..7106ccfac 100644 --- a/lib/modules/trade/download_data_retriever.rb +++ b/lib/modules/trade/download_data_retriever.rb @@ -32,6 +32,7 @@ def self.dashboard_download(params) else "SELECT #{ATTRIBUTES.join(',')} FROM non_compliant_shipments_view WHERE year >= '2012' AND year <= '#{Date.today.year - 1}' ORDER BY year DESC" end + query_runner(query) end @@ -67,6 +68,7 @@ def self.search_download(params) AND taxon_concept_id IN (#{id}) SQL end + when 'commodity' <<-SQL.squish SELECT #{ATTRIBUTES.join(',')} @@ -75,12 +77,14 @@ def self.search_download(params) AND term_id IN (#{id}) SQL end + query_runner(query) end def self.taxonomic_download(params) mapping = Trade::Grouping::Compliance.new('').read_taxonomy_conversion array_ids = [] + mapping[params[:ids]].each do |m| rank_name = m[:rank] == 'Species' ? 'taxon' : m[:rank].downcase @@ -90,6 +94,7 @@ def self.taxonomic_download(params) ids.each { |ob| array_ids << ob['id'] } array_ids = plant_timber_distinction(params[:year], mapping, array_ids) if params[:ids].include?('Plants') end + return if array_ids.empty? query = "SELECT #{ATTRIBUTES.join(',')} @@ -111,12 +116,14 @@ def self.ids_query_condition(id, rank, taxon) def self.plant_timber_distinction(year, mapping, array) timber_ids = [] + mapping['Timber'].each do |mapp| rank_name = mapp[:rank] == 'Species' ? 'taxon' : mapp[:rank].downcase ids_query = ids_query(year, 'Timber', rank_name, mapp[:taxon_name]) ids = query_runner(ids_query) ids.each { |ob| timber_ids << ob['id'] } end + array.reject { |el| timber_ids.include? el } end diff --git a/lib/modules/trade/grouping/base.rb b/lib/modules/trade/grouping/base.rb index 1107286c6..cd358e095 100644 --- a/lib/modules/trade/grouping/base.rb +++ b/lib/modules/trade/grouping/base.rb @@ -52,6 +52,7 @@ def json_by_attribute(data, opts = {}) def read_taxonomy_conversion conversion = {} taxonomy = CSV.read(TAXONOMIC_GROUPING, headers: true) + taxonomy.each do |csv| conversion[csv['group']] ||= [] data = { @@ -60,6 +61,7 @@ def read_taxonomy_conversion } conversion[csv['group']] << data end + conversion end @@ -140,10 +142,12 @@ def sanitise_condition @opts.keep_if do |k, v| filtering_attributes.key?(k.to_sym) && v.present? end + unless condition_attributes.is_a?(Hash) condition_attributes.permit! condition_attributes = condition_attributes.to_h end + # Get default attributes if missing from params if @opts[:with_defaults] condition_attributes.reverse_merge!(self.class.default_filtering_attributes) @@ -216,6 +220,7 @@ def get_condition_value(key, value) else '=' end + "#{operator} #{value.to_i}" end diff --git a/lib/modules/trade/grouping/compliance.rb b/lib/modules/trade/grouping/compliance.rb index c04c14af3..425f9fa1c 100644 --- a/lib/modules/trade/grouping/compliance.rb +++ b/lib/modules/trade/grouping/compliance.rb @@ -80,8 +80,10 @@ def taxonomic_grouping_per_year(year) end end end + # Calculate percentages shipments_no = shipments.count + conversion.map do |group, values| percent = (res[group].to_f / shipments_no.to_f * 100).round(2) { @@ -111,12 +113,15 @@ def build_hash(data, params) merged_hash.map do |k, v| { "#{k}": merged_hash[k].merge(percentage: (v[:cnt] * 100.0 / v[:total_cnt]).round(2)) } end + merged_hash.each do |country| country.values.first.merge!(country: country.keys.first.to_s) array << country.values.first end + hash[params[:year]] = array.sort_by { |x| x[:cnt] }.reverse! end + hash end @@ -168,6 +173,7 @@ def json_by_attribute(data, opts = {}) end grouped_data = data.group_by { |d| d[attribute] } + grouped_data.each do |key, values| # Fetch top 5 and rename 'cnt' to 'value' grouped_data[key] = values[0..4].each { |v| v['value'] = v.delete('cnt') } @@ -190,6 +196,7 @@ def self.default_filtering_attributes time_range_end: 1.year.ago.year }.freeze end + def self.default_filtering_attributes DEFAULT_FILTERING_ATTRIBUTES end @@ -359,6 +366,7 @@ def is_timber?(shipment, groupings) # else # "#{ATTRIBUTES[key]} = #{value}" # end + # end.join(' AND ') # end diff --git a/lib/modules/trade/grouping/trade_plus_static.rb b/lib/modules/trade/grouping/trade_plus_static.rb index ad3ad4a73..f90d7efeb 100644 --- a/lib/modules/trade/grouping/trade_plus_static.rb +++ b/lib/modules/trade/grouping/trade_plus_static.rb @@ -31,6 +31,7 @@ def sanitise_response_over_time_query(response) response.map do |value| value['id'], value['name'] = 'unreported', I18n.t('tradeplus.unreported') if value['id'].nil? end + response.sort_by { |i| i['name'] } response.partition { |value| value['id'] != 'unreported' }.reduce(:+) end @@ -39,6 +40,7 @@ def sanitise_response_aggregated_over_time_query(response) response.map do |value| value['id'], value['name'] = "reported_by_#{@reported_by}", "reported_by_#{@reported_by}" if value['id'].nil? end + response.partition { |value| value['id'] != 'unreported' }.reduce(:+) end @@ -51,9 +53,11 @@ def taxonomic_grouping(opts = {}) def json_by_attribute(data, opts = {}) key = data.fields.first hash = { "#{key}" => [] } + data.each do |d| hash[key] << d end + hash[key] end @@ -173,6 +177,7 @@ def child_taxa_uniquify SQL ).values.first[0].to_i > 0 end + @opts['taxon_id'] = unique_taxa.join(',') end @@ -186,7 +191,6 @@ def child_taxa_join(tc_id = nil) SQL end - def child_taxa_condition return 'TRUE' if @opts['taxon_id'].blank? @@ -269,7 +273,6 @@ def over_time_query SQL end - # TODO refactor to merge this method and the over_time one above together def aggregated_over_time_query quantity_field = @country_ids.present? ? "#{entity_quantity}_reported_quantity" : "#{@reported_by}_reported_quantity" @@ -341,6 +344,7 @@ def taxonomic_query(opts) def ancestors_ranks(taxonomic_level) taxa = [ 'kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'taxon' ] current_idx = taxa.index(taxonomic_level) || 0 + 0.upto(current_idx).map do |i| taxa[i] end diff --git a/lib/modules/trade/mandatory_quotas_shipments.rb b/lib/modules/trade/mandatory_quotas_shipments.rb index d5becd3ec..ce0d65b47 100644 --- a/lib/modules/trade/mandatory_quotas_shipments.rb +++ b/lib/modules/trade/mandatory_quotas_shipments.rb @@ -70,10 +70,12 @@ class Trade::MandatoryQuotasShipments def initialize @queries = [] + CSV.foreach(QUOTAS_PATH, headers: true) do |row| @row = row run end + @final_query = @queries.join("\n\s\s\s\sUNION\s\s\s\s\n") end diff --git a/lib/modules/trade/rebuild_compliance_mviews.rb b/lib/modules/trade/rebuild_compliance_mviews.rb index 7d733209e..0826a86a7 100644 --- a/lib/modules/trade/rebuild_compliance_mviews.rb +++ b/lib/modules/trade/rebuild_compliance_mviews.rb @@ -31,6 +31,7 @@ def self.rebuild_sql_views(type, timestamp) when :mandatory_quotas then Trade::MandatoryQuotasShipments when :cites_suspensions then Trade::CitesSuspensionsShipments end + compliance_type.new.generate_view(timestamp) end diff --git a/lib/modules/trade/trade_plus_filters.rb b/lib/modules/trade/trade_plus_filters.rb index 22ee3240a..d34f97203 100644 --- a/lib/modules/trade/trade_plus_filters.rb +++ b/lib/modules/trade/trade_plus_filters.rb @@ -221,7 +221,6 @@ def query SQL end - private def format_values(key, values) @@ -287,6 +286,7 @@ def format_values(key, values) def ordering(attribute, attribute_value) if attribute == 'taxonomic_groups' # If there are unexpected attribute values put them at the end + taxonomy_ordering.index(attribute_value) || taxonomy_ordering.length elsif attribute == 'units' unit_ordering.index(attribute_value) || unit_ordering.length diff --git a/lib/tasks/dashboard_stats_cache.rake b/lib/tasks/dashboard_stats_cache.rake index d7e20987e..b44aaa9a8 100644 --- a/lib/tasks/dashboard_stats_cache.rake +++ b/lib/tasks/dashboard_stats_cache.rake @@ -1,6 +1,7 @@ namespace :dashboard_stats do namespace :cache do desc 'Update the cache for the dashboard stats' + task update: :environment do DashboardStatsCache.update_dashboard_stats end diff --git a/lib/tasks/db_cleanup.rake b/lib/tasks/db_cleanup.rake index 4ed9d1ad8..736a0df78 100644 --- a/lib/tasks/db_cleanup.rake +++ b/lib/tasks/db_cleanup.rake @@ -1,6 +1,7 @@ namespace :db do namespace :common_names do desc 'Deletes detached common names' + task cleanup: :environment do Rails.logger.warn '### rake db:common_names:cleanup' @@ -23,6 +24,7 @@ namespace :db do namespace :taxon_names do desc 'Deletes detached taxon names' + task cleanup: :environment do Rails.logger.warn '### rake db:taxon_names:cleanup' diff --git a/lib/tasks/db_migrate_plpgsql.rake b/lib/tasks/db_migrate_plpgsql.rake index d7b9699e6..b21e45f57 100644 --- a/lib/tasks/db_migrate_plpgsql.rake +++ b/lib/tasks/db_migrate_plpgsql.rake @@ -1,6 +1,7 @@ namespace :db do namespace :migrate do desc 'Run custom sql scripts' + task sql: :environment do ApplicationRecord.transaction do connection = ApplicationRecord.connection @@ -25,6 +26,7 @@ namespace :db do end desc 'Rebuild all computed values' + task rebuild: :migrate do SapiModule.rebuild end @@ -35,6 +37,7 @@ namespace :db do end desc 'Drop sandboxes in progress' + task drop_sandboxes: :environment do Trade::AnnualReportUpload.where(is_done: false).find_each do |aru| aru.destroy @@ -42,6 +45,7 @@ namespace :db do end desc 'Drop all trade (shipments, permits, arus & sandboxes - use responsibly)' + task drop_trade: [ :environment ] do puts 'Deleting shipments' ApplicationRecord.connection.execute('DELETE FROM trade_shipments') diff --git a/lib/tasks/downloads_cache.rake b/lib/tasks/downloads_cache.rake index d2366bc66..7f26a7ca3 100644 --- a/lib/tasks/downloads_cache.rake +++ b/lib/tasks/downloads_cache.rake @@ -1,16 +1,19 @@ namespace :downloads do namespace :cache do desc 'Remove all CITES Checklist and Species+ downloads' + task clear: :environment do DownloadsCache.clear end desc 'Update the cache for the featured downloads' + task update: :environment do DownloadsCache.update end desc 'Update the cache for the checklist downloads' + task update_checklist_downloads: :environment do DownloadsCache.update_checklist_downloads end diff --git a/lib/tasks/export_nomenclature_notes.rake b/lib/tasks/export_nomenclature_notes.rake index be36c1209..250e598da 100644 --- a/lib/tasks/export_nomenclature_notes.rake +++ b/lib/tasks/export_nomenclature_notes.rake @@ -1,11 +1,13 @@ namespace :export do desc 'Export nomenclature notes for Species' + task nomenclature_notes: :environment do FILENAME = "tmp/nomenclature_#{Date.today}.csv".freeze COLUMN_NAMES = %w[id name nomenclature_note internal_nomenclature_note].freeze CSV.open(FILENAME, 'w') do |csv| csv << COLUMN_NAMES + TaxonConcept.where(rank_id: 8).select(:id, :full_name, :nomenclature_note_en, :internal_nomenclature_note).order(:id).each do |note| csv << note.attributes.values end diff --git a/lib/tasks/export_trade_db.rake b/lib/tasks/export_trade_db.rake index 3d7fdd261..eb048f321 100644 --- a/lib/tasks/export_trade_db.rake +++ b/lib/tasks/export_trade_db.rake @@ -63,6 +63,7 @@ namespace :export do File.open(path_to_file, 'a') do |file| if i == 1 columns = results.fields + columns.map do |column| column.capitalize! column.gsub! '_', ' ' @@ -80,6 +81,7 @@ namespace :export do end Rails.logger.info('Trade database completely exported!') zipfile = 'tmp/trade_db_files/trade_db.zip' + Zip::File.open(zipfile, Zip::File::CREATE) do |zipfile| zipfile.add(filename, path_to_file) end @@ -137,6 +139,7 @@ namespace :export do end Rails.logger.info('Trade database completely exported!') zipfile = 'tmp/trade_db_files/trade_db.zip' + Zip::File.open(zipfile, Zip::File::CREATE) do |zipfile| range.each do |year| if (2012..2015).include?(year) @@ -183,6 +186,7 @@ namespace :export do end Rails.logger.info('Trade database completely exported!') zipfile = 'tmp/trade_db_files/trade_db.zip' + Zip::File.open(zipfile, Zip::File::CREATE) do |zipfile| (1..i).each do |index| filename = "trade_db_#{index}.csv" @@ -205,6 +209,7 @@ namespace :export do def process_results(results, options) columns = results.fields unfrozen_columns = columns.deep_dup + unfrozen_columns.map do |column| column.capitalize! column.gsub! '_', ' ' @@ -221,8 +226,10 @@ namespace :export do filename = 'trade_db_full_export.csv' end Rails.logger.info("Processing #{filename}.") + File.open("#{options[:dir]}#{filename}", 'w') do |file| file.write unfrozen_columns.join('|') + values.each do |record| file.write "\n" file.write record.join('|') diff --git a/lib/tasks/export_users.rake b/lib/tasks/export_users.rake index 156b247ee..5f00ee01a 100644 --- a/lib/tasks/export_users.rake +++ b/lib/tasks/export_users.rake @@ -1,11 +1,13 @@ namespace :export do desc 'Export all users' + task users: :environment do FILENAME = "tmp/users_#{Date.today}.csv".freeze COLUMN_NAMES = %w[id name email role organisation is_cites_authority is_active].freeze CSV.open(FILENAME, 'w') do |csv| csv << [ COLUMN_NAMES, 'country' ].flatten + User.order(:name).each do |user| country = user.geo_entity && user.geo_entity.name_en csv << user.attributes.slice(*COLUMN_NAMES).merge(country: country).values diff --git a/lib/tasks/helpers_for_import.rb b/lib/tasks/helpers_for_import.rb index 09ce91005..c1f964a7a 100644 --- a/lib/tasks/helpers_for_import.rb +++ b/lib/tasks/helpers_for_import.rb @@ -527,6 +527,7 @@ def drop_table(table_name) "Could not drop table #{quoted_table_name}. " + 'It might not exist if this is the first time you are running this rake task.' end + Rails.logger.debug e.inspect raise e @@ -599,7 +600,6 @@ def copy_data_into_table( ] end - row_values = column_names.map do |column_name| row_as_hash[column_name] @@ -608,6 +608,7 @@ def copy_data_into_table( writer.call(row_values) end end + rescue StandardError => e Rails.logger.debug { "Failed at line #{row_count}" } Rails.logger.debug e.inspect @@ -638,7 +639,6 @@ def assert_no_rows(query, why = 'failing rows') raise StandardError.new(error_message) end - def rollback_if_dry_run raise ActiveRecord::Rollback.new do 'Rolling back: dry run' @@ -663,6 +663,7 @@ def self.import_data_for_all_ranks(source_table, kingdom, synonyms = nil) TaxonImportHelper.import_data_for TMP_TABLE, kingdom, Rank::VARIETY, synonyms end end + # Copies data from the temporary table to the correct tables in the database # # @param [String] which the rank to be copied. diff --git a/lib/tasks/import_authors_year.rake b/lib/tasks/import_authors_year.rake index 790732c39..c6c868df9 100644 --- a/lib/tasks/import_authors_year.rake +++ b/lib/tasks/import_authors_year.rake @@ -2,6 +2,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'update author_year TaxonConcept attribute (usage: rake import:authors_year[path/to/file])' + task :authors_year, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_cites_listings.rake b/lib/tasks/import_cites_listings.rake index 0f2e6a7a8..da91692a0 100644 --- a/lib/tasks/import_cites_listings.rake +++ b/lib/tasks/import_cites_listings.rake @@ -2,6 +2,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'Import CITES species listings from csv file (usage: rake import:cites_listings[path/to/file,path/to/another])' + task :cites_listings, 10.times.map { |i| :"file_#{i}" } => [ :environment, 'cites_listings:defaults' ] do |t, args| import_helper = CsvImportHelper.new @@ -34,6 +35,7 @@ namespace :import do where(species_listings: { designation_id: designation.id }).count files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) @@ -276,6 +278,7 @@ namespace :import do namespace :cites_listings do desc 'Add defaults CITES listings and default ChangeTypes' + task defaults: :environment do puts 'Going to create CITES default species listings, if they do not exist' @@ -299,6 +302,7 @@ namespace :import do end desc 'Drop CITES species listings' + task delete_all: :environment do designation = Designation.find_by(name: 'CITES') diff --git a/lib/tasks/import_cites_rst_processes.rake b/lib/tasks/import_cites_rst_processes.rake index 1ea11554a..656b95149 100644 --- a/lib/tasks/import_cites_rst_processes.rake +++ b/lib/tasks/import_cites_rst_processes.rake @@ -1,5 +1,6 @@ namespace :rst_processes do desc 'Import RST(Significant Trade) cases from RST API' + task import: :environment do ApplicationRecord.transaction do Import::Rst::RstCases.import_all diff --git a/lib/tasks/import_cms_listings.rake b/lib/tasks/import_cms_listings.rake index c9305b3b8..cf4924166 100644 --- a/lib/tasks/import_cms_listings.rake +++ b/lib/tasks/import_cms_listings.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import CMS species listings from csv file (usage: rake import:cms_listings[path/to/file,path/to/another])' + task :cms_listings, 10.times.map { |i| :"file_#{i}" } => [ :environment, 'cms_listings:defaults' ] do |t, args| import_helper = CsvImportHelper.new @@ -259,6 +260,7 @@ namespace :import do namespace :cms_listings do desc 'Add defaults CMS listings and default ChangeTypes' + task defaults: :environment do puts 'Going to create CMS default species listings, if they do not exist' @@ -278,6 +280,7 @@ namespace :import do end desc 'Drop CMS species listings' + task delete_all: :environment do designation = Designation.find_by(name: 'CMS') diff --git a/lib/tasks/import_common_names.rake b/lib/tasks/import_common_names.rake index 875663019..f9758df86 100644 --- a/lib/tasks/import_common_names.rake +++ b/lib/tasks/import_common_names.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import common names from csv file (usage: rake import:common_names[path/to/file,path/to/another])' + task :common_names, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -85,6 +86,7 @@ namespace :import do namespace :common_names do desc 'Delete all existing common names, and taxon commons' + task delete_all: :environment do puts "Deleting #{TaxonCommon.delete_all} taxon commons" puts "Deleting #{CommonName.delete_all} common names" diff --git a/lib/tasks/import_countries.rake b/lib/tasks/import_countries.rake index feabc3f67..a3e32e68a 100644 --- a/lib/tasks/import_countries.rake +++ b/lib/tasks/import_countries.rake @@ -5,6 +5,7 @@ namespace :import do ### 1- check current character encoding with: file path/to/file ### 2- change character encoding: iconv -f original_charset -t utf-8 originalfile > newfile desc 'Import countries from csv file (usage: rake import:countries[path/to/file,path/to/another])' + task :countries, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'countries_import' country_type = GeoEntityType.find_by(name: GeoEntityType::COUNTRY) @@ -12,6 +13,7 @@ namespace :import do puts "There are #{GeoEntity.count(conditions: { geo_entity_type_id: country_type.id })} countries in the database." puts "There are #{GeoEntity.count(conditions: { geo_entity_type_id: territory_type.id })} territories in the database." files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) @@ -39,6 +41,7 @@ namespace :import do end desc 'Add country names in spanish and french' + task countries_translations: [ :environment ] do CSV.foreach('lib/files/country_codes_en_es_fr_utf8.csv') do |row| country = GeoEntity.find_or_initialize_by(iso_code2: row[0].strip.upcase) diff --git a/lib/tasks/import_distribution_tags.rake b/lib/tasks/import_distribution_tags.rake index dd32978ea..72a001604 100644 --- a/lib/tasks/import_distribution_tags.rake +++ b/lib/tasks/import_distribution_tags.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import distribution tags from csv file (usage: rake import:distribution_tags[path/to/file,path/to/another])' + task :distribution_tags, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'distribution_tags_import' import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_distributions.rake b/lib/tasks/import_distributions.rake index 81e27dc7f..d7aad8ba3 100644 --- a/lib/tasks/import_distributions.rake +++ b/lib/tasks/import_distributions.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import distributions from csv file (usage: rake import:distributions[path/to/file,path/to/another])' + task :distributions, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| ApplicationRecord.transaction do import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_eu_country_dates.rake b/lib/tasks/import_eu_country_dates.rake index be75cb1b4..00ada0e6d 100644 --- a/lib/tasks/import_eu_country_dates.rake +++ b/lib/tasks/import_eu_country_dates.rake @@ -1,10 +1,12 @@ namespace :import do desc 'Import EU country entry/exit dates from csv file usage: rake import:eu_country_dates' + task eu_country_dates: :environment do file_path = "#{Rails.root.join("lib/files/CITES_trade_EU_countries_list.csv")}" if File.exist?(file_path) Rails.logger.info "There are #{EuCountryDate.count} records in the EuCoutryDate table" + CSV.foreach(file_path, headers: true) do |row| geo_entity = GeoEntity.find_by(iso_code2: row['ISO2']) accession_year = row['EU_accession_year'] diff --git a/lib/tasks/import_eu_decisions.rake b/lib/tasks/import_eu_decisions.rake index 43afb1496..e6c0cb80c 100644 --- a/lib/tasks/import_eu_decisions.rake +++ b/lib/tasks/import_eu_decisions.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import EU decisions from csv file (usage: rake import:eu_decisions[path/to/file,path/to/another])' + task :eu_decisions, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'eu_decisions_import' @@ -7,6 +8,7 @@ namespace :import do designation_id = Designation.find_by(name: 'EU').id puts "There are #{EuDecision.count} EU Decisions in the database." files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_eu_listings.rake b/lib/tasks/import_eu_listings.rake index a63257f05..01422ea31 100644 --- a/lib/tasks/import_eu_listings.rake +++ b/lib/tasks/import_eu_listings.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import EU species listings from csv file (usage: rake import:eu_listings[path/to/file,path/to/another])' + task :eu_listings, 10.times.map { |i| :"file_#{i}" } => [ :environment, 'eu_listings:defaults' ] do |t, args| import_helper = CsvImportHelper.new @@ -237,13 +238,16 @@ namespace :import do namespace :eu_listings do desc 'Add defaults EU listings and default ChangeTypes' + task defaults: :environment do puts 'Going to create EU default species listings, if they do not exist' designation = Designation.find_by(name: 'EU') + [ 'A', 'B', 'C', 'D' ].each do |annex| SpeciesListing.find_or_create_by(name: "Annex #{annex}", abbreviation: annex, designation_id: designation.id) end puts 'Going to create change types defaults, if they dont already exist' + ChangeType.dict.each do |c_type| ChangeType.find_or_create_by(name: c_type, designation_id: designation.id) end @@ -251,6 +255,7 @@ namespace :import do end desc 'Drop EU species listings' + task delete_all: :environment do designation = Designation.find_by(name: 'EU') diff --git a/lib/tasks/import_eu_opinions.rake b/lib/tasks/import_eu_opinions.rake index cc2053f92..cbdaf4f33 100644 --- a/lib/tasks/import_eu_opinions.rake +++ b/lib/tasks/import_eu_opinions.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import EU decisions from csv file (usage: rake import:eu_opinions[path/to/file,path/to/another])' + task :eu_opinions, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_events.rake b/lib/tasks/import_events.rake index b1abeb7d0..7bfe40644 100644 --- a/lib/tasks/import_events.rake +++ b/lib/tasks/import_events.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import events from csv file (usage: rake import:events[path/to/file,path/to/another])' + task :events, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_hash_annotations.rake b/lib/tasks/import_hash_annotations.rake index 5145bb715..4899c24f5 100644 --- a/lib/tasks/import_hash_annotations.rake +++ b/lib/tasks/import_hash_annotations.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import hash annotations from csv file (usage: rake import:hash_annotations[path/to/file,path/to/another])' + task :hash_annotations, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -40,6 +41,7 @@ namespace :import do end desc 'Import hash annotation translations' + task hash_annotations_cites_translations: [ :environment ] do import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_hybrids.rake b/lib/tasks/import_hybrids.rake index 444e123d3..635db3030 100644 --- a/lib/tasks/import_hybrids.rake +++ b/lib/tasks/import_hybrids.rake @@ -1,6 +1,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'Import hybrids records from csv files (usage: rake import:hybrids[path/to/file,path/to/another])' + task :hybrids, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'hybrids_import' taxonomy_id = Taxonomy.where(name: 'CITES_EU').first.id @@ -12,6 +13,7 @@ namespace :import do ).count} Hybrids in the database" files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_languages.rake b/lib/tasks/import_languages.rake index 83cb7197c..2cc8442d3 100644 --- a/lib/tasks/import_languages.rake +++ b/lib/tasks/import_languages.rake @@ -1,9 +1,11 @@ namespace :import do desc 'Import languages from csv file (usage: rake import:languages[path/to/file,path/to/another])' + task :languages, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'languages_import' puts "There are #{Language.count} languages in the database." files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_reference_accepted_links.rake b/lib/tasks/import_reference_accepted_links.rake index f27535709..2b20a5c95 100644 --- a/lib/tasks/import_reference_accepted_links.rake +++ b/lib/tasks/import_reference_accepted_links.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import reference accepted links from csv file (usage: rake import:reference_accepted_links[path/to/file,path/to/another])' + task :reference_accepted_links, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_reference_distribution_links.rake b/lib/tasks/import_reference_distribution_links.rake index 7e047857c..7591a8f2d 100644 --- a/lib/tasks/import_reference_distribution_links.rake +++ b/lib/tasks/import_reference_distribution_links.rake @@ -1,10 +1,12 @@ namespace :import do desc 'Import reference distribution links from csv file (usage: rake import:reference_distribution_links[path/to/file,path/to/another])' + task :reference_distribution_links, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'reference_distribution_links_import' puts "There are #{DistributionReference.count} distribution references in the database." files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_reference_synonym_links.rake b/lib/tasks/import_reference_synonym_links.rake index ff04edfcc..16f30d6cc 100644 --- a/lib/tasks/import_reference_synonym_links.rake +++ b/lib/tasks/import_reference_synonym_links.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import reference synonym links from csv file (usage: rake import:reference_synonym_links[path/to/file,path/to/another])' + task :reference_synonym_links, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'reference_synonym_links_import' puts "There are #{TaxonConceptReference.count} taxon concept references in the database." @@ -10,6 +11,7 @@ namespace :import do ApplicationRecord.connection.execute('CREATE INDEX index_references_on_legacy_id_and_legacy_type ON "references" (legacy_id, legacy_type)') files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_references.rake b/lib/tasks/import_references.rake index 9dd294715..6701bdaab 100644 --- a/lib/tasks/import_references.rake +++ b/lib/tasks/import_references.rake @@ -1,9 +1,11 @@ namespace :import do desc 'Import references from csv file (usage: rake import:references[path/to/file,path/to/another])' + task :references, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'references_import' puts "There are #{Reference.count} references in the database." files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_species.rake b/lib/tasks/import_species.rake index 67ed6b928..745ba7f40 100644 --- a/lib/tasks/import_species.rake +++ b/lib/tasks/import_species.rake @@ -1,6 +1,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'Import species records from csv files (usage: rake import:species[path/to/file,path/to/another])' + task :species, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_species_kew_id.rake b/lib/tasks/import_species_kew_id.rake index b8f0490cb..83ab5fd36 100644 --- a/lib/tasks/import_species_kew_id.rake +++ b/lib/tasks/import_species_kew_id.rake @@ -1,6 +1,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'Import species records from csv files (usage: rake import:species_kew_id[path/to/file,path/to/another])' + task :species_kew_id, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_species_legacy.rake b/lib/tasks/import_species_legacy.rake index 473852d3c..93f452c4a 100644 --- a/lib/tasks/import_species_legacy.rake +++ b/lib/tasks/import_species_legacy.rake @@ -1,9 +1,11 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'Import species records from csv files (usage: rake import:species[path/to/file,path/to/another])' + task :species_legacy, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'species_import_legacy' files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_standard_reference_links.rake b/lib/tasks/import_standard_reference_links.rake index 547800fc3..a6d8fc729 100644 --- a/lib/tasks/import_standard_reference_links.rake +++ b/lib/tasks/import_standard_reference_links.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import standard reference links from csv file (usage: rake import:standard_references[path/to/file,path/to/another])' + task :standard_reference_links, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_synonyms.rake b/lib/tasks/import_synonyms.rake index 1c9bfb524..e9d13945c 100644 --- a/lib/tasks/import_synonyms.rake +++ b/lib/tasks/import_synonyms.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import synonyms from csv file (usage: rake import:synonyms[path/to/file,path/to/another])' + task :synonyms, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_synonyms_kew_id.rake b/lib/tasks/import_synonyms_kew_id.rake index 1f63f6d5d..961d7196a 100644 --- a/lib/tasks/import_synonyms_kew_id.rake +++ b/lib/tasks/import_synonyms_kew_id.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import synonyms from csv file (usage: rake import:synonyms_kew_id[path/to/file,path/to/another])' + task :synonyms_kew_id, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| TMP_TABLE = 'synonym_kew_id_import' puts "There are #{TaxonRelationship. @@ -12,6 +13,7 @@ namespace :import do find_by(name: TaxonRelationshipType::HAS_SYNONYM) files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) @@ -31,6 +33,7 @@ namespace :import do if kingdom == 'Plantae' import_data_for_kew_id kingdom, Rank::VARIETY end + # [END]copied over from import:species [ Taxonomy::CITES_EU, Taxonomy::CMS ].each do |taxonomy_name| diff --git a/lib/tasks/import_synonyms_legacy.rake b/lib/tasks/import_synonyms_legacy.rake index 24e1781ff..0d860e2d7 100644 --- a/lib/tasks/import_synonyms_legacy.rake +++ b/lib/tasks/import_synonyms_legacy.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import synonyms from csv file (usage: rake import:synonyms[path/to/file,path/to/another])' + task :synonyms_legacy, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -15,6 +16,7 @@ namespace :import do find_by(name: TaxonRelationshipType::HAS_SYNONYM) files = import_helper.files_from_args(t, args) + files.each do |file| import_helper.drop_table(TMP_TABLE) import_helper.create_table_from_csv_headers(file, TMP_TABLE) diff --git a/lib/tasks/import_taxon_name_status_changes.rake b/lib/tasks/import_taxon_name_status_changes.rake index b9523b57a..f97d9e7c9 100644 --- a/lib/tasks/import_taxon_name_status_changes.rake +++ b/lib/tasks/import_taxon_name_status_changes.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Apply name status changes from csv file (usage: rake import:taxon_name_status_changes[path/to/file,path/to/another])' + task :taxon_name_status_changes, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new diff --git a/lib/tasks/import_taxon_notes.rake b/lib/tasks/import_taxon_notes.rake index f3297dbc9..93d55cc7a 100644 --- a/lib/tasks/import_taxon_notes.rake +++ b/lib/tasks/import_taxon_notes.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Apply name status changes from csv file (usage: rake import:taxon_name_status_changes[path/to/file,path/to/another])' + task :taxon_notes, 10.times.map { |i| :"file_#{i}" } => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -60,6 +61,7 @@ namespace :import do NOW() AS created_at, NOW() AS updated_at FROM note_changes itc + -- Ensure that we do not insert comments for taxons which do not -- exist JOIN taxon_concepts tc diff --git a/lib/tasks/import_trade_codes.rake b/lib/tasks/import_trade_codes.rake index c2375e720..64e050c20 100644 --- a/lib/tasks/import_trade_codes.rake +++ b/lib/tasks/import_trade_codes.rake @@ -1,5 +1,6 @@ namespace :import do desc 'Import trade codes' + task trade_codes: [ :environment ] do [ Purpose, Source, Term, Unit ].each do |klass| current_count = klass.count @@ -18,6 +19,7 @@ namespace :import do end desc 'Import terms and purpose codes acceptable pairing' + task :trade_codes_t_p_pairs, [ :clear ] => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -58,6 +60,7 @@ namespace :import do end desc 'Import terms and unit codes acceptable pairing' + task :trade_codes_t_u_pairs, [ :clear ] => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -94,6 +97,7 @@ namespace :import do end desc 'Import taxon concepts terms acceptable pairing. (i.e.: which terms can go with each taxon concept)' + task :taxon_concept_terms_pairs, [ :clear ] => [ :environment ] do |t, args| import_helper = CsvImportHelper.new @@ -135,6 +139,7 @@ namespace :import do end desc 'Empties taxon_concept_term_pairs and term_trade_codes_pairs' + task clear_acceptable_pairs: [ :environment ] do puts "#{TermTradeCodesPair.delete_all} term_trade_codes_pairs deleted" puts "#{Trade::TaxonConceptTermPair.delete_all} taxon_concept_term_pairs deleted" diff --git a/lib/tasks/import_trade_plus_static_data.rake b/lib/tasks/import_trade_plus_static_data.rake index dd4a466ab..986ca167b 100644 --- a/lib/tasks/import_trade_plus_static_data.rake +++ b/lib/tasks/import_trade_plus_static_data.rake @@ -1,6 +1,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'import trade plus static data (usage: rake import:trade_plus_static_data[path/to/file])' + task :trade_plus_static_data, [ :path_to_file ] => [ :environment ] do |t, args| abort('File not provided.') unless args[:path_to_file] diff --git a/lib/tasks/import_trade_rules.rake b/lib/tasks/import_trade_rules.rake index 784724774..c035454f2 100644 --- a/lib/tasks/import_trade_rules.rake +++ b/lib/tasks/import_trade_rules.rake @@ -2,6 +2,7 @@ require Rails.root.join('lib/tasks/helpers_for_import.rb') namespace :import do desc 'import trade plus conversion rules' + task trade_rules: [ :environment ] do path_to_groups_file = "#{Rails.application.root}/lib/data/trade_taxon_groups.yml" abort("File doesn't exist.") unless File.exist?(path_to_groups_file) diff --git a/lib/tasks/species_without_trade_or_legislation.rake b/lib/tasks/species_without_trade_or_legislation.rake index 1062fa427..629b06a3a 100644 --- a/lib/tasks/species_without_trade_or_legislation.rake +++ b/lib/tasks/species_without_trade_or_legislation.rake @@ -6,6 +6,7 @@ namespace :species_without_legislation_or_trade do task delete: :environment do cnt = Trade::SpeciesWithoutLegislationOrTradeReport.new.query.count deleted_cnt = 0 + Rails.logger.warn("### BEGIN removal of #{cnt} species without legislation or trade") Trade::SpeciesWithoutLegislationOrTradeReport.new.query.each do |tc| if tc.destroy diff --git a/lib/tasks/taxonomy_mapping.rake b/lib/tasks/taxonomy_mapping.rake index ff4a51fdb..811da65a5 100644 --- a/lib/tasks/taxonomy_mapping.rake +++ b/lib/tasks/taxonomy_mapping.rake @@ -1,15 +1,18 @@ namespace :taxonomy_mapping do desc 'Update mapping between CITES species and IUCN species' + task iucn_mapping: :environment do Admin::IucnMappingManager.sync end desc 'Update mapping between CMS species in Species+ and CMS species' + task cms_mapping: :environment do Admin::CmsMappingManager.sync end desc 'Copy CITES distribution data to CMS species' + task fill_cms_distributions: :environment do Admin::CmsMappingManager.fill_cms_distributions end diff --git a/spec/controllers/admin/documents_controller_spec.rb b/spec/controllers/admin/documents_controller_spec.rb index ed8676c02..a2150df9c 100644 --- a/spec/controllers/admin/documents_controller_spec.rb +++ b/spec/controllers/admin/documents_controller_spec.rb @@ -351,6 +351,7 @@ describe 'DELETE destroy' do login_admin + let(:poland) do create( :geo_entity, diff --git a/spec/controllers/admin/hybrid_relationships_controller_spec.rb b/spec/controllers/admin/hybrid_relationships_controller_spec.rb index a6fa96eec..1ce51d3ac 100644 --- a/spec/controllers/admin/hybrid_relationships_controller_spec.rb +++ b/spec/controllers/admin/hybrid_relationships_controller_spec.rb @@ -7,6 +7,7 @@ let(:taxon_concept) { create(:taxon_concept) } let(:hybrid) { create(:taxon_concept, name_status: 'H') } + let(:hybrid_relationship) do create( :taxon_relationship, diff --git a/spec/controllers/admin/instruments_controller_spec.rb b/spec/controllers/admin/instruments_controller_spec.rb index 8ebfeea3c..570ae7d82 100644 --- a/spec/controllers/admin/instruments_controller_spec.rb +++ b/spec/controllers/admin/instruments_controller_spec.rb @@ -76,7 +76,6 @@ expect(response).to redirect_to(admin_instruments_url) end - it 'fails to delete instrument because there are dependent objects' do delete :destroy, params: { id: instrument2.id } diff --git a/spec/controllers/admin/nomenclature_changes/lump_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/lump_controller_spec.rb index aaffb334e..1aaf3eff1 100644 --- a/spec/controllers/admin/nomenclature_changes/lump_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/lump_controller_spec.rb @@ -130,6 +130,7 @@ context 'when last step' do context 'when user is secretariat' do login_secretariat_user + it 'redirects to admin root path' do put :update, params: { nomenclature_change_id: @lump.id, id: 'summary' } diff --git a/spec/controllers/admin/nomenclature_changes/split_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/split_controller_spec.rb index cd62f35ca..35534dac1 100644 --- a/spec/controllers/admin/nomenclature_changes/split_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/split_controller_spec.rb @@ -213,6 +213,7 @@ context 'when last step' do context 'when user is secretariat' do login_secretariat_user + it 'redirects to admin root path' do put :update, params: { nomenclature_change_id: @split.id, id: 'summary' } diff --git a/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb b/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb index a61328437..e79c4fd64 100644 --- a/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb +++ b/spec/controllers/admin/nomenclature_changes/status_swap_controller_spec.rb @@ -149,6 +149,7 @@ context 'when last step' do context 'when user is secretariat' do login_secretariat_user + it 'redirects to admin root path' do put :update, params: { diff --git a/spec/controllers/admin/synonym_relationships_controller_spec.rb b/spec/controllers/admin/synonym_relationships_controller_spec.rb index f572f8369..6fbec54b2 100644 --- a/spec/controllers/admin/synonym_relationships_controller_spec.rb +++ b/spec/controllers/admin/synonym_relationships_controller_spec.rb @@ -7,6 +7,7 @@ let(:taxon_concept) { create(:taxon_concept) } let(:synonym) { create(:taxon_concept, name_status: 'S') } + let(:synonym_relationship) do create( :taxon_relationship, diff --git a/spec/controllers/admin/taxon_commons_controller_spec.rb b/spec/controllers/admin/taxon_commons_controller_spec.rb index f75d116de..7bf1fe52d 100644 --- a/spec/controllers/admin/taxon_commons_controller_spec.rb +++ b/spec/controllers/admin/taxon_commons_controller_spec.rb @@ -125,8 +125,7 @@ end end - describe "ChangeObserver updates TaxonConcept's dependents_updated_at - when TaxonCommon is changed" do + describe "ChangeObserver updates TaxonConcept's dependents_updated_at when TaxonCommon is changed" do before do @taxon_common = create( :taxon_common, @@ -159,8 +158,7 @@ expect(@taxon_concept.reload.dependents_updated_at).not_to eq(old_date) end - it "updates associated @taxon_concept's - dependents_updated_at when taxon common is deleted" do + it "updates associated @taxon_concept's dependents_updated_at when taxon common is deleted" do expect(@taxon_concept.dependents_updated_at).to be_nil # it gets updated by the creation of the taxon_common diff --git a/spec/controllers/admin/taxon_eu_suspensions_controller_spec.rb b/spec/controllers/admin/taxon_eu_suspensions_controller_spec.rb index 6c38809c9..81bee540d 100644 --- a/spec/controllers/admin/taxon_eu_suspensions_controller_spec.rb +++ b/spec/controllers/admin/taxon_eu_suspensions_controller_spec.rb @@ -214,6 +214,7 @@ describe 'Authorization for contributors' do login_contributor + let!(:eu_suspension) do create( :eu_suspension, diff --git a/spec/controllers/admin/taxon_relationships_controller_spec.rb b/spec/controllers/admin/taxon_relationships_controller_spec.rb index 5487ee1b9..8a7e0f827 100644 --- a/spec/controllers/admin/taxon_relationships_controller_spec.rb +++ b/spec/controllers/admin/taxon_relationships_controller_spec.rb @@ -59,9 +59,11 @@ let(:taxon_concept) do create_cites_eu_species end + let(:other_taxon_concept) do create_cms_species end + let!(:rel) do create( :taxon_relationship, @@ -92,9 +94,11 @@ let(:taxon_concept) do create_cites_eu_species end + let(:other_taxon_concept) do create_cites_eu_species(name_status: 'S') end + let!(:rel) do create( :taxon_relationship, diff --git a/spec/controllers/admin/taxonomies_controller_spec.rb b/spec/controllers/admin/taxonomies_controller_spec.rb index 6b8ebdfb4..4d55f416b 100644 --- a/spec/controllers/admin/taxonomies_controller_spec.rb +++ b/spec/controllers/admin/taxonomies_controller_spec.rb @@ -67,6 +67,7 @@ describe 'Authorization for contributors' do login_contributor + describe 'GET index' do it 'redirects to admin root' do get :index diff --git a/spec/controllers/admin/trade_names_relationships_controller_spec.rb b/spec/controllers/admin/trade_names_relationships_controller_spec.rb index 31ef0870e..f898ada5b 100644 --- a/spec/controllers/admin/trade_names_relationships_controller_spec.rb +++ b/spec/controllers/admin/trade_names_relationships_controller_spec.rb @@ -7,6 +7,7 @@ let(:taxon_concept) { create(:taxon_concept) } let(:trade_name) { create(:taxon_concept, name_status: 'T') } + let(:trade_name_relationship) do create( :taxon_relationship, diff --git a/spec/controllers/api/auto_complete_taxon_concepts_controller_spec.rb b/spec/controllers/api/auto_complete_taxon_concepts_controller_spec.rb index 72f950b12..0fa345d0c 100644 --- a/spec/controllers/api/auto_complete_taxon_concepts_controller_spec.rb +++ b/spec/controllers/api/auto_complete_taxon_concepts_controller_spec.rb @@ -94,7 +94,6 @@ ) end - it 'returns no results when searching for single letter' do get :index, params: { taxonomy: 'CITES', taxon_concept_query: 'B' } diff --git a/spec/controllers/api/document_geo_entities_controller_spec.rb b/spec/controllers/api/document_geo_entities_controller_spec.rb index 8034e8891..1f0fbbd89 100644 --- a/spec/controllers/api/document_geo_entities_controller_spec.rb +++ b/spec/controllers/api/document_geo_entities_controller_spec.rb @@ -3,6 +3,7 @@ describe Api::V1::DocumentGeoEntitiesController do context 'when searching by taxon concept name' do include_context 'Canis lupus' + let!(:document_about_wolf_in_poland) do d = create(:document) c = create(:document_citation, document: d) @@ -10,12 +11,14 @@ create(:document_citation_geo_entity, geo_entity: poland, document_citation: c) d end + let!(:document_not_about_wolf_not_in_poland) do d = create(:document) c = create(:document_citation, document: d) create(:document_citation_geo_entity, geo_entity: nepal, document_citation: c) d end + let!(:document_not_about_wolf_in_poland) do d = create(:document) c = create(:document_citation, document: d) diff --git a/spec/controllers/api/documents_controller_spec.rb b/spec/controllers/api/documents_controller_spec.rb index 531d9df5a..9b3570a57 100644 --- a/spec/controllers/api/documents_controller_spec.rb +++ b/spec/controllers/api/documents_controller_spec.rb @@ -39,6 +39,7 @@ def get_all_documents get :index, params: { taxon_concept_id: @taxon_concept.id } expect(response.body).to have_json_size(4).at_path('documents') end + context 'GET index contributor' do login_contributor @@ -61,6 +62,7 @@ def get_public_documents get :index, params: { taxon_concept_id: @taxon_concept.id } expect(response.body).to have_json_size(3).at_path('documents') end + context 'GET index api user' do login_api_user @@ -81,6 +83,7 @@ def get_public_documents get :index, params: { taxon_concept_id: @taxon_concept.id } expect(response.body).to have_json_size(3).at_path('documents') end + context 'GET index api user' do login_secretariat_user @@ -92,6 +95,7 @@ def get_public_documents context 'show action fails' do login_api_user + it 'returns 403 status when permission denied' do get :show, params: { id: @document2.id } expect(response).to have_http_status(:forbidden) diff --git a/spec/controllers/api/geo_entities_controller_spec.rb b/spec/controllers/api/geo_entities_controller_spec.rb index bed3b896b..dd3250845 100644 --- a/spec/controllers/api/geo_entities_controller_spec.rb +++ b/spec/controllers/api/geo_entities_controller_spec.rb @@ -8,6 +8,7 @@ name: 'Europe' ) end + let!(:france) do create( :geo_entity, @@ -17,6 +18,7 @@ designations: [ cites ] ) end + let!(:andorra) do create( :geo_entity, @@ -25,6 +27,7 @@ iso_code2: 'AD' ) end + let!(:french_guiana) do create( :geo_entity, diff --git a/spec/controllers/api/taxon_concepts_controller_spec.rb b/spec/controllers/api/taxon_concepts_controller_spec.rb index 54e910579..6c5851808 100644 --- a/spec/controllers/api/taxon_concepts_controller_spec.rb +++ b/spec/controllers/api/taxon_concepts_controller_spec.rb @@ -95,6 +95,7 @@ let!(:taxon_concept) do create(:taxon_concept) end + let!(:m_taxon_concept) do taxon_concept.m_taxon_concept end diff --git a/spec/controllers/checklist/geo_entities_controller_spec.rb b/spec/controllers/checklist/geo_entities_controller_spec.rb index 0c27341ae..351a642db 100644 --- a/spec/controllers/checklist/geo_entities_controller_spec.rb +++ b/spec/controllers/checklist/geo_entities_controller_spec.rb @@ -8,6 +8,7 @@ name: 'Europe' ) end + let!(:france) do create( :geo_entity, @@ -17,6 +18,7 @@ designations: [ cites ] ) end + let!(:andorra) do create( :geo_entity, @@ -25,6 +27,7 @@ iso_code2: 'AD' ) end + let!(:french_guiana) do create( :geo_entity, diff --git a/spec/controllers/checklist/taxon_concepts_controller_spec.rb b/spec/controllers/checklist/taxon_concepts_controller_spec.rb index 1ab4791ed..bf69714e6 100644 --- a/spec/controllers/checklist/taxon_concepts_controller_spec.rb +++ b/spec/controllers/checklist/taxon_concepts_controller_spec.rb @@ -2,6 +2,7 @@ describe Checklist::TaxonConceptsController do describe 'XHR GET JSON autocomplete' do include_context 'Arctocephalus' + context 'when searching by accepted name' do it 'returns 1 result' do get :autocomplete, format: 'json', xhr: true, diff --git a/spec/controllers/cites_trade/exports_controller_spec.rb b/spec/controllers/cites_trade/exports_controller_spec.rb index 751fa379d..db424dd03 100644 --- a/spec/controllers/cites_trade/exports_controller_spec.rb +++ b/spec/controllers/cites_trade/exports_controller_spec.rb @@ -28,6 +28,7 @@ allow_any_instance_of(Trade::ShipmentsExport).to receive(:public_file_name).and_return('shipments.csv') allow(Trade::TradeDataDownloadLogger).to receive(:city_country_from).and_return([ 'Cambridge', 'United Kingdom' ]) allow(Trade::TradeDataDownloadLogger).to receive(:organization_from).and_return('UNEP-WCMC') + expect do get :download, params: { filters: { diff --git a/spec/controllers/species/exports_controller_spec.rb b/spec/controllers/species/exports_controller_spec.rb index 2dd5c53ce..52dd0ef8a 100644 --- a/spec/controllers/species/exports_controller_spec.rb +++ b/spec/controllers/species/exports_controller_spec.rb @@ -96,6 +96,7 @@ # get :download, :data_type => 'Listings', :filters => {:designation => 'CITES'}, :format => :json # parse_json(response.body)['total'].should == 1 # end + # it "returns listed species file" do # create_cites_I_addition(:taxon_concept => create_cites_eu_species, :is_current => true) # SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings @@ -104,11 +105,14 @@ # response.content_type.should eq("text/csv") # response.headers["Content-Disposition"].should eq("attachment; filename=\"cites_listings.csv\"") # end + # it "redirects when no results" do # get :download, :data_type => 'Listings', :filters => {:designation => 'CITES'} # response.should redirect_to(species_exports_path) # end + # end + # context "EU listings" do # after(:each){ DownloadsCache.clear_eu_listings } # it "returns count of listed species" do @@ -117,6 +121,7 @@ # get :download, :data_type => 'Listings', :filters => {:designation => 'EU'}, :format => :json # parse_json(response.body)['total'].should == 1 # end + # it "returns listed species file" do # create_eu_A_addition(:taxon_concept => create_cites_eu_species, :event =>reg2013, :effective_at => '2013-08-10', :is_current => true) # SapiModule::StoredProcedures.rebuild_eu_taxonomy_and_listings @@ -125,11 +130,14 @@ # response.content_type.should eq("text/csv") # response.headers["Content-Disposition"].should eq("attachment; filename=\"eu_listings.csv\"") # end + # it "redirects when no results" do # get :download, :data_type => 'Listings', :filters => {:designation => 'EU'} # response.should redirect_to(species_exports_path) # end + # end + # context "CMS listings" do # after(:each){ DownloadsCache.clear_cms_listings } # it "returns count of listed species" do @@ -138,6 +146,7 @@ # get :download, :data_type => 'Listings', :filters => {:designation => 'CMS'}, :format => :json # parse_json(response.body)['total'].should == 1 # end + # it "returns listed species file" do # create_cms_I_addition(:taxon_concept => create_cms_species, :is_current => true) # SapiModule::StoredProcedures.rebuild_cms_taxonomy_and_listings @@ -146,10 +155,14 @@ # response.content_type.should eq("text/csv") # response.headers["Content-Disposition"].should eq("attachment; filename=\"cms_listings.csv\"") # end + # it "redirects when no results" do # get :download, :data_type => 'Listings', :filters => {:designation => 'CMS'} # response.should redirect_to(species_exports_path) # end + # end + # end + # end diff --git a/spec/controllers/trade/annual_report_uploads_controller_spec.rb b/spec/controllers/trade/annual_report_uploads_controller_spec.rb index 40208c3d4..901edef07 100644 --- a/spec/controllers/trade/annual_report_uploads_controller_spec.rb +++ b/spec/controllers/trade/annual_report_uploads_controller_spec.rb @@ -11,6 +11,7 @@ iso_code2: 'FR' ) end + let(:annual_report_upload) do create( :annual_report_upload, diff --git a/spec/controllers/trade/exports_controller_spec.rb b/spec/controllers/trade/exports_controller_spec.rb index 2afa69504..c9c5a6451 100644 --- a/spec/controllers/trade/exports_controller_spec.rb +++ b/spec/controllers/trade/exports_controller_spec.rb @@ -14,6 +14,7 @@ it 'does not log download information from the admin interface' do create(:shipment) allow_any_instance_of(Trade::ShipmentsExport).to receive(:public_file_name).and_return('shipments.csv') + expect do get :download, params: { filters: { diff --git a/spec/controllers/trade/validation_errors_controller_spec.rb b/spec/controllers/trade/validation_errors_controller_spec.rb index 7a86af47e..9ce89b90b 100644 --- a/spec/controllers/trade/validation_errors_controller_spec.rb +++ b/spec/controllers/trade/validation_errors_controller_spec.rb @@ -8,15 +8,19 @@ aru.save(validate: false) aru end + let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end + let!(:shipment) do sandbox_klass.create(taxon_name: 'Caniis lupus') end + let(:validation_rule) do create_taxon_concept_validation end + let!(:validation_error) do create( :validation_error, diff --git a/spec/factories.rb b/spec/factories.rb index ee7aef8c3..bd4baa069 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -37,6 +37,7 @@ factory :eu_regulation, class: 'EuRegulation' do end_date { '2012-01-01' } end + factory :eu_suspension_regulation, class: 'EuSuspensionRegulation' factory :eu_implementing_regulation, class: 'EuImplementingRegulation' factory :eu_council_regulation, class: 'EuCouncilRegulation' diff --git a/spec/factories/document_tag.rb b/spec/factories/document_tag.rb index ce2ecccd3..7b1836b68 100644 --- a/spec/factories/document_tag.rb +++ b/spec/factories/document_tag.rb @@ -1,12 +1,15 @@ FactoryBot.define do factory :document_tag do name { 'You taaaag' } + factory :review_phase, class: 'DocumentTag::ReviewPhase' do type { 'DocumentTag::ReviewPhase' } end + factory :process_stage, class: 'DocumentTag::ProcessStage' do type { 'DocumentTag::ProcessStage' } end + factory :proposal_outcome, class: 'DocumentTag::ProposalOutcome' do type { 'DocumentTag::ProposalOutcome' } end diff --git a/spec/factories/documents.rb b/spec/factories/documents.rb index 28c5c96fa..fa37ec6c5 100644 --- a/spec/factories/documents.rb +++ b/spec/factories/documents.rb @@ -10,9 +10,11 @@ factory :review_of_significant_trade, class: 'Document::ReviewOfSignificantTrade' do type { 'Document::ReviewOfSignificantTrade' } end + factory :proposal, class: 'Document::Proposal' do type { 'Document::Proposal' } end + factory :commission_note, class: 'Document::CommissionNotes' do type { 'Document::CommissionNotes' } end diff --git a/spec/factories/nomenclature_changes.rb b/spec/factories/nomenclature_changes.rb index 64601669e..4a662f102 100644 --- a/spec/factories/nomenclature_changes.rb +++ b/spec/factories/nomenclature_changes.rb @@ -7,15 +7,19 @@ factory :nomenclature_change_split, class: 'NomenclatureChange::Split' do type { 'NomenclatureChange::Split' } end + factory :nomenclature_change_lump, class: 'NomenclatureChange::Lump' do type { 'NomenclatureChange::Lump' } end + factory :nomenclature_change_status_swap, class: 'NomenclatureChange::StatusSwap' do type { 'NomenclatureChange::StatusSwap' } end + factory :nomenclature_change_status_to_accepted, class: 'NomenclatureChange::StatusToAccepted' do type { 'NomenclatureChange::StatusToAccepted' } end + factory :nomenclature_change_status_to_synonym, class: 'NomenclatureChange::StatusToSynonym' do type { 'NomenclatureChange::StatusToSynonym' } end @@ -42,17 +46,21 @@ factory :nomenclature_change_parent_reassignment do type { 'NomenclatureChange::ParentReassignment' } end + factory :nomenclature_change_name_reassignment do type { 'NomenclatureChange::NameReassignment' } reassignable_type { 'TaxonRelationship' } end + factory :nomenclature_change_distribution_reassignment do type { 'NomenclatureChange::DistributionReassignment' } reassignable_type { 'Distribution' } end + factory :nomenclature_change_legislation_reassignment do type { 'NomenclatureChange::LegislationReassignment' } end + factory :nomenclature_change_document_citation_reassignment do type { 'NomenclatureChange::DocumentCitationReassignment' } end @@ -67,14 +75,17 @@ factory :nomenclature_change_output_parent_reassignment do type { 'NomenclatureChange::OutputParentReassignment' } end + factory :nomenclature_change_output_name_reassignment do type { 'NomenclatureChange::OutputNameReassignment' } reassignable_type { 'TaxonRelationship' } end + factory :nomenclature_change_output_distribution_reassignment do type { 'NomenclatureChange::OutputDistributionReassignment' } reassignable_type { 'Distribution' } end + factory :nomenclature_change_output_legislation_reassignment do type { 'NomenclatureChange::OutputLegislationReassignment' } end diff --git a/spec/factories/ranks.rb b/spec/factories/ranks.rb index 6e2dedf8d..230d33081 100644 --- a/spec/factories/ranks.rb +++ b/spec/factories/ranks.rb @@ -58,6 +58,7 @@ def attributes_for_variety Rank::VARIETY ].sample end + display_name_en { |r| r.name } initialize_with { Rank.find_by(name: name) || new(attributes_for_rank(name)) } end diff --git a/spec/factories/taxon_concepts.rb b/spec/factories/taxon_concepts.rb index 54e077a43..20a99a2eb 100644 --- a/spec/factories/taxon_concepts.rb +++ b/spec/factories/taxon_concepts.rb @@ -7,6 +7,7 @@ name_status { 'A' } data { } listing { } + before(:create) do |tc| if tc.parent.nil? && [ 'A', 'N' ].include?(tc.name_status) && tc.rank.try(:name) != 'KINGDOM' tc.parent = create( diff --git a/spec/factories/trade.rb b/spec/factories/trade.rb index ec361adc8..1e22d1a88 100644 --- a/spec/factories/trade.rb +++ b/spec/factories/trade.rb @@ -31,17 +31,21 @@ run_order { 1 } factory :presence_validation_rule, class: 'Trade::PresenceValidationRule' factory :numericality_validation_rule, class: 'Trade::NumericalityValidationRule' + factory :format_validation_rule, class: 'Trade::FormatValidationRule' do format_re { '^\w+$' } end + factory :inclusion_validation_rule, class: 'Trade::InclusionValidationRule' do valid_values_view { 'valid_taxon_concept_view' } end + factory :taxon_concept_appendix_year_validation_rule, class: 'Trade::TaxonConceptAppendixYearValidationRule' do column_names { [ 'taxon_concept_id', 'appendix', 'year' ] } valid_values_view { 'valid_taxon_concept_appendix_year_mview' } end + factory :distinct_values_validation_rule, class: 'Trade::DistinctValuesValidationRule' factory :taxon_concept_source_validation_rule, diff --git a/spec/helpers/admin/nomenclature_changes_helper_spec.rb b/spec/helpers/admin/nomenclature_changes_helper_spec.rb index c1065961b..e50870cba 100644 --- a/spec/helpers/admin/nomenclature_changes_helper_spec.rb +++ b/spec/helpers/admin/nomenclature_changes_helper_spec.rb @@ -8,11 +8,15 @@ # it "concats two strings with spaces" do # helper.concat_strings("this","that").should == "this that" # end + # end + # end + describe Admin::NomenclatureChangesHelper do describe 'split_blurb' do include_context 'split_definitions' + context 'split with input' do before { @nomenclature_change = split_with_input } @@ -34,6 +38,7 @@ describe 'lump_blurb' do include_context 'lump_definitions' + context 'lump with inputs' do before { @nomenclature_change = lump_with_inputs } @@ -55,6 +60,7 @@ describe 'status_change_blurb' do include_context 'status_change_definitions' + context 'status upgrade with primary output' do before { @nomenclature_change = t_to_a_with_primary_output } diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb index fcd0a3234..dbce9b707 100644 --- a/spec/helpers/admin_helper_spec.rb +++ b/spec/helpers/admin_helper_spec.rb @@ -8,8 +8,11 @@ # it "concats two strings with spaces" do # helper.concat_strings("this","that").should == "this that" # end + # end + # end + describe AdminHelper do describe 'edit_icon' do it 'ouputs pencil icon for edit' do diff --git a/spec/helpers/listing_changes_helper_spec.rb b/spec/helpers/listing_changes_helper_spec.rb index 566125da8..b008b6472 100644 --- a/spec/helpers/listing_changes_helper_spec.rb +++ b/spec/helpers/listing_changes_helper_spec.rb @@ -8,17 +8,22 @@ # it "concats two strings with spaces" do # helper.concat_strings("this","that").should == "this that" # end + # end + # end + describe ListingChangesHelper do let(:poland) do GeoEntity.find_by(iso_code2: 'PL') || create(:geo_entity, iso_code2: 'PL', name: 'Poland') end + let(:taxon_concept) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Foobarus') ) end + let(:annotation) do create( :annotation, @@ -26,6 +31,7 @@ full_note_en: 'Only population of Poland' ) end + let(:hash_annotation) do create( :annotation, @@ -34,6 +40,7 @@ full_note_en: 'Only seeds and roots.' ) end + let(:listing_change) do create_cites_I_addition( taxon_concept_id: taxon_concept.id, @@ -87,6 +94,7 @@ taxon_concept_id: listing_change.taxon_concept_id ) end + let!(:listing_distribution) do create( :listing_distribution, diff --git a/spec/models/annotation_spec.rb b/spec/models/annotation_spec.rb index 856fce472..ad35b37c5 100644 --- a/spec/models/annotation_spec.rb +++ b/spec/models/annotation_spec.rb @@ -26,6 +26,7 @@ context 'when event given' do let(:event) { create_cites_cop(name: 'CoP1') } + let(:annotation) do create(:annotation, event_id: event.id, symbol: '#1') end diff --git a/spec/models/document_spec.rb b/spec/models/document_spec.rb index b45453775..6ae5a7aba 100644 --- a/spec/models/document_spec.rb +++ b/spec/models/document_spec.rb @@ -22,6 +22,7 @@ context 'when specified designation conflicts with event' do let(:cites_cop) { create_cites_cop } + let(:document) do create(:document, event: cites_cop, designation: eu) end @@ -32,6 +33,7 @@ context 'when documents with same language and same primary document' do let(:language) { create(:language) } let(:primary_document) { create(:document) } + let!(:document1) do create( :document, language_id: language.id, @@ -55,6 +57,7 @@ let(:primary_document) do create(:proposal, sort_index: 1) end + let!(:secondary_document) do create( :proposal, @@ -82,6 +85,7 @@ let(:primary_document) do create(:proposal) end + let!(:secondary_document) do create(:proposal, primary_language_document_id: primary_document.id) end diff --git a/spec/models/eu_decision_spec.rb b/spec/models/eu_decision_spec.rb index 164d55ebc..bd2263067 100644 --- a/spec/models/eu_decision_spec.rb +++ b/spec/models/eu_decision_spec.rb @@ -53,7 +53,6 @@ ).export end - specify { expect(subject).not_to be_empty } end end @@ -64,7 +63,6 @@ let(:eu_decision) { build(:eu_decision, srg_history_id: nil, eu_decision_type_id: nil) } - specify { expect(subject).to be_falsey } it 'has an error message' do @@ -104,7 +102,6 @@ Species::EuDecisionsExport.new(set: 'current', decision_types: {}).export end - specify { expect(subject).to be_empty } end end diff --git a/spec/models/eu_decisions/eu_suspension_spec.rb b/spec/models/eu_decisions/eu_suspension_spec.rb index 4dc44952d..4117ec29b 100644 --- a/spec/models/eu_decisions/eu_suspension_spec.rb +++ b/spec/models/eu_decisions/eu_suspension_spec.rb @@ -73,6 +73,7 @@ let(:start_event) do create(:event, effective_at: 2.days.from_now) end + let(:eu_suspension) do create(:eu_suspension, start_event: start_event, end_event: nil) end @@ -84,6 +85,7 @@ let(:start_event) do create(:event, effective_at: 2.days.ago, is_current: false) end + let(:eu_suspension) do create(:eu_suspension, start_event: start_event, end_event: nil) end @@ -95,9 +97,11 @@ let(:start_event) do create(:event, effective_at: Date.today, is_current: true) end + let(:start_event2) do create(:event, effective_at: 1.day.ago, is_current: true) end + let(:eu_suspension) do create(:eu_suspension, start_event: start_event, end_event: nil) end @@ -114,6 +118,7 @@ let(:end_event) do create(:event, effective_at: Date.today) end + let(:eu_suspension) do create(:eu_suspension, start_event: nil, end_event: end_event) end @@ -125,9 +130,11 @@ let(:end_event) do create(:event, effective_at: Date.today) end + let(:start_event) do create(:event, effective_at: 1.day.from_now) end + let(:eu_suspension) do create(:eu_suspension, start_event: start_event, end_event: end_event) end @@ -139,9 +146,11 @@ let(:end_event) do create(:event, effective_at: 1.day.from_now) end + let(:start_event) do create(:event, effective_at: 1.day.ago, is_current: true) end + let(:eu_suspension) do create(:eu_suspension, start_event: start_event, end_event: end_event) end @@ -153,9 +162,11 @@ let(:end_event) do create(:event, effective_at: 1.day.ago) end + let(:start_event) do create(:event, effective_at: 2.days.ago) end + let(:eu_suspension) do create(:eu_suspension, start_event: start_event, end_event: end_event) end @@ -177,6 +188,7 @@ let(:eu_suspension) do create(:eu_suspension, start_event: start_event) end + let(:start_event) do create(:event, effective_at: 2.days.ago) end @@ -198,6 +210,7 @@ let(:eu_suspension) do create(:eu_suspension, end_event: end_event) end + let(:end_event) do create(:event, effective_at: 2.days.ago) end diff --git a/spec/models/events/cites_cop_spec.rb b/spec/models/events/cites_cop_spec.rb index f1ff4cae6..0176787af 100644 --- a/spec/models/events/cites_cop_spec.rb +++ b/spec/models/events/cites_cop_spec.rb @@ -72,6 +72,7 @@ context 'when listing change and annotation' do let!(:annotation) { create(:annotation, event: cites_cop) } + let!(:listing_change) do create_cites_I_addition( event: cites_cop, @@ -84,6 +85,7 @@ context 'when listing change and hash annotation' do let!(:hash_annotation) { create(:annotation, event: cites_cop) } + let!(:listing_change) do create_cites_I_addition( event: cites_cop, diff --git a/spec/models/events/cites_suspension_notification_spec.rb b/spec/models/events/cites_suspension_notification_spec.rb index 56e802c84..4bcf273d0 100644 --- a/spec/models/events/cites_suspension_notification_spec.rb +++ b/spec/models/events/cites_suspension_notification_spec.rb @@ -104,7 +104,6 @@ suspension end - specify do cites_suspension_notification.destroy expect(subject.reload).to be_empty @@ -126,7 +125,6 @@ let!(:cites_suspension_notification2) { create_cites_suspension_notification(subtype: 'A') } let!(:cites_suspension_notification3) { create_cites_suspension_notification(subtype: 'B') } - specify { subject.length == 2 } end end diff --git a/spec/models/events/eu_regulation_spec.rb b/spec/models/events/eu_regulation_spec.rb index 5f1bf890b..7d4321378 100644 --- a/spec/models/events/eu_regulation_spec.rb +++ b/spec/models/events/eu_regulation_spec.rb @@ -107,6 +107,7 @@ context 'when listing change and annotation' do let!(:annotation) { create(:annotation, event: eu_regulation) } + let!(:listing_change) do create_eu_A_addition( event: eu_regulation, @@ -119,6 +120,7 @@ context 'when listing change and hash annotation' do let!(:hash_annotation) { create(:annotation, event: eu_regulation) } + let!(:listing_change) do create_eu_A_addition( event: eu_regulation, diff --git a/spec/models/geo_entity_spec.rb b/spec/models/geo_entity_spec.rb index 449519c8f..a05c6613c 100644 --- a/spec/models/geo_entity_spec.rb +++ b/spec/models/geo_entity_spec.rb @@ -9,6 +9,7 @@ name: 'Europe' ) end + let(:poland) do create( :geo_entity, @@ -17,6 +18,7 @@ iso_code2: 'PL' ) end + let(:wolin) do create( :geo_entity, @@ -36,6 +38,7 @@ related_geo_entity: wolin ) end + let!(:europe_contains_poland) do create( :geo_relationship, @@ -45,7 +48,6 @@ ) end - specify { expect(subject.map(&:id)).to include(europe.id, poland.id, wolin.id) } specify { expect(subject.size).to eq(3) } end diff --git a/spec/models/hybrid_relationship_spec.rb b/spec/models/hybrid_relationship_spec.rb index 98b66eb85..c26659e5e 100644 --- a/spec/models/hybrid_relationship_spec.rb +++ b/spec/models/hybrid_relationship_spec.rb @@ -7,12 +7,14 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let!(:tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolatus') ) end + let!(:another_tc) do create_cites_eu_species( parent_id: parent.id, @@ -27,6 +29,7 @@ scientific_name: 'Lolcatus lolatus x lolcatus' ) end + let(:another_hybrid) do create_cites_eu_species( name_status: 'H', @@ -34,6 +37,7 @@ scientific_name: 'Lolcatus lolcatus x ?' ) end + let(:hybrid_rel) do build( :taxon_relationship, @@ -42,6 +46,7 @@ other_taxon_concept_id: hybrid.id ) end + let(:another_hybrid_rel) do build( :taxon_relationship, diff --git a/spec/models/listing_change_spec.rb b/spec/models/listing_change_spec.rb index cc8fd8806..48180d885 100644 --- a/spec/models/listing_change_spec.rb +++ b/spec/models/listing_change_spec.rb @@ -7,6 +7,7 @@ let!(:exception_type) { cites_exception } let(:taxon_concept) { create_cites_eu_species } let(:excluded_taxon_concept) { create_cites_eu_subspecies(parent: taxon_concept) } + let(:listing_change) do build( :listing_change, @@ -23,6 +24,7 @@ context 'inclusion taxon concept is lower rank' do let(:inclusion) { create_cites_eu_subspecies } let(:taxon_concept) { create_cites_eu_species } + let(:listing_change) do build( :listing_change, @@ -37,6 +39,7 @@ context 'species listing designation mismatch' do let(:designation1) { create(:designation) } let(:designation2) { create(:designation) } + let(:listing_change) do build( :listing_change, @@ -51,6 +54,7 @@ context 'event designation mismatch' do let(:designation1) { create(:designation) } let(:designation2) { create(:designation) } + let(:listing_change) do build( :listing_change, @@ -76,6 +80,7 @@ lc.annotation = create(:annotation, full_note_en: ' ') lc end + let(:lc2) do lc = create_cites_I_addition(effective_at: '2014-11-17') lc.annotation = create(:annotation, full_note_en: nil) diff --git a/spec/models/nomenclature_change/output_spec.rb b/spec/models/nomenclature_change/output_spec.rb index 7888fbfed..b33067869 100644 --- a/spec/models/nomenclature_change/output_spec.rb +++ b/spec/models/nomenclature_change/output_spec.rb @@ -46,6 +46,7 @@ context 'when taxon concept specified' do let(:tc) { create_cites_eu_species } + let(:output) do create(:nomenclature_change_output, taxon_concept_id: tc.id) end @@ -62,34 +63,40 @@ let(:output) do create(:nomenclature_change_output, taxon_concept_id: tc.id) end + let(:canis_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Canis') ) end + let(:canis_species) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'lupus'), parent: canis_genus ) end + let(:canis_subspecies) do create_cites_eu_subspecies( taxon_name: create(:taxon_name, scientific_name: 'dingo'), parent: canis_species ) end + let(:magnolia_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Magnolia') ) end + let(:magnolia_species) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'liliifera'), parent: magnolia_genus ) end + let(:magnolia_variety) do create_cites_eu_variety( taxon_name: create(:taxon_name, scientific_name: 'var. obovata'), diff --git a/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb index 155adcf63..fb9048983 100644 --- a/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/common_name_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ reassignable_type: 'TaxonCommon' ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -13,6 +14,7 @@ output: output ) end + before do 2.times { create(:taxon_common, taxon_concept: input_species) } processor.run diff --git a/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb index 4ec587ff3..8e45aff98 100644 --- a/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/distribution_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ reassignable_type: 'Distribution' ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -13,6 +14,7 @@ output: output ) end + let(:poland) do create( :geo_entity, @@ -20,6 +22,7 @@ iso_code2: 'PL' ) end + let(:italy) do create( :geo_entity, @@ -27,6 +30,7 @@ iso_code2: 'IT' ) end + let(:united_kingdom) do create( :geo_entity, @@ -34,6 +38,7 @@ iso_code2: 'UK' ) end + before do original_d = create( :distribution, diff --git a/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb index ea49edc5e..53d1f6ce2 100644 --- a/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/document_reassignments_processor_examples.rb @@ -27,6 +27,7 @@ def create_citation(taxon_concepts_ary, geo_entities_ary, document = nil) end let!(:citation) { create_citation([ input_species ], [ poland ]) } + let(:reassignment) do create( :nomenclature_change_document_citation_reassignment, diff --git a/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb index 7b5769e42..2aac40dd5 100644 --- a/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/legislation_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ iso_code2: 'PL' ) end + let(:portugal) do create( :geo_entity, @@ -13,6 +14,7 @@ iso_code2: 'PT' ) end + before do lc1_annotation = create(:annotation) original_lc1 = create_cites_III_addition( diff --git a/spec/models/nomenclature_change/shared/lump_definitions.rb b/spec/models/nomenclature_change/shared/lump_definitions.rb index ac5bb5cd4..0b20b4a62 100644 --- a/spec/models/nomenclature_change/shared/lump_definitions.rb +++ b/spec/models/nomenclature_change/shared/lump_definitions.rb @@ -3,11 +3,13 @@ let(:input_species1) { input_species } let(:input_species2) { create_cites_eu_species } let(:output_species) { create_cites_eu_species } + let(:errorus_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Errorus') ) end + let(:output_subspecies) do create_cites_eu_subspecies( taxon_name: create(:taxon_name, scientific_name: 'fatalus'), @@ -17,6 +19,7 @@ ) ) end + let(:lump_with_inputs) do create( :nomenclature_change_lump, @@ -26,9 +29,11 @@ } ) end + let(:lump_with_inputs_and_output) do lump_with_inputs_and_output_existing_taxon end + let(:lump_with_inputs_and_same_output) do create( :nomenclature_change_lump, @@ -42,6 +47,7 @@ status: NomenclatureChange::Lump::OUTPUTS ) end + let(:lump_with_inputs_and_output_existing_taxon) do create( :nomenclature_change_lump, @@ -55,6 +61,7 @@ status: NomenclatureChange::Lump::OUTPUTS ) end + let(:lump_with_inputs_and_output_new_taxon) do create( :nomenclature_change_lump, @@ -70,6 +77,7 @@ status: NomenclatureChange::Lump::OUTPUTS ) end + let(:lump_with_inputs_and_output_status_change) do create( :nomenclature_change_lump, @@ -83,6 +91,7 @@ status: NomenclatureChange::Lump::OUTPUTS ) end + let(:lump_with_inputs_and_output_name_change) do create( :nomenclature_change_lump, diff --git a/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb b/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb index 3c29cc5e4..3313a9a8a 100644 --- a/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb +++ b/spec/models/nomenclature_change/shared/name_reassignments_constructor_examples.rb @@ -7,6 +7,7 @@ context 'when names' do let(:input_species) do s = create_cites_eu_species + 2.times do create( :taxon_relationship, @@ -15,6 +16,7 @@ taxon_relationship_type: synonym_relationship_type ) end + s end diff --git a/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb index 153be994a..3a50ed537 100644 --- a/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/name_reassignments_processor_examples.rb @@ -2,6 +2,7 @@ let(:input_species_synonym) do create_cites_eu_species(name_status: 'S') end + let(:input_species_synonym_rel) do create( :taxon_relationship, @@ -10,6 +11,7 @@ other_taxon_concept: input_species_synonym ) end + let(:reassignment) do create( :nomenclature_change_name_reassignment, @@ -17,6 +19,7 @@ reassignable_id: input_species_synonym_rel.id ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -24,6 +27,7 @@ output: output ) end + before do processor.run end diff --git a/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb index 53129eaa9..7cae70939 100644 --- a/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_distribution_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ iso_code2: 'PL' ) end + before do create(:preset_tag, model: 'Distribution', name: 'extinct') d = create( diff --git a/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb index 76037cb13..f3805f1fc 100644 --- a/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_document_reassignments_processor_examples.rb @@ -10,6 +10,7 @@ ) citation end + before do create( :nomenclature_change_output_reassignment, diff --git a/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb index 72dd6b792..16a11b6ff 100644 --- a/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_legislation_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ iso_code2: 'PL' ) end + let(:portugal) do create( :geo_entity, @@ -13,6 +14,7 @@ iso_code2: 'PT' ) end + before do lc1_annotation = create(:annotation) lc1 = create_cites_III_addition( diff --git a/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb index 30081a2ba..46db58071 100644 --- a/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/output_name_reassignments_processor_examples.rb @@ -2,6 +2,7 @@ let(:output_subspecies2_synonym) do create_cites_eu_subspecies(name_status: 'S') end + let(:output_subspecies2_synonym_rel) do create( :taxon_relationship, @@ -10,6 +11,7 @@ other_taxon_concept: output_subspecies2_synonym ) end + before do create( :nomenclature_change_output_name_reassignment, diff --git a/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb index 11486576a..1f4022f56 100644 --- a/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/parent_reassignments_processor_examples.rb @@ -2,6 +2,7 @@ let(:input_species_child) do create_cites_eu_subspecies(parent: input_species) end + let(:reassignment) do create( :nomenclature_change_parent_reassignment, @@ -9,6 +10,7 @@ reassignable_id: input_species_child.id ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -16,6 +18,7 @@ output: output ) end + before do synonym_relationship_type processor.run diff --git a/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb index 82c3b65a6..586b8a0fb 100644 --- a/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/reference_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ reassignable_type: 'TaxonConceptReference' ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -13,6 +14,7 @@ output: output ) end + before do 2.times { create(:taxon_concept_reference, taxon_concept: input_species) } processor.run diff --git a/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb b/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb index 2edff472a..871942972 100644 --- a/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb +++ b/spec/models/nomenclature_change/shared/shipment_reassignments_processor_examples.rb @@ -6,6 +6,7 @@ reassignable_type: 'Trade::Shipment' ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -13,6 +14,7 @@ output: output ) end + before do 2.times { create(:shipment, taxon_concept: input_species) } processor.run diff --git a/spec/models/nomenclature_change/shared/split_definitions.rb b/spec/models/nomenclature_change/shared/split_definitions.rb index b59489408..df9f5861c 100644 --- a/spec/models/nomenclature_change/shared/split_definitions.rb +++ b/spec/models/nomenclature_change/shared/split_definitions.rb @@ -4,19 +4,23 @@ taxon_name: create(:taxon_name, scientific_name: 'Genus1') ) end + let(:genus2) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Genus2') ) end + let(:input_species) { create_cites_eu_species(parent: genus1) } let(:output_species1) { create_cites_eu_species(parent: genus1) } let(:output_species2) { create_cites_eu_species(parent: genus2) } + let(:errorus_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Errorus') ) end + let(:output_subspecies2) do create_cites_eu_subspecies( taxon_name: create(:taxon_name, scientific_name: 'fatalus'), @@ -26,15 +30,18 @@ ) ) end + let(:split_with_input) do create( :nomenclature_change_split, input_attributes: { taxon_concept_id: input_species.id } ) end + let(:split_with_input_and_output) do split_with_input_and_output_existing_taxon end + let(:split_with_input_and_same_output) do create( :nomenclature_change_split, @@ -46,6 +53,7 @@ status: NomenclatureChange::Split::OUTPUTS ) end + let(:split_with_input_and_output_existing_taxon) do create( :nomenclature_change_split, @@ -57,6 +65,7 @@ status: NomenclatureChange::Split::OUTPUTS ) end + let(:split_with_input_and_output_new_taxon) do create( :nomenclature_change_split, @@ -73,6 +82,7 @@ status: NomenclatureChange::Split::OUTPUTS ) end + let(:split_with_input_and_outputs_status_change) do create( :nomenclature_change_split, @@ -88,6 +98,7 @@ status: NomenclatureChange::Split::OUTPUTS ) end + let(:split_with_input_and_outputs_name_change) do create( :nomenclature_change_split, @@ -105,6 +116,7 @@ status: NomenclatureChange::Split::OUTPUTS ) end + let(:split_with_input_with_reassignments) do 2.times { create(:distribution, taxon_concept: input_species) } unreassigned_distribution = create(:distribution, taxon_concept: input_species) @@ -133,6 +145,7 @@ taxon_relationship_type: synonym_relationship_type ) end + name1 = create( :taxon_relationship, taxon_concept: input_species, diff --git a/spec/models/nomenclature_change/shared/status_change_definitions.rb b/spec/models/nomenclature_change/shared/status_change_definitions.rb index 7f4ec3089..0e8e844c4 100644 --- a/spec/models/nomenclature_change/shared/status_change_definitions.rb +++ b/spec/models/nomenclature_change/shared/status_change_definitions.rb @@ -1,6 +1,7 @@ shared_context 'status_change_definitions' do let(:input_species) { create_cites_eu_species } let(:accepted_name) { create_cites_eu_species } + let(:input_trade_name) do tc = create_cites_eu_species( name_status: 'T', @@ -14,11 +15,13 @@ ) tc end + let(:input_trade_name_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Ridiculus') ) end + let(:input_synonym) do tc = create_cites_eu_species( name_status: 'S', @@ -32,11 +35,13 @@ ) tc end + let(:input_synonym_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Confundus') ) end + let(:n_to_s_with_primary_output) do create( :nomenclature_change_status_to_synonym, @@ -48,6 +53,7 @@ status: NomenclatureChange::StatusToSynonym::PRIMARY_OUTPUT ).reload end + let(:t_to_a_with_primary_output) do create( :nomenclature_change_status_to_accepted, @@ -60,6 +66,7 @@ status: NomenclatureChange::StatusToAccepted::PRIMARY_OUTPUT ).reload end + let(:t_to_s_with_primary_and_secondary_output) do create( :nomenclature_change_status_to_synonym, @@ -75,6 +82,7 @@ status: NomenclatureChange::StatusToSynonym::RELAY ).reload end + let(:n_to_s_with_input_and_secondary_output) do create( :nomenclature_change_status_to_synonym, @@ -91,6 +99,7 @@ status: NomenclatureChange::StatusToSynonym::RELAY ).reload end + let(:a_to_s_with_swap_with_primary_output) do create( :nomenclature_change_status_swap, @@ -102,6 +111,7 @@ status: NomenclatureChange::StatusSwap::PRIMARY_OUTPUT ).reload end + let(:a_to_s_with_swap) do create( :nomenclature_change_status_swap, @@ -122,6 +132,7 @@ status: NomenclatureChange::StatusSwap::SECONDARY_OUTPUT ).reload end + let(:t_to_a_with_input) do create( :nomenclature_change_status_to_accepted, diff --git a/spec/models/synonym_relationship_spec.rb b/spec/models/synonym_relationship_spec.rb index bc3b29b57..c5553f866 100644 --- a/spec/models/synonym_relationship_spec.rb +++ b/spec/models/synonym_relationship_spec.rb @@ -7,18 +7,21 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let!(:tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolatus') ) end + let!(:another_tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolcatus') ) end + let(:synonym) do create_cites_eu_species( name_status: 'S', @@ -26,6 +29,7 @@ scientific_name: 'Lolcatus lolus' ) end + let(:another_synonym) do create_cites_eu_species( name_status: 'S', @@ -33,6 +37,7 @@ scientific_name: 'Lolcatus lolatus' ) end + let(:synonymy_rel) do build( :taxon_relationship, @@ -41,6 +46,7 @@ other_taxon_concept_id: synonym.id ) end + let(:another_synonymy_rel) do build( :taxon_relationship, diff --git a/spec/models/taxon_common_spec.rb b/spec/models/taxon_common_spec.rb index f11822d68..b4f2cfa43 100644 --- a/spec/models/taxon_common_spec.rb +++ b/spec/models/taxon_common_spec.rb @@ -5,23 +5,27 @@ let(:language) do create(:language) end + let(:parent) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let!(:tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolatus') ) end + let!(:another_tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolcatus') ) end + let(:tc_common) do build( :taxon_common, diff --git a/spec/models/taxon_concept/boa_constrictor_spec.rb b/spec/models/taxon_concept/boa_constrictor_spec.rb index 1af07d903..953fe7120 100644 --- a/spec/models/taxon_concept/boa_constrictor_spec.rb +++ b/spec/models/taxon_concept/boa_constrictor_spec.rb @@ -3,6 +3,7 @@ describe TaxonConcept do context 'Boa constrictor' do include_context 'Boa constrictor' + context 'TAXONOMY' do describe :full_name do context 'for subspecies Boa constrictor occidentalis' do diff --git a/spec/models/taxon_concept/canis_lupus_spec.rb b/spec/models/taxon_concept/canis_lupus_spec.rb index dc67e5fd0..fa341bbc7 100644 --- a/spec/models/taxon_concept/canis_lupus_spec.rb +++ b/spec/models/taxon_concept/canis_lupus_spec.rb @@ -3,6 +3,7 @@ describe TaxonConcept do context 'Canis lupus' do include_context 'Canis lupus' + context 'LISTING' do describe :cites_listing do context 'for species Canis lupus (population split listing)' do diff --git a/spec/models/taxon_concept/hybrids_spec.rb b/spec/models/taxon_concept/hybrids_spec.rb index b70cc5df5..b22372d67 100644 --- a/spec/models/taxon_concept/hybrids_spec.rb +++ b/spec/models/taxon_concept/hybrids_spec.rb @@ -9,12 +9,14 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let!(:tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolatus') ) end + let(:hybrid) do create_cites_eu_species( name_status: 'H', @@ -22,6 +24,7 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus lolcatus x lolatus') ) end + let!(:hybrid_rel) do create( :taxon_relationship, diff --git a/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb b/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb index c4902c400..bc545d9b4 100644 --- a/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb +++ b/spec/models/taxon_concept/loxodonta_africana_cms_spec.rb @@ -3,6 +3,7 @@ describe TaxonConcept do context 'Loxodonta africana CMS' do include_context 'Loxodonta africana CMS' + context 'TAXONOMY' do describe :full_name do context 'for species Loxodonta africana' do diff --git a/spec/models/taxon_concept/loxodonta_africana_spec.rb b/spec/models/taxon_concept/loxodonta_africana_spec.rb index ec129794d..b6ce97ee9 100644 --- a/spec/models/taxon_concept/loxodonta_africana_spec.rb +++ b/spec/models/taxon_concept/loxodonta_africana_spec.rb @@ -3,6 +3,7 @@ describe TaxonConcept do context 'Loxodonta africana' do include_context 'Loxodonta africana' + context 'TAXONOMY' do describe :full_name do context 'for species Loxodonta africana' do diff --git a/spec/models/taxon_concept/mellivora_capensis_spec.rb b/spec/models/taxon_concept/mellivora_capensis_spec.rb index 2c193fe37..4cd504298 100644 --- a/spec/models/taxon_concept/mellivora_capensis_spec.rb +++ b/spec/models/taxon_concept/mellivora_capensis_spec.rb @@ -3,6 +3,7 @@ describe TaxonConcept do context 'Mellivora capensis' do include_context 'Mellivora capensis' + context 'LISTING' do describe :cites_listing do context 'for species Mellivora capensis' do diff --git a/spec/models/taxon_concept/pseudomys_fieldi_spec.rb b/spec/models/taxon_concept/pseudomys_fieldi_spec.rb index f2a501237..3c9b25c86 100644 --- a/spec/models/taxon_concept/pseudomys_fieldi_spec.rb +++ b/spec/models/taxon_concept/pseudomys_fieldi_spec.rb @@ -39,9 +39,11 @@ # context "for subspecies Pseudomys fieldi preaconis" do # specify{ @subspecies.eu_show.should be_truthy } # end + # context "for species Pseudomys fieldi" do # specify{ @species.eu_show.should be_truthy } # end + # end end end diff --git a/spec/models/taxon_concept/synonyms_spec.rb b/spec/models/taxon_concept/synonyms_spec.rb index c9c48eb9b..2a1e9c545 100644 --- a/spec/models/taxon_concept/synonyms_spec.rb +++ b/spec/models/taxon_concept/synonyms_spec.rb @@ -9,12 +9,14 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let!(:tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolatus') ) end + let(:synonym) do create_cites_eu_species( name_status: 'S', @@ -22,6 +24,7 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus lolus') ) end + let!(:synonym_rel) do create( :taxon_relationship, diff --git a/spec/models/taxon_concept/tapiridae_spec.rb b/spec/models/taxon_concept/tapiridae_spec.rb index 164bd6a17..b7a6aa4aa 100644 --- a/spec/models/taxon_concept/tapiridae_spec.rb +++ b/spec/models/taxon_concept/tapiridae_spec.rb @@ -3,6 +3,7 @@ describe TaxonConcept do context 'Tapiridae' do include_context 'Tapiridae' + context 'TAXONOMY' do describe :full_name do context 'for family Tapiridae' do diff --git a/spec/models/taxon_concept/trade_names_spec.rb b/spec/models/taxon_concept/trade_names_spec.rb index 1a4e46a4d..53a3e4f3f 100644 --- a/spec/models/taxon_concept/trade_names_spec.rb +++ b/spec/models/taxon_concept/trade_names_spec.rb @@ -9,12 +9,14 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let!(:tc) do create_cites_eu_species( parent_id: parent.id, taxon_name: create(:taxon_name, scientific_name: 'lolatus') ) end + let(:trade_name) do create_cites_eu_species( name_status: 'T', @@ -22,6 +24,7 @@ taxon_name: create(:taxon_name, scientific_name: 'Lolcatus lolus') ) end + let!(:trade_name_rel) do create( :taxon_relationship, diff --git a/spec/models/taxon_concept/validation_spec.rb b/spec/models/taxon_concept/validation_spec.rb index 009c9f84c..950d2e53c 100644 --- a/spec/models/taxon_concept/validation_spec.rb +++ b/spec/models/taxon_concept/validation_spec.rb @@ -39,6 +39,7 @@ name_status: 'S' ) end + let(:tc) do build_species( taxonomy_id: cites_eu.id, @@ -67,6 +68,7 @@ parent_id: kingdom_tc.id ) end + let(:tc) do build_kingdom( taxonomy_id: cites_eu.id, @@ -103,12 +105,14 @@ context 'when full name is already given' do let(:tc_parent) { create_cites_eu_species } + let!(:tc1) do create_cites_eu_subspecies( parent: tc_parent, taxon_name: create(:taxon_name, scientific_name: 'duplicatus') ) end + let(:tc2) do build_cites_eu_subspecies( parent: tc_parent, @@ -126,18 +130,21 @@ taxon_name: create(:taxon_name, scientific_name: 'Felidae') ) end + let(:genus) do create_cites_eu_genus( parent: family, taxon_name: create(:taxon_name, scientific_name: 'Lynx') ) end + let(:species) do create_cites_eu_species( parent: genus, taxon_name: create(:taxon_name, scientific_name: 'Domesticus') ) end + let(:s_species) do create_cites_eu_species( parent: genus, @@ -173,6 +180,7 @@ taxon_name: create(:taxon_name, scientific_name: 'Canidae') ) end + let(:new_genus) do create_cites_eu_genus( parent: new_family, diff --git a/spec/models/taxon_relationship_spec.rb b/spec/models/taxon_relationship_spec.rb index 5d4c650e3..2f7198599 100644 --- a/spec/models/taxon_relationship_spec.rb +++ b/spec/models/taxon_relationship_spec.rb @@ -40,6 +40,7 @@ let(:taxon_concept) { create(:taxon_concept, taxonomy_id: taxonomy.id) } let(:taxon_concept2) { create(:taxon_concept, taxonomy_id: taxonomy2.id) } let(:taxon_relationship_type) { create(:taxon_relationship_type) } + let!(:taxon_relationship) do create( :taxon_relationship, @@ -48,6 +49,7 @@ taxon_relationship_type_id: taxon_relationship_type.id ) end + let(:taxon_relationship2) do build( :taxon_relationship, @@ -69,6 +71,7 @@ let(:taxon_concept2) { create(:taxon_concept, taxonomy_id: taxonomy2.id) } let(:taxon_relationship_type) { create(:taxon_relationship_type, is_intertaxonomic: true) } let(:taxon_relationship_type2) { create(:taxon_relationship_type, is_intertaxonomic: true) } + let!(:taxon_relationship) do create( :taxon_relationship, @@ -77,6 +80,7 @@ taxon_relationship_type_id: taxon_relationship_type.id ) end + let(:taxon_relationship2) do build( :taxon_relationship, @@ -98,6 +102,7 @@ let(:taxon_concept2) { create(:taxon_concept, taxonomy_id: taxonomy2.id) } let(:taxon_relationship_type) { create(:taxon_relationship_type, is_intertaxonomic: true) } let(:taxon_relationship_type2) { create(:taxon_relationship_type, is_intertaxonomic: true) } + let!(:taxon_relationship) do create( :taxon_relationship, @@ -129,6 +134,7 @@ let(:taxon_concept3) { create(:taxon_concept, taxonomy_id: taxonomy2.id) } let(:taxon_relationship_type) { create(:taxon_relationship_type, is_intertaxonomic: true) } let(:taxon_relationship_type2) { create(:taxon_relationship_type, is_intertaxonomic: true) } + let!(:taxon_relationship) do create( :taxon_relationship, diff --git a/spec/models/trade/annual_report_upload_spec.rb b/spec/models/trade/annual_report_upload_spec.rb index a6b91e9f6..aff6ba730 100644 --- a/spec/models/trade/annual_report_upload_spec.rb +++ b/spec/models/trade/annual_report_upload_spec.rb @@ -24,6 +24,7 @@ def invalid_file Rails.root.join('spec/support/annual_report_upload_invalid.csv').to_s ) end + describe :valid? do context 'when uploaded file as exporter with exporter column headers' do subject do @@ -87,7 +88,6 @@ def invalid_file create_year_format_validation end - specify { expect(subject.validation_errors).to be_empty } end diff --git a/spec/models/trade/distinct_values_validation_rule_spec.rb b/spec/models/trade/distinct_values_validation_rule_spec.rb index 378e432cb..1a1ac594f 100644 --- a/spec/models/trade/distinct_values_validation_rule_spec.rb +++ b/spec/models/trade/distinct_values_validation_rule_spec.rb @@ -9,6 +9,7 @@ iso_code2: 'CA' ) end + let(:argentina) do create( :geo_entity, @@ -38,7 +39,6 @@ @sandbox_klass.create(trading_partner: canada.iso_code2) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) @@ -61,7 +61,6 @@ @sandbox_klass.create(trading_partner: canada.iso_code2) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) @@ -78,7 +77,6 @@ @sandbox_klass.create(country_of_origin: canada.iso_code2) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) diff --git a/spec/models/trade/inclusion_validation_rule_spec.rb b/spec/models/trade/inclusion_validation_rule_spec.rb index 33a558242..7e9092e98 100644 --- a/spec/models/trade/inclusion_validation_rule_spec.rb +++ b/spec/models/trade/inclusion_validation_rule_spec.rb @@ -9,9 +9,11 @@ annual_report.save(validate: false) annual_report end + let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end + let(:canis_lupus) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'lupus'), @@ -99,6 +101,7 @@ travel_to(Time.now + 1) do @shipment2.update(taxon_name: 'Canis lupus') @shipment3.update(taxon_name: 'Canis lupus') + expect do validation_rule.refresh_errors_if_needed(annual_report_upload) end.to change { Trade::ValidationError.count }.by(-1) @@ -110,6 +113,7 @@ specify 'error record is updated to reflect new error_count' do travel_to(Time.now + 1) do @shipment2.update(taxon_name: 'Canis lupus') + expect do validation_rule.refresh_errors_if_needed(annual_report_upload) end.to change { @validation_error.reload.error_count }.by(-1) @@ -134,7 +138,6 @@ ) end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload)).to be_empty @@ -166,7 +169,6 @@ ) end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) @@ -204,7 +206,6 @@ sandbox_klass.create(term_code: 'CAP', unit_code: 'BAG') end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) @@ -220,7 +221,6 @@ sandbox_klass.create(term_code: 'CAP', unit_code: '') end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) @@ -246,7 +246,6 @@ sandbox_klass.create(term_code: 'CAV', purpose_code: '') end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(2) @@ -265,7 +264,6 @@ @pair = create(:trade_taxon_concept_term_pair, term_id: cav.id, taxon_concept_id: @genus.id) end - context 'when accepted name' do before do @species = create_cites_eu_species(parent: @genus) diff --git a/spec/models/trade/pov_inclusion_validation_rule_spec.rb b/spec/models/trade/pov_inclusion_validation_rule_spec.rb index 098a26451..b1dfa3913 100644 --- a/spec/models/trade/pov_inclusion_validation_rule_spec.rb +++ b/spec/models/trade/pov_inclusion_validation_rule_spec.rb @@ -25,6 +25,7 @@ iso_code2: 'CA' ) end + let(:argentina) do create( :geo_entity, @@ -33,6 +34,7 @@ iso_code2: 'AR' ) end + let(:xx) do create( :geo_entity, @@ -75,7 +77,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) @@ -102,7 +103,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) @@ -129,7 +129,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru)).to be_empty @@ -156,7 +155,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru)).to be_empty @@ -177,7 +175,6 @@ ) end - specify do expect { subject.validation_errors_for_aru(@aru) }.not_to raise_error end diff --git a/spec/models/trade/sandbox_template_spec.rb b/spec/models/trade/sandbox_template_spec.rb index 266d3a1ba..df2d9cef1 100644 --- a/spec/models/trade/sandbox_template_spec.rb +++ b/spec/models/trade/sandbox_template_spec.rb @@ -6,20 +6,24 @@ aru.save(validate: false) aru end + let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end + let(:canis) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Canis') ) end + let(:canis_lupus) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'lupus'), parent: canis ) end + let(:canis_aureus) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'aureus'), diff --git a/spec/models/trade/scoped_inclusion_validation_rule_spec.rb b/spec/models/trade/scoped_inclusion_validation_rule_spec.rb index 4803a364d..70fd0d937 100644 --- a/spec/models/trade/scoped_inclusion_validation_rule_spec.rb +++ b/spec/models/trade/scoped_inclusion_validation_rule_spec.rb @@ -14,13 +14,13 @@ end include_context 'Pecari tajacu' + before do @sandbox_klass.create( taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: 'AR' ) end - specify do expect(subject.validation_errors.reload.size).to eq(0) end @@ -32,6 +32,7 @@ end include_context 'Pecari tajacu' + before do @sandbox_klass.create( taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: 'PL' @@ -45,13 +46,13 @@ end include_context 'Pecari tajacu' + before do @sandbox_klass.create( taxon_name: 'Pecari tajacu', source_code: 'W', country_of_origin: nil ) end - specify do expect(subject.validation_errors.reload.size).to eq(0) end diff --git a/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb b/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb index a97a18925..8bc8916e7 100644 --- a/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb +++ b/spec/models/trade/taxon_concept_appendix_year_validation_rule_spec.rb @@ -58,7 +58,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) @@ -79,7 +78,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) @@ -103,7 +101,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) @@ -127,7 +124,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) @@ -168,7 +164,6 @@ ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) @@ -182,13 +177,13 @@ end include_context 'Cedrela montana' + before do @sandbox_klass.create( taxon_name: 'Cedrela montana', appendix: 'N', year: '2013' ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(0) @@ -201,13 +196,13 @@ end include_context 'Agave' + before do @sandbox_klass.create( taxon_name: 'Agave arizonica', appendix: 'N', year: '2013' ) end - specify do subject.refresh_errors_if_needed(@aru) expect(subject.validation_errors_for_aru(@aru).size).to eq(1) diff --git a/spec/models/trade/taxon_concept_source_validation_rule_spec.rb b/spec/models/trade/taxon_concept_source_validation_rule_spec.rb index 4385b5669..ebb9b7e59 100644 --- a/spec/models/trade/taxon_concept_source_validation_rule_spec.rb +++ b/spec/models/trade/taxon_concept_source_validation_rule_spec.rb @@ -9,6 +9,7 @@ annual_report.save(validate: false) annual_report end + let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end @@ -25,7 +26,6 @@ sandbox_klass.create(source_code: 'B', taxon_name: @animal.full_name) end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(1) @@ -51,7 +51,6 @@ sandbox_klass.create(source_code: 'B', taxon_name: @plant.full_name) end - specify do subject.refresh_errors_if_needed(annual_report_upload) expect(subject.validation_errors_for_aru(annual_report_upload).size).to eq(2) diff --git a/spec/models/trade/validation_rule_spec.rb b/spec/models/trade/validation_rule_spec.rb index 12a3b4253..26d834a37 100644 --- a/spec/models/trade/validation_rule_spec.rb +++ b/spec/models/trade/validation_rule_spec.rb @@ -9,6 +9,7 @@ annual_report.save(validate: false) annual_report end + let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end @@ -89,6 +90,7 @@ travel_to(Time.now + 1) do @shipment2.update(taxon_name: 'Canis lupus') @shipment3.update(taxon_name: 'Canis lupus') + expect do validation_rule.refresh_errors_if_needed(annual_report_upload) end.to change { Trade::ValidationError.count }.by(-1) @@ -100,6 +102,7 @@ specify 'error record is updated to reflect new error_count' do travel_to(Time.now + 1) do @shipment2.update(taxon_name: 'Canis lupus') + expect do validation_rule.refresh_errors_if_needed(annual_report_upload) end.to change { @validation_error.reload.error_count }.by(-1) diff --git a/spec/models/trade_restrictions/cites_suspension_spec.rb b/spec/models/trade_restrictions/cites_suspension_spec.rb index 6b6f6dd8b..7d90705a2 100644 --- a/spec/models/trade_restrictions/cites_suspension_spec.rb +++ b/spec/models/trade_restrictions/cites_suspension_spec.rb @@ -41,6 +41,7 @@ iso_code2: 'TZ' ) end + let(:rwanda) do create( :geo_entity, @@ -273,7 +274,6 @@ CitesSuspension.export('set' => 'current') end - specify { expect(subject).not_to be_empty } end end @@ -297,7 +297,6 @@ s.destroy end - specify do # Currently fails because the clearing happens in an after_commit hook, # which does not run until the test is over. diff --git a/spec/models/trade_restrictions/quota_spec.rb b/spec/models/trade_restrictions/quota_spec.rb index ad8c8b945..c45222568 100644 --- a/spec/models/trade_restrictions/quota_spec.rb +++ b/spec/models/trade_restrictions/quota_spec.rb @@ -47,7 +47,6 @@ Quota.export('set' => 'current') end - specify { expect(subject).not_to be_empty } end end @@ -70,7 +69,6 @@ q.destroy end - specify do # Currently fails because the clearing happens in an after_commit hook, # which does not run until the test is over. diff --git a/spec/services/checklist/annotations_spec.rb b/spec/services/checklist/annotations_spec.rb index 01305cac7..e8fd8a6bc 100644 --- a/spec/services/checklist/annotations_spec.rb +++ b/spec/services/checklist/annotations_spec.rb @@ -3,6 +3,7 @@ describe Checklist do include_context 'Panax ginseng' include_context 'Caiman latirostris' + describe 'ann_symbol' do before(:all) do @checklist = Checklist::Checklist.new( diff --git a/spec/services/checklist/checklist_spec.rb b/spec/services/checklist/checklist_spec.rb index 98404978b..c3f6fb885 100644 --- a/spec/services/checklist/checklist_spec.rb +++ b/spec/services/checklist/checklist_spec.rb @@ -94,6 +94,7 @@ geo_entity_type_id: region_type.id ) end + let(:summary) do Checklist::Checklist.summarise_filters({ cites_region_ids: [ region.id ] }) end @@ -119,6 +120,7 @@ ) [ region.id, region2.id ] end + let(:summary) do Checklist::Checklist.summarise_filters({ cites_region_ids: regions }) end diff --git a/spec/services/checklist/higher_taxa_item_spec.rb b/spec/services/checklist/higher_taxa_item_spec.rb index 720796ac6..83108f00c 100644 --- a/spec/services/checklist/higher_taxa_item_spec.rb +++ b/spec/services/checklist/higher_taxa_item_spec.rb @@ -17,7 +17,6 @@ ) end - specify { expect(subject.ancestors_path).to eq('Chordata,Reptilia,Crocodylia,Alligatoridae') } end @@ -36,7 +35,6 @@ ) end - specify { expect(subject.ancestors_path).to eq('Agavaceae') } end end diff --git a/spec/services/checklist/order_spec.rb b/spec/services/checklist/order_spec.rb index 0581fca5c..a306e8632 100644 --- a/spec/services/checklist/order_spec.rb +++ b/spec/services/checklist/order_spec.rb @@ -7,6 +7,7 @@ include_context 'Hirudo medicinalis' include_context 'Panax ginseng' include_context 'Agave' + context 'when taxonomic order' do context('Plantae') do before(:all) do diff --git a/spec/services/checklist/pdf/history_annotations_key_spec.rb b/spec/services/checklist/pdf/history_annotations_key_spec.rb index d52afbd16..a0a4402d9 100644 --- a/spec/services/checklist/pdf/history_annotations_key_spec.rb +++ b/spec/services/checklist/pdf/history_annotations_key_spec.rb @@ -59,7 +59,6 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - specify do expect(subject.hash_annotations_key).to eq("\\hashAnnotationsHistoryInfo\n\n\\hashannotationstable{\n\\rowcolor{pale_aqua}\nCoP1 & \\validFrom \\hspace{2 pt} 01/07/2012\\\\\n\\#1 & Only trunks \\\\\n\n}\n\\hashannotationstable{\n\\rowcolor{pale_aqua}\nCoP2 & \\validFrom \\hspace{2 pt} 01/07/2013\\\\\n\\#1 & Only bark \\\\\n\n}\n") end diff --git a/spec/services/checklist/pdf/history_spec.rb b/spec/services/checklist/pdf/history_spec.rb index 695ae72d7..5273db676 100644 --- a/spec/services/checklist/pdf/history_spec.rb +++ b/spec/services/checklist/pdf/history_spec.rb @@ -4,6 +4,7 @@ let(:en) { create(:language, name: 'English', iso_code1: 'EN') } let!(:fr) { create(:language, name: 'French', iso_code1: 'FR') } let!(:es) { create(:language, name: 'Spanish', iso_code1: 'ES') } + let(:family_tc) do tc = create_cites_eu_family( taxon_name: create(:taxon_name, scientific_name: 'Foobaridae') @@ -11,6 +12,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:genus_tc) do tc = create_cites_eu_genus( parent_id: family_tc.id, @@ -25,6 +27,7 @@ subject { Checklist::Pdf::History.new(scientific_name: tc.full_name, show_english: true) } let(:tc) { family_tc } + let!(:taxon_common) do create( :taxon_common, @@ -38,7 +41,6 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - specify do expect(subject.higher_taxon_name(tc.reload)).to eq("\\subsection*{FOOBARIDAE (E) Foobars }\n") end @@ -50,6 +52,7 @@ subject { Checklist::Pdf::History.new(scientific_name: tc.full_name) } let(:tc) { family_tc } + let!(:lc) do lc = create_cites_I_addition( taxon_concept_id: tc.id, @@ -59,7 +62,6 @@ MCitesListingChange.find(lc.id) end - specify do expect(subject.listed_taxon_name(tc)).to eq('FOOBARIDAE spp.') end @@ -69,6 +71,7 @@ subject { Checklist::Pdf::History.new(scientific_name: tc.full_name) } let(:tc) { genus_tc } + let!(:lc) do lc = create_cites_I_addition( taxon_concept_id: tc.id, @@ -78,7 +81,6 @@ MCitesListingChange.find(lc.id) end - specify do expect(subject.listed_taxon_name(tc)).to eq('\emph{Foobarus} spp.') end @@ -97,7 +99,9 @@ display_in_footnote: true ) end + let(:tc) { genus_tc } + let(:lc) do lc = create_cites_I_addition( taxon_concept_id: tc.id, @@ -109,7 +113,6 @@ MCitesListingChange.find(lc.id) end - specify do expect(subject.annotation_for_language(lc, 'en')).to eq("Except \\textit{Foobarus cracoviensis}\n\nPreviously listed as \\textit{Foobarus polonicus}.\\footnote{...}") end diff --git a/spec/services/checklist/pdf/index_annotations_key_spec.rb b/spec/services/checklist/pdf/index_annotations_key_spec.rb index be496d33a..80240bb8d 100644 --- a/spec/services/checklist/pdf/index_annotations_key_spec.rb +++ b/spec/services/checklist/pdf/index_annotations_key_spec.rb @@ -46,7 +46,6 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - specify do expect(subject.hash_annotations_key).to eq("\\newpage\n\\section*{\\hashAnnotations}\n\\hashAnnotationsIndexInfo\n\n\\hashannotationstable{\n\\rowcolor{pale_aqua}\nCoP2 & \\validFrom \\hspace{2 pt} 01/07/2013\\\\\n\\#1 & Only bark \\\\\n\n}\n") end @@ -105,7 +104,6 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - specify do allow(LatexToPdf).to receive(:html2latex).and_return('x') expect(subject.non_hash_annotations_key).to eq("\\section*{\\nonHashAnnotations}\n\\cfbox{orange}{\\superscript{1} \\textbf{\\textit{Foobarus bizarrus}}}\n\nx\n\n\\cfbox{green}{\\superscript{2} \\textbf{\\textit{Foobaria curiosa}}}\n\nx\n\n") diff --git a/spec/services/checklist/pdf/index_fetcher_spec.rb b/spec/services/checklist/pdf/index_fetcher_spec.rb index 7a9e05b95..cdd5d3b24 100644 --- a/spec/services/checklist/pdf/index_fetcher_spec.rb +++ b/spec/services/checklist/pdf/index_fetcher_spec.rb @@ -6,6 +6,7 @@ create(:language, name_en: 'Spanish', iso_code1: 'ES', iso_code3: 'SPA') create(:language, name_en: 'English', iso_code1: 'EN', iso_code3: 'ENG') end + let(:es) do Language.find_by(name_en: 'Spanish') end @@ -17,6 +18,7 @@ language: en ) end + let(:spanish_common_name) do create( :common_name, @@ -24,6 +26,7 @@ language: es ) end + let!(:tc) do tc = create( :taxon_concept, @@ -34,6 +37,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings tc end + let(:rel) { MTaxonConcept.by_scientific_name('Lolcatus') } context 'with common names' do @@ -48,7 +52,6 @@ ) end - specify { expect(subject.next.first.sort_name).to eq('lolcat, Domestic') } end @@ -62,6 +65,7 @@ scientific_name: 'Catus fluffianus' ) end + let!(:synonymy_rel) do create( :taxon_relationship, @@ -71,6 +75,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end + let(:query) do Checklist::Pdf::IndexQuery.new( rel, { @@ -80,7 +85,6 @@ ) end - specify { expect(subject.next.first.sort_name).to eq('Catus fluffianus') } end end diff --git a/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb b/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb index ff62c5d0d..b041e8e70 100644 --- a/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb +++ b/spec/services/checklist/taxon_concept_prefix_matcher_spec.rb @@ -2,6 +2,7 @@ describe Species::TaxonConceptPrefixMatcher do include_context 'Boa constrictor' + describe :results do context 'when query in capital letters' do subject do diff --git a/spec/services/checklist/timeline_spec.rb b/spec/services/checklist/timeline_spec.rb index 3fcdb335b..9f7efc3c9 100644 --- a/spec/services/checklist/timeline_spec.rb +++ b/spec/services/checklist/timeline_spec.rb @@ -17,6 +17,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.first } @@ -77,6 +78,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.last } @@ -106,6 +108,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.first } @@ -148,6 +151,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.first.timelines.first } @@ -196,6 +200,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.last.timelines.first } @@ -221,6 +226,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.first } @@ -252,6 +258,7 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings MTaxonConcept.find(tc.id) end + let(:ttc) { Checklist::TimelinesForTaxonConcept.new(tc) } let(:subject) { ttc.timelines.first } diff --git a/spec/services/checklist/timelines_for_taxon_concept_spec.rb b/spec/services/checklist/timelines_for_taxon_concept_spec.rb index 1f5862d0f..3548a6431 100644 --- a/spec/services/checklist/timelines_for_taxon_concept_spec.rb +++ b/spec/services/checklist/timelines_for_taxon_concept_spec.rb @@ -20,7 +20,6 @@ MTaxonConcept.find(tc.id) end - specify { expect(subject.raw_timelines['I'].timeline_events).not_to be_empty } specify { expect(subject.raw_timelines['II'].timeline_events).to be_empty } end @@ -45,7 +44,6 @@ MTaxonConcept.find(tc.id) end - specify { expect(subject.raw_timelines['III'].timeline_events).not_to be_empty } specify { expect(subject.raw_timelines['I'].timeline_events).to be_empty } end @@ -70,7 +68,6 @@ MTaxonConcept.find(tc.id) end - specify { expect(subject.raw_timelines['III'].timeline_events).to be_empty } specify { expect(subject.raw_timelines['III'].timelines.first.timeline_events).not_to be_empty } specify { expect(subject.raw_timelines['I'].timeline_events).to be_empty } @@ -87,7 +84,6 @@ MTaxonConcept.find(tc.id) end - specify { expect(subject.size).to eq(5) } specify { expect(subject.first.year).to eq(1975) } specify { expect(subject.last.year).to eq(1995) } diff --git a/spec/services/dashboard_stats_species_spec.rb b/spec/services/dashboard_stats_species_spec.rb index 27758ba02..5874c5f2e 100644 --- a/spec/services/dashboard_stats_species_spec.rb +++ b/spec/services/dashboard_stats_species_spec.rb @@ -9,6 +9,7 @@ iso_code2: 'AR' ) end + let(:ghana) do create( :geo_entity, @@ -17,9 +18,11 @@ iso_code2: 'GH' ) end + let(:ds_ar) do DashboardStats.new argentina, { kingdom: 'Animalia', trade_limit: 5 } end + let(:ds_gh) do DashboardStats.new ghana, { kingdom: 'Animalia', trade_limit: 5 } end @@ -32,6 +35,7 @@ describe '#species' do include_context 'Caiman latirostris' + it 'has one results for argentina' do expect(ds_ar.species[:cites_eu][0][:count]).to eq 1 end diff --git a/spec/services/dashboard_stats_trade_spec.rb b/spec/services/dashboard_stats_trade_spec.rb index 2f8388212..a14213a41 100644 --- a/spec/services/dashboard_stats_trade_spec.rb +++ b/spec/services/dashboard_stats_trade_spec.rb @@ -2,6 +2,7 @@ describe DashboardStats do include_context 'Shipments' + describe '#trade' do before do SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings diff --git a/spec/services/document_search_spec.rb b/spec/services/document_search_spec.rb index cf192b477..12c19ec36 100644 --- a/spec/services/document_search_spec.rb +++ b/spec/services/document_search_spec.rb @@ -6,6 +6,7 @@ taxon_name: create(:taxon_name, scientific_name: 'Meliaceae') ) end + let(:swietenia_macrophylla) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'Swietenia macrophylla'), @@ -15,6 +16,7 @@ ) ) end + let(:cedrela_odorata) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'Cedrela odorata'), @@ -24,6 +26,7 @@ ) ) end + let(:belize) do create( :geo_entity, @@ -32,6 +35,7 @@ iso_code2: 'BZ' ) end + let(:brazil) do create( :geo_entity, @@ -40,6 +44,7 @@ iso_code2: 'BR' ) end + let(:document_on_swietenia) do document = create( :proposal, @@ -58,6 +63,7 @@ ) document end + let(:document_on_swietenia_in_belize) do document = create( :proposal, is_public: true, @@ -80,6 +86,7 @@ ) document end + let(:document_on_swietenia_in_brazil) do document = create( :proposal, is_public: true, @@ -102,6 +109,7 @@ ) document end + let(:document_on_swietenia_in_belize_and_brazil) do document = create( :proposal, is_public: true, @@ -129,6 +137,7 @@ ) document end + let(:document_on_swietenia_in_belize_and_cedrela_in_brazil) do document = create( :proposal, is_public: true, @@ -164,6 +173,7 @@ ) document end + let(:document_on_brazil) do document = create( :proposal, is_public: true, @@ -181,6 +191,7 @@ ) document end + let(:document_without_citations) do document = create( :proposal, is_public: true, diff --git a/spec/services/geo_entity_search_spec.rb b/spec/services/geo_entity_search_spec.rb index 8b39d03ad..68ab36c24 100644 --- a/spec/services/geo_entity_search_spec.rb +++ b/spec/services/geo_entity_search_spec.rb @@ -119,7 +119,6 @@ ) end - specify do subject.cached_results @burma.update({ is_current: false }) diff --git a/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb b/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb index af4782439..ca593e1ec 100644 --- a/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb +++ b/spec/services/nomenclature_change/delete_unreassigned_processor_spec.rb @@ -10,6 +10,7 @@ describe :run do let(:split) { split_with_input_with_reassignments } let(:input) { split.input } + let(:processor) do NomenclatureChange::DeleteUnreassignedProcessor.new(input) end diff --git a/spec/services/nomenclature_change/full_reassignment_spec.rb b/spec/services/nomenclature_change/full_reassignment_spec.rb index 28a07c247..86992e27d 100644 --- a/spec/services/nomenclature_change/full_reassignment_spec.rb +++ b/spec/services/nomenclature_change/full_reassignment_spec.rb @@ -7,7 +7,6 @@ let(:old_tc) { create_cites_eu_species } let(:new_tc) { create_cites_eu_species } - context 'when distributions present' do before do create(:distribution, taxon_concept: old_tc) diff --git a/spec/services/nomenclature_change/lump/constructor_spec.rb b/spec/services/nomenclature_change/lump/constructor_spec.rb index e22f4cb17..d13b5b0a7 100644 --- a/spec/services/nomenclature_change/lump/constructor_spec.rb +++ b/spec/services/nomenclature_change/lump/constructor_spec.rb @@ -96,6 +96,7 @@ let(:input) do create(:nomenclature_change_input, nomenclature_change: lump, note_en: 'blah') end + let(:output) do create(:nomenclature_change_output, nomenclature_change: lump, note_en: 'blah') end @@ -119,6 +120,7 @@ 2.times { create_cites_eu_subspecies(parent: s) } s end + let(:lump_with_inputs_and_output) { lump_with_inputs_and_same_output } let(:input) { lump.inputs_intersect_outputs.first } let(:default_output) { lump.output } @@ -151,6 +153,7 @@ context 'when output = input' do let(:input_species) do s = create_cites_eu_species + 2.times do create( :taxon_relationship, @@ -159,8 +162,10 @@ taxon_relationship_type: synonym_relationship_type ) end + s end + let(:lump_with_inputs_and_output) { lump_with_inputs_and_same_output } let(:input) { lump.inputs_intersect_outputs.first } let(:default_output) { lump.output } diff --git a/spec/services/nomenclature_change/lump/processor_spec.rb b/spec/services/nomenclature_change/lump/processor_spec.rb index 95e0b72df..3991993f5 100644 --- a/spec/services/nomenclature_change/lump/processor_spec.rb +++ b/spec/services/nomenclature_change/lump/processor_spec.rb @@ -85,9 +85,11 @@ let!(:input_species1_child) do create_cites_eu_subspecies(parent: input_species1) end + let!(:input_species1_child_listing) do create_cites_I_addition(taxon_concept: input_species1_child) end + let(:lump) do create( :nomenclature_change_lump, @@ -143,13 +145,17 @@ let!(:input_species1_child) do create_cites_eu_subspecies(parent: input_species1) end + let(:output_species_genus_name) { output_species.parent.full_name } + let!(:input_species1_child_listing) do create_cites_I_addition(taxon_concept: input_species1_child) end + let!(:output_species_child) do create_cites_eu_subspecies(parent: output_species) end + let(:lump) do create( :nomenclature_change_lump, @@ -169,8 +175,10 @@ status: NomenclatureChange::Lump::LEGISLATION ) end + let(:input) { lump.inputs.first } let(:output) { lump.output } + let(:reassignment) do create( :nomenclature_change_parent_reassignment, @@ -178,6 +186,7 @@ reassignable_id: input_species1_child.id ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -185,14 +194,15 @@ output: output ) end + let(:output_species_children) { output_species.children } + let(:output_species1_child) do output_species_children.where.not(id: output_species_child.id).first end before { processor.run } - specify 'input species has public nomenclature note set' do expect(input_species1.reload.nomenclature_note_en).to eq(' input species 1 has been lumped into output species') end @@ -243,7 +253,6 @@ ).to eq(input_species1.reload.nomenclature_note_en) end - specify 'original output species child retains higher taxa intact' do expect(output_species_child.data['genus_name']).to eq(output_species_genus_name) end @@ -268,27 +277,33 @@ taxon_name: create(:taxon_name, scientific_name: 'Crotalus') ) end + let(:input_genus_child) do create_cites_eu_species( parent: input_genus, taxon_name: create(:taxon_name, scientific_name: 'durissus') ) end + let!(:input_genus_child_child) do create_cites_eu_subspecies( parent: input_genus_child, taxon_name: create(:taxon_name, scientific_name: 'unicolor') ) end + let!(:quota) { create(:quota, taxon_concept: input_genus_child, geo_entity: create(:geo_entity)) } + let!(:document_citation_taxon_concept_input_genus_child) do create(:document_citation_taxon_concept, taxon_concept: input_genus_child) end + let(:output_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Paracrotalus') ) end + let(:lump) do create( :nomenclature_change_lump, @@ -300,6 +315,7 @@ status: NomenclatureChange::Lump::LEGISLATION ) end + let(:reassignment) do create( :nomenclature_change_parent_reassignment, @@ -307,6 +323,7 @@ reassignable_id: input_genus_child.id ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, diff --git a/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb b/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb index 8cf76acdc..d9c91b300 100644 --- a/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb +++ b/spec/services/nomenclature_change/reassignment_copy_processor_spec.rb @@ -2,10 +2,12 @@ describe NomenclatureChange::ReassignmentCopyProcessor do include_context 'split_definitions' + describe :run do let(:split) { split_with_input_and_same_output } let(:input) { split.input } let(:output) { split.outputs.first } + let(:processor) do NomenclatureChange::ReassignmentCopyProcessor.new(input, output) end diff --git a/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb b/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb index 28053f640..95b75a699 100644 --- a/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb +++ b/spec/services/nomenclature_change/reassignment_transfer_processor_spec.rb @@ -2,11 +2,13 @@ describe NomenclatureChange::ReassignmentTransferProcessor do include_context 'split_definitions' + describe :run do context 'input reassignments' do let(:split) { split_with_input_and_output } let(:input) { split.input } let(:output) { split.outputs.first } + let(:processor) do NomenclatureChange::ReassignmentTransferProcessor.new(input, output) end @@ -57,9 +59,11 @@ let(:output) { split.outputs.last } let(:old_output_subspecies) { output.taxon_concept } let(:new_output_species) { output.new_taxon_concept } + let(:output_processor) do NomenclatureChange::OutputTaxonConceptProcessor.new(output) end + let(:processor) do NomenclatureChange::ReassignmentTransferProcessor.new(output, output) end diff --git a/spec/services/nomenclature_change/split/constructor_spec.rb b/spec/services/nomenclature_change/split/constructor_spec.rb index 506a67e0e..c3ccbf38e 100644 --- a/spec/services/nomenclature_change/split/constructor_spec.rb +++ b/spec/services/nomenclature_change/split/constructor_spec.rb @@ -88,6 +88,7 @@ let(:input) do create(:nomenclature_change_input, nomenclature_change: split, note_en: 'blah') end + let(:output) do create(:nomenclature_change_output, nomenclature_change: split, note_en: 'blah') end @@ -111,6 +112,7 @@ 2.times { create_cites_eu_subspecies(parent: s) } s end + let(:split_with_input_and_output) { split_with_input_and_same_output } let(:default_output) { split.outputs_intersect_inputs.first } @@ -142,6 +144,7 @@ context 'when output = input' do let(:input_species) do s = create_cites_eu_species + 2.times do create( :taxon_relationship, @@ -150,8 +153,10 @@ taxon_relationship_type: synonym_relationship_type ) end + s end + let(:split_with_input_and_output) { split_with_input_and_same_output } let(:default_output) { split.outputs_intersect_inputs.first } @@ -183,6 +188,7 @@ context 'when geo_entity citations mismatch distribution' do let(:geo_entity) { create(:geo_entity) } + let(:input_species) do s = create_cites_eu_species dc = create(:document_citation) @@ -203,6 +209,7 @@ ) s end + let(:default_output) { split.outputs.first } let(:non_default_output) { split.outputs.where.not(id: default_output.id).first } @@ -215,7 +222,6 @@ non_default_target.destroy distribution_reassignment.reassignment_targets.reload - # split.input.distribution_reassignments.first. # update(output_ids: [split.outputs.first.id]) constructor.build_document_reassignments diff --git a/spec/services/nomenclature_change/split/processor_spec.rb b/spec/services/nomenclature_change/split/processor_spec.rb index 3684b675d..ca3521943 100644 --- a/spec/services/nomenclature_change/split/processor_spec.rb +++ b/spec/services/nomenclature_change/split/processor_spec.rb @@ -56,11 +56,13 @@ taxon_name: create(:taxon_name, scientific_name: 'Notio mirabilis') ) end + let(:genus2) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Notio') ) end + let!(:split) { split_with_input_and_outputs_status_change } specify { expect { processor.run }.not_to change(TaxonConcept, :count) } @@ -98,9 +100,11 @@ let!(:input_species_child) do create_cites_eu_subspecies(parent: input_species) end + let!(:input_species_child_listing) do create_cites_I_addition(taxon_concept: input_species_child) end + let(:split) do create( :nomenclature_change_split, @@ -156,13 +160,17 @@ let!(:input_species_child) do create_cites_eu_subspecies(parent: input_species) end + let(:output_species1_genus_name) { output_species1.parent.full_name } + let!(:input_species_child_listing) do create_cites_I_addition(taxon_concept: input_species_child) end + let!(:output_species1_child) do create_cites_eu_subspecies(parent: output_species1) end + let(:split) do create( :nomenclature_change_split, @@ -182,8 +190,10 @@ status: NomenclatureChange::Split::LEGISLATION ) end + let(:input) { split.input } let(:output) { split.outputs.first } + let(:reassignment) do create( :nomenclature_change_parent_reassignment, @@ -191,6 +201,7 @@ reassignable_id: input_species_child.id ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, @@ -198,14 +209,15 @@ output: output ) end + let(:output_species) { output.taxon_concept.reload } + let(:output_species_child) do output.taxon_concept.children.where.not(id: output_species1_child.id).first end before { processor.run } - specify 'input species has public nomenclature note set' do expect(input_species.reload.nomenclature_note_en).to eq(' input species was split into output species 1 and output species 2') end @@ -256,7 +268,6 @@ ).to eq(output_species.nomenclature_note_en) end - specify 'original output species child retains higher taxa intact' do expect(output_species_child.data['genus_name']).to eq(output_species1_genus_name) end @@ -281,27 +292,33 @@ taxon_name: create(:taxon_name, scientific_name: 'Crotalus') ) end + let(:input_genus_child) do create_cites_eu_species( parent: input_genus, taxon_name: create(:taxon_name, scientific_name: 'durissus') ) end + let!(:input_genus_child_child) do create_cites_eu_subspecies( parent: input_genus_child, taxon_name: create(:taxon_name, scientific_name: 'unicolor') ) end + let!(:quota) { create(:quota, taxon_concept: input_genus_child, geo_entity: create(:geo_entity)) } + let!(:document_citation_taxon_concept_input_genus_child) do create(:document_citation_taxon_concept, taxon_concept: input_genus_child) end + let(:output_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Paracrotalus') ) end + let(:split) do create( :nomenclature_change_split, @@ -313,6 +330,7 @@ status: NomenclatureChange::Split::LEGISLATION ) end + let(:reassignment) do create( :nomenclature_change_parent_reassignment, @@ -320,6 +338,7 @@ reassignable_id: input_genus_child.id ) end + let!(:reassignment_target) do create( :nomenclature_change_reassignment_target, diff --git a/spec/services/nomenclature_change/status_swap/constructor_spec.rb b/spec/services/nomenclature_change/status_swap/constructor_spec.rb index 365bb97bb..e6e3e7db4 100644 --- a/spec/services/nomenclature_change/status_swap/constructor_spec.rb +++ b/spec/services/nomenclature_change/status_swap/constructor_spec.rb @@ -56,7 +56,6 @@ constructor.build_secondary_output_note end - context 'when previously no notes in place' do specify { expect(primary_output.internal_note).to be_blank } specify { expect(secondary_output.note_en).not_to be_blank } @@ -66,6 +65,7 @@ let(:primary_output) do create(:nomenclature_change_output, nomenclature_change: status_change, internal_note: 'blah') end + let(:secondary_output) do create(:nomenclature_change_output, nomenclature_change: status_change, note_en: 'blah') end diff --git a/spec/services/nomenclature_change/status_swap/processor_spec.rb b/spec/services/nomenclature_change/status_swap/processor_spec.rb index dc772fd63..b6c756dd0 100644 --- a/spec/services/nomenclature_change/status_swap/processor_spec.rb +++ b/spec/services/nomenclature_change/status_swap/processor_spec.rb @@ -21,7 +21,6 @@ before { synonym_relationship_type } - describe :run do context 'from accepted name' do let(:accepted_name_parent) { create_cites_eu_genus } diff --git a/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb b/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb index be9565ca1..a3c2427f2 100644 --- a/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb +++ b/spec/services/nomenclature_change/status_to_accepted/processor_spec.rb @@ -21,11 +21,13 @@ ) tc end + let(:trade_name_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Lolcatus') ) end + let(:synonym) do tc = create_cites_eu_species( name_status: 'S', @@ -39,6 +41,7 @@ ) tc end + let(:synonym_genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Foobarus') @@ -47,7 +50,6 @@ before { synonym_relationship_type } - describe :run do context 'from trade name' do let(:output_species) { secondary_output_taxon_concept } diff --git a/spec/services/species/common_names_export_spec.rb b/spec/services/species/common_names_export_spec.rb index 772dcdf8f..fda198c8a 100644 --- a/spec/services/species/common_names_export_spec.rb +++ b/spec/services/species/common_names_export_spec.rb @@ -41,7 +41,6 @@ FileUtils.remove_dir('spec/public/downloads/common_names', true) end - context 'when file not cached' do specify do subject.export diff --git a/spec/services/species/documents_export_spec.rb b/spec/services/species/documents_export_spec.rb index 624daf036..83168ebe6 100644 --- a/spec/services/species/documents_export_spec.rb +++ b/spec/services/species/documents_export_spec.rb @@ -34,7 +34,6 @@ FileUtils.rm_rf(Dir.glob("#{SPEC_DOCUMENTS_DOWNLOAD_PATH}/*")) end - specify 'when file not cached it should not be generated' do expect(subject.export).to be_falsey end diff --git a/spec/services/species/hybrid_prefix_matcher_spec.rb b/spec/services/species/hybrid_prefix_matcher_spec.rb index 8d8fca45a..f71b08951 100644 --- a/spec/services/species/hybrid_prefix_matcher_spec.rb +++ b/spec/services/species/hybrid_prefix_matcher_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Species::TaxonConceptPrefixMatcher do include_context 'Falconiformes' + describe :results do context 'when searching for hybrid' do context 'when trade visibility' do diff --git a/spec/services/species/invisible_subspecies_search_spec.rb b/spec/services/species/invisible_subspecies_search_spec.rb index 983142ce8..8f4cbfe51 100644 --- a/spec/services/species/invisible_subspecies_search_spec.rb +++ b/spec/services/species/invisible_subspecies_search_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Species::Search do include_context 'Psittaciformes' + describe :results do context 'when searching by scientific name' do context 'when subspecies never listed' do diff --git a/spec/services/species/listings_export_spec.rb b/spec/services/species/listings_export_spec.rb index 6b109e831..f3e01d5e3 100644 --- a/spec/services/species/listings_export_spec.rb +++ b/spec/services/species/listings_export_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Species::ListingsExport do include_context 'Canis lupus' + describe :path do subject do Species::ListingsExportFactory.new( @@ -51,7 +52,6 @@ FileUtils.remove_dir('spec/public/downloads/cites_listings', true) end - context 'when file not cached' do specify do subject.export @@ -142,7 +142,6 @@ SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings end - specify { expect(subject.query.to_a.size).to eq(1) } end end diff --git a/spec/services/species/orphaned_taxon_concepts_export_spec.rb b/spec/services/species/orphaned_taxon_concepts_export_spec.rb index 6cee3c733..45e7ef9ce 100644 --- a/spec/services/species/orphaned_taxon_concepts_export_spec.rb +++ b/spec/services/species/orphaned_taxon_concepts_export_spec.rb @@ -39,7 +39,6 @@ FileUtils.remove_dir('spec/public/downloads/orphaned_taxon_concepts', true) end - context 'when file not cached' do specify do subject.export diff --git a/spec/services/species/species_reference_output_spec.rb b/spec/services/species/species_reference_output_spec.rb index 61b55f85e..fe8708ee3 100644 --- a/spec/services/species/species_reference_output_spec.rb +++ b/spec/services/species/species_reference_output_spec.rb @@ -37,7 +37,6 @@ FileUtils.remove_dir('spec/public/downloads/species_reference_output', true) end - context 'when file not cached' do specify do subject.export diff --git a/spec/services/species/standard_reference_output_spec.rb b/spec/services/species/standard_reference_output_spec.rb index aeda4d0f7..d233b9921 100644 --- a/spec/services/species/standard_reference_output_spec.rb +++ b/spec/services/species/standard_reference_output_spec.rb @@ -37,7 +37,6 @@ FileUtils.remove_dir('spec/public/downloads/standard_reference_output', true) end - context 'when file not cached' do specify do subject.export diff --git a/spec/services/species/synonyms_and_trade_names_export_spec.rb b/spec/services/species/synonyms_and_trade_names_export_spec.rb index ec673102e..3d6725055 100644 --- a/spec/services/species/synonyms_and_trade_names_export_spec.rb +++ b/spec/services/species/synonyms_and_trade_names_export_spec.rb @@ -42,7 +42,6 @@ FileUtils.remove_dir('spec/public/downloads/synonyms_and_trade_names', true) end - context 'when file not cached' do specify do subject.export diff --git a/spec/services/species/taxon_concept_prefix_matcher_spec.rb b/spec/services/species/taxon_concept_prefix_matcher_spec.rb index 9f10473bc..4669fa98f 100644 --- a/spec/services/species/taxon_concept_prefix_matcher_spec.rb +++ b/spec/services/species/taxon_concept_prefix_matcher_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Species::TaxonConceptPrefixMatcher do include_context 'Boa constrictor' + describe :results do context 'when searching by common name' do context 'when searching by hyphenated common name' do diff --git a/spec/services/species/taxon_concepts_export_spec.rb b/spec/services/species/taxon_concepts_export_spec.rb index 06cb44e89..7c7e345a0 100644 --- a/spec/services/species/taxon_concepts_export_spec.rb +++ b/spec/services/species/taxon_concepts_export_spec.rb @@ -35,7 +35,6 @@ FileUtils.remove_dir('spec/public/downloads/taxon_concepts_names', true) end - context 'when file not cached' do specify do subject.export diff --git a/spec/services/species/visible_subspecies_search_spec.rb b/spec/services/species/visible_subspecies_search_spec.rb index 6fbd7ef56..eab47b3f2 100644 --- a/spec/services/species/visible_subspecies_search_spec.rb +++ b/spec/services/species/visible_subspecies_search_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Species::Search do include_context 'Canis lupus' + describe :results do context 'when searching by scientific name' do context 'when subspecies previously listed' do diff --git a/spec/services/taxon_concept_data_spec.rb b/spec/services/taxon_concept_data_spec.rb index a9bb4cf3c..88a09492e 100644 --- a/spec/services/taxon_concept_data_spec.rb +++ b/spec/services/taxon_concept_data_spec.rb @@ -7,15 +7,18 @@ taxon_name: create(:taxon_name, scientific_name: 'Canidae') ) end + let(:genus) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Canis'), parent: family ) end + let(:accepted_species) do create_cites_eu_species(parent: genus) end + let(:tcd_to_h) { TaxonConceptData.new(taxon_concept).to_h } context 'when regular accepted name' do @@ -38,6 +41,7 @@ let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'H') end + let!(:hybrid_parent_relationship) do create( :taxon_relationship, @@ -54,6 +58,7 @@ let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'S') end + let!(:hybrid_parent_relationship) do create( :taxon_relationship, @@ -70,6 +75,7 @@ let(:taxon_concept) do create_cites_eu_subspecies(name_status: 'T') end + let!(:hybrid_parent_relationship) do create( :taxon_relationship, diff --git a/spec/services/taxon_concept_prefix_matcher_spec.rb b/spec/services/taxon_concept_prefix_matcher_spec.rb index 32f53b531..4d58946b7 100644 --- a/spec/services/taxon_concept_prefix_matcher_spec.rb +++ b/spec/services/taxon_concept_prefix_matcher_spec.rb @@ -22,12 +22,14 @@ parent: taxon_concept2 ) end + let!(:taxon_concept4) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Abb'), parent: taxon_concept3 ) end + let!(:taxon_concept4_sibling) do create_cites_eu_genus( taxon_name: create(:taxon_name, scientific_name: 'Aaab'), @@ -89,6 +91,7 @@ let(:self_and_ancestor_matcher) do TaxonConceptPrefixMatcher.new self_and_ancestor_matcher_params end + let(:self_and_ancestor_matcher_params) do SearchParams.new( taxonomy: { id: taxonomy.id }, @@ -96,9 +99,11 @@ scientific_name: 'AAA' ) end + let(:ancestor_matcher) do TaxonConceptPrefixMatcher.new ancestor_matcher_params end + let(:ancestor_matcher_params) do SearchParams.new( taxonomy: { id: taxonomy.id }, @@ -113,16 +118,12 @@ ) end - - specify do expect(ancestor_matcher.taxon_concepts.map(&:full_name)).to eq( [ 'Aaa' ] ) end - - specify do expect(self_and_ancestor_matcher.taxon_concepts.map(&:full_name)).to eq( [ 'Aaa', 'Aaab' ] @@ -138,6 +139,7 @@ scientific_name: 'A' ) end + let(:ancestor_matcher) do TaxonConceptPrefixMatcher.new ancestor_matcher_params end @@ -145,6 +147,7 @@ let(:descendant_matcher) do TaxonConceptPrefixMatcher.new descendant_matcher_params end + let(:descendant_matcher_params) do SearchParams.new( taxonomy: { id: taxonomy.id }, @@ -159,8 +162,6 @@ ) end - - specify do expect(descendant_matcher.taxon_concepts.map(&:full_name)).to eq( [ 'Aaab', 'Aab', 'Abb' ] diff --git a/spec/services/trade/filter_spec.rb b/spec/services/trade/filter_spec.rb index 146204e22..be5c82df0 100644 --- a/spec/services/trade/filter_spec.rb +++ b/spec/services/trade/filter_spec.rb @@ -90,7 +90,6 @@ @shipment_of_status_N = create(:shipment, taxon_concept_id: @status_N_species.id) end - specify { expect(subject).to include(@shipment_of_status_N) } end @@ -107,7 +106,6 @@ @shipment_of_subspecies = create(:shipment, taxon_concept_id: @subspecies.id) end - specify { expect(subject).to include(@shipment_of_subspecies) } end @@ -166,7 +164,6 @@ ) end - specify { expect(subject).to include(@shipment_of_trade_name) } end end diff --git a/spec/services/trade/sandbox_filter_spec.rb b/spec/services/trade/sandbox_filter_spec.rb index b3060d662..57b80fe6e 100644 --- a/spec/services/trade/sandbox_filter_spec.rb +++ b/spec/services/trade/sandbox_filter_spec.rb @@ -5,9 +5,11 @@ aru.save(validate: false) aru end + let(:sandbox_klass) do Trade::SandboxTemplate.ar_klass(annual_report_upload.sandbox.table_name) end + let(:canis_lupus) do create_cites_eu_species( taxon_name: create(:taxon_name, scientific_name: 'lupus'), @@ -16,6 +18,7 @@ ) ) end + let(:validation_rule) do create_taxon_concept_appendix_year_validation end diff --git a/spec/shared/agalychnis.rb b/spec/shared/agalychnis.rb index 773fc6e68..2890e024c 100644 --- a/spec/shared/agalychnis.rb +++ b/spec/shared/agalychnis.rb @@ -51,6 +51,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/agave.rb b/spec/shared/agave.rb index f7a489d94..0d6f70a56 100644 --- a/spec/shared/agave.rb +++ b/spec/shared/agave.rb @@ -2,12 +2,15 @@ def en @en ||= create(:language, name: 'English', iso_code1: 'EN', iso_code3: 'ENG') end + def es @es ||= create(:language, name: 'Spanish', iso_code1: 'ES', iso_code3: 'SPA') end + def fr @fr ||= create(:language, name: 'French', iso_code1: 'FR', iso_code3: 'FRA') end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Liliales'), @@ -73,6 +76,7 @@ def fr ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/ailuropoda.rb b/spec/shared/ailuropoda.rb index 0412a7a58..b52dba84b 100644 --- a/spec/shared/ailuropoda.rb +++ b/spec/shared/ailuropoda.rb @@ -42,6 +42,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/arctocephalus.rb b/spec/shared/arctocephalus.rb index 1598755ea..ce65de2ea 100644 --- a/spec/shared/arctocephalus.rb +++ b/spec/shared/arctocephalus.rb @@ -2,12 +2,15 @@ def en @en ||= create(:language, name: 'English', iso_code1: 'EN', iso_code3: 'ENG') end + def es @es ||= create(:language, name: 'Spanish', iso_code1: 'ES', iso_code3: 'SPA') end + def fr @fr ||= create(:language, name: 'French', iso_code1: 'FR', iso_code3: 'FRA') end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Carnivora'), @@ -112,6 +115,7 @@ def fr ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/caiman_latirostris.rb b/spec/shared/caiman_latirostris.rb index f9cf41a4f..32490a651 100644 --- a/spec/shared/caiman_latirostris.rb +++ b/spec/shared/caiman_latirostris.rb @@ -23,6 +23,7 @@ def en instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Crocodylia'), @@ -154,6 +155,7 @@ def en ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/canis_lupus.rb b/spec/shared/canis_lupus.rb index 805123b4d..f8c305e10 100644 --- a/spec/shared/canis_lupus.rb +++ b/spec/shared/canis_lupus.rb @@ -79,6 +79,7 @@ effective_at: '2010-06-23', parent_id: cites_lc_II.id ) + [ bhutan, india, nepal, pakistan ].each do |country| create( :listing_distribution, @@ -129,6 +130,7 @@ end SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/caretta_caretta_cms.rb b/spec/shared/caretta_caretta_cms.rb index a405b2c52..fb13e3e0b 100644 --- a/spec/shared/caretta_caretta_cms.rb +++ b/spec/shared/caretta_caretta_cms.rb @@ -30,6 +30,7 @@ ) SapiModule::StoredProcedures.rebuild_cms_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/cedrela_montana.rb b/spec/shared/cedrela_montana.rb index cd72d8324..752d7b473 100644 --- a/spec/shared/cedrela_montana.rb +++ b/spec/shared/cedrela_montana.rb @@ -25,6 +25,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/cervus_elaphus.rb b/spec/shared/cervus_elaphus.rb index 2da9033e0..2662bb7b7 100644 --- a/spec/shared/cervus_elaphus.rb +++ b/spec/shared/cervus_elaphus.rb @@ -70,6 +70,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/cervus_elaphus_cms.rb b/spec/shared/cervus_elaphus_cms.rb index 16c49a69f..2aa92157d 100644 --- a/spec/shared/cervus_elaphus_cms.rb +++ b/spec/shared/cervus_elaphus_cms.rb @@ -53,6 +53,7 @@ ) SapiModule::StoredProcedures.rebuild_cms_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/colophon.rb b/spec/shared/colophon.rb index e6a12932f..755397ec2 100644 --- a/spec/shared/colophon.rb +++ b/spec/shared/colophon.rb @@ -52,6 +52,7 @@ def south_africa ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/dalbergia.rb b/spec/shared/dalbergia.rb index 797ab6fbc..04530eb73 100644 --- a/spec/shared/dalbergia.rb +++ b/spec/shared/dalbergia.rb @@ -2,12 +2,15 @@ def en @en ||= create(:language, name: 'English', iso_code1: 'EN', iso_code3: 'ENG') end + def es @es ||= create(:language, name: 'Spanish', iso_code1: 'ES', iso_code3: 'SPA') end + def fr @fr ||= create(:language, name: 'French', iso_code1: 'FR', iso_code3: 'FRA') end + { madagascar: 'MG', thailand: 'TH' @@ -26,6 +29,7 @@ def fr instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Fabales'), @@ -74,6 +78,7 @@ def fr ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/diospyros.rb b/spec/shared/diospyros.rb index 5b51ae581..5cade8f42 100644 --- a/spec/shared/diospyros.rb +++ b/spec/shared/diospyros.rb @@ -17,6 +17,7 @@ instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Ebenales'), @@ -126,6 +127,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/falconiformes.rb b/spec/shared/falconiformes.rb index b94bb8c7d..48f60484b 100644 --- a/spec/shared/falconiformes.rb +++ b/spec/shared/falconiformes.rb @@ -158,6 +158,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/hirudo_medicinalis.rb b/spec/shared/hirudo_medicinalis.rb index 73bfe8fe4..18b31e9b0 100644 --- a/spec/shared/hirudo_medicinalis.rb +++ b/spec/shared/hirudo_medicinalis.rb @@ -31,6 +31,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/loxodonta_africana.rb b/spec/shared/loxodonta_africana.rb index 96bca792d..546ca33eb 100644 --- a/spec/shared/loxodonta_africana.rb +++ b/spec/shared/loxodonta_africana.rb @@ -20,6 +20,7 @@ instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Proboscidea'), @@ -48,6 +49,7 @@ taxon_concept: @species, effective_at: '1997-09-18' ) + [ botswana, namibia, zimbabwe ].each do |country| create( :listing_distribution, @@ -56,6 +58,7 @@ is_party: false ) end + cites_lc1 = create_cites_I_addition( taxon_concept: @species, effective_at: '2000-07-19', @@ -78,6 +81,7 @@ event: reg2013, is_current: true ) + [ botswana, namibia, zambia, zimbabwe ].each do |country| create( :listing_distribution, @@ -94,6 +98,7 @@ end SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/loxodonta_africana_cms.rb b/spec/shared/loxodonta_africana_cms.rb index 961d8ebc4..0ffb6d81b 100644 --- a/spec/shared/loxodonta_africana_cms.rb +++ b/spec/shared/loxodonta_africana_cms.rb @@ -24,6 +24,7 @@ ) SapiModule::StoredProcedures.rebuild_cms_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/mellivora_capensis.rb b/spec/shared/mellivora_capensis.rb index 25eb00efa..400b40830 100644 --- a/spec/shared/mellivora_capensis.rb +++ b/spec/shared/mellivora_capensis.rb @@ -17,6 +17,7 @@ instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Carnivora'), @@ -119,6 +120,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/moschus.rb b/spec/shared/moschus.rb index 5dadbe19f..5ba17dc51 100644 --- a/spec/shared/moschus.rb +++ b/spec/shared/moschus.rb @@ -19,6 +19,7 @@ instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Artiodactyla'), @@ -52,6 +53,7 @@ geo_entity: country ) end + [ @species2, @subspecies ].each do |taxon| create( :distribution, @@ -103,6 +105,7 @@ effective_at: '1983-07-29', is_current: true ) + [ bhutan, india, nepal ].each do |country| create( :listing_distribution, @@ -111,6 +114,7 @@ is_party: false ) end + cites_lc2 = create_cites_II_addition( taxon_concept: @genus, effective_at: '1983-07-29', @@ -122,6 +126,7 @@ effective_at: '1983-07-29', parent_id: cites_lc2.id ) + [ bhutan, india, nepal ].each do |country| create( :listing_distribution, @@ -145,6 +150,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/natator_depressus.rb b/spec/shared/natator_depressus.rb index da94ef1db..b1081249e 100644 --- a/spec/shared/natator_depressus.rb +++ b/spec/shared/natator_depressus.rb @@ -50,6 +50,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/notomys_aquilo.rb b/spec/shared/notomys_aquilo.rb index c43272ca3..cb7723f25 100644 --- a/spec/shared/notomys_aquilo.rb +++ b/spec/shared/notomys_aquilo.rb @@ -35,6 +35,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/panax_ginseng.rb b/spec/shared/panax_ginseng.rb index 4a859ecfa..60ebf4770 100644 --- a/spec/shared/panax_ginseng.rb +++ b/spec/shared/panax_ginseng.rb @@ -17,6 +17,7 @@ instance_variable_set("@#{name}", country) end end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Apiales'), @@ -87,6 +88,7 @@ end SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/pecari_tajacu.rb b/spec/shared/pecari_tajacu.rb index 11791d060..b01c861d6 100644 --- a/spec/shared/pecari_tajacu.rb +++ b/spec/shared/pecari_tajacu.rb @@ -46,6 +46,7 @@ def america iso_code2: 'US' ) end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Artiodactyla'), @@ -75,6 +76,7 @@ def america parent_id: cites_lc1.id, is_current: true ) + [ america, mexico ].each do |country| create( :listing_distribution, @@ -100,6 +102,7 @@ def america geo_relationship_type: contains_geo_relationship_type ) end + create( :geo_relationship, geo_entity: south_america, @@ -108,6 +111,7 @@ def america ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/pereskia.rb b/spec/shared/pereskia.rb index dcd1f1741..a396e9e4d 100644 --- a/spec/shared/pereskia.rb +++ b/spec/shared/pereskia.rb @@ -56,6 +56,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/platysternon_megacephalum.rb b/spec/shared/platysternon_megacephalum.rb index 559b8d510..7b902d576 100644 --- a/spec/shared/platysternon_megacephalum.rb +++ b/spec/shared/platysternon_megacephalum.rb @@ -52,6 +52,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/pristis_microdon.rb b/spec/shared/pristis_microdon.rb index cdc4dcf60..c83867371 100644 --- a/spec/shared/pristis_microdon.rb +++ b/spec/shared/pristis_microdon.rb @@ -60,6 +60,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/pseudomys_fieldi.rb b/spec/shared/pseudomys_fieldi.rb index 08c3bda1b..97ef07970 100644 --- a/spec/shared/pseudomys_fieldi.rb +++ b/spec/shared/pseudomys_fieldi.rb @@ -51,6 +51,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/psittaciformes.rb b/spec/shared/psittaciformes.rb index adf012e62..94c9de1bb 100644 --- a/spec/shared/psittaciformes.rb +++ b/spec/shared/psittaciformes.rb @@ -8,6 +8,7 @@ def ghana iso_code2: 'GH' ) end + before(:all) do @order = create_cites_eu_order( taxon_name: create(:taxon_name, scientific_name: 'Psittaciformes'), @@ -252,6 +253,7 @@ def ghana ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/uroplatus.rb b/spec/shared/uroplatus.rb index 6e4904a3e..fb2458ac3 100644 --- a/spec/shared/uroplatus.rb +++ b/spec/shared/uroplatus.rb @@ -51,6 +51,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/shared/varanidae.rb b/spec/shared/varanidae.rb index 21d0aee6b..657342e81 100644 --- a/spec/shared/varanidae.rb +++ b/spec/shared/varanidae.rb @@ -76,6 +76,7 @@ ) SapiModule::StoredProcedures.rebuild_cites_taxonomy_and_listings + self.instance_variables.each do |t| # Skip old sapi context let statements, # which are now instance variables starting with _ diff --git a/spec/support/sapi_helpers.rb b/spec/support/sapi_helpers.rb index 55b85dcf8..628747765 100644 --- a/spec/support/sapi_helpers.rb +++ b/spec/support/sapi_helpers.rb @@ -585,6 +585,7 @@ def reg2013 trade: GeoEntityType::TRADE_ENTITY }.each do |name, geo_type| met_name = "#{name}_geo_entity_type" + define_method(met_name) do met_name = met_name.to_s var = instance_variable_get("@_#{met_name}") @@ -606,6 +607,7 @@ def contains_geo_relationship_type hybrid: TaxonRelationshipType::HAS_HYBRID }.each do |name, rel_type| met_name = "#{name}_relationship_type" + define_method(met_name) do met_name = met_name.to_s var = instance_variable_get("@_#{met_name}") diff --git a/spec/workers/eu_regulation_activation_worker_spec.rb b/spec/workers/eu_regulation_activation_worker_spec.rb index d29385930..839202737 100644 --- a/spec/workers/eu_regulation_activation_worker_spec.rb +++ b/spec/workers/eu_regulation_activation_worker_spec.rb @@ -9,12 +9,14 @@ is_current: true ) end + let!(:listing_change) do create_eu_A_addition( event_id: prev_eu_regulation.id, is_current: true ) end + let!(:eu_regulation) do create_eu_regulation( name: 'REGULATION 2.0', diff --git a/spec/workers/event_listing_changes_copy_worker_spec.rb b/spec/workers/event_listing_changes_copy_worker_spec.rb index a4c2ae8c1..1f88e2e94 100644 --- a/spec/workers/event_listing_changes_copy_worker_spec.rb +++ b/spec/workers/event_listing_changes_copy_worker_spec.rb @@ -8,6 +8,7 @@ is_current: true ) end + let(:eu_regulation) do create_eu_regulation( name: 'REGULATION 2.0', @@ -16,12 +17,15 @@ is_current: true ) end + let(:species) do create_cites_eu_species end + let(:subspecies) do create_cites_eu_subspecies(parent: species) end + let!(:listing_change) do create_eu_A_addition( event_id: prev_eu_regulation.id, @@ -59,12 +63,14 @@ taxon_concept_id: subspecies.id ) end + let!(:geographic_exclusion) do create_eu_A_exception( parent_id: listing_change.id, taxon_concept_id: species.id ) end + let!(:exclusion_distribution) do create(:listing_distribution, listing_change_id: geographic_exclusion.id) end diff --git a/spec/workers/quotas_copy_worker_spec.rb b/spec/workers/quotas_copy_worker_spec.rb index 657cdc9e0..605137e4a 100644 --- a/spec/workers/quotas_copy_worker_spec.rb +++ b/spec/workers/quotas_copy_worker_spec.rb @@ -7,18 +7,21 @@ name: 'CITES_EU' ) end + let(:geo_entity) do create( :geo_entity, name_en: 'Portugal' ) end + let(:taxon_concept) do create( :taxon_concept, taxonomy_id: taxonomy.id ) end + let!(:quota) do create( :quota,