-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pablo Brasero <pablo@pablobm.com>
- Loading branch information
Showing
13 changed files
with
287 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class FilesController < ApplicationController | ||
def download | ||
filename = params[:filename] | ||
match = %r{receipt-(\d+)}.match(filename) | ||
if match | ||
payment_id = match[1] | ||
send_data("This is the receipt for payment ##{payment_id}", filename: "#{filename}.txt") | ||
else | ||
render status: 404, layout: false, file: Rails.root.join("public/404.html") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_to field.filename, field.data %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_to field.filename, field.data %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "administrate/field/base" | ||
|
||
module Administrate | ||
module Field | ||
class ReceiptLink < Base | ||
def data | ||
"/files/receipts/#{filename}" | ||
end | ||
|
||
def filename | ||
"receipt-#{resource.id}.txt" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "payment index page" do | ||
it "displays payments' id and receipt link" do | ||
payment = create(:payment) | ||
|
||
visit admin_payments_path | ||
|
||
expect(page).to have_header("Payments") | ||
expect(page).to have_content(payment.id) | ||
expect(page).to have_content("receipt-#{payment.id}.txt") | ||
end | ||
|
||
it "allows downloading the receipt" do | ||
payment = create(:payment) | ||
|
||
visit admin_payments_path | ||
click_on("receipt-#{payment.id}.txt") | ||
|
||
expect(page.body).to eq("This is the receipt for payment ##{payment.id}") | ||
expect(response_headers["Content-Disposition"]).to match(%r{^attachment; filename=}) | ||
end | ||
|
||
it "links to the payment show page", :js do | ||
payment = create(:payment) | ||
|
||
visit admin_payments_path | ||
click_row_for(payment) | ||
|
||
expect(page).to have_content(payment.id) | ||
expect(page).to have_current_path(admin_payment_path(payment)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters