Add valid factory check for Project, MyModules, notification, protocol

This commit is contained in:
Urban Rotnik 2019-05-06 16:14:50 +02:00
parent 3348b81b14
commit a7558d83be
11 changed files with 81 additions and 22 deletions

View file

@ -9,7 +9,7 @@ class Project < ApplicationRecord
validates :name,
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH },
uniqueness: { scope: :team, case_sensitive: false }
uniqueness: { scope: :team_id, case_sensitive: false }
validates :visibility, presence: true
validates :team, presence: true

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
FactoryBot.define do
factory :mm_repository_row, class: MyModuleRepositoryRow do
association :repository_row, factory: :repository_row
association :my_module, factory: :my_module
repository_row
my_module
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
FactoryBot.define do
factory :notification do
title '<i>Admin</i> was added as Owner to project ' \

View file

@ -1,6 +1,14 @@
# frozen_string_literal: true
require 'rails_helper'
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
expect(subject.class).to eq MyModuleGroup
end
@ -19,7 +27,7 @@ describe MyModuleGroup, type: :model do
it { should have_many(:my_modules) }
end
describe 'Should be a valid object' do
describe 'Validations' do
it { should validate_presence_of :experiment }
end
end

View file

@ -1,6 +1,14 @@
# frozen_string_literal: true
require 'rails_helper'
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
expect(subject.class).to eq MyModuleRepositoryRow
end
@ -20,7 +28,7 @@ describe MyModuleRepositoryRow, type: :model do
it { should belong_to :repository_row }
end
describe 'Should be a valid object' do
describe 'Validations' do
it { should validate_presence_of :repository_row }
it { should validate_presence_of :my_module }
end

View file

@ -1,6 +1,14 @@
# frozen_string_literal: true
require 'rails_helper'
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
expect(subject.class).to eq MyModule
end

View file

@ -1,6 +1,14 @@
# frozen_string_literal: true
require 'rails_helper'
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
expect(subject.class).to eq MyModuleTag
end
@ -17,7 +25,7 @@ describe MyModuleTag, type: :model do
it { should belong_to :tag }
end
describe 'Should be a valid object' do
describe 'Validations' do
it { should validate_presence_of :my_module }
it { should validate_presence_of :tag }
end

View file

@ -1,6 +1,14 @@
# frozen_string_literal: true
require 'rails_helper'
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
expect(subject.class).to eq Notification
end

View file

@ -1,6 +1,14 @@
# frozen_string_literal: true
require 'rails_helper'
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
expect(subject.class).to eq ProjectComment
end
@ -20,7 +28,7 @@ describe ProjectComment, type: :model do
it { should belong_to(:project).with_foreign_key('associated_id') }
end
describe 'Should be a valid object' do
describe 'Validations' do
it { should validate_presence_of :project }
end
end

View file

@ -3,6 +3,12 @@
require 'rails_helper'
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
expect(subject.class).to eq Project
end
@ -44,27 +50,21 @@ describe Project, type: :model do
describe 'Validations' do
describe '#visibility' do
it { should validate_presence_of :visibility }
it { is_expected.to validate_presence_of :visibility }
end
describe '#team' do
it { should validate_presence_of :team }
it { is_expected.to validate_presence_of :team }
end
describe '#name' do
it 'should be at least 2 long and max 255 long' do
should validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
it do
is_expected.to(validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH))
end
it 'should be uniq per project and team' do
first_project = create :project
second_project = build :project,
name: first_project.name,
team: first_project.team
expect(second_project).to_not be_valid
it do
expect(project).to validate_uniqueness_of(:name).scoped_to(:team_id).case_insensitive
end
end
end

View file

@ -3,6 +3,12 @@
require 'rails_helper'
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
expect(subject.class).to eq Protocol
end
@ -40,7 +46,7 @@ describe Protocol, type: :model do
it { should have_many :steps }
end
describe 'Should be a valid object' do
describe 'Validations' do
it { should validate_presence_of :team }
it { should validate_presence_of :protocol_type }
it do
@ -51,6 +57,7 @@ describe Protocol, type: :model do
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH)
end
end
describe '.archive(user)' do
let(:protocol) { create :protocol, :in_public_repository, added_by: user }
let(:user) { create :user }