mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 06:35:56 +08:00
Add valid factory check to Steps models
This commit is contained in:
parent
1e60102a7d
commit
15cbd8864c
|
@ -8,5 +8,4 @@ class ResultText < ApplicationRecord
|
|||
validates :text, length: { maximum: Constants::RICH_TEXT_MAX_LENGTH }
|
||||
|
||||
belongs_to :result, inverse_of: :result_text, touch: true
|
||||
has_many :tiny_mce_assets, inverse_of: :result_text, dependent: :destroy
|
||||
end
|
||||
|
|
|
@ -13,25 +13,16 @@ class Step < ApplicationRecord
|
|||
validates :user, :protocol, presence: true
|
||||
validates :completed_on, presence: true, if: proc { |s| s.completed? }
|
||||
|
||||
belongs_to :user, inverse_of: :steps, optional: true
|
||||
belongs_to :last_modified_by,
|
||||
foreign_key: 'last_modified_by_id',
|
||||
class_name: 'User',
|
||||
optional: true
|
||||
belongs_to :protocol,
|
||||
inverse_of: :steps,
|
||||
optional: true
|
||||
has_many :checklists, inverse_of: :step,
|
||||
dependent: :destroy
|
||||
belongs_to :user, inverse_of: :steps
|
||||
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true
|
||||
belongs_to :protocol, inverse_of: :steps
|
||||
has_many :checklists, inverse_of: :step, dependent: :destroy
|
||||
has_many :step_comments, foreign_key: :associated_id, dependent: :destroy
|
||||
has_many :step_assets, inverse_of: :step,
|
||||
dependent: :destroy
|
||||
has_many :step_assets, inverse_of: :step, dependent: :destroy
|
||||
has_many :assets, through: :step_assets
|
||||
has_many :step_tables, inverse_of: :step,
|
||||
dependent: :destroy
|
||||
has_many :step_tables, inverse_of: :step, dependent: :destroy
|
||||
has_many :tables, through: :step_tables
|
||||
has_many :report_elements, inverse_of: :step,
|
||||
dependent: :destroy
|
||||
has_many :report_elements, inverse_of: :step, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :checklists,
|
||||
reject_if: :all_blank,
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StepComment < Comment
|
||||
belongs_to :step,
|
||||
foreign_key: :associated_id,
|
||||
inverse_of: :step_comments,
|
||||
touch: true,
|
||||
optional: true
|
||||
belongs_to :step, foreign_key: :associated_id, inverse_of: :step_comments, touch: true
|
||||
|
||||
validates :step, presence: true
|
||||
end
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe StepComment, type: :model do
|
||||
let(:step_comment) { build :step_comment }
|
||||
|
||||
it 'is valid' do
|
||||
expect(step_comment).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class StepComment' do
|
||||
expect(subject.class).to eq StepComment
|
||||
end
|
||||
|
@ -19,7 +27,7 @@ describe StepComment, type: :model do
|
|||
it { should belong_to :step }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
describe 'Validations' do
|
||||
it { should validate_presence_of :step }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Step, type: :model do
|
||||
let(:step) { build :step }
|
||||
|
||||
it 'is valid' do
|
||||
expect(step).to be_valid
|
||||
end
|
||||
|
||||
it 'should be of class Step' do
|
||||
expect(subject.class).to eq Step
|
||||
end
|
||||
|
@ -32,7 +40,7 @@ describe Step, type: :model do
|
|||
it { should have_many :tiny_mce_assets }
|
||||
end
|
||||
|
||||
describe 'Should be a valid object' do
|
||||
describe 'Validations' do
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_presence_of :position }
|
||||
it { should validate_presence_of :user }
|
||||
|
|
Loading…
Reference in a new issue