Commit 56d1f6b4 by John Donnal

working on folder editing

parent 9ad4c8b7
// Place your settings in this file to overwrite default and user settings.
{
"editor.autoClosingBrackets": false,
"editor.suggestOnTriggerCharacters": false,
"editor.formatOnType": false,
"editor.quickSuggestionsDelay": 100000
}
\ No newline at end of file
# frozen_string_literal: true
# Handles changing DbFolder attributes
class EditFolder
include ServiceStatus
def initialize(db_adapter)
super()
end
def run(db_file, *attribs)
# only accept valid attributes
attribs.slice!([:name, :description])
# assign the new attributes and check if the
# result is valid (eg file's can't have the same name)
db_file.assign_attributes(attribs)
unless db_file.valid?
add_error(db_file.errors)
return self
end
# local model checks out, update the remote NilmDB
db_adapter.update_metadata(db_file.path,
attribs.filter { |x| x.in[:name, :description] } )
# if there was an error don't save the model
if db_adapter.status == ERROR:
add_error(db_adapter.error_msg)
return self
end
# everything went well, save the model
db_file.save!
self
end
end
\ No newline at end of file
# frozen_string_literal: true
require 'rails_helper'
describe 'EditFolder service' do
let(:mock_adapter) { }
let(:service) { EditFolder.new(mock_adapter) }
it 'changes folder attributes' do
folder = DbFolder.new(name: 'old')
service.run(folder,name: 'new')
expect(mock_adapter).to be called once
expect(folder.name).to eq('new')
end
it 'does not change folder on a server error'
end
\ No newline at end of file
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