From e6c411684f851165464594e2a6731cf72d966b19 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 9 Sep 2020 14:58:09 +1000 Subject: [PATCH 1/3] Don't fail on missing images when resizing The changed code obtains the image dimensions when you first upload an image. Unfortunately it's also triggered when thumbnails are refreshed. That doesn't change the size of the original image though. --- app/models/spree/image.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index 24d20aeb93..ce9b03d9a2 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -34,6 +34,8 @@ module Spree end def find_dimensions + return if attachment.errors.present? + temporary = attachment.queued_for_write[:original] filename = temporary.path unless temporary.nil? filename = attachment.path if filename.blank? From 6bf041aa74d45e234f57c117ac224f7c43fd8eb3 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 11 Sep 2020 16:33:28 +1000 Subject: [PATCH 2/3] Reduce complexity --- app/models/spree/image.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index ce9b03d9a2..0bbdc5a85d 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -36,14 +36,22 @@ module Spree def find_dimensions return if attachment.errors.present? - temporary = attachment.queued_for_write[:original] - filename = temporary.path unless temporary.nil? - filename = attachment.path if filename.blank? - geometry = Paperclip::Geometry.from_file(filename) + geometry = Paperclip::Geometry.from_file(local_filename_of_original) + self.attachment_width = geometry.width self.attachment_height = geometry.height end + def local_filename_of_original + temporary = attachment.queued_for_write[:original] + + if temporary&.path.present? + temporary.path + else + attachment.path + end + end + # if there are errors from the plugin, then add a more meaningful message def no_attachment_errors return if attachment.errors.empty? From 3f6288d5c7b6bbed7d7d2581822d7913f91bf544 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 17 Sep 2020 15:53:27 +1000 Subject: [PATCH 3/3] Load rake task under test for all its specs If you ran only the second spec without the first, the rake file wasn't loaded and the test failed. --- spec/lib/tasks/users_rake_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/lib/tasks/users_rake_spec.rb b/spec/lib/tasks/users_rake_spec.rb index 9229d5b032..cfddfec7ae 100644 --- a/spec/lib/tasks/users_rake_spec.rb +++ b/spec/lib/tasks/users_rake_spec.rb @@ -4,12 +4,14 @@ require 'spec_helper' require 'rake' describe 'users.rake' do + before(:all) do + Rake.application.rake_require 'tasks/users' + Rake::Task.define_task(:environment) + end + describe ':remove_enterprise_limit' do context 'when the user exists' do it 'sets the enterprise_limit to the maximum integer' do - Rake.application.rake_require 'tasks/users' - Rake::Task.define_task(:environment) - max_integer = 2_147_483_647 user = create(:user)