mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Rename validation
This commit is contained in:
parent
d5716c4260
commit
b8bf7bbd9b
3 changed files with 5 additions and 7 deletions
|
@ -17,7 +17,7 @@ class MyModule < ApplicationRecord
|
||||||
validates :experiment, presence: true
|
validates :experiment, presence: true
|
||||||
validates :my_module_group, presence: true,
|
validates :my_module_group, presence: true,
|
||||||
if: proc { |mm| !mm.my_module_group_id.nil? }
|
if: proc { |mm| !mm.my_module_group_id.nil? }
|
||||||
validate :coordinates, if: proc { |mm| !mm.archived? }
|
validate :coordinates_uniqueness_check, if: :active?
|
||||||
|
|
||||||
belongs_to :created_by,
|
belongs_to :created_by,
|
||||||
foreign_key: 'created_by_id',
|
foreign_key: 'created_by_id',
|
||||||
|
@ -502,10 +502,8 @@ class MyModule < ApplicationRecord
|
||||||
protocols << Protocol.new_blank_for_module(self)
|
protocols << Protocol.new_blank_for_module(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def coordinates
|
def coordinates_uniqueness_check
|
||||||
my_modules_on_same_position =
|
if experiment && experiment.my_modules.active.where(x: x, y: y).where.not(id: id).any?
|
||||||
MyModule.where(experiment_id: experiment_id, x: x, y: y, archived: false).where.not(id: id)
|
|
||||||
if my_modules_on_same_position.any?
|
|
||||||
errors.add(:position, I18n.t('activerecord.errors.models.my_module.attributes.position.not_unique'))
|
errors.add(:position, I18n.t('activerecord.errors.models.my_module.attributes.position.not_unique'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace :my_modules do
|
||||||
query = MyModule.select('COUNT(*) as duplicates', :x, :y, :experiment_id)
|
query = MyModule.select('COUNT(*) as duplicates', :x, :y, :experiment_id)
|
||||||
.where(archived: false)
|
.where(archived: false)
|
||||||
.group(:x, :y, :experiment_id)
|
.group(:x, :y, :experiment_id)
|
||||||
.having('COUNT(*)>1')
|
.having('COUNT(my_modules.id)>1')
|
||||||
|
|
||||||
Rails.logger.info '*********************************************************************************'
|
Rails.logger.info '*********************************************************************************'
|
||||||
Rails.logger.info "You have to relocate #{query.sum { |a| a.duplicates - 1 }} tasks"
|
Rails.logger.info "You have to relocate #{query.sum { |a| a.duplicates - 1 }} tasks"
|
||||||
|
|
|
@ -34,7 +34,7 @@ describe 'my_modules:fix_positions' do
|
||||||
my_module.valid?
|
my_module.valid?
|
||||||
|
|
||||||
expect(my_module.errors.messages[:position])
|
expect(my_module.errors.messages[:position])
|
||||||
.to(eq ['and Y position has already been taken by another task in the experiment.'])
|
.to(eq ['X and Y position has already been taken by another task in the experiment.'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue