scinote-web/spec/lib/tasks/my_modules.rb
aignatov-bio 7f7bf0533a
Fix tests [SCI-6486] (#3913)
* Fix tests [SCI-6486]

* Fix rspec tests [SCI-6486]

Co-authored-by: Anton <anton@scinote.net>
2022-03-09 14:12:16 +01:00

43 lines
1.2 KiB
Ruby

# 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, created_by: experiment.created_by
end
# set 10 tasks same position
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)
@my_module_id = my_modules_with_same_position.fourth.id
end
context 'when record is valid except position' do
it 'changes position for my_module' do
expect { subject.invoke }.to(change { MyModule.find(@my_module_id).y })
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])
.to(eq ['X and Y position has already been taken by another task in the experiment.'])
end
end
end