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

pulibrary / tigerdata-app / 8f14883f-0ae2-4a66-9ab3-48069d0f2a95

11 Aug 2025 10:06PM UTC coverage: 76.229% (-0.3%) from 76.482%
8f14883f-0ae2-4a66-9ab3-48069d0f2a95

Pull #1669

circleci

tpendragon
Try this.
Pull Request #1669: Testing pulibrary resource class

2264 of 2970 relevant lines covered (76.23%)

176.36 hits per line

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

95.12
/app/models/request.rb
1
# frozen_string_literal: true
2
class Request < ApplicationRecord
1✔
3
  DRAFT = "draft" # default state set by database
1✔
4
  SUBMITTED = "submitted" # Ready to be approved
1✔
5

6
  def valid_to_submit?
1✔
7
    errors.clear
30✔
8
    # run all validations and then check for errors otherwise ruby stops at the first error
9
    valid_title?
30✔
10
    valid_data_sponsor?
30✔
11
    valid_data_manager?
30✔
12
    valid_departments?
30✔
13
    valid_quota?
30✔
14
    valid_description?
30✔
15
    # Is parent folder really required?  For Skeletor let's skip it.
16
    # valid_parent_folder?
17
    valid_project_folder?
30✔
18
    # For Skeletor we are setting the requestor to the data sponsor
19
    # valid_requested_by?
20
    errors.count == 0
30✔
21
  end
22

23
  def valid_title?
1✔
24
    field_present?(project_title, :project_title)
36✔
25
  end
26

27
  def valid_data_sponsor?
1✔
28
    valid_uid?(data_sponsor, :data_sponsor)
33✔
29
  end
30

31
  def valid_data_manager?
1✔
32
    valid_uid?(data_manager, :data_manager)
33✔
33
  end
34

35
  def valid_departments?
1✔
36
    field_present?(departments, :departments)
32✔
37
  end
38

39
  def valid_description?
1✔
40
    field_present?(description, :description)
32✔
41
  end
42

43
  def valid_parent_folder?
1✔
44
    field_present?(parent_folder, :parent_folder)
2✔
45
  end
46

47
  def valid_project_folder?
1✔
48
    field_present?(project_folder, :project_folder)
32✔
49
  end
50

51
  def valid_quota?
1✔
52
    if ((quota == "500 GB") || (quota == "2 TB") || (quota == "10 TB") || (quota == "25 TB")) ||
38✔
53
       (custom_quota? && (storage_size.present? && (storage_size > 0)) && ((storage_unit == "GB") || (storage_unit == "TB")))
4✔
54
      true
35✔
55
    else
56
      errors.add(:quota, :invalid, message: "must be one of '500 GB', '2 TB', '10 TB', '25 TB', or 'custom'")
3✔
57
      false
3✔
58
    end
59
  end
60

61
  def custom_quota?
1✔
62
    quota == "custom"
24✔
63
  end
64

65
  def valid_requested_by?
1✔
66
    field_present?(requested_by, :requested_by)
2✔
67
  end
68

69
  def approve(approver)
1✔
70
    create_project_operation = ProjectCreate.new
1✔
71
    result = create_project_operation.call(request: self, approver: approver)
1✔
72
    result = result.flatten while result.class != Project
×
73
    result
×
74
  rescue ProjectCreate::ProjectCreateError => ex
75
    # Save the error within the Request object
76
    self.error_message = { message: ex.message }
1✔
77
    save!
1✔
78
    # ..and get rid of the Rails project
79
    project.destroy!
1✔
80
    raise "Error approving request #{id}"
×
81
  end
82

83
  def approved_quota_size
1✔
84
    if approved_quota.present?
5✔
85
      if approved_quota == "custom"
1✔
86
        approved_storage_size.to_f
×
87
      else
88
        approved_quota.split.first.to_f
1✔
89
      end
90
    else
91
      requested_quota_size
4✔
92
    end
93
  end
94

95
  def requested_quota_size
1✔
96
    if custom_quota?
10✔
97
      storage_size.to_f
4✔
98
    else
99
      quota.split.first.to_f
6✔
100
    end
101
  end
102

103
  def approved_quota_unit
1✔
104
    if approved_quota.present?
8✔
105
      if approved_quota == "custom"
3✔
106
        approved_storage_unit
2✔
107
      else
108
        approved_quota.split.last
1✔
109
      end
110
    else
111
      requested_quota_unit
5✔
112
    end
113
  end
114

115
  def requested_quota_unit
1✔
116
    if custom_quota?
10✔
117
      storage_unit
4✔
118
    else
119
      quota.split.last
6✔
120
    end
121
  end
122

123
  def submitted?
1✔
124
    state == Request::SUBMITTED
8✔
125
  end
126

127
  private
1✔
128

129
    def field_present?(value, name)
1✔
130
      if value.present?
136✔
131
        true
58✔
132
      else
133
        errors.add(name, :invalid, message: "cannot be empty")
78✔
134
        false
78✔
135
      end
136
    end
137

138
    def valid_uid?(uid, field)
1✔
139
      if uid.blank?
66✔
140
        errors.add(field, :blank, message: "cannot be empty")
33✔
141
        false
33✔
142
      elsif User.where(uid: uid).count == 0
33✔
143
        errors.add(field, :invalid, message: "must be a valid user")
2✔
144
        false
2✔
145
      else
146
        true
31✔
147
      end
148
    end
149
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