# encoding: utf-8
#--
# Copyright (C) 2012 Gitorious AS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#++
require "test_helper"
require "libdolt/view/single_repository"
require "libdolt/view/multi_repository"
require "libdolt/view/blob"
describe Dolt::View::Blob do
include Dolt::View::Blob
describe "single repo mode" do
include Dolt::View::SingleRepository
it "returns blame url" do
url = blame_url("myrepo", "master", "some/path")
assert_equal "/blame/master:some/path", url
end
it "returns history url" do
url = history_url("myrepo", "master", "some/path")
assert_equal "/history/master:some/path", url
end
it "returns raw url" do
url = raw_url("myrepo", "master", "some/path")
assert_equal "/raw/master:some/path", url
end
end
describe "multi repo mode" do
include Dolt::View::MultiRepository
it "returns blame url" do
url = blame_url("myrepo", "master", "some/path")
assert_equal "/myrepo/blame/master:some/path", url
end
it "returns history url" do
url = history_url("myrepo", "master", "some/path")
assert_equal "/myrepo/history/master:some/path", url
end
it "returns raw url" do
url = raw_url("myrepo", "master", "some/path")
assert_equal "/myrepo/raw/master:some/path", url
end
end
describe "#multiline" do
it "adds line number markup to code" do
html = multiline("A few\nLines\n Here")
assert_match "
A few", html
assert_match "
Lines", html
assert_match " Here", html
end
it "adds custom class name" do
html = multiline("A few\nLines\n Here", :class_names => ["ruby"])
assert_match "prettyprint", html
assert_match "linenums", html
assert_match "ruby", html
end
end
describe "#format_text_blob" do
it "escapes brackets" do
html = format_text_blob("file.txt", "")
assert_match /<hey>/, html
end
end
describe "#format_binary_blob" do
include Dolt::View::SingleRepository
it "renders link to binary blob" do
content = "GIF89aK\000 \000\367\000\000\266\270\274\335\336\337\214"
html = format_binary_blob("some/file.gif", content, "gitorious", "master")
assert_match /")
assert_match /<hey>/, html
end
end
end