Skip to content

Commit

Permalink
By adding the study uuid while importing, the plate transfer was fail…
Browse files Browse the repository at this point in the history
…ing while

copying the fact that stored the study. This was happening because the
transfer method was not copying the literal property from the original fact.

Added a validation to fact to check that you cannot have a fact that is not
a literal and does not contain a relation either.
  • Loading branch information
emrojo committed Sep 20, 2019
1 parent 1854c82 commit a585723
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/fact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Fact < ActiveRecord::Base
scope :with_fact, -> (predicate, object) { where(:predicate => predicate, :object => object)}
scope :from_remote_asset, ->() { where(:is_remote? => true) }

validates :object_asset_id, presence: true, unless: :literal?
validates :object_asset_id, presence: false, if: :literal?

def set_to_remove_by(step)
update_attributes!(:to_remove_by => step)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/plate_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def self.transfer_with_asset_creation(plate, destination, updates=nil)
destination_well = Asset.new
updates.create_assets([destination_well])
source_well.facts.each do |fact|
updates.add(destination_well, fact.predicate, fact.object_value)
updates.add(destination_well, fact.predicate, fact.object_value, literal: fact.literal)
end
updates.add(destination_well, 'barcodeType', 'NoBarcode')
updates.add(destination_well, 'aliquotType', aliquot.object) if aliquot && !source_well.has_predicate?('aliquotType')
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/actions/plate_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
expect(updates.to_h[:add_facts].select{|t| t[1]=='concentration'}.map{|t| t[2]}).to eq(["1.3"])
expect(updates.to_h[:add_facts].select{|t| t[1]=='a'}.map{|t| t[2]}).to eq(["Well", "Well"])
end
it 'can copy facts with uuid values' do
source = create :asset
well = create(:asset)

source.facts << create(:fact, predicate: 'contains', object_asset: well)
well.facts << create(:fact, predicate: 'study', object: SecureRandom.uuid, literal: true)

destination = create :asset
updates = Actions::PlateTransfer.transfer_plates(source,destination)
expect(updates.to_h[:set_errors].nil?).to eq(true)
end

end
end
end
26 changes: 26 additions & 0 deletions spec/models/fact_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rails_helper'

RSpec.describe Fact do
context 'when it defines a literal' do
it 'can store a uuid' do
fact = build(:fact, predicate: 'pred', object: SecureRandom.uuid, object_asset_id: nil, literal: true)
expect(fact).to be_valid
end
it 'can store a string' do
fact = build(:fact, predicate: 'pred', object: 'str', object_asset_id: nil, literal: true)
expect(fact).to be_valid
end
end
context 'when defines a relation' do
let(:asset) { create :asset }
it 'cannot store anything without object_asset_id defined' do
fact = build(:fact, predicate: 'pred', object: "str", object_asset_id: asset, literal: false)
expect(fact).not_to be_valid
end
it 'cannot store any string if object_asset_id defined' do
fact = build(:fact, predicate: 'pred', object: "str", object_asset_id: asset, literal: false)
expect(fact).not_to be_valid
end
end

end

0 comments on commit a585723

Please sign in to comment.