Commit 8e58fdd5 by John Doe

can now parse simple_db

parent f56b2319
...@@ -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
...@@ -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)
......
...@@ -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]
......
...@@ -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
...@@ -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
# 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment