File tree Expand file tree Collapse file tree 7 files changed +38
-23
lines changed
controllers/better_together
views/better_together/uploads Expand file tree Collapse file tree 7 files changed +38
-23
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ class UploadsController < FriendlyResourceController
66 before_action :set_resource_instance , only : %i[ show edit update destroy download ]
77 before_action :authorize_resource , only : %i[ new show edit update destroy download ]
88
9+ def index
10+ @total_size = policy_scope ( Upload ) . sum ( &:byte_size )
11+ end
12+
913 def download # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
1014 if resource_instance . attached?
1115 # Trigger the background job to log the download
Original file line number Diff line number Diff line change 33module BetterTogether
44 # helper methods for file uploads
55 module UploadsHelper
6+ def total_upload_size ( uploads )
7+ number_to_human_size ( uploads . sum ( &:byte_size ) )
8+ end
69 end
710end
Original file line number Diff line number Diff line change 1- < h1 > Files#index</ h1 >
2- < p > Find me in app/views/better_together/files/index.html.erb</ p >
1+ <% content_for :page_title do %>
2+ <%= resource_class.model_name.human.pluralize %>
3+ <% end %>
4+
5+ <div class ="container my-3 ">
6+ < h1 > <%= resource_class . model_name . human . pluralize %> </ h1 >
7+ < p > <%= t ( '.storage_usage' , size : number_to_human_size ( @total_size ) ) %> </ p >
8+ </ div >
Original file line number Diff line number Diff line change 613613 contact_details : Contact details
614614 details : Details
615615 images : Images
616+ uploads :
617+ index :
618+ storage_usage : " You're using %{size} of storage"
616619 contact_details :
617620 contact_information : Contact information
618621 title : Contact Details
Original file line number Diff line number Diff line change 22
33require 'rails_helper'
44
5- # Specs in this file have access to a helper object that includes
6- # the UploadsHelper. For example:
7- #
8- # describe UploadsHelper do
9- # describe "string concat" do
10- # it "concats two strings with spaces" do
11- # expect(helper.concat_strings("this","that")).to eq("this that")
12- # end
13- # end
14- # end
155module BetterTogether
166 RSpec . describe UploadsHelper , type : :helper do
17- it 'exists' do
18- expect ( described_class ) . to be
7+ describe '#total_upload_size' do
8+ it 'returns human readable total size' do
9+ uploads = [ double ( byte_size : 2 . megabytes ) , double ( byte_size : 3 . megabytes ) ]
10+ expect ( helper . total_upload_size ( uploads ) ) . to eq '5 MB'
11+ end
1912 end
2013 end
2114end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'rails_helper'
4+
5+ RSpec . describe 'better_together/uploads/index.html.erb' , type : :view do
6+ it 'renders total storage usage' do
7+ allow ( view ) . to receive ( :resource_class ) . and_return ( BetterTogether ::Upload )
8+ assign ( :uploads , [ ] )
9+ assign ( :total_size , 3 . megabytes )
10+
11+ render
12+
13+ expect ( rendered ) . to include ( "You're using 3 MB of storage" )
14+ end
15+ end
You can’t perform that action at this time.
0 commit comments