Skip to content

Commit

Permalink
Split test in optional and mandatory test
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Oct 22, 2024
1 parent 190cd76 commit 60763a1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/unit/sample_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,18 @@ def setup

assert sample_type.valid?

# Adding attribute
sample_type.sample_attributes.build(title: 'test 123')
# Adding optional attribute
sample_type.sample_attributes.build(title: 'optional test 123', sample_attribute_type: FactoryBot.create(:string_sample_attribute_type), required: false, is_title: false, linked_sample_type: nil)
assert sample_type.valid?
assert sample_type.errors.none?

sample_type.reload
assert sample_type.valid?

# Adding mandatory attribute
sample_type.sample_attributes.build(title: 'mandatory test 123', sample_attribute_type: FactoryBot.create(:string_sample_attribute_type), required: true, is_title: false, linked_sample_type: nil)
refute sample_type.valid?
assert sample_type.errors.added?(:sample_attributes, 'cannot be added, new attributes are not allowed (test 123)')
assert sample_type.errors.added?(:'sample_attributes.required', 'cannot be changed (mandatory test 123)')

sample_type.reload
assert sample_type.valid?
Expand Down

0 comments on commit 60763a1

Please sign in to comment.