Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8e58fdd5
authored
May 22, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
can now parse simple_db
parent
f56b2319
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
7 deletions
app/controllers/dbs_controller.rb
app/models/db_file.rb
spec/builders/db_builder_spec.rb
spec/controllers/dbs_controller_spec.rb
spec/factories/db_schema_helper.rb
spec/features/list_db_contents_spec.rb
app/controllers/dbs_controller.rb
View file @
8e58fdd5
...
@@ -2,4 +2,8 @@
...
@@ -2,4 +2,8 @@
# Controller for Database Objects
# Controller for Database Objects
class
DbsController
<
ApplicationController
class
DbsController
<
ApplicationController
def
show
db
=
Db
.
find
(
params
[
:id
])
render
json:
db
end
end
end
app/models/db_file.rb
View file @
8e58fdd5
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
class
DbFile
<
ActiveRecord
::
Base
class
DbFile
<
ActiveRecord
::
Base
belongs_to
:db_folder
belongs_to
:db_folder
has_many
:db_streams
,
dependent: :destroy
has_many
:db_streams
,
dependent: :destroy
accepts_nested_attributes_for
:db_streams
def
remove
(
db_service
:)
def
remove
(
db_service
:)
db_service
.
remove_file
(
path
)
db_service
.
remove_file
(
path
)
...
...
spec/builders/db_builder_spec.rb
View file @
8e58fdd5
...
@@ -13,8 +13,10 @@ helper = DbSchemaHelper.new
...
@@ -13,8 +13,10 @@ helper = DbSchemaHelper.new
# `- file2_2
# `- file2_2
simple_db
=
[
simple_db
=
[
helper
.
entry
(
'/folder1/f1_1'
,
metadata:
{
name:
'file1_1'
}),
helper
.
entry
(
'/folder1/f1_1'
,
helper
.
entry
(
'/folder1/f1_2'
,
metadata:
{
name:
'file1_2'
}),
metadata:
{
name:
'file1_1'
},
stream_count:
4
),
helper
.
entry
(
'/folder1/f1_2'
,
metadata:
{
name:
'file1_2'
},
stream_count:
5
),
helper
.
entry
(
'/folder2/f2_1'
,
metadata:
{
name:
'file2_1'
}),
helper
.
entry
(
'/folder2/f2_1'
,
metadata:
{
name:
'file2_1'
}),
helper
.
entry
(
'/folder2/f2_2'
,
metadata:
{
name:
'file2_2'
})
helper
.
entry
(
'/folder2/f2_2'
,
metadata:
{
name:
'file2_2'
})
]
]
...
@@ -24,7 +26,7 @@ describe DbBuilder do
...
@@ -24,7 +26,7 @@ describe DbBuilder do
def
update_with_schema
(
schema
)
def
update_with_schema
(
schema
)
@db
=
Db
.
new
@db
=
Db
.
new
@db_builder
=
DbBuilder
.
new
(
db:
@db
)
@db_builder
=
DbBuilder
.
new
(
db:
@db
)
@db_builder
.
update_db
(
schema:
schema
)
@db_builder
.
update_db
(
schema:
Array
.
new
(
schema
)
)
@root
=
@db
.
root_folder
@root
=
@db
.
root_folder
end
end
describe
'given the simple_db schema'
do
describe
'given the simple_db schema'
do
...
@@ -38,10 +40,19 @@ describe DbBuilder do
...
@@ -38,10 +40,19 @@ describe DbBuilder do
update_with_schema
(
simple_db
)
update_with_schema
(
simple_db
)
folder1
=
@root
.
subfolders
[
0
]
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
name
).
to
eq
(
'folder1'
)
expect
(
folder1
.
name
).
to
eq
(
'folder1'
)
expect
(
folder1
.
db_files
.
count
).
to
eq
(
2
)
expect
(
folder1
.
db_files
[
0
].
name
).
to
eq
(
'file1_1'
)
expect
(
folder1
.
db_files
[
0
].
name
).
to
eq
(
'file1_1'
)
expect
(
folder1
.
db_files
[
1
].
name
).
to
eq
(
'file1_2'
)
expect
(
folder1
.
db_files
[
1
].
name
).
to
eq
(
'file1_2'
)
end
end
it
'builds files in sub-folder1'
do
update_with_schema
(
simple_db
)
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
db_files
.
count
).
to
eq
(
2
)
file1
=
folder1
.
db_files
[
0
]
file2
=
folder1
.
db_files
[
1
]
expect
(
file1
.
db_streams
.
count
).
to
eq
(
4
)
expect
(
file2
.
db_streams
.
count
).
to
eq
(
5
)
end
it
'builds sub-folder2'
do
it
'builds sub-folder2'
do
update_with_schema
(
simple_db
)
update_with_schema
(
simple_db
)
folder2
=
@root
.
subfolders
[
1
]
folder2
=
@root
.
subfolders
[
1
]
...
...
spec/controllers/dbs_controller_spec.rb
View file @
8e58fdd5
...
@@ -3,4 +3,12 @@
...
@@ -3,4 +3,12 @@
require
'rails_helper'
require
'rails_helper'
RSpec
.
describe
DbsController
,
type: :controller
do
RSpec
.
describe
DbsController
,
type: :controller
do
describe
'GET show'
do
it
'lists the database contents'
do
allow
(
Db
).
to
receive
(
:find
).
and_return
(
Db
.
new
)
get
:show
,
id:
1
expect
(
Db
).
to
have_received
(
:find
)
expect
(
response
.
header
[
'Content-Type'
]).
to
include
(
'application/json'
)
end
end
end
end
spec/factories/db_schema_helper.rb
View file @
8e58fdd5
...
@@ -4,11 +4,27 @@
...
@@ -4,11 +4,27 @@
# are usually returned by DbAdapter.schema
# are usually returned by DbAdapter.schema
class
DbSchemaHelper
class
DbSchemaHelper
# schema data
# schema data
def
entry
(
path
,
type:
'uint8_1'
,
metadata:
{})
def
entry
(
path
,
type:
'uint8_1'
,
metadata:
{},
stream_count:
0
)
if
stream_count
>
0
metadata
[
:db_streams_attributes
]
=
__build_streams
(
stream_count
)
end
{
path:
path
,
type:
type
,
{
path:
path
,
type:
type
,
start_time:
0
,
end_time:
0
,
start_time:
0
,
end_time:
0
,
total_rows:
0
,
total_time:
0
,
total_rows:
0
,
total_time:
0
,
metadata:
metadata
metadata:
metadata
}
}
end
# build stream hash for a file
def
__build_streams
(
count
)
return
nil
unless
count
>
0
streams
=
[]
(
0
..
(
count
-
1
)).
each
do
|
i
|
streams
<<
{
'name'
:
"stream
#{
i
}
"
,
'units'
:
'unit'
,
'column'
:
i
}
end
streams
end
end
end
end
spec/features/list_db_contents_spec.rb
0 → 100644
View file @
8e58fdd5
# frozen_string_literal: true
require
'rails_helper'
helper
=
DbSchemaHelper
.
new
simple_db
=
[
helper
.
entry
(
'/folder1/f1_1'
,
metadata:
{
name:
'file1_1'
},
stream_count:
4
),
helper
.
entry
(
'/folder1/f1_2'
,
metadata:
{
name:
'file1_2'
},
stream_count:
5
),
helper
.
entry
(
'/folder2/f2_1'
,
metadata:
{
name:
'file2_1'
}),
helper
.
entry
(
'/folder2/f2_2'
,
metadata:
{
name:
'file2_2'
})
]
RSpec
.
describe
'parse and display a database'
do
def
update_with_schema
(
schema
)
@db
=
Db
.
new
@db_builder
=
DbBuilder
.
new
(
db:
@db
)
@db_builder
.
update_db
(
schema:
Array
.
new
(
schema
))
@db
.
save
end
it
'loads and displays a database'
do
# TODO
# update_with_schema(simple_db)
# visit db_path(@db)
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