From b49fcaae5d00a9d079e438db8fbb2f1db1cb8d7c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 6 Jul 2020 12:47:55 +0200 Subject: [PATCH] Do not enable image cropper if file is missing --- app/models/alchemy/essence_picture.rb | 2 +- spec/models/alchemy/essence_picture_spec.rb | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/alchemy/essence_picture.rb b/app/models/alchemy/essence_picture.rb index 82c1d5eeb1..7750e4d133 100644 --- a/app/models/alchemy/essence_picture.rb +++ b/app/models/alchemy/essence_picture.rb @@ -143,7 +143,7 @@ def allow_image_cropping? picture.can_be_cropped_to( content.settings[:size], content.settings[:upsample], - ) + ) && !!picture.image_file end def crop_values_present? diff --git a/spec/models/alchemy/essence_picture_spec.rb b/spec/models/alchemy/essence_picture_spec.rb index 3e539b0000..0367ac4abb 100644 --- a/spec/models/alchemy/essence_picture_spec.rb +++ b/spec/models/alchemy/essence_picture_spec.rb @@ -350,10 +350,22 @@ module Alchemy context "with crop set to true" do before do - allow(content).to receive(:settings) { {crop: true} } + allow(content).to receive(:settings) { { crop: true } } end - it { is_expected.to be(true) } + context "if picture.image_file is nil" do + before do + expect(picture).to receive(:image_file) { nil } + end + + it { is_expected.to be_falsy } + end + + context "if picture.image_file is present" do + let(:picture) { build_stubbed(:alchemy_picture) } + + it { is_expected.to be(true) } + end end end end