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

pulibrary / tigerdata-app / b489533f-9066-4a1f-b488-40e1f0465f4b

04 Aug 2025 05:29PM UTC coverage: 75.6% (-1.5%) from 77.142%
b489533f-9066-4a1f-b488-40e1f0465f4b

Pull #1657

circleci

JaymeeH
Merge branch 'i1632-save-data-users' of https://github.com/pulibrary/tiger-data-app into i1632-save-data-users
Pull Request #1657: Add data users to a project after it is created in mediaflux

23 of 81 new or added lines in 4 files covered. (28.4%)

5 existing lines in 2 files now uncovered.

2206 of 2918 relevant lines covered (75.6%)

314.38 hits per line

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

95.08
/app/models/request.rb
1
# frozen_string_literal: true
2
# Explicitly require the file from your model.
3
require_relative "../operations/project_create"
1✔
4
class Request < ApplicationRecord
1✔
5
  DRAFT = "draft" # default state set by database
1✔
6
  SUBMITTED = "submitted" # Ready to be approved
1✔
7

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

25
  def valid_title?
1✔
26
    field_present?(project_title, :project_title)
24✔
27
  end
28

29
  def valid_data_sponsor?
1✔
30
    valid_uid?(data_sponsor, :data_sponsor)
25✔
31
  end
32

33
  def valid_data_manager?
1✔
34
    valid_uid?(data_manager, :data_manager)
25✔
35
  end
36

37
  def valid_departments?
1✔
38
    field_present?(departments, :departments)
24✔
39
  end
40

41
  def valid_description?
1✔
42
    field_present?(description, :description)
24✔
43
  end
44

45
  def valid_parent_folder?
1✔
46
    field_present?(parent_folder, :parent_folder)
2✔
47
  end
48

49
  def valid_project_folder?
1✔
50
    field_present?(project_folder, :project_folder)
24✔
51
  end
52

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

63
  def custom_quota?
1✔
64
    quota == "custom"
7✔
65
  end
66

67
  def valid_requested_by?
1✔
68
    field_present?(requested_by, :requested_by)
2✔
69
  end
70

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

85
  private
1✔
86

87
    def field_present?(value, name)
1✔
88
      if value.present?
100✔
89
        true
38✔
90
      else
91
        errors.add(name, :invalid, message: "cannot be empty")
62✔
92
        false
62✔
93
      end
94
    end
95

96
    def valid_uid?(uid, field)
1✔
97
      if uid.blank?
50✔
98
        errors.add(field, :blank, message: "cannot be empty")
25✔
99
        false
25✔
100
      elsif User.where(uid: uid).count == 0
25✔
101
        errors.add(field, :invalid, message: "must be a valid user")
2✔
102
        false
2✔
103
      else
104
        true
23✔
105
      end
106
    end
107
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