Commit e91d5caa authored by Fernando D'Agostino's avatar Fernando D'Agostino
Browse files

Add molecule_id to samples. Sample belong to molecule. Molecule has many samples

Check SHA of a loaded file with a stored file
parent b7aa7dd9
class Molecule < ActiveRecord::Base
belongs_to :sample
has_many :samples
validates_uniqueness_of :inchikey
end
......@@ -9,6 +9,8 @@ class Sample < ActiveRecord::Base
has_many :reactions_as_starting_material, through: :reactions_starting_material_samples, source: :reaction
has_many :reactions_as_reactant, through: :reactions_reactant_samples, source: :reaction
has_many :reactions_as_product, through: :reactions_product_samples, source: :reaction
belongs_to :molecule
composed_of :amount, mapping: %w(amount_value, amount_unit)
end
class CreateMolecules < ActiveRecord::Migration
def change
create_table :molecules do |t|
t.integer :sample_id
t.string :inchikey
t.string :inchistring
t.float :density
......
class AddMoleculeIdToSamples < ActiveRecord::Migration
def change
add_column :samples, :molecule_id, :integer
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150817200859) do
ActiveRecord::Schema.define(version: 20150818100730) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -105,6 +105,7 @@ ActiveRecord::Schema.define(version: 20150817200859) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description", default: ""
t.integer "molecule_id"
end
create_table "users", force: :cascade do |t|
......
......@@ -27,14 +27,16 @@ RSpec.describe Molecule, type: :model do
end
it 'should persist the binary molfile' do
molecule.molfile =
(Digest::SHA256.new << "Example Binary Molefile Content").hexdigest
molfile_example = File.open("spec/models/molecule_spec.rb", "rb")
molecule.molfile = molfile_example.read
molfile_example.close
molecule.save
persisted_molecule = Molecule.last
expect(persisted_molecule.molfile).to be === (molecule.molfile)
persisted_molfile_SHA =
(Digest::SHA256.new << persisted_molecule.molfile).hexdigest
molfile_SHA =
(Digest::SHA256.new << molecule.molfile).hexdigest
expect(persisted_molfile_SHA).to be === (molfile_SHA)
end
end
# concern "with sample"
# it should belong to a sample
end
......@@ -11,4 +11,18 @@ RSpec.describe Sample, type: :model do
context 'with molecule' do
let(:sample) { build(:sample) }
let(:molecule) {create(:molecule)}
it 'it should belong to a sample' do
sample.molecule = molecule
sample.save
persisted_sample = Sample.last
expect(persisted_sample.molecule).to be === (molecule)
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment