Remove result validation [SCI-2376]

This commit is contained in:
Oleksii Kriuchykhin 2018-06-13 14:06:55 +02:00
parent 29fe58de80
commit e10ed86fa1

View file

@ -4,7 +4,6 @@ class Result < ApplicationRecord
auto_strip_attributes :name, nullify: false
validates :user, :my_module, presence: true
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
validate :text_or_asset_or_table
belongs_to :user, inverse_of: :results, optional: true
belongs_to :last_modified_by,
@ -104,21 +103,4 @@ class Result < ApplicationRecord
true
end
end
private
def text_or_asset_or_table
num_of_assigns = 0
num_of_assigns += result_text.blank? ? 0 : 1
num_of_assigns += asset.blank? ? 0 : 1
num_of_assigns += table.blank? ? 0 : 1
# Theoretically, we should make sure == 1, not > 1,
# but due to GUI problems this is how it is
if num_of_assigns > 1
errors.add(:base, "Result can only be instance of text/asset/table.")
elsif num_of_assigns < 1
errors.add(:base, "Result should be instance of text/asset/table.")
end
end
end