Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/fix minor offenses #269

Merged
merged 4 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/autoheathen/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Config
def load_config(defaults = {}, config_file = nil, overwrites = {})
cfg = symbolize_keys(defaults)
if config_file && File.exist?(config_file)
cfg.merge! symbolize_keys(YAML::load_file config_file)
cfg.merge! symbolize_keys(YAML::load_file(config_file))
end
cfg.merge! symbolize_keys(overwrites) # non-file opts have precedence
return cfg
Expand Down
8 changes: 4 additions & 4 deletions lib/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def initialize(storage_dir: C_.storage_directory, logger: Logger.new(C_.conversi
def convert(doc_key, version, filename, action)
doc = Document.load @storage_dir, doc_key
ignore, orig_content = doc.get_file(version, filename)
language = 'en' # TODO - add to spec and upload
language = 'en' # TODO: add to spec and upload
new_content = convert_file action, orig_content, language
# TODO - handling for variant formats with the same extension
# probably by adding format info before suffix
# e.g. foo.40x40.jpg
# TODO: handling for variant formats with the same extension
# probably by adding format info before suffix
# e.g. foo.40x40.jpg
new_filename = Heathen::Filename.suggest filename, new_content.mime_type
doc.add_file version, new_filename, new_content
doc.save_metadata
Expand Down
6 changes: 3 additions & 3 deletions lib/heathen/executioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Heathen
# STDOUT and STDERR for perusal.
class Executioner
attr_reader :logger, :last_exit_status, :last_messages, :last_command,
:stdout, :stderr
:stdout, :stderr

def initialize(log)
@logger = log
Expand Down Expand Up @@ -58,7 +58,7 @@ def _execute(*argv, options)
builder.directory(dir)
end

process = builder.start()
process = builder.start

# Dirty hack, works on UNIX only.
pid = if process.is_a?(Java::JavaLang::UNIXProcess)
Expand Down Expand Up @@ -96,7 +96,7 @@ def _execute(*argv, options)
command = argv.shift

Open3.popen3(ENV, [command, "heathen: #{command}"], *argv,
chdir: options[:dir] || Dir.getwd
chdir: options[:dir] || Dir.getwd
) do |stdin, stdout, stderr, wait_thr|
pid = wait_thr[:pid]
logger.info "[#{pid}] spawn '#{command} #{argv.join(' ')}'"
Expand Down
2 changes: 1 addition & 1 deletion lib/heathen/filename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.suggest(filename, mime_type)
mime_type = muck_mime_type(mime_type)
ext = File.extname(filename)
temp_file = filename[0..-(ext.length + 1)]
ext = MIME::Types[mime_type].first.preferred_extension rescue 'txt' # FIXME use a saner extension
ext = MIME::Types[mime_type].first.preferred_extension rescue 'txt' # FIXME: use a saner extension
"#{temp_file}.#{ext}"
end

Expand Down
12 changes: 6 additions & 6 deletions spec/heathen/filename_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
let(:mime_type) { content.mime_type }
context '.suggest' do
it 'suggests foo.pdf' do
expect(described_class.suggest 'foo.pdf', mime_type).to eq 'foo.txt'
expect(described_class.suggest('foo.pdf', mime_type)).to eq 'foo.txt'
end

it 'suggests bar/foo.pdf' do
expect(described_class.suggest 'bar/foo.pdf', mime_type).to eq 'bar/foo.txt'
expect(described_class.suggest('bar/foo.pdf', mime_type)).to eq 'bar/foo.txt'
end

it 'suggests foo' do
expect(described_class.suggest 'foo', mime_type).to eq 'foo.txt'
expect(described_class.suggest('foo', mime_type)).to eq 'foo.txt'
end

it 'suggests bar/foo' do
expect(described_class.suggest 'bar/foo', mime_type).to eq 'bar/foo.txt'
expect(described_class.suggest('bar/foo', mime_type)).to eq 'bar/foo.txt'
end
end

context '.suggest_in_new_dir' do
it 'suggests (short dir) -> (longer dir)' do
expect(
described_class.suggest_in_new_dir '/home/joe/src/foo.pdf', mime_type, '/home', '/opt/users'
described_class.suggest_in_new_dir('/home/joe/src/foo.pdf', mime_type, '/home', '/opt/users')
).to eq '/opt/users/joe/src/foo.txt'
end

it 'suggests (longer dir) -> (short dir)' do
expect(
described_class.suggest_in_new_dir '/opt/users/joe/src/foo.pdf', mime_type, '/opt/users', '/home'
described_class.suggest_in_new_dir('/opt/users/joe/src/foo.pdf', mime_type, '/opt/users', '/home')
).to eq '/home/joe/src/foo.txt'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def show_backtrace(response)
return unless response.status == 500

begin
puts JSON.pretty_generate(JSON.parse response.body)
puts JSON.pretty_generate(JSON.parse(response.body))
rescue StandardError => e
puts response.body
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/autoheathen/email_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
end

it 'validates content types' do
expect(processor.get_action 'image/tiff').to eq 'ocr'
expect(processor.get_action 'application/pdf; charset=utf-8').to eq 'ocr'
expect(processor.get_action 'application/msword').to eq 'pdf'
expect(processor.get_action('image/tiff')).to eq 'ocr'
expect(processor.get_action('application/pdf; charset=utf-8')).to eq 'ocr'
expect(processor.get_action('application/msword')).to eq 'pdf'
expect { processor.get_action 'foobar' }.to raise_error(RuntimeError)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
foo = double(Heathen::Converter)
allow(Heathen::Converter).to receive(:new) { foo }
allow(foo).to receive(:convert) { "The quick brown fox" }
expect(converter.convert doc_key, version, filename, action).to eq new_filename
expect(converter.convert(doc_key, version, filename, action)).to eq new_filename
content_type, content = document.get_file version, new_filename
expect(content_type).to eq 'text/plain; charset=us-ascii'
expect(content.to_s).to eq 'The quick brown fox'
Expand Down
28 changes: 14 additions & 14 deletions spec/lib/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
context '.delete' do
it 'runs' do
Colore::Document.delete storage_dir, doc_key
expect(Colore::Document.exists? storage_dir, doc_key).to eq false
expect(Colore::Document.exists?(storage_dir, doc_key)).to eq false
end
end

context '#directory' do
it 'runs' do
dir = document.directory
expect(dir).to_not be_nil
expect(File.exist? dir).to eq true
expect(File.exist?(dir)).to eq true
end
end

Expand Down Expand Up @@ -105,13 +105,13 @@

context '#has_version?' do
it 'runs' do
expect(document.has_version? 'v001').to eq true
expect(document.has_version?('v001')).to eq true
end
it 'accepts current' do
expect(document.has_version? 'current').to eq true
expect(document.has_version?('current')).to eq true
end
it 'rejects invalid' do
expect(document.has_version? 'foo').to eq false
expect(document.has_version?('foo')).to eq false
end
end

Expand All @@ -131,9 +131,9 @@
it 'runs' do
version = document.new_version
expect(version).to_not be_nil
expect(File.exist? document.directory + version).to eq true
expect(File.exist?(document.directory + version)).to eq true
new_doc = described_class.load storage_dir, doc_key
expect(new_doc.versions.include? version).to eq true
expect(new_doc.versions.include?(version)).to eq true
end
end

Expand All @@ -142,21 +142,21 @@
file = __FILE__
body = File.read(file)
document.add_file 'v002', File.basename(file), body
expect(File.exist? document.directory + 'v002' + File.basename(file)).to eq true
expect(File.exist?(document.directory + 'v002' + File.basename(file))).to eq true
end
it 'runs with author' do
file = __FILE__
body = File.read(file)
document.add_file 'v002', File.basename(file), body, author
expect(File.exist? document.directory + 'v002' + File.basename(file)).to eq true
expect(File.exist? document.directory + 'v002' + described_class::AUTHOR_FILE).to eq true
expect(File.exist?(document.directory + 'v002' + File.basename(file))).to eq true
expect(File.exist?(document.directory + 'v002' + described_class::AUTHOR_FILE)).to eq true
expect(File.read(document.directory + 'v002' + described_class::AUTHOR_FILE).chomp).to eq author
end
it 'runs with IO for body' do
file = __FILE__
body = File.open(file)
document.add_file 'v002', File.basename(file), body
expect(File.exist? document.directory + 'v002' + File.basename(file)).to eq true
expect(File.exist?(document.directory + 'v002' + File.basename(file))).to eq true
end
end

Expand Down Expand Up @@ -184,7 +184,7 @@
context '#delete_version' do
it 'runs' do
document.delete_version 'v001'
expect(File.exist? document.directory + 'v001').to eq false
expect(File.exist?(document.directory + 'v001')).to eq false
end
it 'refuses to delete "current"' do
expect {
Expand All @@ -203,7 +203,7 @@

context '#file_path' do
it 'runs' do
expect(document.file_path 'v001', 'arglebargle.docx').to eq "/document/#{app}/#{doc_id}/v001/arglebargle.docx"
expect(document.file_path('v001', 'arglebargle.docx')).to eq "/document/#{app}/#{doc_id}/v001/arglebargle.docx"
end
end

Expand Down Expand Up @@ -256,7 +256,7 @@
context '#save_metadata' do
it 'runs' do
document.save_metadata
expect(File.exist? document.directory + 'metadata.json').to eq true
expect(File.exist?(document.directory + 'metadata.json')).to eq true
# expect this to pass
JSON.parse File.read(document.directory + 'metadata.json')
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/legacy_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
context '#get_file' do
it 'runs' do
filename = converter.convert_file new_format, content
expect(converter.get_file File.basename(filename)).to eq 'The quick brown fox'
expect(converter.get_file(File.basename(filename))).to eq 'The quick brown fox'
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{ 'type' => 'George Cross', reason: 'Bravery' },
]
}
expect(symbolize_keys h).to eq({
expect(symbolize_keys(h)).to eq({
name: 'Fred',
address: {
house_number: 12,
Expand Down