Commit 7d7b0e32 by John Doe

can refresh database

parent 7aa5e7cd
...@@ -8,6 +8,16 @@ class DbAdapter ...@@ -8,6 +8,16 @@ class DbAdapter
@url = url @url = url
end end
def dbinfo
version = self.class.get("#{@url}/version").parsed_response
info = self.class.get("#{@url}/dbinfo").parsed_response
{
version: version,
size_db: info['size'],
size_other: info['other'],
size_total: info["size"]+info["other"]+info["free"]+info["reserved"]
}
end
def schema def schema
# GET extended info stream list # GET extended info stream list
dump = self.class.get("#{@url}/stream/list?extended=1") dump = self.class.get("#{@url}/stream/list?extended=1")
......
...@@ -6,8 +6,8 @@ class DbStreamsController < ApplicationController ...@@ -6,8 +6,8 @@ class DbStreamsController < ApplicationController
stream = DbStream.find(params[:id]) stream = DbStream.find(params[:id])
adapter = DbAdapter.new(stream.db.url) adapter = DbAdapter.new(stream.db.url)
service = EditStream.new(adapter) service = EditStream.new(adapter)
service.run(stream, stream_params.symbolize_keys) service.run(stream, stream_params)
if(service.success?) if service.success?
render json: stream render json: stream
else else
render json: service, status: :unprocessable_entity render json: service, status: :unprocessable_entity
...@@ -15,8 +15,13 @@ class DbStreamsController < ApplicationController ...@@ -15,8 +15,13 @@ class DbStreamsController < ApplicationController
end end
private private
def stream_params def stream_params
params.permit(:name, :description, :hidden, :name_abbrev, :elements) params.require(:stream)
.permit(:name, :description, :name_abbrev, :hidden,
db_elements_attributes:
[:id, :name, :units,
:default_max, :default_min, :scale_factor, :offset,
:plottable, :discrete])
end end
end end
...@@ -6,4 +6,36 @@ class DbsController < ApplicationController ...@@ -6,4 +6,36 @@ class DbsController < ApplicationController
db = Db.find(params[:id]) db = Db.find(params[:id])
render json: db render json: db
end end
def update
db = Db.find(params[:id])
prev_url = db.url
if db.update_attributes(db_params)
if(prev_url != db.url || params[:refresh])
refresh(db) and return
end
render json: db
else
render json: "adfs"
end
end
private
def refresh(db)
adapter = DbAdapter.new(db.url)
service = UpdateDb.new(db: db)
service.run(adapter.dbinfo, adapter.schema)
if(service.success?)
render json: db
else
render json: service, status: :unprocessable_entity
end
end
def db_params
params.permit(:url, :max_points_per_plot)
end
end end
...@@ -9,6 +9,21 @@ class DbElement < ApplicationRecord ...@@ -9,6 +9,21 @@ class DbElement < ApplicationRecord
validates :name, uniqueness: { scope: :db_stream_id, validates :name, uniqueness: { scope: :db_stream_id,
message: ' is already used in this folder'} message: ' is already used in this folder'}
validates :scale_factor, presence: true, numericality: true
validates :scale_factor, presence: true, numericality: true
validates :default_min, allow_nil: true, numericality: true
validates :default_max, allow_nil: true, numericality: true
# force set any validated params to acceptable
# default values this allows us to process corrupt databases
def use_default_attributes
self.name = "element#{self.column}"
self.units = ""
self.default_min = nil
self.default_max = nil
self.scale_factor = 1.0
self.offset = 0.0
end
def as_json(_options = {}) def as_json(_options = {})
super(except: [:created_at, :updated_at]) super(except: [:created_at, :updated_at])
......
...@@ -19,11 +19,13 @@ class DbFolder < ApplicationRecord ...@@ -19,11 +19,13 @@ class DbFolder < ApplicationRecord
validates_presence_of :name validates_presence_of :name
# validates_with DbFolderValidator # validates_with DbFolderValidator
validates :name, uniqueness: { scope: :parent_id, validates :name, uniqueness: { scope: :parent_id,
message: ' is already used in this folder'} message: ' is already used in this folder'}, unless: :root_folder?
#:section: Utility Methods #:section: Utility Methods
def root_folder?
self.parent == nil
end
def self.defined_attributes def self.defined_attributes
...@@ -38,6 +40,13 @@ class DbFolder < ApplicationRecord ...@@ -38,6 +40,13 @@ class DbFolder < ApplicationRecord
true true
end end
# force set any validated params to acceptable
# default values this allows us to process corrupt databases
def use_default_attributes
self.name = self.path
self.description = ''
end
def as_json(options = {shallow: true}) def as_json(options = {shallow: true})
folder = super(except: [:created_at, :updated_at]) folder = super(except: [:created_at, :updated_at])
if(options[:shallow]== false) if(options[:shallow]== false)
......
...@@ -45,6 +45,14 @@ class DbStream < ApplicationRecord ...@@ -45,6 +45,14 @@ class DbStream < ApplicationRecord
/^\w*_(\d*)$/.match(data_type)[1].to_i /^\w*_(\d*)$/.match(data_type)[1].to_i
end end
# force set any validated params to acceptable
# default values this allows us to process corrupt databases
def use_default_attributes
self.name = self.path
self.description = ''
end
def as_json(_options = {}) def as_json(_options = {})
stream = super(except: [:created_at, :updated_at]) stream = super(except: [:created_at, :updated_at])
stream[:elements] = db_elements.map(&:as_json) stream[:elements] = db_elements.map(&:as_json)
......
...@@ -9,7 +9,7 @@ class UpdateDb ...@@ -9,7 +9,7 @@ class UpdateDb
super() super()
end end
def run(schema) def run(dbinfo, schema)
# create the root folder if it doesn't exist # create the root folder if it doesn't exist
@db.root_folder ||= DbFolder.create(db: @db, name: 'root', path: '/') @db.root_folder ||= DbFolder.create(db: @db, name: 'root', path: '/')
@root_folder = @db.root_folder @root_folder = @db.root_folder
...@@ -18,6 +18,11 @@ class UpdateDb ...@@ -18,6 +18,11 @@ class UpdateDb
entries = __create_entries(schema) entries = __create_entries(schema)
updater = UpdateFolder.new(@root_folder, entries) updater = UpdateFolder.new(@root_folder, entries)
# update db attributes from dbinfo
@db.size_total = dbinfo[:size_total]
@db.size_db = dbinfo[:size_db]
@db.size_other = dbinfo[:size_other]
@db.version = dbinfo[:version]
absorb_status(updater.run) absorb_status(updater.run)
@db.save @db.save
......
...@@ -25,9 +25,12 @@ class UpdateFolder ...@@ -25,9 +25,12 @@ class UpdateFolder
def run def run
# update the folder attributes from metadata # update the folder attributes from metadata
info = __read_info_entry(@entries) || {} info = __read_info_entry(@entries) || {}
@folder.update_attributes( # if metadata is corrupt, use default values instead
info.slice(*DbFolder.defined_attributes) unless @folder.update_attributes(
) info.slice(*DbFolder.defined_attributes))
@folder.use_default_attributes
Rails.logger.warn("corrupt metadata: #{@folder.path}")
end
# process the contents of the folder # process the contents of the folder
__parse_folder_entries(@folder, @entries) __parse_folder_entries(@folder, @entries)
# delete any streams or folders still in the # delete any streams or folders still in the
...@@ -48,6 +51,9 @@ class UpdateFolder ...@@ -48,6 +51,9 @@ class UpdateFolder
@folder.end_time = @end_time @folder.end_time = @end_time
@folder.size_on_disk = @size_on_disk @folder.size_on_disk = @size_on_disk
# save the result # save the result
unless @folder.valid?
byebug
end
@folder.save! @folder.save!
self self
end end
...@@ -183,7 +189,6 @@ class UpdateFolder ...@@ -183,7 +189,6 @@ class UpdateFolder
# update extents based on result of updater # update extents based on result of updater
# (either a stream or a subfolder) # (either a stream or a subfolder)
def absorb_data_extents(updater) def absorb_data_extents(updater)
byebug if(@folder.name=="tutorial")
if @start_time.nil? if @start_time.nil?
@start_time = updater.start_time @start_time = updater.start_time
elsif !updater.start_time.nil? elsif !updater.start_time.nil?
......
...@@ -11,18 +11,11 @@ class EditStream ...@@ -11,18 +11,11 @@ class EditStream
def run(db_stream, attribs) def run(db_stream, attribs)
# only accept valid attributes # only accept valid attributes
stream_attribs = attribs.slice(:name, :description, attribs.slice!(:name, :description, :name_abbrev, :hidden,
:hidden, :name_abbrev) :db_elements_attributes)
begin
stream_attribs[:db_elements_attributes] =
__parse_element_attribs(attribs[:elements])
rescue TypeError
add_error("invalid db_elements_attributes parameter")
return self
end
# assign the new attributes and check if the # assign the new attributes and check if the
# result is valid (eg elements can't have the same name) # result is valid (eg elements can't have the same name)
db_stream.assign_attributes(stream_attribs) db_stream.assign_attributes(attribs)
unless db_stream.valid? unless db_stream.valid?
db_stream.errors db_stream.errors
.full_messages .full_messages
......
...@@ -29,7 +29,12 @@ class UpdateStream ...@@ -29,7 +29,12 @@ class UpdateStream
# create or update a DbStream object at the # create or update a DbStream object at the
# specified path. # specified path.
def __update_stream(stream, base_entry, decimation_entries) def __update_stream(stream, base_entry, decimation_entries)
stream.update_attributes(base_entry[:attributes]) # use default attributes if metadata is corrupt
unless stream.update_attributes(base_entry[:attributes])
stream.use_default_attributes
Rails.logger.warn("corrupt metadata: #{stream.path}")
end
__compute_extents([base_entry] + decimation_entries) __compute_extents([base_entry] + decimation_entries)
stream.start_time = @start_time stream.start_time = @start_time
stream.end_time = @end_time stream.end_time = @end_time
...@@ -58,11 +63,16 @@ class UpdateStream ...@@ -58,11 +63,16 @@ class UpdateStream
def __build_elements(stream:, stream_data:) def __build_elements(stream:, stream_data:)
stream.column_count.times do |x| stream.column_count.times do |x|
element = stream.db_elements.find_by_column(x) element = stream.db_elements.find_by_column(x)
element ||= DbElement.new(db_stream: stream) element ||= DbElement.new(db_stream: stream, column: x)
# check if there is stream metadata for column x # check if there is stream metadata for column x
entry = stream_data.select { |meta| meta[:column] == x } entry = stream_data.select { |meta| meta[:column] == x }
# use the metadata if present # use the metadata if present
element.update_attributes(entry[0] || {}) unless element.update_attributes(entry[0] || {})
element.use_default_attributes
Rails.logger.warn(stream_data)
Rails.logger.warn("corrupt metadata: #{stream.path}:"\
"e#{element.column}")
end
element.save! element.save!
end end
end end
......
...@@ -18,6 +18,6 @@ class CreateNilm ...@@ -18,6 +18,6 @@ class CreateNilm
db = Db.create(nilm: @nilm, url: db_url) db = Db.create(nilm: @nilm, url: db_url)
service = UpdateDb.new(db: db) service = UpdateDb.new(db: db)
adapter = DbAdapter.new(db.url) adapter = DbAdapter.new(db.url)
service.run(adapter.schema) service.run(adapter.dbinfo, adapter.schema)
end end
end end
class AddFieldsToDb < ActiveRecord::Migration[5.0]
def change
add_column :dbs, :size_total, :integer, :limit => 8
add_column :dbs, :size_db, :integer, :limit => 8
add_column :dbs, :size_other, :integer, :limit => 8
add_column :dbs, :version, :string
add_column :dbs, :max_points_per_plot, :integer, :default => 3600
end
end
class ExtendSizeOnDiskType < ActiveRecord::Migration[5.0]
def change
change_column :db_folders, :size_on_disk, :integer, limit: 8
change_column :db_streams, :size_on_disk, :integer, limit: 8
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170118013812) do ActiveRecord::Schema.define(version: 20170127033854) do
create_table "db_decimations", force: :cascade do |t| create_table "db_decimations", force: :cascade do |t|
t.integer "start_time", limit: 8 t.integer "start_time", limit: 8
...@@ -50,7 +50,7 @@ ActiveRecord::Schema.define(version: 20170118013812) do ...@@ -50,7 +50,7 @@ ActiveRecord::Schema.define(version: 20170118013812) do
t.integer "db_id" t.integer "db_id"
t.integer "start_time", limit: 8 t.integer "start_time", limit: 8
t.integer "end_time", limit: 8 t.integer "end_time", limit: 8
t.integer "size_on_disk" t.integer "size_on_disk", limit: 8
end end
create_table "db_streams", force: :cascade do |t| create_table "db_streams", force: :cascade do |t|
...@@ -68,7 +68,7 @@ ActiveRecord::Schema.define(version: 20170118013812) do ...@@ -68,7 +68,7 @@ ActiveRecord::Schema.define(version: 20170118013812) do
t.string "name_abbrev" t.string "name_abbrev"
t.boolean "delete_locked" t.boolean "delete_locked"
t.boolean "hidden" t.boolean "hidden"
t.integer "size_on_disk" t.integer "size_on_disk", limit: 8
t.integer "db_id" t.integer "db_id"
end end
...@@ -78,6 +78,11 @@ ActiveRecord::Schema.define(version: 20170118013812) do ...@@ -78,6 +78,11 @@ ActiveRecord::Schema.define(version: 20170118013812) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "nilm_id" t.integer "nilm_id"
t.integer "size_total", limit: 8
t.integer "size_db", limit: 8
t.integer "size_other", limit: 8
t.string "version"
t.integer "max_points_per_plot", default: 3600
end end
create_table "nilms", force: :cascade do |t| create_table "nilms", force: :cascade do |t|
......
...@@ -6,6 +6,13 @@ RSpec.describe 'Db' do ...@@ -6,6 +6,13 @@ RSpec.describe 'Db' do
let(:db) { Db.new } let(:db) { Db.new }
specify { expect(db).to respond_to(:url) } specify { expect(db).to respond_to(:url) }
specify { expect(db).to respond_to(:root_folder) } specify { expect(db).to respond_to(:root_folder) }
specify { expect(db).to respond_to(:size_db) }
specify { expect(db).to respond_to(:size_total) }
specify { expect(db).to respond_to(:size_other) }
specify { expect(db).to respond_to(:version) }
specify { expect(db).to respond_to(:max_points_per_plot) }
end end
it 'removes the root folder when destroyed' do it 'removes the root folder when destroyed' do
......
...@@ -24,11 +24,13 @@ simple_db = [ ...@@ -24,11 +24,13 @@ simple_db = [
] ]
describe 'UpdateDb' do describe 'UpdateDb' do
let(:dbinfo) { double('dbinfo').as_null_object}
describe '*run*' do describe '*run*' do
def update_with_schema(schema, db: nil) def update_with_schema(schema, db: nil)
@db = db || Db.new @db = db || Db.new
@service = UpdateDb.new(db: @db) @service = UpdateDb.new(db: @db)
@service.run(schema) mock_info =
@service.run(dbinfo, schema) #ignore dbinfo
@root = @db.root_folder @root = @db.root_folder
end end
# simple schema parsing # simple schema parsing
......
...@@ -14,7 +14,7 @@ describe 'EditStream service' do ...@@ -14,7 +14,7 @@ describe 'EditStream service' do
it 'changes stream and element attributes' do it 'changes stream and element attributes' do
attribs = { id: 0, invalid_attrib: 'ignore', attribs = { id: 0, invalid_attrib: 'ignore',
name: 'new name', name_abbrev: 'nn', name: 'new name', name_abbrev: 'nn',
elements: [{id: element.id, name: 'new!'}] } db_elements_attributes: [{id: element.id, name: 'new!'}] }
allow(db_adapter).to receive(:set_stream_metadata).and_return(success) allow(db_adapter).to receive(:set_stream_metadata).and_return(success)
# run the service, it should call the adapter and save the folder # run the service, it should call the adapter and save the folder
service.run(stream, attribs) service.run(stream, attribs)
...@@ -34,7 +34,8 @@ describe 'EditStream service' do ...@@ -34,7 +34,8 @@ describe 'EditStream service' do
end end
it 'does not change stream or elements on a server error' do it 'does not change stream or elements on a server error' do
attribs = { name: 'new', elements: [{id: element.id, name: 'new'}]} attribs = { name: 'new',
db_elements_attributes: [{id: element.id, name: 'new'}]}
allow(db_adapter).to receive(:set_stream_metadata).and_return(error) allow(db_adapter).to receive(:set_stream_metadata).and_return(error)
allow(stream).to receive(:save!) allow(stream).to receive(:save!)
allow(element).to receive(:save!) allow(element).to receive(:save!)
...@@ -45,12 +46,4 @@ describe 'EditStream service' do ...@@ -45,12 +46,4 @@ describe 'EditStream service' do
expect(element).to_not have_received(:save!) expect(element).to_not have_received(:save!)
end end
it 'produces error for invalid parameter structure' do
attribs = {name: 'new', elements: {id: 0, name: 'nice try'}}
allow(db_adapter).to receive(:set_stream_metadata).and_return(success)
# run the service, it shouldn't call the database adapter
service.run(stream, attribs)
expect(service.errors?).to be true
expect(db_adapter).to_not have_received(:set_stream_metadata)
end
end end
...@@ -6,6 +6,8 @@ describe 'UpdateStream service' do ...@@ -6,6 +6,8 @@ describe 'UpdateStream service' do
let(:db) { Db.new } let(:db) { Db.new }
let(:service) { UpdateDb.new(db: db) } let(:service) { UpdateDb.new(db: db) }
let(:helper) { DbSchemaHelper.new } let(:helper) { DbSchemaHelper.new }
let(:mock_dbinfo) { double('dbinfo').as_null_object}
def build_entry(path, start, last, rows, width) def build_entry(path, start, last, rows, width)
helper.entry(path, start_time: start, end_time: last, helper.entry(path, start_time: start, end_time: last,
element_count: width, total_rows: rows) element_count: width, total_rows: rows)
...@@ -14,13 +16,13 @@ describe 'UpdateStream service' do ...@@ -14,13 +16,13 @@ describe 'UpdateStream service' do
it 'updates stream info' do it 'updates stream info' do
# create Db with 1 folder and stream # create Db with 1 folder and stream
service.run([helper.entry('/folder1/stream1', service.run(mock_dbinfo, [helper.entry('/folder1/stream1',
metadata: { name: 'old_name' })]) metadata: { name: 'old_name' })])
stream = DbStream.find_by_name('old_name') stream = DbStream.find_by_name('old_name')
expect(stream).to be_present expect(stream).to be_present
# run update again with new metadata # run update again with new metadata
service = UpdateDb.new(db: db) service = UpdateDb.new(db: db)
service.run([helper.entry('/folder1/stream1', service.run(mock_dbinfo, [helper.entry('/folder1/stream1',
metadata: { name: 'new_name' })]) metadata: { name: 'new_name' })])
stream.reload stream.reload
expect(stream.name).to eq('new_name') expect(stream.name).to eq('new_name')
...@@ -32,7 +34,7 @@ describe 'UpdateStream service' do ...@@ -32,7 +34,7 @@ describe 'UpdateStream service' do
# expect stream to have min_start => max_end duration # expect stream to have min_start => max_end duration
# and size_on_disk to be sum of base+decimations # and size_on_disk to be sum of base+decimations
service.run([build_entry('/a/path', 1, 90, 20, 8), service.run(mock_dbinfo,[build_entry('/a/path', 1, 90, 20, 8),
build_entry('/a/path~decim-4', 10, 110, 25, 24), build_entry('/a/path~decim-4', 10, 110, 25, 24),
build_entry('/a/path~decim-16', -10, 100, 28, 24), build_entry('/a/path~decim-16', -10, 100, 28, 24),
build_entry('/a/path~decim-64', nil, nil, 0, 24)]) build_entry('/a/path~decim-64', nil, nil, 0, 24)])
...@@ -48,14 +50,26 @@ describe 'UpdateStream service' do ...@@ -48,14 +50,26 @@ describe 'UpdateStream service' do
schema = [helper.entry('/folder1/subfolder/stream', schema = [helper.entry('/folder1/subfolder/stream',
element_count: 1)] element_count: 1)]
schema[0][:elements][0][:name] = 'old_name' schema[0][:elements][0][:name] = 'old_name'
service.run(schema) service.run(mock_dbinfo, schema)
element = DbElement.find_by_name('old_name') element = DbElement.find_by_name('old_name')
expect(element).to be_present expect(element).to be_present
# run update again with new metadata # run update again with new metadata
schema[0][:elements][0][:name] = 'new_name' schema[0][:elements][0][:name] = 'new_name'
service = UpdateDb.new(db: db) service = UpdateDb.new(db: db)
service.run(schema) service.run(mock_dbinfo, schema)
element.reload element.reload
expect(element.name).to eq('new_name') expect(element.name).to eq('new_name')
end end
it 'uses default attributes if metadata is corrupt' do
#metadata missing stream name and an element name
bad_entry = helper.entry('/a/path',metadata: {name: ''})
bad_entry[:elements] = [{column: 0, name: ''}]
service.run(mock_dbinfo, [bad_entry])
stream = DbStream.find_by_path('/a/path')
expect(stream.name).to eq('/a/path')
expect(stream.db_elements
.find_by_column(0)
.name).to eq('element0')
end
end end
...@@ -40,6 +40,5 @@ describe 'EditFolder service' do ...@@ -40,6 +40,5 @@ describe 'EditFolder service' do
service.run(folder, attribs) service.run(folder, attribs)
expect(service.errors?).to be true expect(service.errors?).to be true
expect(folder).to_not have_received(:save!) expect(folder).to_not have_received(:save!)
end end
end end
...@@ -5,7 +5,9 @@ require 'rails_helper' ...@@ -5,7 +5,9 @@ require 'rails_helper'
describe 'UpdateFolder service' do describe 'UpdateFolder service' do
let(:db) { Db.new } let(:db) { Db.new }
let(:service) { UpdateDb.new(db: db) } let(:service) { UpdateDb.new(db: db) }
let(:helper) {DbSchemaHelper.new} let(:helper) { DbSchemaHelper.new }
let(:mock_dbinfo) { double('dbinfo').as_null_object }
def build_entry(path, start, last, rows, width) def build_entry(path, start, last, rows, width)
helper.entry(path, start_time: start, end_time: last, helper.entry(path, start_time: start, end_time: last,
element_count: width, total_rows: rows) element_count: width, total_rows: rows)
...@@ -13,13 +15,13 @@ describe 'UpdateFolder service' do ...@@ -13,13 +15,13 @@ describe 'UpdateFolder service' do
it 'updates folder info' do it 'updates folder info' do
# create Db with folder and subfolder # create Db with folder and subfolder
service.run([helper.entry('/folder1/subfolder/info', service.run(mock_dbinfo, [helper.entry('/folder1/subfolder/info',
metadata: { name: 'old_name' })]) metadata: { name: 'old_name' })])
folder = DbFolder.find_by_name('old_name') folder = DbFolder.find_by_name('old_name')
expect(folder).to be_present expect(folder).to be_present
# run update again with new metadata # run update again with new metadata
service = UpdateDb.new(db: db) service = UpdateDb.new(db: db)
service.run([helper.entry('/folder1/subfolder/info', service.run(mock_dbinfo, [helper.entry('/folder1/subfolder/info',
metadata: { name: 'new_name' })]) metadata: { name: 'new_name' })])
folder.reload folder.reload
expect(folder.name).to eq('new_name') expect(folder.name).to eq('new_name')
...@@ -31,10 +33,10 @@ describe 'UpdateFolder service' do ...@@ -31,10 +33,10 @@ describe 'UpdateFolder service' do
# expect stream to have min_start => max_end duration # expect stream to have min_start => max_end duration
# and size_on_disk to be sum of base+decimations # and size_on_disk to be sum of base+decimations
service.run([build_entry('/a/path', 1, 90, 20, 8), service.run(mock_dbinfo, [build_entry('/a/path', 1, 90, 20, 8),
build_entry('/a/path~decim-4', 10, 110, 25, 24), build_entry('/a/path~decim-4', 10, 110, 25, 24),
build_entry('/a/path2', -10, 100, 28, 24), build_entry('/a/path2', -10, 100, 28, 24),
#build_entry('/a/path', nil, nil, 0, 24), # build_entry('/a/path', nil, nil, 0, 24),
build_entry('/a/deep/path', 0, 400, 8, 10)]) build_entry('/a/deep/path', 0, 400, 8, 10)])
folder = DbFolder.find_by_path('/a') folder = DbFolder.find_by_path('/a')
expect(folder.start_time).to eq(-10) expect(folder.start_time).to eq(-10)
...@@ -42,4 +44,19 @@ describe 'UpdateFolder service' do ...@@ -42,4 +44,19 @@ describe 'UpdateFolder service' do
# (4*8+8)*20 + (4*24+8)*25 + (4*24+8)*28 + (4*10+8)*8 # (4*8+8)*20 + (4*24+8)*25 + (4*24+8)*28 + (4*10+8)*8
expect(folder.size_on_disk).to eq(6696) expect(folder.size_on_disk).to eq(6696)
end end
it 'uses default attributes if metadata is missing' do
service.run(mock_dbinfo, [helper.entry('/a/path', metadata: {})])
folder = DbFolder.find_by_path('/a')
expect(folder.name).to eq('a')
end
it 'uses default attributes if metadata is corrupt' do
bad = { name: '' }
service.run(mock_dbinfo, [helper.entry('/a/path'),
helper.entry('/a/info', metadata: bad)])
folder = DbFolder.find_by_path('/a')
expect(folder.name).to eq('/a')
end
end end
# frozen_string_literal: true # frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
test_nilm_url = 'http://192.168.42.17' test_nilm_url = 'http://localhost:8080'
RSpec.describe 'CreateNilm' do RSpec.describe 'CreateNilm' do
describe 'build' do describe 'build' do
......
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