Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
gy4443
chemotion_eln_server
Commits
e91d5caa
Commit
e91d5caa
authored
Aug 18, 2015
by
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
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/models/molecule.rb
View file @
e91d5caa
class
Molecule
<
ActiveRecord
::
Base
belongs_to
:sample
has_many
:sample
s
validates_uniqueness_of
:inchikey
end
app/models/sample.rb
View file @
e91d5caa
...
...
@@ -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
db/migrate/20150817200859_create_molecules.rb
View file @
e91d5caa
class
CreateMolecules
<
ActiveRecord
::
Migration
def
change
create_table
:molecules
do
|
t
|
t
.
integer
:sample_id
t
.
string
:inchikey
t
.
string
:inchistring
t
.
float
:density
...
...
db/migrate/20150818100730_add_molecule_id_to_samples.rb
0 → 100644
View file @
e91d5caa
class
AddMoleculeIdToSamples
<
ActiveRecord
::
Migration
def
change
add_column
:samples
,
:molecule_id
,
:integer
end
end
db/schema.rb
View file @
e91d5caa
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2015081
7200859
)
do
ActiveRecord
::
Schema
.
define
(
version:
2015081
8100730
)
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
|
...
...
spec/models/molecule_spec.rb
View file @
e91d5caa
...
...
@@ -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
spec/models/sample_spec.rb
View file @
e91d5caa
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment