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

Add rspec for the Molecule model

parent 2a1f253e
FactoryGirl.define do
factory :molecule do
sample_id "1"
inchikey "inchikey"
inchistring "inchistring"
density 0.12345
molecular_weight 0.54321
molfile ""
melting_point 150.00
boiling_point 100.00
sum_formular "sum_formular"
names %w(name1 name2 name3)
iupac_name "iupac_name"
molecule_svg_file "molecule_svg_file"
end
end
require 'rails_helper'
require 'digest'
RSpec.describe Molecule, type: :model do
describe 'creation' do
let(:molecule) { create(:molecule) }
it 'is possible to create a valid molecule' do
expect(molecule.valid?).to be(true)
end
it 'should have a unique inchikey' do
molecule.save
invalid_molecule = Molecule.new
invalid_molecule.inchikey = molecule.inchikey
expect {invalid_molecule.save!}.to raise_error
end
end
describe 'persistance' do
let (:molecule) { build(:molecule) }
it 'should persist array of names' do
molecule.names = %w(foo bar quz)
molecule.save
persisted_molecule = Molecule.last
expect(persisted_molecule.names).to match_array(molecule.names)
end
it 'should persist the binary molfile' do
molecule.molfile =
(Digest::SHA256.new << "Example Binary Molefile Content").hexdigest
molecule.save
persisted_molecule = Molecule.last
expect(persisted_molecule.molfile).to be === (molecule.molfile)
end
end
# concern "with sample"
# it should belong to a sample
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