From e3c90174eed1fb5ac6d3cd3be8adc6e023632a37 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 6 Jun 2017 14:11:28 +0200 Subject: [PATCH] Added save_to_file as helper to get attachments for testing assets. --- app/models/store.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/models/store.rb b/app/models/store.rb index a5ea0520c..d423b90bc 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -139,6 +139,19 @@ returns true end +=begin + +get content of file + + store = Store.find(store_id) + content_as_string = store.content + +returns + + content_as_string + +=end + def content file = Store::File.find_by(id: store_file_id) if !file @@ -147,6 +160,34 @@ returns file.content end +=begin + +get content of file + + store = Store.find(store_id) + location_of_file = store.save_to_file + +returns + + location_of_file + +=end + + def save_to_file(path = nil) + content + file = Store::File.find_by(id: store_file_id) + if !file + raise "No such file #{store_file_id}!" + end + if !path + path = "#{Rails.root}/tmp/#{filename}" + end + ::File.open(path, 'wb') { |handle| + handle.write file.content + } + path + end + def provider file = Store::File.find_by(id: store_file_id) if !file