2019-09-26 14:47:43 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe 'my_modules:fix_positions' do
|
|
|
|
include_context 'rake'
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
experiment = create :experiment
|
|
|
|
|
|
|
|
100.times do
|
|
|
|
create :my_module, experiment: experiment
|
|
|
|
end
|
|
|
|
|
2019-10-22 16:28:24 +08:00
|
|
|
# set 10 tasks same position
|
2019-09-26 14:47:43 +08:00
|
|
|
my_modules_with_same_position = MyModule.limit(10)
|
|
|
|
my_modules_with_same_position.update_all(x: 0, y: 0)
|
|
|
|
|
|
|
|
# 1 module should be invalid
|
|
|
|
my_modules_with_same_position.second.update_column(:name, 'a')
|
|
|
|
|
|
|
|
my_modules_with_same_position.third.update_column(:archived, true)
|
2019-10-22 16:28:24 +08:00
|
|
|
@my_module_id = my_modules_with_same_position.fourth.id
|
2019-09-26 14:47:43 +08:00
|
|
|
end
|
|
|
|
context 'when record is valid except position' do
|
|
|
|
it 'changes position for my_module' do
|
2019-10-22 16:28:24 +08:00
|
|
|
expect { subject.invoke }.to(change { MyModule.find(@my_module_id).y })
|
2019-09-26 14:47:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when record is invalid' do
|
|
|
|
it 'remains error on position' do
|
|
|
|
subject.invoke
|
|
|
|
my_module = MyModule.find_by(name: 'a')
|
|
|
|
my_module.valid?
|
|
|
|
|
|
|
|
expect(my_module.errors.messages[:position])
|
2019-10-22 15:03:33 +08:00
|
|
|
.to(eq ['X and Y position has already been taken by another task in the experiment.'])
|
2019-09-26 14:47:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|