Skip to content

Commit

Permalink
Populate blank Sample fingerprint
Browse files Browse the repository at this point in the history
- Re-populate samples if no associated fingerprint
- Check sample - fingerprint association before saving
- Change fingerprint requirement to fit with spec
  • Loading branch information
camannguyenthanh committed Feb 10, 2017
1 parent 6961ad6 commit 5b84b92
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/fingerprint.rb
Expand Up @@ -27,7 +27,7 @@ class Fingerprint < ActiveRecord::Base
presence: true,
numericality: {
only_integer: true,
greater_than: 0,
greater_than_or_equal_to: 0,
less_than: 1024,
message: "must be integer between 0 and 1024"
}
Expand Down
7 changes: 7 additions & 0 deletions app/models/sample.rb
Expand Up @@ -110,6 +110,7 @@ class Sample < ActiveRecord::Base
before_save :auto_set_molfile_to_molecules_molfile
before_save :find_or_create_molecule_based_on_inchikey
before_save :check_molfile_polymer_section
before_save :find_or_create_fingerprint

has_ancestry

Expand Down Expand Up @@ -256,6 +257,12 @@ def find_or_create_molecule_based_on_inchikey
end
end

def find_or_create_fingerprint
if self.fingerprint_id == nil
self.fingerprint_id = Fingerprint.find_or_create_by_molfile(self.molfile.clone)
end
end

def get_svg_path
if self.sample_svg_file.present?
"/images/samples/#{self.sample_svg_file}"
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20170210102655_repopulate_fingerprint.rb
@@ -0,0 +1,12 @@
class RepopulateFingerprint < ActiveRecord::Migration
def change
Sample.reset_column_information
# Extract all molecule
Sample.all.each do |sample|
next unless sample.fingerprint_id == nil

sample.fingerprint_id = Fingerprint.find_or_create_by_molfile(sample.molfile.clone)
sample.save!
end
end
end
4 changes: 2 additions & 2 deletions spec/models/fingerprint_spec.rb
Expand Up @@ -74,8 +74,8 @@
fingerprint.num_set_bits = -1
expect(fingerprint.valid?).to be(false)

fingerprint.num_set_bits = 0
expect(fingerprint.valid?).to be(false)
# fingerprint.num_set_bits = 0
# expect(fingerprint.valid?).to be(false)
end

it 'must check if fingerprint existed' do
Expand Down

0 comments on commit 5b84b92

Please sign in to comment.