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

pulibrary / oawaiver / 11c952aa-d8e8-4073-941a-ba08eee9b0bb

24 Sep 2024 03:41PM UTC coverage: 70.281% (-28.5%) from 98.795%
11c952aa-d8e8-4073-941a-ba08eee9b0bb

push

circleci

jrgriffiniii
wip

525 of 747 relevant lines covered (70.28%)

9.14 hits per line

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

78.33
/app/models/waiver_info.rb
1
# frozen_string_literal: true
2

3
class WaiverInfo < ApplicationRecord
1✔
4
  # USE THIS when searching for all waiver infos
5
  @@MAX_WAIVER_MATCH = 10_000
1✔
6

7
  self.per_page = 10
1✔
8

9
  has_many :mail_records
1✔
10

11
  # Set the default order to the :created_at attribute
12
  default_scope { order(created_at: :desc) }
92✔
13

14
  before_save :lower_case_fields
1✔
15

16
  validates :requester, :requester_email, presence: true
1✔
17
  validates :author_first_name, :author_last_name, :author_email, :author_status, :author_department, presence: true
1✔
18
  validates_presence_of :title, :journal, presence: true
1✔
19

20
  validates_format_of :author_email,
1✔
21
                      with: /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/
22
  validates_format_of :requester_email,
1✔
23
                      with: /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/
24

25
  validates_format_of :cc_email,
1✔
26
                      with: /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/,
27
                      allow_nil: true
28

29
  validates_format_of :author_unique_id,
1✔
30
                      with: /\b\d{9}\z/,
31
                      message: "id must be 9 digits",
32
                      allow_nil: true
33

34
  validates :author_unique_id, presence: true, if: :faculty?
1✔
35

36
  attr_accessor :author_preferred_name; # not stored to db - used in waiver_infos/_edit_form
1✔
37
  attr_accessor :cc_email; # not stored to db - used in waiver_infos/_edit_form
1✔
38

39
  # store requester, requester_email, and author_email in lower case
40
  def lower_case_fields
1✔
41
    self.author_email = author_email.downcase
47✔
42
    self.requester = requester.downcase
47✔
43
    self.requester_email = requester_email.downcase
47✔
44
  end
45

46
  def valid_author?
1✔
47
    return true if valid?
2✔
48

49
    error_messages = errors.messages
1✔
50
    author_keys = error_messages.keys.select { |key| key.to_s.include?("author_") }
2✔
51

52
    author_keys.empty?
1✔
53
  end
54

55
  def faculty?
1✔
56
    AuthorStatus.faculty_status?(author_status)
83✔
57
  end
58

59
  def legacy?
1✔
60
    mail_records.none?
×
61
  end
62

63
  def self.find_by_email(email)
1✔
64
    email = email.downcase
×
65
    where("requester_email = ? OR author_email = ?", email, email)
×
66
  end
67

68
  def self.find_by_missing_unique_id
1✔
69
    where(author_unique_id: nil)
2✔
70
  end
71

72
  def citation
1✔
73
    "#{title}, #{journal}, #{author_last_name}, #{author_first_name}"
47✔
74
  end
75

76
  def mail_records
1✔
77
    values = super
×
78
    return [] if values.nil?
×
79

80
    values
×
81
  end
82

83
  # ---------------------
84
  # Search/Solr
85
  # ---------------------
86
  def all_word_fields
1✔
87
    [citation, author_department, notes]
47✔
88
  end
89

90
  def unique_title
1✔
91
    "#{title} #{id}"
47✔
92
  end
93

94
  def unique_author
1✔
95
    "#{author_last_name} #{id}"
47✔
96
  end
97

98
  searchable do
1✔
99
    text :all_word_fields, stored: true
1✔
100
    string :author_last_name, stored: true
1✔
101
    string :unique_title, multiple: false, stored: true
1✔
102
    string :unique_author, multiple: false, stored: true
1✔
103
  end
104

105
  # search for employees with a matching first, last or preferred_name
106
  # return Sunspot::Search object
107
  def self.all_with_words(words)
1✔
108
    search_with_words(words, nil, @@MAX_WAIVER_MATCH)
×
109
  end
110

111
  # search for employees with a matching first, last or preferred_name
112
  # return Sunspot::Search object
113
  def self.search_with_words(words, page, per_page)
1✔
114
    per_page ||= self.per_page
×
115
    s = WaiverInfo.search do
×
116
      fulltext words, fields: [:all_word_fields]
×
117
      order_by :author_last_name
×
118
      paginate page: page, per_page: per_page
×
119
    end
120
    s
×
121
  end
122
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc