Skip to content

Commit

Permalink
rubocopping
Browse files Browse the repository at this point in the history
  • Loading branch information
simonneutert committed Sep 1, 2024
1 parent 348c202 commit 0639709
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 62 deletions.
2 changes: 1 addition & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class App < Roda

@media_files = Dir.glob(".#{@current_path_memo}/**")
.filter { |filename| MEDIA_WHITELIST.any? { |t| filename.downcase.end_with?(t.downcase) } }
.reject { |filename| filename.end_with?('memo.md') || filename.end_with?('meta.yaml') }
.reject { |filename| filename.end_with?('memo.md', 'meta.yaml') }

r.on 'destroy' do
FileOperations::DeleteMemo.new(memo_path, @current_path_memo).run
Expand Down
2 changes: 1 addition & 1 deletion lib/file_operations/file_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def store
filename = @params_file_data[:filename].encode('utf-8', invalid: :replace, undef: :replace, replace: '_')
validate!(filename)

pathy_filename = "#{Time.now.to_i}-#{filename}"[1..].gsub('/', '_').gsub(' ', '_')
pathy_filename = "#{Time.now.to_i}-#{filename}"[1..].tr('/', '_').tr(' ', '_')
file_content = File.read(@params_file_data[:tempfile])

File.write("#{@root_path}#{@params_path}/#{pathy_filename}",
Expand Down
2 changes: 1 addition & 1 deletion lib/file_operations/files_sort_by_latest_modified.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def latest_n_memos_by_file_modified(num)
#
def all_files_order_from_least_to_newest_modified
Dir.glob('memos/**/**')
.filter { |paths| paths.match(/\.md/) }
.filter { |paths| paths.include?('.md') }
.sort_by { |f| File.mtime(f) }
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/file_operations/meta_data_param_deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def read(params)
private

def markdown_url_escape(url)
return url unless url.start_with?('[')
return url unless markdown_style_url?(url)

begin
url.split('](').last.split(')').first
Expand All @@ -27,6 +27,10 @@ def markdown_url_escape(url)
url
end
end

def markdown_style_url?(url)
url.include?('](') && url.end_with?(')')
end
end
end
end
2 changes: 1 addition & 1 deletion lib/helper/simple_uid_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Helper
class SimpleUidGenerator
class << self
def generate
8.times.map do
Array.new(8) do
('a'..'z').to_a.sample
end.join.insert(4, '-')
end
Expand Down
2 changes: 1 addition & 1 deletion test/default_memos_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

class TestMemosOnFilesystem < Minitest::Test
def test_memos_default
assert_equal Dir.glob('.defaults/memos/**/*.md').size, 2
assert_equal 2, Dir.glob('.defaults/memos/**/*.md').size
end
end
39 changes: 21 additions & 18 deletions test/endpoints_api_v1_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def test_memos_tantiny_reload
post '/api/v1/memos/reload'

json = JSON.parse(last_response.body)
assert_equal json['status'], 'success'

assert_equal 'success', json['status']
end

# rubocop:disable Layout/LineLength
Expand All @@ -35,17 +36,17 @@ def test_memos_tantiny_search
post('/api/v1/memos/search', { search: 'pug' })

json = JSON.parse(last_response.body)
assert_equal last_response.status, 200

assert_equal 200, last_response.status
assert_kind_of Array, json
assert_equal json.size, 2
assert_equal json.first.size, 3
assert_equal 2, json.size
assert_equal 3, json.first.size

first_result_triplet = json.first

assert_equal '/memos/2021/08/21/hgfe-dcba', first_result_triplet.first
assert_equal 'Facts about Pugs!', first_result_triplet[1]
assert_equal ["The Pug is a breed of dog originally from China, with physically distinctive features of a wrinkly, short-muzzled face and curled tail. The breed has a fine, glossy coat that comes in a variety of colors, most often light brown (fawn) or black, and a compact, square body with well developed and thick muscles all over the body.\r",
"![](/memos/2021/08/21/hgfe-dcba/665507228-pug.jpg)\r"], first_result_triplet.last
assert_equal ['The Pug is a breed of dog originally from China, with physically distinctive features of a wrinkly, short-muzzled face and curled tail. The breed has a fine, glossy coat that comes in a variety of colors, most often light brown (fawn) or black, and a compact, square body with well developed and thick muscles all over the body.', '![](/memos/2021/08/21/hgfe-dcba/665507228-pug.jpg)', '[Wikipedia](https://en.wikipedia.org/wiki/Pug)'], first_result_triplet.last
assert_kind_of Array, first_result_triplet.last
end
# rubocop:enable Layout/LineLength
Expand All @@ -56,34 +57,36 @@ def test_memos_tantiny_search_without_match
post('/api/v1/memos/search', { search: 'pugxxx' })

json = JSON.parse(last_response.body)
assert_equal last_response.status, 200

assert_equal 200, last_response.status
assert_kind_of Array, json
assert_equal json.size, 0
assert_equal 0, json.size
assert_nil json.first
assert json.empty?
assert_empty json
end

def test_memos_markdown_to_html_preview
post('/api/v1/memos/preview', { md: '' })
json = JSON.parse(last_response.body)

assert_equal json['md'], '<span></span>'
assert_equal '<span></span>', json['md']

post('/api/v1/memos/preview', { md: '# Labradorite' })
json = JSON.parse(last_response.body)

assert_equal json['md'], "<h1>Labradorite</h1>\n"
assert_equal "<h1>Labradorite</h1>\n", json['md']
end

# rubocop:disable Layout/LineLength
def test_memos_update_memo
post('/api/v1/memos/2021/08/21/hgfe-dcba/update', { 'title' => 'Facts about Pugsies!',
'tags' => 'dog,pug,pet',
'content' =>
"The Pug is a breed of dog originally from China, with physically distinctive features of a wrinkly, short-muzzled face and curled tail. The breed has a fine, glossy coat that comes in a variety of colors, most often light brown (fawn) or black, and a compact, square body with well developed and thick muscles all over the body.\r\n\r\n![](/memos/2021/08/21/hgfe-dcba/665507228-pug.jpg)\r\n\r\n## Second\r\n\r\nSecond paragraph with a link to a [GitHub](http://localhost:9292/memos/2022/09/26/abcd-efgh/edit) repository.\r\n\r\n### Thirds\r\n\r\nhere are some links to help you\r\n\r\nhttp://localhost:9292/memos/2022/09/25/abcd-efgh/edit\r\n\r\nhttp://localhost:9292/memos/2022/09/24/abcd-efgh/edit\r\n" })

assert_equal last_response.status, 200
assert_equal JSON.parse(last_response.body)['status'], 'success'
post('/api/v1/memos/2021/08/21/hgfe-dcba/update', {
'title' => 'Facts about Pugsies!',
'tags' => 'dog,pug,pet',
'content' => "The Pug is a breed of dog originally from China, with physically distinctive features of a wrinkly, short-muzzled face and curled tail. The breed has a fine, glossy coat that comes in a variety of colors, most often light brown (fawn) or black, and a compact, square body with well developed and thick muscles all over the body.\r\n\r\n![](/memos/2021/08/21/hgfe-dcba/665507228-pug.jpg)\r\n\r\n## Second\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nSecond paragraph with a link to a [GitHub](http://localhost:9292/memos/2022/09/26/abcd-efgh/edit) repository.\r\n\r\n### Thirds\r\n\r\nhere are some links to help you\r\n\r\nhttp://localhost:9292/memos/2022/09/25/abcd-efgh/edit\r\n\r\nhttp://localhost:9292/memos/2022/09/24/abcd-efgh/edit\r\n"
})

assert_equal 200, last_response.status
assert_equal 'success', JSON.parse(last_response.body)['status']
end
# rubocop:enable Layout/LineLength
end
17 changes: 11 additions & 6 deletions test/endpoints_get_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@ def after_teardown

def test_index_redirect
get '/'
assert_equal last_response.status, 302

assert_equal 302, last_response.status
end

def test_memos_index
get '/memos'
assert_equal last_response.status, 200

assert_equal 200, last_response.status
end

def test_memos_show
get '/memos/2021/08/21/hgfe-dcba'
assert_equal last_response.status, 200

assert_equal 200, last_response.status
end

def test_memos_edit
get '/memos/2021/08/21/hgfe-dcba/edit'
assert_equal last_response.status, 200

assert_equal 200, last_response.status
end

def test_memos_delete_or_destroy
get '/memos/2021/08/21/hgfe-dcba/destroy'
assert_equal last_response.status, 302
assert_equal Dir.glob('memos/**/*/').size, 6

assert_equal 302, last_response.status
assert_equal 6, Dir.glob('memos/**/*/').size
end
end
62 changes: 31 additions & 31 deletions test/meta_data_serializer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ def after_teardown
end

def test_meta_struct
assert(@yaml_data_as_struct.public_methods.include?(:id))
assert(@yaml_data_as_struct.public_methods.include?(:title))
assert(@yaml_data_as_struct.public_methods.include?(:tags))
assert(@yaml_data_as_struct.public_methods.include?(:urls))
assert(@yaml_data_as_struct.public_methods.include?(:updated_at))
assert(@yaml_data_as_struct.is_a?(FileOperations::MetaStruct))
assert_equal(@yaml_data_as_struct.id, '2021/08/21/hgfe-dcba')
assert_equal(@yaml_data_as_struct.title, 'Facts about Pugs!')
assert_equal(@yaml_data_as_struct.tags, 'dog,pug,pet')
assert(@yaml_data_as_struct.urls.is_a?(Array))
assert_equal(@yaml_data_as_struct.urls.first, 'http://localhost:9292/memos/2022/09/26/abcd-efgh/edit')
assert(@yaml_data_as_struct.updated_at.is_a?(DateTime))
assert_includes(@yaml_data_as_struct.public_methods, :id)
assert_includes(@yaml_data_as_struct.public_methods, :title)
assert_includes(@yaml_data_as_struct.public_methods, :tags)
assert_includes(@yaml_data_as_struct.public_methods, :urls)
assert_includes(@yaml_data_as_struct.public_methods, :updated_at)
assert_kind_of(FileOperations::MetaStruct, @yaml_data_as_struct)
assert_equal('2021/08/21/hgfe-dcba', @yaml_data_as_struct.id)
assert_equal('Facts about Pugs!', @yaml_data_as_struct.title)
assert_equal('dog,pug,pet', @yaml_data_as_struct.tags)
assert_kind_of(Array, @yaml_data_as_struct.urls)
assert_equal('http://localhost:9292/memos/2022/09/26/abcd-efgh/edit', @yaml_data_as_struct.urls.first)
assert_kind_of(DateTime, @yaml_data_as_struct.updated_at)
end

def test_yaml_serialiazation_from_string
assert(@yaml_data_from_string.is_a?(Hash))
assert_kind_of(Hash, @yaml_data_from_string)
assert(@yaml_data_from_string['id'], '2021/08/21/hgfe-dcba')
assert_equal(@yaml_data_from_string['title'], 'Facts about Pugs!')
assert_equal(@yaml_data_from_string['tags'], 'dog,pug,pet')
assert(@yaml_data_from_string['urls'].is_a?(Array))
assert_equal(@yaml_data_from_string['urls'].first, 'http://localhost:9292/memos/2022/09/26/abcd-efgh/edit')
assert(@yaml_data_from_string['updated_at'].is_a?(DateTime))
assert_equal(@yaml_data_from_string['updated_at'].year, 2021)
assert_equal(@yaml_data_from_string['updated_at'].month, 8)
assert_equal(@yaml_data_from_string['updated_at'].day, 21)
assert_equal('Facts about Pugs!', @yaml_data_from_string['title'])
assert_equal('dog,pug,pet', @yaml_data_from_string['tags'])
assert_kind_of(Array, @yaml_data_from_string['urls'])
assert_equal('http://localhost:9292/memos/2022/09/26/abcd-efgh/edit', @yaml_data_from_string['urls'].first)
assert_kind_of(DateTime, @yaml_data_from_string['updated_at'])
assert_equal(2021, @yaml_data_from_string['updated_at'].year)
assert_equal(8, @yaml_data_from_string['updated_at'].month)
assert_equal(21, @yaml_data_from_string['updated_at'].day)
end

def test_yaml_serialiazation_from_file
assert(@yaml_data_from_demo_file.is_a?(Hash))
assert_equal(@yaml_data_from_demo_file['id'], '2022/09/26/abcd-efgh')
assert_equal(@yaml_data_from_demo_file['title'], 'All about Pugs!!!')
assert_equal(@yaml_data_from_demo_file['tags'], 'dog,pug,pet')
assert(@yaml_data_from_demo_file['urls'].is_a?(Array))
assert(@yaml_data_from_demo_file['urls'].empty?)
assert(@yaml_data_from_demo_file['updated_at'].is_a?(DateTime))
assert_equal(@yaml_data_from_demo_file['updated_at'].year, 2022)
assert_equal(@yaml_data_from_demo_file['updated_at'].month, 9)
assert_equal(@yaml_data_from_demo_file['updated_at'].day, 29)
assert_kind_of(Hash, @yaml_data_from_demo_file)
assert_equal('2022/09/26/abcd-efgh', @yaml_data_from_demo_file['id'])
assert_equal('All about Pugs!!!', @yaml_data_from_demo_file['title'])
assert_equal('dog,pug,pet', @yaml_data_from_demo_file['tags'])
assert_kind_of(Array, @yaml_data_from_demo_file['urls'])
assert_empty(@yaml_data_from_demo_file['urls'])
assert_kind_of(DateTime, @yaml_data_from_demo_file['updated_at'])
assert_equal(2022, @yaml_data_from_demo_file['updated_at'].year)
assert_equal(9, @yaml_data_from_demo_file['updated_at'].month)
assert_equal(29, @yaml_data_from_demo_file['updated_at'].day)
end
end
2 changes: 1 addition & 1 deletion test/simple_uid_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def setup
end

def test_uid_pattern
assert @simple_uid.match?(/^\w{4}-\w{4}$/)
assert_match(/^\w{4}-\w{4}$/, @simple_uid)
end
end

0 comments on commit 0639709

Please sign in to comment.