Skip to content

Commit

Permalink
Merge branch 'release_1.103.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
aploshay committed Dec 13, 2021
2 parents dafba86 + e1a0529 commit f5d9928
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/pod_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index
def show
respond_to do |format|
response.headers['Content-Length'] = @pod_report.size.to_s
format.xls { send_file("public/reports/#{@pod_report.filename}", filename: @pod_report.filename) }
format.xls { send_file(Rails.root.join("public/reports/#{@pod_report.filename}"), filename: @pod_report.filename) }
end
end

Expand Down
12 changes: 7 additions & 5 deletions app/models/pod_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def full_path

def display_size
megabytes = (size.to_f / 2**20).round(0)
megabytes = 1 if size > 0 && megabytes.zero?
if complete?
megabytes.to_s
elsif status.match '%'
Expand All @@ -30,10 +31,11 @@ def display_size
end

def size
begin
File.size(self.full_path)
rescue Errno::ENOENT
0
end
@size ||=
begin
File.exist?(self.full_path) ? File.size(self.full_path) : 0
rescue Errno::ENOENT
0
end
end
end
36 changes: 30 additions & 6 deletions spec/models/pod_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,36 @@
end
end
context "with file present" do
before(:each) do
allow(File).to receive(:size).and_return(2**20)
allow(pod_report).to receive(:complete?).and_return(true)
context "with incomplete status" do
before(:each) do
allow(pod_report).to receive(:complete?).and_return(false)
allow(pod_report).to receive(:size).and_return(42 * 2**20)
allow(pod_report).to receive(:status).and_return("42% (ETA: tomorrow)")
end
it "returns current, projected total" do
expect(pod_report.display_size).to match /projected total/
end
end
it "returns filesize in MB" do
expect(pod_report.display_size).to eq '1'
context "with complete status" do
before(:each) do
allow(pod_report).to receive(:complete?).and_return(true)
end
context "with a small file" do
before(:each) do
allow(pod_report).to receive(:size).and_return(42)
end
it "returns minimum of 1 MB" do
expect(pod_report.display_size).to eq '1'
end
end
context "with a large file" do
before(:each) do
allow(pod_report).to receive(:size).and_return(42 * 2**20)
end
it "returns minimum of 1 MB" do
expect(pod_report.display_size).to eq '42'
end
end
end
end
end
Expand All @@ -90,8 +114,8 @@
context "with file present" do
let(:size) { 42 }
before(:each) do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:size).and_return(42)
allow(pod_report).to receive(:complete?).and_return(true)
end
it "returns filesize in MB" do
expect(pod_report.size).to eq size
Expand Down

0 comments on commit f5d9928

Please sign in to comment.