diff options
Diffstat (limited to 'app/models/snippet_input_action.rb')
-rw-r--r-- | app/models/snippet_input_action.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/snippet_input_action.rb b/app/models/snippet_input_action.rb index 7f4ab775ab0..cc6373264cc 100644 --- a/app/models/snippet_input_action.rb +++ b/app/models/snippet_input_action.rb @@ -15,9 +15,10 @@ class SnippetInputAction validates :action, inclusion: { in: ACTIONS, message: "%{value} is not a valid action" } validates :previous_path, presence: true, if: :move_action? - validates :file_path, presence: true + validates :file_path, presence: true, unless: :create_action? validates :content, presence: true, if: -> (action) { action.create_action? || action.update_action? } validate :ensure_same_file_path_and_previous_path, if: :update_action? + validate :ensure_different_file_path_and_previous_path, if: :move_action? validate :ensure_allowed_action def initialize(action: nil, previous_path: nil, file_path: nil, content: nil, allowed_actions: nil) @@ -52,6 +53,12 @@ class SnippetInputAction errors.add(:file_path, "can't be different from the previous_path attribute") end + def ensure_different_file_path_and_previous_path + return if previous_path != file_path + + errors.add(:file_path, 'must be different from the previous_path attribute') + end + def ensure_allowed_action return if @allowed_actions.empty? |