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

pulibrary / tigerdata-app / 8306569a-4f72-444d-ba8a-d69ed227106c

05 Nov 2025 07:43PM UTC coverage: 91.527% (+0.03%) from 91.5%
8306569a-4f72-444d-ba8a-d69ed227106c

push

circleci

web-flow
Set the displayed value to the entire name (#2151)

Centralize the view and javascript for data manager and sponsor
Set the displayed value to the entire name and have a hidden field with
the uid

fix spec error "not to search for nil"
<img width="1707" height="1085" alt="Screenshot 2025-11-05 at 2 38
43 PM"
src="https://github.com/user-attachments/assets/82278712-d16d-4b58-8b9c-5c33587a7810"
/>

6 of 10 new or added lines in 1 file covered. (60.0%)

1010 existing lines in 37 files now uncovered.

2841 of 3104 relevant lines covered (91.53%)

792.96 hits per line

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

97.37
/app/presenters/project_show_presenter.rb
1
# frozen_string_literal: true
UNCOV
2
class ProjectShowPresenter
4✔
UNCOV
3
  delegate "id", "in_mediaflux?", "mediaflux_id", "status", to: :project
4✔
UNCOV
4
  delegate "project_id", "storage_performance_expectations", to: :project_metadata
4✔
5

UNCOV
6
  attr_reader :project, :project_metadata
4✔
7

8
  # @return [Class] The presenter class for building XML Documents from Projects
UNCOV
9
  def self.xml_presenter_class
4✔
UNCOV
10
    ProjectXmlPresenter
14✔
UNCOV
11
  end
12

13
  # While we are transitioning to fetching the data straight from Mediaflux `project` can be
14
  # an ActiveRecord Project model (when used from the Project show page) or a Hash with the
15
  # data from Mediaflux (when used from the Dashboard).
16
  # This branching can be refactored (elimitated?) once we implement ticket
17
  # https://github.com/pulibrary/tigerdata-app/issues/2039 and the project data will always
18
  # come from Mediaflux.
UNCOV
19
  def initialize(project)
4✔
UNCOV
20
    if project.is_a?(Hash)
2,508✔
21
      @project_mf = project
2,399✔
22
      @project = rails_project(@project_mf)
2,399✔
UNCOV
23
    else
UNCOV
24
      @project_mf = nil
109✔
UNCOV
25
      @project = project
109✔
UNCOV
26
    end
UNCOV
27
    @project_metadata = @project&.metadata_model
2,508✔
UNCOV
28
  end
29

UNCOV
30
  def title
4✔
UNCOV
31
    if @project_mf.nil?
204✔
UNCOV
32
      @project.title
52✔
UNCOV
33
    else
34
      @project_mf[:title]
152✔
UNCOV
35
    end
UNCOV
36
  end
37

UNCOV
38
  def description
4✔
UNCOV
39
    if @project_mf.nil?
52✔
UNCOV
40
      @project.metadata_model.description
52✔
UNCOV
41
    else
42
      @project_mf[:description]
×
UNCOV
43
    end
UNCOV
44
  end
45

46
  # @return [String] the XML for the project Document
UNCOV
47
  def to_xml
4✔
UNCOV
48
    xml_document.to_xml
12✔
UNCOV
49
  end
50

51
  # @return [Nokogiri::XML::Document] the XML Document for the Project
UNCOV
52
  def xml_document
4✔
UNCOV
53
    @xml_document ||= xml_presenter.document
14✔
UNCOV
54
  end
55

UNCOV
56
  def created
4✔
UNCOV
57
    @project.created_at.strftime("%b %e, %Y %l:%M %p")
35✔
UNCOV
58
  end
59

UNCOV
60
  def updated
4✔
UNCOV
61
    @project.updated_at.strftime("%b %e, %Y %l:%M %p")
35✔
UNCOV
62
  end
63

UNCOV
64
  def data_sponsor
4✔
UNCOV
65
    if @project_mf.nil?
193✔
UNCOV
66
      User.find_by(uid: @project.metadata["data_sponsor"]).uid
35✔
UNCOV
67
    else
68
      User.find_by(uid: @project_mf[:data_sponsor])&.uid
158✔
UNCOV
69
    end
UNCOV
70
  end
71

UNCOV
72
  def data_manager
4✔
UNCOV
73
    if @project_mf.nil?
111✔
UNCOV
74
      User.find_by(uid: @project.metadata["data_manager"]).uid
35✔
UNCOV
75
    else
76
      User.find_by(uid: @project_mf[:data_manager])&.uid
76✔
UNCOV
77
    end
UNCOV
78
  end
79

UNCOV
80
  def project_purpose
4✔
81
    if @project_mf.nil?
4✔
82
      project_metadata.project_purpose
4✔
UNCOV
83
    else
84
      @project_mf[:project_purpose]
×
UNCOV
85
    end
UNCOV
86
  end
87

88
  # used to hide the project root that is not visible to the end user
UNCOV
89
  def project_directory
4✔
UNCOV
90
    project.project_directory.gsub(Mediaflux::Connection.hidden_root, "")
17✔
UNCOV
91
  end
92

UNCOV
93
  def storage_capacity(session_id: nil)
4✔
UNCOV
94
    return project_metadata.storage_capacity if session_id.nil?
39✔
95

UNCOV
96
    persisted = project.storage_capacity_raw(session_id: session_id)
35✔
UNCOV
97
    value = persisted.to_f
35✔
98

UNCOV
99
    value*default_capacity_divisor
35✔
UNCOV
100
  end
101

UNCOV
102
  def formatted_storage_capacity(session_id:)
4✔
UNCOV
103
    value = storage_capacity(session_id: session_id)
35✔
UNCOV
104
    format("%.3f", value)
35✔
UNCOV
105
  end
106

UNCOV
107
  def formatted_quota_percentage(session_id:)
4✔
UNCOV
108
    value = quota_percentage(session_id:)
35✔
UNCOV
109
    format("%.3f", value)
35✔
UNCOV
110
  end
111

UNCOV
112
  def quota_usage(session_id:)
4✔
UNCOV
113
    "#{project.storage_usage(session_id:)} out of #{project.storage_capacity(session_id:)} used"
187✔
UNCOV
114
  end
115

UNCOV
116
  def quota_percentage(session_id:)
4✔
UNCOV
117
    storage_capacity = project.storage_capacity_raw(session_id:)
146✔
UNCOV
118
    return 0 if storage_capacity.zero?
146✔
119

120
    storage_usage = project.storage_usage_raw(session_id:)
128✔
121
    (storage_usage.to_f / storage_capacity.to_f) * 100
128✔
UNCOV
122
  end
123

UNCOV
124
  def project_in_rails?
4✔
125
    project != nil
2,399✔
UNCOV
126
  end
127

UNCOV
128
  private
4✔
129

130
    # Capacity is in bytes
UNCOV
131
    def default_capacity_divisor
4✔
UNCOV
132
      1.0/(1000.0**3)
35✔
UNCOV
133
    end
134

UNCOV
135
    def xml_presenter_args
4✔
UNCOV
136
      project
14✔
UNCOV
137
    end
138

UNCOV
139
    def xml_presenter
4✔
UNCOV
140
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
14✔
UNCOV
141
    end
142

UNCOV
143
    def rails_project(project_mf)
4✔
144
      database_record = Project.where(mediaflux_id:project_mf[:mediaflux_id]).first
2,399✔
145
      if database_record.nil?
2,399✔
146
        Rails.logger.warn("Mediaflux project with ID #{project_mf[:mediaflux_id]} is not in the Rails database (title: #{project_mf[:title]})")
2,300✔
147
        Honeybadger.notify("Mediaflux project with ID #{project_mf[:mediaflux_id]} is not in the Rails database (title: #{project_mf[:title]})")
2,300✔
UNCOV
148
      end
149
      database_record
2,399✔
UNCOV
150
    end
UNCOV
151
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