2019-05-06 22:14:50 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-30 00:49:07 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe MyModule, type: :model do
|
2019-05-06 22:14:50 +08:00
|
|
|
let(:my_module) { build :my_module }
|
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(my_module).to be_valid
|
|
|
|
end
|
|
|
|
|
2017-08-30 00:49:07 +08:00
|
|
|
it 'should be of class MyModule' do
|
|
|
|
expect(subject.class).to eq MyModule
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Database table' do
|
|
|
|
it { should have_db_column :id }
|
|
|
|
it { should have_db_column :name }
|
|
|
|
it { should have_db_column :due_date }
|
|
|
|
it { should have_db_column :description }
|
|
|
|
it { should have_db_column :x }
|
|
|
|
it { should have_db_column :y }
|
|
|
|
it { should have_db_column :my_module_group_id }
|
|
|
|
it { should have_db_column :created_at }
|
|
|
|
it { should have_db_column :updated_at }
|
|
|
|
it { should have_db_column :archived }
|
|
|
|
it { should have_db_column :archived_on }
|
|
|
|
it { should have_db_column :created_by_id }
|
|
|
|
it { should have_db_column :last_modified_by_id }
|
|
|
|
it { should have_db_column :archived_by_id }
|
|
|
|
it { should have_db_column :restored_by_id }
|
|
|
|
it { should have_db_column :restored_on }
|
|
|
|
it { should have_db_column :nr_of_assigned_samples }
|
|
|
|
it { should have_db_column :workflow_order }
|
|
|
|
it { should have_db_column :experiment_id }
|
|
|
|
it { should have_db_column :state }
|
|
|
|
it { should have_db_column :completed_on }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Relations' do
|
2019-07-26 18:40:36 +08:00
|
|
|
it { should belong_to(:experiment) }
|
|
|
|
it { should belong_to(:my_module_group).optional }
|
|
|
|
it { should belong_to(:created_by).class_name('User').optional }
|
|
|
|
it { should belong_to(:last_modified_by).class_name('User').optional }
|
|
|
|
it { should belong_to(:archived_by).class_name('User').optional }
|
|
|
|
it { should belong_to(:restored_by).class_name('User').optional }
|
2017-08-30 00:49:07 +08:00
|
|
|
it { should have_many :results }
|
|
|
|
it { should have_many :my_module_tags }
|
|
|
|
it { should have_many :tags }
|
|
|
|
it { should have_many :task_comments }
|
|
|
|
it { should have_many :my_modules }
|
|
|
|
it { should have_many :sample_my_modules }
|
|
|
|
it { should have_many :samples }
|
|
|
|
it { should have_many :my_module_repository_rows }
|
|
|
|
it { should have_many :repository_rows }
|
|
|
|
it { should have_many :user_my_modules }
|
|
|
|
it { should have_many :users }
|
|
|
|
it { should have_many :activities }
|
|
|
|
it { should have_many :report_elements }
|
|
|
|
it { should have_many :protocols }
|
|
|
|
it { should have_many(:inputs).class_name('Connection') }
|
|
|
|
it { should have_many(:outputs).class_name('Connection') }
|
|
|
|
it { should have_many(:my_module_antecessors).class_name('MyModule') }
|
|
|
|
end
|
|
|
|
|
2019-09-16 15:29:34 +08:00
|
|
|
describe 'Validations' do
|
|
|
|
describe '#name' do
|
|
|
|
it do
|
|
|
|
is_expected.to(validate_length_of(:name)
|
|
|
|
.is_at_least(Constants::NAME_MIN_LENGTH)
|
|
|
|
.is_at_most(Constants::NAME_MAX_LENGTH))
|
|
|
|
end
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
2019-09-16 15:29:34 +08:00
|
|
|
|
|
|
|
describe '#description' do
|
|
|
|
it do
|
|
|
|
is_expected.to(validate_length_of(:description)
|
|
|
|
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-26 14:44:34 +08:00
|
|
|
describe '#x, #y scoped to experiment for active modules' do
|
2019-09-16 15:29:34 +08:00
|
|
|
it { is_expected.to validate_presence_of :x }
|
|
|
|
it { is_expected.to validate_presence_of :y }
|
|
|
|
|
2019-09-26 14:44:34 +08:00
|
|
|
it 'should be invalid for same x, y, and experiment' do
|
|
|
|
my_module.save
|
|
|
|
new_my_module = my_module.dup
|
|
|
|
|
|
|
|
expect(new_my_module).not_to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be valid when module with same x, y and expriment is archived' do
|
|
|
|
my_module.save
|
|
|
|
new_my_module = my_module.dup
|
|
|
|
my_module.update_column(:archived, true)
|
|
|
|
|
|
|
|
expect(new_my_module).to be_valid
|
2019-09-16 15:29:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#workflow_order' do
|
|
|
|
it { is_expected.to validate_presence_of :workflow_order }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#experiment' do
|
|
|
|
it { is_expected.to validate_presence_of :experiment }
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|