mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 09:23:58 +08:00
Checklist, checklist_item, activity, experiment spec and factories updated
This commit is contained in:
parent
6321c0f5c0
commit
3348b81b14
7 changed files with 64 additions and 40 deletions
|
@ -3,7 +3,7 @@ class CustomField < ApplicationRecord
|
|||
validates :name,
|
||||
presence: true,
|
||||
length: { maximum: Constants::NAME_MAX_LENGTH },
|
||||
uniqueness: { scope: :team, case_sensitive: true },
|
||||
uniqueness: { scope: :team_id, case_sensitive: true },
|
||||
exclusion: { in: ['Assigned', 'Sample name', 'Sample type',
|
||||
'Sample group', 'Added on', 'Added by'] }
|
||||
validates :user, :team, presence: true
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :custom_field do
|
||||
name 'My custom field'
|
||||
user
|
||||
team
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Activity, type: :model do
|
||||
subject(:activity) { create :activity }
|
||||
let(:old_activity) { create :activity, :old }
|
||||
let(:activity) { build :activity }
|
||||
let(:old_activity) { build :activity, :old }
|
||||
|
||||
it 'should be of class Activity' do
|
||||
expect(subject.class).to eq Activity
|
||||
|
@ -39,11 +39,16 @@ describe Activity, type: :model do
|
|||
end
|
||||
|
||||
describe 'Validations' do
|
||||
it { should validate_presence_of :type_of }
|
||||
it { should validate_presence_of :owner }
|
||||
describe '#type_of' do
|
||||
it { is_expected.to validate_presence_of :type_of }
|
||||
end
|
||||
|
||||
Extends::ACTIVITY_SUBJECT_TYPES.each do |value|
|
||||
it { is_expected.to allow_values(value).for(:subject_type) }
|
||||
describe '#owner' do
|
||||
it { is_expected.to validate_presence_of :owner }
|
||||
end
|
||||
|
||||
describe '#subject_type' do
|
||||
it { is_expected.to validate_inclusion_of(:subject_type).in_array(Extends::ACTIVITY_SUBJECT_TYPES) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -58,7 +63,7 @@ describe Activity, type: :model do
|
|||
|
||||
describe '.save' do
|
||||
it 'adds user to message items' do
|
||||
create :activity
|
||||
activity.save
|
||||
|
||||
expect(activity.message_items).to include(user: be_an(Hash))
|
||||
end
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ChecklistItem, type: :model do
|
||||
let(:checklist_item) { build :checklist_item }
|
||||
|
||||
it 'is valid' do
|
||||
expect(checklist_item).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class ChecklistItem' do
|
||||
expect(subject.class).to eq ChecklistItem
|
||||
end
|
||||
|
@ -23,7 +31,7 @@ describe ChecklistItem, type: :model do
|
|||
it { should belong_to(:last_modified_by).class_name('User') }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
describe 'Validations' do
|
||||
it { should validate_presence_of :text }
|
||||
it { should validate_length_of(:text).is_at_most(Constants::TEXT_MAX_LENGTH) }
|
||||
it { should validate_presence_of :checklist }
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Checklist, type: :model do
|
||||
let(:checklist) { build :checklist }
|
||||
|
||||
it 'is valid' do
|
||||
expect(checklist).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class Checklist' do
|
||||
expect(subject.class).to eq Checklist
|
||||
end
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CustomField, type: :model do
|
||||
let(:custom_field) { build :custom_field }
|
||||
|
||||
it 'is valid' do
|
||||
expect(custom_field).to be_valid
|
||||
end
|
||||
it 'should be of class CustomField' do
|
||||
expect(subject.class).to eq CustomField
|
||||
end
|
||||
|
@ -23,39 +30,25 @@ describe CustomField, type: :model do
|
|||
it { should have_many :sample_custom_fields }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
before do
|
||||
@user = create :user, email: 'example_one@adsf.com'
|
||||
@team = create :team
|
||||
@samples_table = create :samples_table, user: @user, team: @team
|
||||
describe 'Validations' do
|
||||
describe '#name' do
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
it { is_expected.to validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
|
||||
it do
|
||||
is_expected.to validate_exclusion_of(:name).in_array(
|
||||
['Assigned', 'Sample name', 'Sample type', 'Sample group', 'Added on', 'Added by']
|
||||
)
|
||||
end
|
||||
it do
|
||||
allow_any_instance_of(CustomField).to receive(:update_samples_table_state)
|
||||
|
||||
expect(custom_field).to validate_uniqueness_of(:name).scoped_to(:team_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_presence_of :user }
|
||||
|
||||
it do
|
||||
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
|
||||
end
|
||||
|
||||
it do
|
||||
should validate_exclusion_of(:name).in_array(
|
||||
['Assigned', 'Sample name', 'Sample type',
|
||||
'Sample group', 'Added on', 'Added by']
|
||||
)
|
||||
end
|
||||
|
||||
it 'should have uniq name scoped on team' do
|
||||
create :custom_field, user: @user, team: @team
|
||||
custom_field_two = build :custom_field, user: @user, team: @team
|
||||
|
||||
expect(custom_field_two).to_not be_valid
|
||||
end
|
||||
|
||||
it 'should have uniq case sensitive name' do
|
||||
build_stubbed :custom_field, name: 'custom one', user: @user, team: @team
|
||||
cf = build :custom_field, name: 'CUSTOM ONE', user: @user, team: @team
|
||||
|
||||
expect(cf).to be_valid
|
||||
describe '#user' do
|
||||
it { is_expected.to validate_presence_of :user }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Experiment, type: :model do
|
||||
let(:experiment) { build :experiment }
|
||||
|
||||
it 'is valid' do
|
||||
expect(experiment).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class Experiment' do
|
||||
expect(subject.class).to eq Experiment
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue