mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Add valid factory check for Project, MyModules, notification, protocol
This commit is contained in:
parent
3348b81b14
commit
a7558d83be
11 changed files with 81 additions and 22 deletions
|
@ -9,7 +9,7 @@ class Project < ApplicationRecord
|
||||||
validates :name,
|
validates :name,
|
||||||
length: { minimum: Constants::NAME_MIN_LENGTH,
|
length: { minimum: Constants::NAME_MIN_LENGTH,
|
||||||
maximum: Constants::NAME_MAX_LENGTH },
|
maximum: Constants::NAME_MAX_LENGTH },
|
||||||
uniqueness: { scope: :team, case_sensitive: false }
|
uniqueness: { scope: :team_id, case_sensitive: false }
|
||||||
validates :visibility, presence: true
|
validates :visibility, presence: true
|
||||||
validates :team, presence: true
|
validates :team, presence: true
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :mm_repository_row, class: MyModuleRepositoryRow do
|
factory :mm_repository_row, class: MyModuleRepositoryRow do
|
||||||
association :repository_row, factory: :repository_row
|
repository_row
|
||||||
association :my_module, factory: :my_module
|
my_module
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :notification do
|
factory :notification do
|
||||||
title '<i>Admin</i> was added as Owner to project ' \
|
title '<i>Admin</i> was added as Owner to project ' \
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe MyModuleGroup, type: :model do
|
describe MyModuleGroup, type: :model do
|
||||||
|
let(:my_module_group) { build :my_module_group }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(my_module_group).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class MyModuleGroup' do
|
it 'should be of class MyModuleGroup' do
|
||||||
expect(subject.class).to eq MyModuleGroup
|
expect(subject.class).to eq MyModuleGroup
|
||||||
end
|
end
|
||||||
|
@ -19,7 +27,7 @@ describe MyModuleGroup, type: :model do
|
||||||
it { should have_many(:my_modules) }
|
it { should have_many(:my_modules) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :experiment }
|
it { should validate_presence_of :experiment }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe MyModuleRepositoryRow, type: :model do
|
describe MyModuleRepositoryRow, type: :model do
|
||||||
|
let(:my_module_repository_row) { build :mm_repository_row }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(my_module_repository_row).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class MyModuleRepositoryRow' do
|
it 'should be of class MyModuleRepositoryRow' do
|
||||||
expect(subject.class).to eq MyModuleRepositoryRow
|
expect(subject.class).to eq MyModuleRepositoryRow
|
||||||
end
|
end
|
||||||
|
@ -20,7 +28,7 @@ describe MyModuleRepositoryRow, type: :model do
|
||||||
it { should belong_to :repository_row }
|
it { should belong_to :repository_row }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :repository_row }
|
it { should validate_presence_of :repository_row }
|
||||||
it { should validate_presence_of :my_module }
|
it { should validate_presence_of :my_module }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe MyModule, type: :model do
|
describe MyModule, type: :model do
|
||||||
|
let(:my_module) { build :my_module }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(my_module).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class MyModule' do
|
it 'should be of class MyModule' do
|
||||||
expect(subject.class).to eq MyModule
|
expect(subject.class).to eq MyModule
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe MyModuleTag, type: :model do
|
describe MyModuleTag, type: :model do
|
||||||
|
let(:my_module_tag) { build :my_module_tag }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(my_module_tag).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class MyModuleTag' do
|
it 'should be of class MyModuleTag' do
|
||||||
expect(subject.class).to eq MyModuleTag
|
expect(subject.class).to eq MyModuleTag
|
||||||
end
|
end
|
||||||
|
@ -17,7 +25,7 @@ describe MyModuleTag, type: :model do
|
||||||
it { should belong_to :tag }
|
it { should belong_to :tag }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :my_module }
|
it { should validate_presence_of :my_module }
|
||||||
it { should validate_presence_of :tag }
|
it { should validate_presence_of :tag }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Notification, type: :model do
|
describe Notification, type: :model do
|
||||||
|
let(:notification) { build :notification }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(notification).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class Notification' do
|
it 'should be of class Notification' do
|
||||||
expect(subject.class).to eq Notification
|
expect(subject.class).to eq Notification
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ProjectComment, type: :model do
|
describe ProjectComment, type: :model do
|
||||||
|
let(:project_comment) { build :project_comment }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(project_comment).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class MyModuleTag' do
|
it 'should be of class MyModuleTag' do
|
||||||
expect(subject.class).to eq ProjectComment
|
expect(subject.class).to eq ProjectComment
|
||||||
end
|
end
|
||||||
|
@ -20,7 +28,7 @@ describe ProjectComment, type: :model do
|
||||||
it { should belong_to(:project).with_foreign_key('associated_id') }
|
it { should belong_to(:project).with_foreign_key('associated_id') }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :project }
|
it { should validate_presence_of :project }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Project, type: :model do
|
describe Project, type: :model do
|
||||||
|
let(:project) { build :project }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(project).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class Project' do
|
it 'should be of class Project' do
|
||||||
expect(subject.class).to eq Project
|
expect(subject.class).to eq Project
|
||||||
end
|
end
|
||||||
|
@ -44,27 +50,21 @@ describe Project, type: :model do
|
||||||
|
|
||||||
describe 'Validations' do
|
describe 'Validations' do
|
||||||
describe '#visibility' do
|
describe '#visibility' do
|
||||||
it { should validate_presence_of :visibility }
|
it { is_expected.to validate_presence_of :visibility }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#team' do
|
describe '#team' do
|
||||||
it { should validate_presence_of :team }
|
it { is_expected.to validate_presence_of :team }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#name' do
|
describe '#name' do
|
||||||
it 'should be at least 2 long and max 255 long' do
|
it do
|
||||||
should validate_length_of(:name)
|
is_expected.to(validate_length_of(:name)
|
||||||
.is_at_least(Constants::NAME_MIN_LENGTH)
|
.is_at_least(Constants::NAME_MIN_LENGTH)
|
||||||
.is_at_most(Constants::NAME_MAX_LENGTH)
|
.is_at_most(Constants::NAME_MAX_LENGTH))
|
||||||
end
|
end
|
||||||
|
it do
|
||||||
it 'should be uniq per project and team' do
|
expect(project).to validate_uniqueness_of(:name).scoped_to(:team_id).case_insensitive
|
||||||
first_project = create :project
|
|
||||||
second_project = build :project,
|
|
||||||
name: first_project.name,
|
|
||||||
team: first_project.team
|
|
||||||
|
|
||||||
expect(second_project).to_not be_valid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Protocol, type: :model do
|
describe Protocol, type: :model do
|
||||||
|
let(:protocol) { build :protocol }
|
||||||
|
|
||||||
|
it 'is valid' do
|
||||||
|
expect(protocol).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it 'should be of class Protocol' do
|
it 'should be of class Protocol' do
|
||||||
expect(subject.class).to eq Protocol
|
expect(subject.class).to eq Protocol
|
||||||
end
|
end
|
||||||
|
@ -40,7 +46,7 @@ describe Protocol, type: :model do
|
||||||
it { should have_many :steps }
|
it { should have_many :steps }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Should be a valid object' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :team }
|
it { should validate_presence_of :team }
|
||||||
it { should validate_presence_of :protocol_type }
|
it { should validate_presence_of :protocol_type }
|
||||||
it do
|
it do
|
||||||
|
@ -51,6 +57,7 @@ describe Protocol, type: :model do
|
||||||
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH)
|
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.archive(user)' do
|
describe '.archive(user)' do
|
||||||
let(:protocol) { create :protocol, :in_public_repository, added_by: user }
|
let(:protocol) { create :protocol, :in_public_repository, added_by: user }
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
|
|
Loading…
Reference in a new issue