libdolt 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +56 -0
  3. data/Rakefile +10 -0
  4. data/Readme.md +99 -0
  5. data/lib/libdolt/async/when.rb +128 -0
  6. data/lib/libdolt/disk_repo_resolver.rb +39 -0
  7. data/lib/libdolt/git/blame.rb +112 -0
  8. data/lib/libdolt/git/commit.rb +73 -0
  9. data/lib/libdolt/git/repository.rb +139 -0
  10. data/lib/libdolt/git/submodule.rb +35 -0
  11. data/lib/libdolt/git/tree.rb +42 -0
  12. data/lib/libdolt/repo_actions.rb +95 -0
  13. data/lib/libdolt/version.rb +21 -0
  14. data/lib/libdolt/view/binary_blob_embedder.rb +41 -0
  15. data/lib/libdolt/view/blame.rb +57 -0
  16. data/lib/libdolt/view/blob.rb +97 -0
  17. data/lib/libdolt/view/breadcrumb.rb +47 -0
  18. data/lib/libdolt/view/commit.rb +27 -0
  19. data/lib/libdolt/view/gravatar.rb +29 -0
  20. data/lib/libdolt/view/markup.rb +44 -0
  21. data/lib/libdolt/view/multi_repository.rb +27 -0
  22. data/lib/libdolt/view/object.rb +44 -0
  23. data/lib/libdolt/view/single_repository.rb +27 -0
  24. data/lib/libdolt/view/smart_blob_renderer.rb +33 -0
  25. data/lib/libdolt/view/syntax_highlight.rb +40 -0
  26. data/lib/libdolt/view/tab_width.rb +30 -0
  27. data/lib/libdolt/view/tree.rb +100 -0
  28. data/lib/libdolt/view.rb +23 -0
  29. data/lib/libdolt.rb +29 -0
  30. data/libdolt.gemspec +35 -0
  31. data/test/libdolt/async/when_test.rb +112 -0
  32. data/test/libdolt/git/blame_test.rb +128 -0
  33. data/test/libdolt/git/commit_test.rb +89 -0
  34. data/test/libdolt/git/repository_test.rb +186 -0
  35. data/test/libdolt/repo_actions_test.rb +236 -0
  36. data/test/libdolt/templates/blame_test.rb +54 -0
  37. data/test/libdolt/templates/blob_test.rb +116 -0
  38. data/test/libdolt/templates/commits_test.rb +59 -0
  39. data/test/libdolt/templates/raw_test.rb +39 -0
  40. data/test/libdolt/templates/refs_test.rb +36 -0
  41. data/test/libdolt/templates/tree_history_test.rb +91 -0
  42. data/test/libdolt/templates/tree_test.rb +63 -0
  43. data/test/libdolt/view/binary_blob_embedder_test.rb +49 -0
  44. data/test/libdolt/view/blame_test.rb +122 -0
  45. data/test/libdolt/view/blob_test.rb +116 -0
  46. data/test/libdolt/view/breadcrumb_test.rb +46 -0
  47. data/test/libdolt/view/commit_test.rb +31 -0
  48. data/test/libdolt/view/gravatar_test.rb +30 -0
  49. data/test/libdolt/view/markup_test.rb +70 -0
  50. data/test/libdolt/view/multi_repository_test.rb +35 -0
  51. data/test/libdolt/view/object_test.rb +83 -0
  52. data/test/libdolt/view/single_repository_test.rb +30 -0
  53. data/test/libdolt/view/smart_blob_renderer_test.rb +38 -0
  54. data/test/libdolt/view/syntax_highlight_test.rb +80 -0
  55. data/test/libdolt/view/tab_width_test.rb +40 -0
  56. data/test/libdolt/view/tree_test.rb +196 -0
  57. data/test/test_helper.rb +50 -0
  58. data/views/500.erb +22 -0
  59. data/views/blame.erb +42 -0
  60. data/views/blob.erb +31 -0
  61. data/views/commits.erb +26 -0
  62. data/views/index.erb +25 -0
  63. data/views/layout.erb +45 -0
  64. data/views/raw.erb +19 -0
  65. data/views/refs.erb +22 -0
  66. data/views/tree.erb +50 -0
  67. data/views/tree_history.erb +19 -0
  68. metadata +326 -0
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view"
20
+ require "json"
21
+
22
+ describe "refs template" do
23
+ include Dolt::ViewTest
24
+
25
+ before do
26
+ @repo = "the-dolt"
27
+ @renderer = prepare_renderer
28
+ end
29
+
30
+ it "renders JSON" do
31
+ data = { "heads" => ["libgit2", "master"], "tags" => ["v2.1.0"] }
32
+ html = @renderer.render(:refs, data)
33
+
34
+ assert_equal data, JSON.parse(html)
35
+ end
36
+ end
@@ -0,0 +1,91 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view"
20
+ require "json"
21
+
22
+ describe "tree_history template" do
23
+ include Dolt::ViewTest
24
+
25
+ before do
26
+ @repo = "the-dolt"
27
+ @renderer = prepare_renderer
28
+ @tree = [{
29
+ :type => :blob,
30
+ :oid => "e90021f89616ddf86855d05337c188408d3b417e",
31
+ :filemode => 33188,
32
+ :name => ".gitmodules",
33
+ :history => [{
34
+ :oid => "906d67b4f3e5de7364ba9b57d174d8998d53ced6",
35
+ :author => { :name => "Christian Johansen",
36
+ :email => "christian@cjohansen.no" },
37
+ :summary => "Working Moron server for viewing blobs",
38
+ :date => Time.parse("Mon Sep 10 15:07:39 +0200 2012"),
39
+ :message => ""
40
+ }]
41
+ }, {
42
+ :type => :blob,
43
+ :oid => "c80ee3697054566d1a4247d80be78ec3ddfde295",
44
+ :filemode => 33188,
45
+ :name => "Gemfile",
46
+ :history => [{
47
+ :oid => "26139a3aba4aac8cbf658c0d0ea58b8983e4090b",
48
+ :author => { :name => "Christian Johansen",
49
+ :email => "christian@cjohansen.no" },
50
+ :summary => "Initial commit",
51
+ :date => Time.parse("Thu Aug 23 11:40:39 +0200 2012"),
52
+ :message => ""
53
+ }]
54
+ }]
55
+
56
+ @tree_array = [{
57
+ "type" => "blob",
58
+ "oid" => "e90021f89616ddf86855d05337c188408d3b417e",
59
+ "filemode" => 33188,
60
+ "name" => ".gitmodules",
61
+ "history" => [{
62
+ "oid" => "906d67b4f3e5de7364ba9b57d174d8998d53ced6",
63
+ "author" => { "name" => "Christian Johansen",
64
+ "email" => "christian@cjohansen.no" },
65
+ "summary" => "Working Moron server for viewing blobs",
66
+ "date" => "2012-09-10T15:07:39+02:00",
67
+ "message" => ""
68
+ }]
69
+ }, {
70
+ "type" => "blob",
71
+ "oid" => "c80ee3697054566d1a4247d80be78ec3ddfde295",
72
+ "filemode" => 33188,
73
+ "name" => "Gemfile",
74
+ "history" => [{
75
+ "oid" => "26139a3aba4aac8cbf658c0d0ea58b8983e4090b",
76
+ "author" => { "name" => "Christian Johansen",
77
+ "email" => "christian@cjohansen.no" },
78
+ "summary" => "Initial commit",
79
+ "date" => "2012-08-23T11:40:39+02:00",
80
+ "message" => ""
81
+ }]
82
+ }]
83
+ end
84
+
85
+ it "renders JSON" do
86
+ data = { "tree" => @tree, "repository" => @repo, "ref" => "master", "path" => "" }
87
+ json = @renderer.render(:tree_history, data)
88
+
89
+ assert_equal @tree_array, JSON.parse(json)
90
+ end
91
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view"
20
+
21
+ class Tree
22
+ attr_reader :entries
23
+ def initialize(entries); @entries = entries; end
24
+ end
25
+
26
+ describe "tree template" do
27
+ include Dolt::ViewTest
28
+
29
+ before do
30
+ @repo = "the-dolt"
31
+ end
32
+
33
+ def render(path, tree, options = {})
34
+ renderer = prepare_renderer(options)
35
+ renderer.render(:tree, {
36
+ :tree => tree,
37
+ :repository => @repo,
38
+ :ref => options[:ref] || "master",
39
+ :path => path
40
+ })
41
+ end
42
+
43
+ it "renders empty tree" do
44
+ tree = Tree.new([])
45
+ markup = render("app/models", tree)
46
+
47
+ assert_match /<table class="table table-striped gts-tree-explorer"/, markup
48
+ assert_match /data-gts-tree-history="/, markup
49
+ end
50
+
51
+ it "renders context for non-empty tree" do
52
+ tree = Tree.new([
53
+ { :type => :tree, :name => "lib" },
54
+ { :type => :submodule, :name => "ui", :url => "git://git.git" },
55
+ { :type => :blob, :name => "file.txt" }
56
+ ])
57
+
58
+ markup = render("app/models", tree)
59
+
60
+ assert_match /icon-folder-open/, markup
61
+ assert_match /tree\/master:app"/, markup
62
+ end
63
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/single_repository"
20
+ require "libdolt/view/blob"
21
+ require "libdolt/view/binary_blob_embedder"
22
+
23
+ describe Dolt::View::BinaryBlobEmbedder do
24
+ include Dolt::View::Blob
25
+ include Dolt::View::BinaryBlobEmbedder
26
+ include Dolt::View::SingleRepository
27
+
28
+ it "renders image tag to view gif" do
29
+ html = format_binary_blob("file.gif", "...", "gitorious", "master")
30
+
31
+ assert_match /<img/, html
32
+ assert_match /src="\/raw\/master:file.gif"/, html
33
+ end
34
+
35
+ it "renders image tag to view png" do
36
+ html = format_binary_blob("file.png", "...", "gitorious", "master")
37
+ assert_match /src="\/raw\/master:file.png"/, html
38
+ end
39
+
40
+ it "renders image tag to view jpg" do
41
+ html = format_binary_blob("file.jpg", "...", "gitorious", "master")
42
+ assert_match /src="\/raw\/master:file.jpg"/, html
43
+ end
44
+
45
+ it "renders image tag to view jpeg" do
46
+ html = format_binary_blob("file.jpeg", "...", "gitorious", "master")
47
+ assert_match /src="\/raw\/master:file.jpeg"/, html
48
+ end
49
+ end
@@ -0,0 +1,122 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/blame"
20
+ require "ostruct"
21
+
22
+ describe Dolt::View::Blame do
23
+ include Dolt::Html
24
+ include Dolt::View::Blame
25
+
26
+ before do
27
+ chunks = [{ :oid => "0000001", :lines => ["1", "2", "3"] },
28
+ { :oid => "0000002", :lines => ["4", "5"] }]
29
+ @blame = OpenStruct.new({ :chunks => chunks })
30
+ end
31
+
32
+ describe "#blame_annotations" do
33
+ it "returns array of same length as total number of lines" do
34
+ annotations = blame_annotations(@blame)
35
+
36
+ assert_equal 5, annotations.length
37
+ end
38
+
39
+ it "stores annotation for first occurrence" do
40
+ annotations = blame_annotations(@blame)
41
+
42
+ assert_equal "0000001", annotations.first[:oid]
43
+ end
44
+
45
+ it "stores nil for consecutive entries in same chunk" do
46
+ annotations = blame_annotations(@blame)
47
+
48
+ assert_nil annotations[1]
49
+ assert_nil annotations[2]
50
+ refute_nil annotations[3]
51
+ assert_nil annotations[4]
52
+ end
53
+ end
54
+
55
+ describe "#blame_lines" do
56
+ it "returns array of lines" do
57
+ assert_equal 5, blame_lines("file.rb", @blame).length
58
+ end
59
+
60
+ it "does not modify lines" do
61
+ assert_equal "1", blame_lines("file.rb", @blame).first
62
+ end
63
+ end
64
+
65
+ describe "#blame_lines with #highlight" do
66
+ def highlight(path, code)
67
+ "{" + code.split("\n").map { |l| "#{path}:#{l}" }.join("\n") + "}"
68
+ end
69
+
70
+ it "highlights code before splitting" do
71
+ lines = blame_lines("file.rb", @blame)
72
+
73
+ assert_equal "{file.rb:1", lines.first
74
+ assert_equal "file.rb:2", lines[1]
75
+ assert_equal "file.rb:5}", lines.last
76
+ end
77
+ end
78
+
79
+ describe "#blame_annotation_cell" do
80
+ before do
81
+ @oid = "1234567890" * 4
82
+
83
+ @committer = {
84
+ :name => "Christian Johansen",
85
+ :time => Time.utc(2012, 1, 1, 12)
86
+ }
87
+ end
88
+
89
+ it "returns table cell with annotated class" do
90
+ html = blame_annotation_cell({ :committer => @committer, :oid => @oid })
91
+
92
+ assert_match /gts-blame-annotation/, html
93
+ assert_match /gts-annotated/, html
94
+ assert_match /Christian Johansen/, html
95
+ end
96
+
97
+ it "includes the commit oid" do
98
+ html = blame_annotation_cell({ :committer => @committer, :oid => @oid })
99
+
100
+ assert_match /gts-sha/, html
101
+ assert_match /1234567/, html
102
+ refute_match /890/, html
103
+ end
104
+
105
+ it "includes the commit date" do
106
+ html = blame_annotation_cell({ :committer => @committer, :oid => @oid })
107
+
108
+ assert_match /2012-01-01/, html
109
+ end
110
+ end
111
+
112
+ describe "#blame_code_cell" do
113
+ it "returns table cell with code element" do
114
+ html = blame_code_cell("var a = 42;")
115
+
116
+ assert_equal 1, select(html, "td").length
117
+ assert_match /gts-code/, html
118
+ assert_equal 1, select(html, "code").length
119
+ assert_match /a = 42/, html
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/single_repository"
20
+ require "libdolt/view/multi_repository"
21
+ require "libdolt/view/blob"
22
+
23
+ describe Dolt::View::Blob do
24
+ include Dolt::View::Blob
25
+
26
+ describe "single repo mode" do
27
+ include Dolt::View::SingleRepository
28
+
29
+ it "returns blame url" do
30
+ url = blame_url("myrepo", "master", "some/path")
31
+ assert_equal "/blame/master:some/path", url
32
+ end
33
+
34
+ it "returns history url" do
35
+ url = history_url("myrepo", "master", "some/path")
36
+ assert_equal "/history/master:some/path", url
37
+ end
38
+
39
+ it "returns raw url" do
40
+ url = raw_url("myrepo", "master", "some/path")
41
+ assert_equal "/raw/master:some/path", url
42
+ end
43
+ end
44
+
45
+ describe "multi repo mode" do
46
+ include Dolt::View::MultiRepository
47
+
48
+ it "returns blame url" do
49
+ url = blame_url("myrepo", "master", "some/path")
50
+ assert_equal "/myrepo/blame/master:some/path", url
51
+ end
52
+
53
+ it "returns history url" do
54
+ url = history_url("myrepo", "master", "some/path")
55
+ assert_equal "/myrepo/history/master:some/path", url
56
+ end
57
+
58
+ it "returns raw url" do
59
+ url = raw_url("myrepo", "master", "some/path")
60
+ assert_equal "/myrepo/raw/master:some/path", url
61
+ end
62
+ end
63
+
64
+ describe "#multiline" do
65
+ it "adds line number markup to code" do
66
+ html = multiline("A few\nLines\n Here")
67
+
68
+ assert_match "<pre", html
69
+ assert_match "<ol class=\"linenums", html
70
+ assert_match "<li class=\"L1\"><span class=\"line\">A few</span></li>", html
71
+ assert_match "<li class=\"L2\"><span class=\"line\">Lines</span></li>", html
72
+ assert_match "<li class=\"L3\"><span class=\"line\"> Here</span></li>", html
73
+ end
74
+
75
+ it "adds custom class name" do
76
+ html = multiline("A few\nLines\n Here", :class_names => ["ruby"])
77
+
78
+ assert_match "prettyprint", html
79
+ assert_match "linenums", html
80
+ assert_match "ruby", html
81
+ end
82
+ end
83
+
84
+ describe "#format_text_blob" do
85
+ it "escapes brackets" do
86
+ html = format_text_blob("file.txt", "<hey>")
87
+ assert_match /&lt;hey&gt;/, html
88
+ end
89
+ end
90
+
91
+ describe "#format_binary_blob" do
92
+ include Dolt::View::SingleRepository
93
+
94
+ it "renders link to binary blob" do
95
+ content = "GIF89aK\000 \000\367\000\000\266\270\274\335\336\337\214"
96
+ html = format_binary_blob("some/file.gif", content, "gitorious", "master")
97
+ assert_match /<a href="\/raw\/master:some\/file.gif"/, html
98
+ assert_match "Download file.gif", html
99
+ end
100
+ end
101
+
102
+ describe "#format_blob" do
103
+ include Dolt::View::SingleRepository
104
+
105
+ it "renders link to binary blob" do
106
+ content = "GIF89aK\000 \000\367\000\000\266\270\274\335\336\337\214"
107
+ html = format_blob("file.gif", content, "gitorious", "master")
108
+ assert_match "Download file.gif", html
109
+ end
110
+
111
+ it "renders text blob" do
112
+ html = format_blob("file.txt", "<hey>")
113
+ assert_match /&lt;hey&gt;/, html
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/breadcrumb"
20
+
21
+ describe Dolt::View::Breadcrumb do
22
+ include Dolt::Html
23
+ include Dolt::View::SingleRepository
24
+ include Dolt::View::Breadcrumb
25
+
26
+ it "renders li element for root" do
27
+ html = breadcrumb("myrepo", "master", "path.txt")
28
+
29
+ assert_equal 1, select(html, "a").length
30
+ assert_match /icon-file/, select(html, "li").first
31
+ end
32
+
33
+ it "renders li element for file" do
34
+ html = breadcrumb("myrepo", "master", "path.txt")
35
+
36
+ assert_match /path.txt/, select(html, "li").last
37
+ end
38
+
39
+ it "renders links to accumulated paths" do
40
+ html = breadcrumb("myrepo", "master", "some/nested/path.txt")
41
+
42
+ links = select(html, "a")
43
+ assert_match /\"\/tree\/master:some"/, links[1]
44
+ assert_match /\"\/tree\/master:some\/nested"/, links[2]
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/commit"
20
+
21
+ describe Dolt::View::Commit do
22
+ include Dolt::Html
23
+ include Dolt::View::Commit
24
+
25
+ describe "#commit_oid" do
26
+ it "returns the first seven characters" do
27
+ oid = "38b06b3f65a9c84ac860bf0ce0a69e43a23bc765"
28
+ assert_equal "38b06b3", commit_oid(oid)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/gravatar"
20
+
21
+ describe Dolt::View::Gravatar do
22
+ include Dolt::View::Gravatar
23
+
24
+ describe "#gravatar" do
25
+ it "returns gravatar URL" do
26
+ url = gravatar("christian@gitorious.com")
27
+ assert_equal "http://www.gravatar.com/avatar/38b06b3f65a9c84ac860bf0ce0a69e43", url
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ #--
3
+ # Copyright (C) 2012 Gitorious AS
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Affero General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Affero General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Affero General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #++
18
+ require "test_helper"
19
+ require "libdolt/view/markup"
20
+ require "libdolt/view/syntax_highlight"
21
+
22
+ module StubHighlighter
23
+ def highlight(path, code, opt = {})
24
+ return "##[#{opt[:lexer]}]#{code}##"
25
+ end
26
+ end
27
+
28
+ describe Dolt::View::Markup do
29
+ include Dolt::View::Markup
30
+
31
+ describe "#render_markup" do
32
+ include Dolt::View::SyntaxHighlight
33
+
34
+ it "wraps markup in .gts-markup" do
35
+ html = render_markup("file.md", "# Hey")
36
+ assert_match "<div class=\"gts-markup\">", html
37
+ end
38
+
39
+ it "renders multi-line code blocks with syntax highlighting" do
40
+ html = render_markup("file.md", <<-MD)
41
+ ```cl
42
+ (s-trim-left "trim ") ;; => "trim "
43
+ (s-trim-left " this") ;; => "this"
44
+ ```
45
+ MD
46
+
47
+ assert_match "<pre class=\"common-lisp prettyprint\">", html
48
+ end
49
+
50
+ it "highlights multiple separate multi-line code blocks" do
51
+ html = render_markup("file.md", <<-MD)
52
+ # # This stuff
53
+
54
+ ```cl
55
+ (s-trim-left "trim ") ;; => "trim "
56
+ (s-trim-left " this") ;; => "this"
57
+ ```
58
+
59
+ # And this stuff
60
+
61
+ ```cl
62
+ (s-trim-left "trim ") ;; => "trim "
63
+ (s-trim-left " this") ;; => "this"
64
+ ```
65
+ MD
66
+
67
+ assert_equal 2, html.scan(/common-lisp/).length
68
+ end
69
+ end
70
+ end