build lists create api: fix error with blank parameters

This commit is contained in:
Alexander Machehin 2015-03-26 19:53:34 +05:00
parent 6346c65939
commit fa39de82d9
1 changed files with 16 additions and 6 deletions

View File

@ -56,19 +56,29 @@ class BuildList < ActiveRecord::Base
validates :update_type, inclusion: { in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform') },
if: Proc.new { |b| b.advisory.present? }
validate -> {
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.main? && save_to_platform_id != build_for_platform_id
if save_to_platform.try(:main?) && save_to_platform_id != build_for_platform_id
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform'))
end
}
validate -> {
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_build_for_platform')) unless build_for_platform.main?
unless build_for_platform.try :main?
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_build_for_platform'))
end
}
validate -> {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) if save_to_repository.platform_id != save_to_platform.id
if save_to_repository.try(:platform_id) != save_to_platform.try(:id)
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository'))
end
}
validate -> {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos')) if build_for_platform.repositories.where(id: include_repos).count != include_repos.size
if build_for_platform && build_for_platform.repositories.where(id: include_repos).count != include_repos.size
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos'))
end
}
validate -> {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project')) unless save_to_repository.projects.exists?(project_id)
unless save_to_repository && save_to_repository.projects.exists?(project_id)
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project'))
end
}
before_validation -> { self.include_repos = include_repos.uniq if include_repos.present? }, on: :create
before_validation :prepare_extra_repositories, on: :create
@ -751,7 +761,7 @@ class BuildList < ActiveRecord::Base
if external_nodes.present?
self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE
end
if auto_publish? && !save_to_repository.publish_without_qa?
if auto_publish? && save_to_repository && !save_to_repository.publish_without_qa?
self.auto_publish_status = AUTO_PUBLISH_STATUS_NONE
end
if auto_publish? || auto_publish_into_testing?