Skip to content

Commit

Permalink
Merge pull request #1281 from sparc-request/wth-document-bug
Browse files Browse the repository at this point in the history
wth - (SPARCRequest & SPARC Dashboard) Document upload bug
  • Loading branch information
Stuart-Johnson committed Apr 4, 2018
2 parents 6fee8e0 + 64326da commit a77a14f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
36 changes: 16 additions & 20 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@ class Document < ApplicationRecord
has_and_belongs_to_many :sub_service_requests
belongs_to :protocol
has_attached_file :document #, :preserve_files => true
validates_attachment :document, content_type: { content_type: [
"application/pdf",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.ms-office",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.ms-powerpoint",
"application/octet-stream",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/msword",
"application/vnd.ms-excel",
"image/jpeg",
"text/csv",
"text/rtf",
"text/plain",
"text/msg",
"message/rfc822",
"image/gif",
"image/png",
"image/tiff"
] }
validates_attachment_file_name :document, matches: [
/\.pdf$/,
/\.docx?$/,
/\.xlsx?$/,
/\.rtf$/,
/\.txt$/,
/\.csv$/,
/\.ppt?$/,
/\.msg$/,
/\.eml$/,
/\.jpg$/,
/\.gif$/,
/\.png$/,
/\.tiff$/,
/\.jpeg$/
]

validates :doc_type, :document, presence: true
validates :doc_type_other, presence: true, if: Proc.new { |doc| doc.doc_type == 'other' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def go_to_show_protocol(protocol_id)
let!(:super_user) { create(:super_user, organization: organization, identity: logged_in_user) }
let!(:service_request) { create(:service_request_without_validations, protocol: protocol) }
let!(:ssr) { create(:sub_service_request_without_validations, service_request: service_request, organization: organization, status: 'draft') }
let!(:document_with_access) { create(:document, protocol: protocol, doc_type: 'Protocol', document_file_name: 'accessible_doc') }
let!(:document_no_access) { create(:document, protocol: protocol, doc_type: 'Consent', document_file_name: 'inaccessible_doc') }
let!(:document_with_access) { create(:document, protocol: protocol, doc_type: 'Protocol', document_file_name: 'accessible_doc.pdf') }
let!(:document_no_access) { create(:document, protocol: protocol, doc_type: 'Consent', document_file_name: 'inaccessible_doc.pdf') }

before :each do
document_with_access.sub_service_requests = [ssr]
Expand Down

0 comments on commit a77a14f

Please sign in to comment.