Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
hh1966
chemotion_eln_server
Commits
89da2cff
Commit
89da2cff
authored
Mar 25, 2019
by
hh1966
Browse files
Add spec for Export::ExportCollections and Import::ImportCollections
parent
a8f1f832
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/import/import_collections.rb
View file @
89da2cff
...
...
@@ -7,7 +7,7 @@ module Import
@import_id
=
import_id
@current_user_id
=
current_user_id
@zip_file_path
=
File
.
join
(
'tmp'
,
'import'
,
'
#{import_id}.zip
'
)
@zip_file_path
=
File
.
join
(
'tmp'
,
'import'
,
"
#{
import_id
}
.zip
"
)
@directory
=
File
.
join
(
'tmp'
,
'import'
,
import_id
)
@data
=
nil
...
...
spec/fixtures/import/2541a423-11d9-4c76-a7e1-0da470644012.zip
0 → 100644
View file @
89da2cff
File added
spec/lib/export/export_collections.rb
0 → 100644
View file @
89da2cff
# frozen_string_literal: true
require
'rails_helper'
# test for ExportJson ImportJson
RSpec
.
describe
'ExportImportCollection'
do
let
(
:user
)
{
create
(
:person
,
first_name:
'Ulf'
,
last_name:
'User'
,
name_abbreviation:
'UU'
)
}
let
(
:collection
)
{
create
(
:collection
,
user_id:
user
.
id
,
label:
'Awesome Collection'
)
}
let
(
:molfile
){
IO
.
read
(
Rails
.
root
.
join
(
"spec"
,
"fixtures"
,
"test_2.mol"
))
}
let
(
:svg
)
{
IO
.
read
(
Rails
.
root
.
join
(
"spec"
,
"fixtures"
,
"images"
,
"molecule.svg"
))
}
let
(
:sample
)
{
build
(
:sample
,
created_by:
user
.
id
,
name:
'Sample zero'
,
molfile:
molfile
,
collections:
[
collection
]
)
}
let
(
:molecule_name_name
)
{
'Awesome Molecule'
}
let
(
:molecule_name
)
{
build
(
:molecule_name
,
user_id:
user
.
id
,
name:
molecule_name_name
,
molecule_id:
sample
.
molecule_id
)
}
let
(
:job_id
)
{
SecureRandom
.
uuid
}
before
do
user
.
save!
collection
.
save!
sample
.
save!
molecule_name
.
save!
sample
.
update!
(
molecule_name_id:
molecule_name
.
id
)
end
context
'creates an export file, '
do
before
do
export
=
Export
::
ExportCollections
.
new
(
job_id
,
[
collection
.
id
],
'zip'
,
true
)
export
.
prepare_data
export
.
to_file
end
it
'which exists'
do
file_path
=
File
.
join
(
'public'
,
'zip'
,
"
#{
job_id
}
.zip"
)
expect
(
File
.
exist?
(
file_path
)).
to
be
true
end
it
'which is a zip file containing export.json, schema.json and description.txt'
do
file_names
=
[]
file_path
=
File
.
join
(
'public'
,
'zip'
,
"
#{
job_id
}
.zip"
)
Zip
::
File
.
open
(
file_path
)
do
|
files
|
files
.
each
do
|
file
|
file_names
<<
file
.
name
end
end
expect
(
file_names
).
to
include
(
'export.json'
,
'schema.json'
,
'description.txt'
)
end
end
end
spec/lib/import/import_collections.rb
0 → 100644
View file @
89da2cff
# frozen_string_literal: true
require
'rails_helper'
# test for ExportJson ImportJson
RSpec
.
describe
'ExportImportCollection'
do
let
(
:user
)
{
create
(
:person
,
first_name:
'Ulf'
,
last_name:
'User'
,
name_abbreviation:
'UU'
)
}
before
do
user
.
save!
end
context
'imports from a file'
do
before
do
# create the `tmp/imports/` if it does not exist yet
import_path
=
File
.
join
(
'tmp'
,
'import'
)
FileUtils
.
mkdir_p
(
import_path
)
unless
Dir
.
exist?
(
import_path
)
# store the file as `tmp/imports/<import_id>.zip`
import_id
=
'2541a423-11d9-4c76-a7e1-0da470644012'
import_file_path
=
File
.
join
(
'spec'
,
'fixtures'
,
'import'
,
"
#{
import_id
}
.zip"
)
zip_file_path
=
File
.
join
(
'tmp'
,
'import'
,
"
#{
import_id
}
.zip"
)
File
.
open
(
zip_file_path
,
'wb'
)
do
|
file
|
file
.
write
(
File
.
open
(
import_file_path
).
read
)
end
import
=
Import
::
ImportCollections
.
new
(
import_id
,
user
.
id
)
import
.
extract
import
.
read
import
.
import
import
.
cleanup
end
it
'creates a collection'
do
collection
=
Collection
.
find_by
(
label:
'Awesome Collection'
)
expect
(
collection
).
to
be_present
end
end
end
Write
Preview
Markdown
is supported
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