scinote-web/spec/lib/tasks/my_modules_spec.rb

42 lines
1.1 KiB
Ruby
Raw Normal View History

# 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
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
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 })
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.'])
end
end
end