2019-01-10 01:30:33 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-06 23:37:29 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Project, type: :model do
|
2019-05-06 22:14:50 +08:00
|
|
|
let(:project) { build :project }
|
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
expect(project).to be_valid
|
|
|
|
end
|
|
|
|
|
2017-07-06 23:37:29 +08:00
|
|
|
it 'should be of class Project' do
|
|
|
|
expect(subject.class).to eq Project
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Database table' do
|
|
|
|
it { should have_db_column :id }
|
|
|
|
it { should have_db_column :name }
|
|
|
|
it { should have_db_column :visibility }
|
|
|
|
it { should have_db_column :due_date }
|
|
|
|
it { should have_db_column :team_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 :experiments_order }
|
2019-01-25 17:50:08 +08:00
|
|
|
it { should have_db_column :template }
|
2017-07-06 23:37:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Relations' do
|
2019-07-26 18:40:36 +08:00
|
|
|
it { should belong_to(:team) }
|
|
|
|
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-07-06 23:37:29 +08:00
|
|
|
it { should have_many :user_projects }
|
|
|
|
it { should have_many :users }
|
|
|
|
it { should have_many :experiments }
|
|
|
|
it { should have_many :project_comments }
|
|
|
|
it { should have_many :activities }
|
|
|
|
it { should have_many :tags }
|
|
|
|
it { should have_many :reports }
|
|
|
|
it { should have_many :report_elements }
|
|
|
|
end
|
|
|
|
|
2019-01-10 01:30:33 +08:00
|
|
|
describe 'Validations' do
|
|
|
|
describe '#visibility' do
|
2019-05-06 22:14:50 +08:00
|
|
|
it { is_expected.to validate_presence_of :visibility }
|
2019-01-10 01:30:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#team' do
|
2019-05-06 22:14:50 +08:00
|
|
|
it { is_expected.to validate_presence_of :team }
|
2017-07-06 23:37:29 +08:00
|
|
|
end
|
2017-07-10 20:38:18 +08:00
|
|
|
|
2019-01-10 01:30:33 +08:00
|
|
|
describe '#name' do
|
2019-05-06 22:14:50 +08:00
|
|
|
it do
|
|
|
|
is_expected.to(validate_length_of(:name)
|
|
|
|
.is_at_least(Constants::NAME_MIN_LENGTH)
|
|
|
|
.is_at_most(Constants::NAME_MAX_LENGTH))
|
2019-01-10 01:30:33 +08:00
|
|
|
end
|
2019-05-06 22:14:50 +08:00
|
|
|
it do
|
|
|
|
expect(project).to validate_uniqueness_of(:name).scoped_to(:team_id).case_insensitive
|
2019-01-10 01:30:33 +08:00
|
|
|
end
|
2017-07-06 23:37:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|