Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions app/helpers/distributions_helper.rb

This file was deleted.

10 changes: 10 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#

class Organization < ApplicationRecord
DIAPER_APP_LOGO = Rails.root.join("app", "assets", "images", "DiaperBase-Logo.png")

validates :name, presence: true
validates :short_name, presence: true, format: /\A[a-z0-9_]+\z/i
validates :url, format: { with: URI::DEFAULT_PARSER.make_regexp, message: "it should look like 'http://www.example.com'" }, allow_blank: true
Expand Down Expand Up @@ -95,6 +97,14 @@ def self.seed_items(org)
org.reload
end

def logo_path
if logo.attached?
ActiveStorage::Blob.service.send(:path_for, logo.key).to_s
else
Organization::DIAPER_APP_LOGO.to_s
end
end

private

def correct_logo_mime_type
Expand Down
4 changes: 2 additions & 2 deletions app/views/distributions/print.pdf.prawn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
prawn_document do |pdf|
pdf.image logo_file_path(current_organization), height: 110
pdf.image current_organization.logo_path, fit: [325, 110]

pdf.bounding_box [pdf.bounds.right - 225, pdf.bounds.top - 20], width: 225 do
pdf.text current_organization.name, align: :right
Expand Down Expand Up @@ -117,7 +117,7 @@ prawn_document do |pdf|
logo_offset = (pdf.bounds.width - 190) / 2
pdf.bounding_box([logo_offset, 0], width: 190, height: 33) do
pdf.text "Lovingly created with", valign: :center
pdf.image logo_file_path, width: 75, vposition: :center, position: :right
pdf.image Organization::DIAPER_APP_LOGO, width: 75, vposition: :center, position: :right
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,19 @@
expect(organization.total_inventory).to eq(0)
end
end

describe "logo_path" do
it "returns the the default logo path when no logo attached" do
org = build(:organization, logo: nil)
expect(org.logo_path).to include("app/assets/images/DiaperBase-Logo.png")
end

it "returns the logo path attached for the organization" do
org = build(:organization,
logo: Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/logo.jpg"),
"image/jpeg"))

expect(org.logo_path).to include(Rails.root.join("tmp/storage").to_s)
end
end
end