-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(smrtlink): adds custom validator for use_adaptive_loading smrt l…
…ink option
- Loading branch information
1 parent
b411d5a
commit 987009d
Showing
6 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
# Validator for ensuring use_adaptive_loading is consistent across all wells | ||
class UseAdaptiveLoadingValidator < ActiveModel::Validator | ||
# @param [ActiveRecord::Base] record | ||
def validate(record) | ||
return if record.use_adaptive_loading == record.run.wells.first.use_adaptive_loading | ||
|
||
record.errors.add(:base, "well #{record.position} has a differing 'Use Adaptive Loading' value") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe UseAdaptiveLoadingValidator do | ||
before do | ||
create(:pacbio_smrt_link_version, name: 'v13_1_revio', default: true) | ||
end | ||
|
||
let(:run) { create(:pacbio_revio_run) } | ||
let(:validator) { described_class.new(run:, exclude_marked_for_destruction: true) } | ||
|
||
it 'is valid when all wells have the same use_adaptive_loading value' do | ||
# Factory defaults to false for use_adaptive_loading for all wells | ||
well = run.wells.first | ||
validator.validate(well) | ||
expect(well.errors).to be_empty | ||
end | ||
|
||
it 'is invalid when all wells do not have the same use_adaptive_loading value' do | ||
well = run.wells.last | ||
well.use_adaptive_loading = true | ||
|
||
validator.validate(well) | ||
expect(well.errors[:base]).to include("well #{run.wells.last.position} has a differing 'Use Adaptive Loading' value") | ||
end | ||
end |