- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
Support for virtual fields #2658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f377679
              
                Support for virtual fields
              
              
                goosys a575bde
              
                WIP: fix read_value method in Administrate::Field::Base
              
              
                goosys 7266daa
              
                Add virtual field full_address for sample purposes
              
              
                goosys 07e927d
              
                Update spec/lib/fields/base_spec.rb
              
              
                goosys c6c32a4
              
                Add ReceiptLink field as virtual field sample
              
              
                goosys bb4e196
              
                Remove unnecessary examples and specs
              
              
                goosys cab6096
              
                Force searchable to false when getter is specified
              
              
                goosys d1fd3a9
              
                Add docs about virtual fields
              
              
                goosys bf727b7
              
                Update docs/customizing_dashboards.md
              
              
                goosys 87c7e4c
              
                Refactor base_spec.rb to remove unnecessary code
              
              
                goosys ff843b8
              
                Unused. Leftover from changes?
              
              
                pablobm 9d43275
              
                Better experience for example app
              
              
                pablobm 157485a
              
                Merge pull request #1 from pablobm/goosys-issue-1586-virtual-fields
              
              
                goosys 4ea760a
              
                Refactor payment_index_spec to use have_current_path instead of curre…
              
              
                goosys File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.