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

pulibrary / tigerdata-app / ef572ceb-a81a-43e7-bdc7-686bc2a048ee

05 Nov 2025 10:27PM UTC coverage: 83.655% (-7.4%) from 91.073%
ef572ceb-a81a-43e7-bdc7-686bc2a048ee

Pull #2154

circleci

JaymeeH
Display project directory correctly and consistently
Pull Request #2154: Display project directory correctly and consistently

0 of 2 new or added lines in 2 files covered. (0.0%)

711 existing lines in 37 files now uncovered.

2600 of 3108 relevant lines covered (83.66%)

315.14 hits per line

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

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

6
  attr_reader :project, :project_metadata
3✔
7

8
  # @return [Class] The presenter class for building XML Documents from Projects
9
  def self.xml_presenter_class
3✔
10
    ProjectXmlPresenter
6✔
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.
19
  def initialize(project)
3✔
20
    if project.is_a?(Hash)
1,242✔
UNCOV
21
      @project_mf = project
1,203✔
UNCOV
22
      @project = rails_project(@project_mf)
1,203✔
23
    else
24
      @project_mf = nil
39✔
25
      @project = project
39✔
26
    end
27
    @project_metadata = @project&.metadata_model
1,242✔
28
  end
29

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

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

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

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

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

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

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

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

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

88
  # used to hide the project root that is not visible to the end user
89
  def project_directory
3✔
NEW
90
    "/#{project.project_directory.gsub(Mediaflux::Connection.hidden_root, "")}"
11✔
91
  end
92

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

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

99
    value*default_capacity_divisor
33✔
100
  end
101

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

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

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

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

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

124
  def project_in_rails?
3✔
UNCOV
125
    project != nil
1,203✔
126
  end
127

128
  private
3✔
129

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

135
    def xml_presenter_args
3✔
136
      project
6✔
137
    end
138

139
    def xml_presenter
3✔
140
      @xml_presenter ||= self.class.xml_presenter_class.new(xml_presenter_args)
6✔
141
    end
142

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