• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MushroomObserver / mushroom-observer / 14820646101

04 May 2025 11:13AM UTC coverage: 94.712% (+0.03%) from 94.686%
14820646101

push

github

web-flow
Merge pull request #2936 from MushroomObserver/njw-user-current-names-controller

Eliminate User.current from NamesControllerTest

266 of 276 new or added lines in 71 files covered. (96.38%)

4 existing lines in 2 files now uncovered.

34030 of 35930 relevant lines covered (94.71%)

487.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/app/controllers/application_controller/name_validation.rb
1
# frozen_string_literal: true
2

3
# see application_controller.rb
4
module ApplicationController::NameValidation
1✔
5
  ##############################################################################
6
  #
7
  #  :section: Name validation
8
  #
9
  ##############################################################################
10

11
  # Goes through list of names entered by user and creates (and saves) any that
12
  # are not in the database (but only if user has approved them).
13
  #
14
  # Used by: change_synonyms, create/edit_species_list
15
  #
16
  # Inputs:
17
  #
18
  #   name_list         string, delimted by newlines (see below for syntax)
19
  #   approved_names    array of real_search_names (or string delimited by "/")
20
  #   deprecate?        are any created names to be deprecated?
21
  #
22
  # Syntax: (NameParse class does the actual parsing)
23
  #
24
  #   Xxx yyy
25
  #   Xxx yyy var. zzz
26
  #   Xxx yyy Author
27
  #   Xxx yyy sensu Blah
28
  #   Valid name Author = Deprecated name Author
29
  #   blah blah [comment]
30
  #
31
  def construct_approved_names(name_list, approved_names, deprecate: false)
1✔
32
    return unless approved_names
58✔
33

34
    if approved_names.is_a?(String)
13✔
35
      approved_names = approved_names.split(/\r?\n/)
13✔
36
    end
37
    name_list.split("\n").each do |ns|
13✔
38
      next if ns.blank?
38✔
39

40
      name_parse = NameParse.new(ns)
38✔
41
      construct_approved_name(name_parse, approved_names, deprecate)
38✔
42
    end
43
  end
44

45
  # Processes a single line from the list above.
46
  # Used only by construct_approved_names().
47
  def construct_approved_name(name_parse, approved_names, deprecate)
1✔
48
    # Don't do anything if the given names are not approved
49
    if approved_names.member?(name_parse.name)
38✔
50
      # Build just the given names (not synonyms)
51
      construct_given_name(name_parse, deprecate)
20✔
52
    end
53

54
    # Do the same thing for synonym (found the Approved = Synonym syntax).
55
    return unless name_parse.has_synonym &&
38✔
56
                  approved_names.member?(name_parse.synonym)
57

58
    construct_synonyms(name_parse)
×
59
  end
60

61
  def construct_given_name(name_parse, deprecate)
1✔
62
    # Create name object for this name (and any parents, such as genus).
63
    names = Name.find_or_create_name_and_parents(@user, name_parse.search_name)
20✔
64

65
    # if above parse was successful
66
    if (name = names.last)
20✔
67
      name.rank = name_parse.rank if name_parse.rank
19✔
68
      save_approved_given_names(names, deprecate)
19✔
69

70
    # Parse must have failed.
71
    else
72
      flash_error(:runtime_no_create_name.t(type: :name,
1✔
73
                                            value: name_parse.name))
74
    end
75
  end
76

77
  def save_approved_given_names(names, deprecate2)
1✔
78
    Name.save_names(@user, names, deprecate2)
19✔
79
    names.each { |n| flash_object_errors(n) }
52✔
80
  end
81

82
  def construct_synonyms(name_parse)
1✔
83
    synonyms = create_synonym(name_parse)
×
84

85
    # Parse was successful
86
    if (synonym = synonyms.last)
×
87
      synonym.rank = name_parse.synonym_rank if name_parse.synonym_rank
×
88
      save_synonyms(synonym, synonyms)
×
89

90
    # Parse must have failed.
91
    else
92
      flash_error(:runtime_no_create_name.t(type: :name,
×
93
                                            value: name_parse.synonym))
94
    end
95
  end
96

97
  def create_synonym(name_parse)
1✔
NEW
98
    Name.find_or_create_name_and_parents(@user, name_parse.synonym_search_name)
×
99
  end
100

101
  # Deprecate and save.
102
  def save_synonyms(synonym, synonyms)
1✔
103
    synonym.change_deprecated(true)
×
NEW
104
    synonym.save_with_log(@user, :log_deprecated_by, touch: true)
×
NEW
105
    Name.save_names(@user, synonyms[0..-2], nil) # Don't change higher taxa
×
106
  end
107
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc