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

pulibrary / tigerdata-app / 47f8b36e-6cbd-422b-b67d-16bb6ff637e9

29 Oct 2025 11:56AM UTC coverage: 82.265% (-9.1%) from 91.333%
47f8b36e-6cbd-422b-b67d-16bb6ff637e9

Pull #2118

circleci

bess
Update expected version of mediaflux
Pull Request #2118: Upgrade to mediaflux_dev v0.17.0

1 of 1 new or added line in 1 file covered. (100.0%)

568 existing lines in 35 files now uncovered.

2528 of 3073 relevant lines covered (82.26%)

296.63 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
2✔
3
  delegate "id", "in_mediaflux?", "mediaflux_id", "status", to: :project
2✔
4
  delegate "project_id", "storage_performance_expectations", to: :project_metadata
2✔
5

6
  attr_reader :project, :project_metadata
2✔
7

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

30
  def title
2✔
31
    if @project_mf.nil?
198✔
32
      @project.title
46✔
33
    else
34
      @project_mf[:title]
152✔
35
    end
36
  end
37

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

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

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

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

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

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

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

80
  def project_purpose
2✔
UNCOV
81
    if @project_mf.nil?
×
UNCOV
82
      project_metadata.project_purpose
×
83
    else
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
2✔
90
    project.project_directory.gsub(Mediaflux::Connection.hidden_root, "")
12✔
91
  end
92

93
  def storage_capacity(session_id: nil)
2✔
94
    return project_metadata.storage_capacity if session_id.nil?
34✔
95

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

99
    value*default_capacity_divisor
34✔
100
  end
101

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

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

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

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

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?
2✔
UNCOV
125
    project != nil
940✔
126
  end
127

128
  private
2✔
129

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

135
    def xml_presenter_args
2✔
136
      project
5✔
137
    end
138

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

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