From c4d03cd08a8644e315a1c3b3fb8b06baaaa2a774 Mon Sep 17 00:00:00 2001 From: Andrew Kuklewicz Date: Sat, 21 Dec 2024 15:28:10 -0800 Subject: [PATCH] only validate image when changed --- app/models/episode_image.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/episode_image.rb b/app/models/episode_image.rb index 8e6be52c8..6f4de4ecb 100644 --- a/app/models/episode_image.rb +++ b/app/models/episode_image.rb @@ -3,8 +3,12 @@ class EpisodeImage < ApplicationRecord belongs_to :episode, touch: true, optional: true - validates :height, :width, numericality: {greater_than_or_equal_to: 1400, less_than_or_equal_to: 3000}, if: :status_complete? - validates :width, comparison: {equal_to: :height}, if: :status_complete? + validates :height, :width, numericality: {greater_than_or_equal_to: 1400, less_than_or_equal_to: 3000}, if: :should_validate? + validates :width, comparison: {equal_to: :height}, if: :should_validate? + + def should_validate? + status_complete? && (height_changed? || width_changed?) + end def destination_path "#{episode.path}/#{image_path}"