changeset 484:84ca55a0568e

Fix pasting base64 gzip and fix tests
author nanaya <me@nanaya.pro>
date Sun, 28 Nov 2021 20:01:18 +0900
parents 02d043b1967d
children 6cac8fcf8164
files app/models/paste.rb test/controllers/pastes_controller_test.rb test/fixtures/files/hello_world.txt.gz
diffstat 3 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/app/models/paste.rb	Sun Nov 28 19:54:08 2021 +0900
+++ b/app/models/paste.rb	Sun Nov 28 20:01:18 2021 +0900
@@ -36,7 +36,9 @@
   end
 
   def paste_gzip=(paste)
-    self.paste = ActiveSupport::Gzip.decompress paste.read
+    paste = paste.read if paste.is_a? ActionDispatch::Http::UploadedFile
+
+    self.paste = ActiveSupport::Gzip.decompress paste
   end
 
   def paste_gzip_base64=(paste)
--- a/test/controllers/pastes_controller_test.rb	Sun Nov 28 19:54:08 2021 +0900
+++ b/test/controllers/pastes_controller_test.rb	Sun Nov 28 20:01:18 2021 +0900
@@ -11,7 +11,7 @@
 
   test "creates paste from gzip" do
     assert_difference("Paste.count", 1) do
-      post :create, :params => { "paste" => { "paste_gzip" => ActiveSupport::Gzip.compress("here be paste") } }
+      post :create, :params => { "paste" => { "paste_gzip" => fixture_file_upload('hello_world.txt.gz') } }
     end
 
     assert_response :redirect
Binary file test/fixtures/files/hello_world.txt.gz has changed