Commit 7aba763f by John Donnal

rubocop fixes

parent 6c82e8d4
...@@ -19,7 +19,8 @@ class DbAdapter ...@@ -19,7 +19,8 @@ class DbAdapter
# Create the schema: # Create the schema:
# 3 elements: path, attributes, streams # 3 elements: path, attributes, streams
{ path: entry[0], {
path: entry[0],
attributes: { attributes: {
data_type: entry[1], data_type: entry[1],
start_time: entry[2] || 0, start_time: entry[2] || 0,
......
...@@ -21,7 +21,8 @@ class UpdateFolder ...@@ -21,7 +21,8 @@ class UpdateFolder
# 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( @folder.update_attributes(
info.slice(*DbFolder.defined_attributes)) info.slice(*DbFolder.defined_attributes)
)
# process the contents of the folder # process the contents of the folder
__parse_folder_entries(@folder, @entries) __parse_folder_entries(@folder, @entries)
# delete any files or folders still in the # delete any files or folders still in the
...@@ -114,7 +115,7 @@ class UpdateFolder ...@@ -114,7 +115,7 @@ class UpdateFolder
# if any entry_group has chunks left, this is a folder # if any entry_group has chunks left, this is a folder
entry_group.select { |entry| entry_group.select { |entry|
!entry[:chunks].empty? !entry[:chunks].empty?
}.count == 0 }.count.zero?
end end
# create or update a DbFile object at the # create or update a DbFile object at the
......
...@@ -11,7 +11,8 @@ describe DbAdapter do ...@@ -11,7 +11,8 @@ describe DbAdapter do
expect(entry).to include(:path, :attributes) expect(entry).to include(:path, :attributes)
expect(entry[:attributes]).to( expect(entry[:attributes]).to(
include(:data_type, :start_time, include(:data_type, :start_time,
:end_time, :total_rows, :total_time)) :end_time, :total_rows, :total_time)
)
end end
end end
end end
...@@ -12,20 +12,23 @@ class DbSchemaHelper ...@@ -12,20 +12,23 @@ class DbSchemaHelper
start_time: 0, start_time: 0,
end_time: 0, end_time: 0,
total_rows: 0, total_rows: 0,
total_time: 0 }.merge(metadata), total_time: 0
}.merge(metadata),
streams: __build_streams(stream_count) streams: __build_streams(stream_count)
} }
end end
# build stream hash for a file # build stream hash for a file
def __build_streams(count) def __build_streams(count)
return {} unless count > 0 return {} unless count.positive?
streams = [] streams = []
(0..(count - 1)).each do |i| (0..(count - 1)).each do |i|
streams << streams <<
{ 'name': "stream#{i}", {
'name': "stream#{i}",
'units': 'unit', 'units': 'unit',
'column': i } 'column': i
}
end end
streams streams
end end
......
...@@ -21,9 +21,9 @@ RSpec.describe 'Db' do ...@@ -21,9 +21,9 @@ RSpec.describe 'Db' do
expect(db_x.url).to eq('custom_string') expect(db_x.url).to eq('custom_string')
end end
it 'can be left as default' do it 'can be left as default' do
nilm = Nilm.create(url: "base") nilm = Nilm.create(url: 'base')
db_x = Db.new(nilm: nilm, url: '') db_x = Db.new(nilm: nilm, url: '')
expect(db_x.url).to eq("base/nilmdb") expect(db_x.url).to eq('base/nilmdb')
end end
end end
end end
...@@ -129,15 +129,14 @@ describe 'UpdateDb' do ...@@ -129,15 +129,14 @@ describe 'UpdateDb' do
# create Db with a file 'temp' # create Db with a file 'temp'
update_with_schema([helper.entry('/folder1/temp'), update_with_schema([helper.entry('/folder1/temp'),
helper.entry('/folder1/info', helper.entry('/folder1/info',
metadata: { name: 'f1' }) metadata: { name: 'f1' })])
])
temp = DbFile.find_by_name('temp') temp = DbFile.find_by_name('temp')
# the file 'temp' should be here # the file 'temp' should be here
expect(temp).to be_present expect(temp).to be_present
# update Db without 'temp' # update Db without 'temp'
update_with_schema([helper.entry('/folder1/info', update_with_schema([helper.entry('/folder1/info',
metadata: { name: 'f1' }) metadata: { name: 'f1' })],
], db: @db) db: @db)
# it should be gone # it should be gone
expect(DbFile.find_by_name('temp')).to be nil expect(DbFile.find_by_name('temp')).to be nil
# ...and the service should have a warning # ...and the service should have a warning
...@@ -147,8 +146,7 @@ describe 'UpdateDb' do ...@@ -147,8 +146,7 @@ describe 'UpdateDb' do
# create Db with a folder 'temp' # create Db with a folder 'temp'
update_with_schema([helper.entry('/folder1/stub'), update_with_schema([helper.entry('/folder1/stub'),
helper.entry('/folder1/temp/info', helper.entry('/folder1/temp/info',
metadata: { name: 'temp' }) metadata: { name: 'temp' })])
])
temp = DbFolder.find_by_name('temp') temp = DbFolder.find_by_name('temp')
# the file 'temp' should be here # the file 'temp' should be here
expect(temp).to be_present expect(temp).to be_present
......
...@@ -54,16 +54,16 @@ describe 'ServiceStatus' do ...@@ -54,16 +54,16 @@ describe 'ServiceStatus' do
child.add_warning('test') child.add_warning('test')
expect( expect(
parent.absorb_status(child, parent.absorb_status(child,
action: ServiceStatus::NEVER_FAIL)) action: ServiceStatus::NEVER_FAIL)
.to be true ).to be true
end end
it 'fails on errors and warnings with FAIL_ON_WARNING' do it 'fails on errors and warnings with FAIL_ON_WARNING' do
child.add_warning('test') child.add_warning('test')
expect( expect(
parent.absorb_status(child, parent.absorb_status(child,
action: ServiceStatus::FAIL_ON_WARNING)) action: ServiceStatus::FAIL_ON_WARNING)
.to be false ).to be false
end end
it 'fails on errors with FAIL_ON_ERROR' do it 'fails on errors with FAIL_ON_ERROR' do
child.add_error('test') child.add_error('test')
......
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