Blob of spec/helpers/browse_helper_spec.rb (raw blob data)

1 require File.dirname(__FILE__) + '/../spec_helper'
2
3 describe BrowseHelper do
4
5 before(:each) do
6 @project = projects(:johans)
7 @repository = @project.repositories.first
8 end
9
10 def generic_sha(letter = "a")
11 letter * 40
12 end
13
14 it "has a browse_path shortcut" do
15 browse_path.should == project_repository_browse_path(@project, @repository)
16 end
17
18 it "has a log_path shortcut" do
19 log_path.should == project_repository_log_path(@project, @repository)
20 end
21
22 it "has a log_path shortcut that takes args" do
23 log_path(:page => 2).should == project_repository_log_path(@project,
24 @repository, {:page => 2})
25 end
26
27 it "has a tree_path shortcut" do
28 tree_path.should == project_repository_tree_path(@project, @repository)
29 end
30
31 it "has a tree_path shortcut that takes an sha1" do
32 tree_path(generic_sha).should == project_repository_tree_path(@project,
33 @repository, generic_sha)
34 end
35
36 it "has a tree_path shortcut that takes an sha1 and a path glob" do
37 tree_path(generic_sha, ["a", "b"]).should == project_repository_tree_path(@project,
38 @repository, generic_sha, ["a", "b"])
39 end
40
41 it "has a commit_path shortcut" do
42 commit_path(generic_sha).should == project_repository_commit_path(@project,
43 @repository, generic_sha)
44 end
45
46 it "has a blob_path shortcut" do
47 blob_path(generic_sha, ["a","b"]).should == project_repository_blob_path(@project,
48 @repository, generic_sha, ["a","b"])
49 end
50
51 it "has a raw_blob_path shortcut" do
52 raw_blob_path(generic_sha, ["a","b"]).should == project_repository_raw_blob_path(
53 @project, @repository, generic_sha, ["a","b"])
54 end
55
56 it "has a diff_path shortcut" do
57 diff_path(generic_sha("a"), generic_sha("b")).should == project_repository_diff_path(@project,
58 @repository, generic_sha("a"), generic_sha("b"))
59 end
60
61 it "has a current_path based on the *path glob" do
62 params[:path] = ["one", "two"]
63 current_path.should == ["one", "two"]
64 end
65
66 it "builds a tree from current_path" do
67 params[:path] = ["one", "two"]
68 build_tree_path("three").should == ["one", "two", "three"]
69 end
70
71 describe "with_line_numbers" do
72 it "renders something with line numbers" do
73 numbered = with_line_numbers { "foo\nbar\nbaz" }
74 numbered.should include(%Q{<td class="line-numbers"><a href="#line2" name="line2">2</a></td>})
75 numbered.should include(%Q{<td class="code">bar</td>})
76 end
77
78 it "renders one line with line numbers" do
79 numbered = with_line_numbers { "foo" }
80 numbered.should include(%Q{<td class="line-numbers"><a href="#line1" name="line1">1</a></td>})
81 numbered.should include(%Q{<td class="code">foo</td>})
82 end
83
84 it "doesn't blow up when with_line_numbers receives nil" do
85 proc{
86 with_line_numbers{ nil }.should == "<table id=\"codeblob\">\n</table>"
87 }.should_not raise_error
88 end
89 end
90
91 # it "builds breadcrumbs of the current_path" do
92 # stub!(:current_path).and_return(["one", "two", "tree"])
93 # breadcrumb_path.should include(%Q{<ul class="path_breadcrumbs">})
94 # breadcrumb_path.should include("<li> / ")
95 # end
96
97 end