libdolt 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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,186 @@
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/git/repository"
20
+ require "time"
21
+
22
+ describe Dolt::Git::Repository do
23
+ include EM::MiniTest::Spec
24
+ before { @repository = Dolt::Git::Repository.new(".") }
25
+
26
+ describe "#submodules" do
27
+ it "returns deferrable" do
28
+ deferrable = @repository.submodules("master")
29
+ assert deferrable.respond_to?(:callback)
30
+ assert deferrable.respond_to?(:errback)
31
+ end
32
+
33
+ it "yields list of submodules" do
34
+ @repository.submodules("c1f6cd9").callback do |submodules|
35
+ url = "git://gitorious.org/gitorious/ui3.git"
36
+ assert_equal [{ :path => "vendor/ui", :url => url }], submodules
37
+ done!
38
+ end
39
+ wait!
40
+ end
41
+
42
+ it "resolves with empty array if no submodules" do
43
+ @repository.submodules("26139a3").callback do |submodules|
44
+ assert_equal [], submodules
45
+ done!
46
+ end
47
+ wait!
48
+ end
49
+ end
50
+
51
+ describe "#tree" do
52
+ it "includes submodule data for trees" do
53
+ @repository.tree("3dc532f", "vendor").callback do |tree|
54
+ assert_equal({
55
+ :type => :submodule,
56
+ :filemode => 57344,
57
+ :name => "ui",
58
+ :oid => "d167e3e1c17a27e4cf459dd380670801b0659659",
59
+ :url => "git://gitorious.org/gitorious/ui3.git"
60
+ }, tree.entries.first)
61
+ done!
62
+ end
63
+ wait!
64
+ end
65
+ end
66
+
67
+ describe "#blame" do
68
+ it "returns deferrable" do
69
+ deferrable = @repository.blame("master", "Gemfile")
70
+ assert deferrable.respond_to?(:callback)
71
+ assert deferrable.respond_to?(:errback)
72
+ end
73
+
74
+ it "yields blame" do
75
+ @repository.blame("master", "Gemfile").callback do |blame|
76
+ assert Dolt::Git::Blame === blame
77
+ done!
78
+ end
79
+ wait!
80
+ end
81
+ end
82
+
83
+ describe "#log" do
84
+ it "returns deferrable" do
85
+ deferrable = @repository.log("master", "Gemfile", 1)
86
+ assert deferrable.respond_to?(:callback)
87
+ assert deferrable.respond_to?(:errback)
88
+ end
89
+
90
+ it "yields commits" do
91
+ @repository.log("master", "dolt.gemspec", 2).callback do |log|
92
+ assert_equal 2, log.length
93
+ assert Hash === log[0]
94
+ done!
95
+ end
96
+ wait!
97
+ end
98
+ end
99
+
100
+ describe "#tree_history" do
101
+ it "returns deferrable" do
102
+ deferrable = @repository.tree_history("master", "")
103
+ assert deferrable.respond_to?(:callback)
104
+ assert deferrable.respond_to?(:errback)
105
+ end
106
+
107
+ it "fails if path is not a tree" do
108
+ deferrable = @repository.tree_history("master", "Gemfile")
109
+ deferrable.errback do |err|
110
+ assert_match /not a tree/, err.message
111
+ done!
112
+ end
113
+ wait!
114
+ end
115
+
116
+ it "fails if path does not exist in ref" do
117
+ deferrable = @repository.tree_history("26139a3", "test")
118
+ deferrable.errback do |err|
119
+ assert_match /does not exist/, err.message
120
+ done!
121
+ end
122
+ wait!
123
+ end
124
+
125
+ it "yields tree with history" do
126
+ promise = @repository.tree_history("48ffbf7", "")
127
+
128
+ promise.callback do |log|
129
+ assert_equal 11, log.length
130
+ expected = {
131
+ :type => :blob,
132
+ :oid => "e90021f89616ddf86855d05337c188408d3b417e",
133
+ :filemode => 33188,
134
+ :name => ".gitmodules",
135
+ :history => [{
136
+ :oid => "906d67b4f3e5de7364ba9b57d174d8998d53ced6",
137
+ :author => { :name => "Christian Johansen",
138
+ :email => "christian@cjohansen.no" },
139
+ :summary => "Working Moron server for viewing blobs",
140
+ :date => Time.parse("Mon Sep 10 15:07:39 +0200 2012"),
141
+ :message => ""
142
+ }]
143
+ }
144
+
145
+ assert_equal expected, log[0]
146
+ done!
147
+ end
148
+
149
+ promise.errback do |err|
150
+ puts "FAILED! #{err.inspect}"
151
+ end
152
+
153
+ wait!
154
+ end
155
+
156
+ it "yields nested tree with history" do
157
+ promise = @repository.tree_history("48ffbf7", "lib")
158
+
159
+ promise.callback do |log|
160
+ expected = [{
161
+ :type => :tree,
162
+ :oid => "58f84405b588699b24c619aa4cd83669c5623f88",
163
+ :filemode => 16384,
164
+ :name => "dolt",
165
+ :history => [{
166
+ :oid => "8ab4f8c42511f727244a02aeee04824891610bbd",
167
+ :author => { :name => "Christian Johansen",
168
+ :email => "christian@gitorious.com" },
169
+ :summary => "New version",
170
+ :date => Time.parse("Mon Oct 1 16:34:00 +0200 2012"),
171
+ :message => ""
172
+ }]
173
+ }]
174
+
175
+ assert_equal expected, log
176
+ done!
177
+ end
178
+
179
+ promise.errback do |err|
180
+ puts "FAILED! #{err.inspect}"
181
+ end
182
+
183
+ wait!
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,236 @@
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/repo_actions"
20
+ require "libdolt/async/when"
21
+ require "ostruct"
22
+
23
+ class Repository
24
+ attr_reader :name
25
+ def initialize(name); @name = name; end
26
+ def tree(ref, path); stub; end
27
+ def rev_parse(rev); stub; end
28
+ def blame(ref, path); stub; end
29
+ def log(ref, path, limit); stub; end
30
+ def refs; stub; end
31
+ def tree_history(ref, path, count); stub; end
32
+
33
+ def resolve_promise(blob)
34
+ @deferred.resolve(blob)
35
+ end
36
+
37
+ private
38
+ def stub
39
+ @deferred = When::Deferred.new
40
+ @deferred.promise
41
+ end
42
+ end
43
+
44
+ class Resolver
45
+ attr_reader :resolved
46
+ def initialize; @resolved = []; end
47
+
48
+ def resolve(repo)
49
+ repository = Repository.new(repo)
50
+ @resolved << repository
51
+ repository
52
+ end
53
+ end
54
+
55
+ describe Dolt::RepoActions do
56
+ before do
57
+ @resolver = Resolver.new
58
+ @actions = Dolt::RepoActions.new(@resolver)
59
+ end
60
+
61
+ describe "#blob" do
62
+ it "resolves repository" do
63
+ @actions.blob("gitorious", "master", "app")
64
+
65
+ assert_equal ["gitorious"], @resolver.resolved.map(&:name)
66
+ end
67
+
68
+ it "yields path, blob, repo, ref and base_tree_url to block" do
69
+ data = nil
70
+ @actions.blob("gitorious", "babd120", "app") do |err, d|
71
+ data = d
72
+ end
73
+
74
+ @resolver.resolved.last.resolve_promise("Blob")
75
+
76
+ assert_equal({
77
+ :blob => "Blob",
78
+ :repository => "gitorious",
79
+ :ref => "babd120",
80
+ :path => "app"
81
+ }, data)
82
+ end
83
+ end
84
+
85
+ describe "#tree" do
86
+ it "resolves repository" do
87
+ @actions.tree("gitorious", "master", "app")
88
+
89
+ assert_equal ["gitorious"], @resolver.resolved.map(&:name)
90
+ end
91
+
92
+ it "yields tree, repo and ref to block" do
93
+ data = nil
94
+ @actions.tree("gitorious", "babd120", "app") do |err, d|
95
+ data = d
96
+ end
97
+
98
+ repo = @resolver.resolved.last
99
+ repo.resolve_promise "Tree"
100
+
101
+ expected = {
102
+ :tree => "Tree",
103
+ :repository => "gitorious",
104
+ :ref => "babd120",
105
+ :path => "app"
106
+ }
107
+ assert_equal expected, data
108
+ end
109
+ end
110
+
111
+ describe "#blame" do
112
+ it "resolves repository" do
113
+ @actions.blame("gitorious", "master", "app")
114
+
115
+ assert_equal ["gitorious"], @resolver.resolved.map(&:name)
116
+ end
117
+
118
+ it "yields blame, repo and ref to block" do
119
+ data = nil
120
+ @actions.blame("gitorious", "babd120", "app") do |err, d|
121
+ data = d
122
+ end
123
+
124
+ repo = @resolver.resolved.last
125
+ repo.resolve_promise "Blame"
126
+
127
+ expected = {
128
+ :blame => "Blame",
129
+ :repository => "gitorious",
130
+ :ref => "babd120",
131
+ :path => "app"
132
+ }
133
+ assert_equal expected, data
134
+ end
135
+ end
136
+
137
+ describe "#history" do
138
+ it "resolves repository" do
139
+ @actions.history("gitorious", "master", "app", 1)
140
+
141
+ assert_equal ["gitorious"], @resolver.resolved.map(&:name)
142
+ end
143
+
144
+ it "yields commits, repo and ref to block" do
145
+ data = nil
146
+ @actions.history("gitorious", "babd120", "app", 2) do |err, d|
147
+ data = d
148
+ end
149
+
150
+ repo = @resolver.resolved.last
151
+ repo.resolve_promise "History"
152
+
153
+ expected = {
154
+ :commits => "History",
155
+ :repository => "gitorious",
156
+ :ref => "babd120",
157
+ :path => "app"
158
+ }
159
+ assert_equal expected, data
160
+ end
161
+ end
162
+
163
+ describe "#refs" do
164
+ before do
165
+ @refs = ["refs/stash",
166
+ "refs/tags/v0.2.1",
167
+ "refs/tags/v0.2.0",
168
+ "refs/remotes/origin/master",
169
+ "refs/heads/libgit2",
170
+ "refs/heads/master"].map { |n| OpenStruct.new(:name => n) }
171
+ end
172
+
173
+ it "yields repositories, tags and heads" do
174
+ data = nil
175
+ @actions.refs("gitorious") { |err, d| data = d }
176
+
177
+ repo = @resolver.resolved.last
178
+ repo.resolve_promise(@refs)
179
+
180
+ expected = {
181
+ :repository => "gitorious",
182
+ :heads => ["libgit2", "master"],
183
+ :tags => ["v0.2.1", "v0.2.0"]
184
+ }
185
+ assert_equal expected, data
186
+ end
187
+ end
188
+
189
+ describe "#tree_history" do
190
+ before do
191
+ @tree = [{
192
+ :type => :blob,
193
+ :oid => "e90021f89616ddf86855d05337c188408d3b417e",
194
+ :filemode => 33188,
195
+ :name => ".gitmodules",
196
+ :history => [{
197
+ :oid => "906d67b4f3e5de7364ba9b57d174d8998d53ced6",
198
+ :author => { :name => "Christian Johansen",
199
+ :email => "christian@cjohansen.no" },
200
+ :summary => "Working Moron server for viewing blobs",
201
+ :date => Time.parse("Mon Sep 10 15:07:39 +0200 2012"),
202
+ :message => ""
203
+ }]
204
+ }, {
205
+ :type => :blob,
206
+ :oid => "c80ee3697054566d1a4247d80be78ec3ddfde295",
207
+ :filemode => 33188,
208
+ :name => "Gemfile",
209
+ :history => [{
210
+ :oid => "26139a3aba4aac8cbf658c0d0ea58b8983e4090b",
211
+ :author => { :name => "Christian Johansen",
212
+ :email => "christian@cjohansen.no" },
213
+ :summary => "Initial commit",
214
+ :date => Time.parse("Thu Aug 23 11:40:39 +0200 2012"),
215
+ :message => ""
216
+ }]
217
+ }]
218
+ end
219
+
220
+ it "yields repository, path, ref and history" do
221
+ data = nil
222
+ @actions.tree_history("gitorious", "master", "", 1) { |err, d| data = d }
223
+
224
+ repo = @resolver.resolved.last
225
+ repo.resolve_promise(@tree)
226
+
227
+ expected = {
228
+ :repository => "gitorious",
229
+ :ref => "master",
230
+ :path => "",
231
+ :tree => @tree
232
+ }
233
+ assert_equal expected, data
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,54 @@
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 Blame
22
+ attr_reader :chunks
23
+ def initialize(chunks); @chunks = chunks; end
24
+ end
25
+
26
+ describe "blame template" do
27
+ include Dolt::ViewTest
28
+
29
+ before do
30
+ @repo = "the-dolt"
31
+ @committer = {
32
+ :name => "Christian Johansen",
33
+ :mail => "christian@cjohansen.no",
34
+ :time => Time.now
35
+ }
36
+ end
37
+
38
+ def render(path, blame, options = {})
39
+ renderer = prepare_renderer(options)
40
+ renderer.render(:blame, {
41
+ :blame => blame,
42
+ :repository => @repo,
43
+ :ref => options[:ref] || "master",
44
+ :path => path
45
+ })
46
+ end
47
+
48
+ it "renders blame" do
49
+ blob = Blame.new([{ :oid => "0123456", :committer => @committer, :lines => [] }])
50
+ markup = render("app/models/repository.rb", blob)
51
+
52
+ assert_match /<table class="gts-code-listing">/, markup
53
+ end
54
+ 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"
20
+
21
+ class Blob
22
+ attr_reader :content
23
+ def initialize(content); @content = content; end
24
+ end
25
+
26
+ describe "blob template" do
27
+ include Dolt::ViewTest
28
+
29
+ before do
30
+ @repo = "the-dolt"
31
+ end
32
+
33
+ def render(path, blob, options = {}, helpers = nil)
34
+ renderer = prepare_renderer(options, helpers)
35
+ renderer.render(:blob, {
36
+ :blob => blob,
37
+ :repository => @repo,
38
+ :ref => options[:ref] || "master",
39
+ :path => path
40
+ })
41
+ end
42
+
43
+ it "renders blob without errors" do
44
+ markup = render("file.txt", Blob.new("Something something"))
45
+
46
+ assert_match /Something something/, markup
47
+ end
48
+
49
+ it "renders blob with line numbers" do
50
+ markup = render("file.txt", Blob.new("One\nTwo\nThree"))
51
+
52
+ assert_match /<li.*One.*<\/li>/, markup
53
+ assert_match /<li.*Two.*<\/li>/, markup
54
+ assert_match /<li.*Three.*<\/li>/, markup
55
+ end
56
+
57
+ it "renders blob with layout" do
58
+ markup = render("file.txt", Blob.new("Something something"), :layout => "layout")
59
+
60
+ assert_match /Something something/, markup
61
+ end
62
+
63
+ it "renders repo title in page" do
64
+ @repo = "my-magic-repo"
65
+ markup = render("file.txt", Blob.new("Something something"), :layout => "layout")
66
+
67
+ assert_match "my-magic-repo", markup
68
+ end
69
+
70
+ it "renders links to other views" do
71
+ markup = render("file.txt", Blob.new("Something something"))
72
+
73
+ assert_match "/the-dolt/blame/master:file.txt", markup
74
+ assert_match "/the-dolt/history/master:file.txt", markup
75
+ assert_match "/the-dolt/raw/master:file.txt", markup
76
+ end
77
+
78
+ it "renders links to other views for correct ref" do
79
+ markup = render("file.txt", Blob.new("Something something"), :ref => "123bc21")
80
+
81
+ assert_match "/the-dolt/blame/123bc21:file.txt", markup
82
+ assert_match "/the-dolt/history/123bc21:file.txt", markup
83
+ assert_match "/the-dolt/raw/123bc21:file.txt", markup
84
+ end
85
+
86
+ it "renders the path clickable" do
87
+ markup = render("some/deeply/nested/file.txt", Blob.new("Something something"))
88
+
89
+ assert_match 'href="/the-dolt/tree/master:some"', markup
90
+ assert_match 'href="/the-dolt/tree/master:some/deeply"', markup
91
+ assert_match 'href="/the-dolt/tree/master:some/deeply/nested"', markup
92
+ end
93
+
94
+ describe "with smart blob rendering" do
95
+ include Dolt::Html
96
+
97
+ before do
98
+ @helpers = [Dolt::View::SingleRepository,
99
+ Dolt::View::Breadcrumb,
100
+ Dolt::View::Blob,
101
+ Dolt::View::SmartBlobRenderer]
102
+ end
103
+
104
+ it "renders markdown as html" do
105
+ markup = render("file.md", Blob.new("# Cool"), {}, @helpers)
106
+ assert_equal 1, select(markup, "h1").length
107
+ end
108
+
109
+ it "syntax highlights ruby" do
110
+ blob = Blob.new("class Person\n attr_reader :name\nend")
111
+ markup = render("file.rb", blob, {}, @helpers)
112
+
113
+ assert_equal 0, select(markup, "h1").length
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,59 @@
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
+ describe "commits template" do
22
+ include Dolt::ViewTest
23
+
24
+ def commit(num)
25
+ { :oid => num + ("0" * 39),
26
+ :summary => "Commit ##{num}",
27
+ :author => @author,
28
+ :date => Time.now }
29
+ end
30
+
31
+ before do
32
+ @repo = "the-dolt"
33
+ @author = {
34
+ :name => "Christian Johansen",
35
+ :email => "christian@gitorious.com"
36
+ }
37
+ @commit1 = commit("1")
38
+ @commit2 = commit("2")
39
+ @commit3 = commit("3")
40
+ end
41
+
42
+ def render(path, commits, options = {})
43
+ renderer = prepare_renderer(options)
44
+ renderer.render(:commits, {
45
+ :commits => commits,
46
+ :repository => @repo,
47
+ :ref => options[:ref] || "master",
48
+ :path => path
49
+ })
50
+ end
51
+
52
+ it "renders history" do
53
+ markup = render("app/models/repository.rb", [@commit1, @commit2, @commit3])
54
+
55
+ assert_match /Commit #1/, markup
56
+ assert_match /Commit #2/, markup
57
+ assert_match /Commit #3/, markup
58
+ end
59
+ end
@@ -0,0 +1,39 @@
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 Blob
22
+ attr_reader :content
23
+ def initialize(content); @content = content; end
24
+ end
25
+
26
+ describe "raw template" do
27
+ include Dolt::ViewTest
28
+
29
+ before do
30
+ @repo = "the-dolt"
31
+ end
32
+
33
+ it "renders raw contents" do
34
+ renderer = prepare_renderer
35
+ html = renderer.render(:raw, { :blob => Blob.new("Something something") })
36
+
37
+ assert_equal "Something something\n", html
38
+ end
39
+ end