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

pulibrary / oawaiver / 40ca2f09-e694-44a5-b909-7cce179b9e67

11 Jul 2024 05:42PM UTC coverage: 0.0% (-80.4%) from 80.383%
40ca2f09-e694-44a5-b909-7cce179b9e67

push

circleci

jrgriffiniii
Trying to expand the RSpec test suite for EmployeesController#ajax_search

0 of 1206 relevant lines covered (0.0%)

0.0 hits per line

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

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

3
class WaiverInfo < ApplicationRecord
×
4
  # USE THIS when searching for all waiver infos
5
  @@MAX_WAIVER_MATCH = 10_000
×
6
  self.per_page = 10
×
7

8
  has_many :mail_records
×
9

10
  # Set the default order to the :created_at attribute
11
  default_scope { order(created_at: :desc) }
×
12

13
  before_save :lower_case_fields
×
14

15
  validates :requester, :requester_email, presence: true
×
16
  validates :author_first_name, :author_last_name, :author_email, :author_status, :author_department, presence: true
×
17
  validates_presence_of :title, :journal, presence: true
×
18

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

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

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

33
  validates :author_unique_id, presence: true, if: :faculty?
×
34

35
  attr_accessor :author_preferred_name; # not stored to db - used in waiver_infos/_edit_form
×
36
  attr_accessor :cc_email; # not stored to db - used in waiver_infos/_edit_form
×
37

38
  # store requester, requester_email, and author_email in lower case
39
  def lower_case_fields
×
40
    self.author_email = author_email.downcase
×
41
    self.requester = requester.downcase
×
42
    self.requester_email = requester_email.downcase
×
43
  end
×
44

45
  def valid_author?
×
46
    return true if valid?
×
47

48
    # check that none of the author_fields are in the errors list
49
    ms = errors.messages
×
50
    return false if ms.key?(:author_last_name)
×
51
    return false if ms.key?(:author_first_name)
×
52
    return false if ms.key?(:author_department)
×
53
    return false if ms.key?(:author_status)
×
54
    return false if ms.key?(:author_email)
×
55

56
    true
×
57
  end
×
58

59
  def faculty?
×
60
    AuthorStatus.faculty_status?(author_status)
×
61
  end
×
62

63
  def legacy?
×
64
    mail_records.none?
×
65
  end
×
66

67
  def self.find_by_email(email)
×
68
    email = email.downcase
×
69
    where("requester_email = ? OR author_email = ?", email, email)
×
70
  end
×
71

72
  def self.find_by_missing_unique_id
×
73
    where(author_unique_id: nil)
×
74
  end
×
75

76
  def citation
×
77
    "#{title}, #{journal}, #{author_last_name}, #{author_first_name}"
×
78
  end
×
79

80
  def mail_records
×
81
    values = super
×
82
    return [] if values.nil?
×
83

84
    values
×
85
  end
×
86

87
  # ---------------------
88
  # Search/Solr
89
  # ---------------------
90
  def all_word_fields
×
91
    [citation, author_department, notes]
×
92
  end
×
93

94
  def unique_title
×
95
    "#{title} #{id}"
×
96
  end
×
97

98
  def unique_author
×
99
    "#{author_last_name} #{id}"
×
100
  end
×
101

102
  searchable do
×
103
    text :all_word_fields, stored: true
×
104
    string :author_last_name, stored: true
×
105
    string :unique_title, multiple: false, stored: true
×
106
    string :unique_author, multiple: false, stored: true
×
107
  end
×
108

109
  # search for employees with a matching first, last or preferred_name
110
  # return Sunspot::Search object
111
  def self.all_with_words(words)
×
112
    search_with_words(words, nil, @@MAX_WAIVER_MATCH)
×
113
  end
×
114

115
  # search for employees with a matching first, last or preferred_name
116
  # return Sunspot::Search object
117
  def self.search_with_words(words, page, per_page)
×
118
    per_page ||= self.per_page
×
119
    s = WaiverInfo.search do
×
120
      fulltext words, fields: [:all_word_fields]
×
121
      order_by :author_last_name
×
122
      paginate page: page, per_page: per_page
×
123
    end
×
124
    s
×
125
  end
×
126
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