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
|
|
|
|
|
|
|
|
describe 'Should be a valid object' do
|
|
|
|
it { should validate_presence_of :x }
|
|
|
|
it { should validate_presence_of :y }
|
|
|
|
it { should validate_presence_of :workflow_order }
|
|
|
|
it { should validate_presence_of :experiment }
|
|
|
|
it do
|
|
|
|
should validate_length_of(:name)
|
|
|
|
.is_at_least(Constants::NAME_MIN_LENGTH)
|
|
|
|
.is_at_most(Constants::NAME_MAX_LENGTH)
|
|
|
|
end
|
|
|
|
it do
|
|
|
|
should validate_length_of(:description)
|
2019-04-24 19:45:29 +08:00
|
|
|
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH)
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|