Add history view test
This commit is contained in:
@@ -33,9 +33,9 @@ module Precious
|
|||||||
(r & 2147483648) == 0 ? r : r - 4294967296
|
(r & 2147483648) == 0 ? r : r - 4294967296
|
||||||
end
|
end
|
||||||
|
|
||||||
def _identicon_code(blob)
|
def string_to_code string
|
||||||
# sha bytes
|
# sha bytes
|
||||||
b = [Digest::SHA1.hexdigest(blob + @request.host)[0,20]].pack('H*').bytes.to_a
|
b = [Digest::SHA1.hexdigest(string)[0,20]].pack('H*').bytes.to_a
|
||||||
# Thanks donpark's IdenticonUtil.java for this.
|
# Thanks donpark's IdenticonUtil.java for this.
|
||||||
# Match the following Java code
|
# Match the following Java code
|
||||||
# ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) |
|
# ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) |
|
||||||
@@ -47,6 +47,10 @@ module Precious
|
|||||||
b[3] & 0xFF
|
b[3] & 0xFF
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _identicon_code(blob)
|
||||||
|
string_to_code blob + @request.host
|
||||||
|
end
|
||||||
|
|
||||||
def use_identicon
|
def use_identicon
|
||||||
@page.wiki.user_icons == 'identicon'
|
@page.wiki.user_icons == 'identicon'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# ~*~ encoding: utf-8 ~*~
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
require File.expand_path '../../lib/gollum/frontend/views/history', __FILE__
|
||||||
|
|
||||||
|
context "Precious::Views::History" do
|
||||||
|
setup do
|
||||||
|
@history = Precious::Views::History.new
|
||||||
|
end
|
||||||
|
|
||||||
|
test "string_to_code" do
|
||||||
|
# Result must match the following Java code.
|
||||||
|
=begin
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
final String s = "code@example.com";
|
||||||
|
final byte[] b = MessageDigest.getInstance("SHA1").digest(s.toString().getBytes("UTF-8"));
|
||||||
|
final int c = ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16)
|
||||||
|
| ((b[2] & 0xFF) << 8) | (b[3] & 0xFF);
|
||||||
|
// 143327882
|
||||||
|
System.out.println(c);
|
||||||
|
}
|
||||||
|
=end
|
||||||
|
actual = @history.string_to_code 'code@example.com'
|
||||||
|
assert_equal 143327882, actual
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user