Add option to show browser's local time (#1653)

* Add tests for --local-time option
* Update Readme
This commit is contained in:
Nikita Ivanov
2022-01-13 22:19:22 +05:00
committed by GitHub
parent f30058f4ee
commit 6f870501a0
19 changed files with 285 additions and 38 deletions
+6 -6
View File
@@ -121,7 +121,7 @@ EOF
post "/gollum/edit/A", :content => 'def', :page => 'A',
:format => page.format, :message => 'def', :etag => old_sha
assert_equal last_response.status, 412
assert_equal last_response.status, 412
end
test "edit page with empty message" do
@@ -328,9 +328,9 @@ EOF
page='_Template'
post '/gollum/create', :content => 'fake template with some Utf-8: Ü', :page => page,
:path => '/', :format => 'markdown', :message => ''
follow_redirect!
follow_redirect!
assert last_response.ok?
@wiki.clear_cache
@wiki.clear_cache
get "/gollum/create/TT"
assert last_response.ok?
post '/gollum/delete/_Template'
@@ -338,7 +338,7 @@ EOF
end
test "create with template succeed if template doesn't exist" do
Precious::App.set(:wiki_options, { :template_page => true })
Precious::App.set(:wiki_options, { :template_page => true })
get "/gollum/create/TT"
assert last_response.ok?
Precious::App.set(:wiki_options, { :template_page => false })
@@ -824,7 +824,7 @@ context "Frontend with lotr" do
assert last_response.ok?
assert_equal last_response.body.include?('delete-link'), false
assert_equal last_response.body.include?('page-info-toggle'), false
assert last_response.body.include?('This version of the page was edited by <b>Tom Preston-Werner</b> at 2010-04-07')
assert_match %r{This version of the page was edited by <b>Tom Preston-Werner</b> at <time datetime="2010-04-07T19:49:43Z" data-format="%Y-%m-%d %H:%M:%S">\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}</time>.}, last_response.body
assert last_response.body.include?("<a href=\"/Bilbo-Baggins.md\">View the most recent version.</a></p>")
end
@@ -995,5 +995,5 @@ context 'Frontend with base path' do
def app
Precious::MapGollum.new(@base_path)
end
end
end
+66
View File
@@ -0,0 +1,66 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
require 'nokogiri'
require 'json'
require 'time'
def local_time
Precious::App.set(:wiki_options, { show_local_time: true})
end
def no_local_time
Precious::App.set(:wiki_options, { show_local_time: false})
end
def assert_time_tags(body)
tags = Nokogiri::HTML(body).css('time')
assert_equal tags.empty?, false
tags.each do |tag|
assert Time.parse(tag[:datetime]).utc?
end
end
context ":show_local_time option" do
include Rack::Test::Methods
setup do
@path = cloned_testpath('examples/lotr.git')
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
local_time()
end
teardown do
FileUtils.rm_rf(@path)
end
test "last_commit_info no local time" do
no_local_time()
get '/gollum/last_commit_info', {path: 'Home.textile'}
assert_equal Time.parse(JSON.parse(last_response.body)['date']).utc?, false
end
test "last_commit_info local time" do
local_time()
get '/gollum/last_commit_info', {path: 'Home.textile'}
assert Time.parse(JSON.parse(last_response.body)['date']).utc?
end
test "datetime attributes in utc" do
get '/Home/b0d108328459e44fff4a76cd19b10ddc34adce4b'
assert_time_tags last_response.body
get '/gollum/latest_changes'
assert_time_tags last_response.body
get '/gollum/history/Home'
assert_time_tags last_response.body
get '/gollum/commit/b0d108328459e44fff4a76cd19b10ddc34adce4b'
assert_time_tags last_response.body
end
def app
Precious::App
end
end