Commit de2770bba98cd568d3c467ce2fd1e218e63c19a7
1 parent
e1b4e22e
Exists in
master
and in
4 other branches
Add GFM helper specs
tests references to * commits * team members * issues * merge requests * snipptes
Showing
1 changed file
with
166 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,166 @@ |
1 | +require "spec_helper" | |
2 | + | |
3 | +describe ApplicationHelper do | |
4 | + before do | |
5 | + @project = Project.find_by_path("gitlabhq") || Factory(:project) | |
6 | + @commit = @project.repo.commits.first.parents.first | |
7 | + @commit = CommitDecorator.decorate(Commit.new(@commit)) | |
8 | + @other_project = Factory :project, :path => "OtherPath", :code => "OtherCode" | |
9 | + @fake_user = Factory :user, :name => "fred" | |
10 | + end | |
11 | + | |
12 | + describe "#gfm" do | |
13 | + describe "referencing a commit" do | |
14 | + it "should link using a full id" do | |
15 | + gfm("Reverts changes from #{@commit.id}").should == "Reverts changes from #{link_to @commit.id, project_commit_path(@project, :id => @commit.id), :title => "Commit: #{@commit.author_name} - #{@commit.title}", :class => "gfm gfm-commit "}" | |
16 | + end | |
17 | + | |
18 | + it "should link using a short id" do | |
19 | + gfm("Backported from #{@commit.id[0, 6]}").should == "Backported from #{link_to @commit.id[0, 6], project_commit_path(@project, :id => @commit.id), :title => "Commit: #{@commit.author_name} - #{@commit.title}", :class => "gfm gfm-commit "}" | |
20 | + end | |
21 | + | |
22 | + it "should link with adjecent text" do | |
23 | + gfm("Reverted (see #{@commit.id})").should == "Reverted (see #{link_to @commit.id, project_commit_path(@project, :id => @commit.id), :title => "Commit: #{@commit.author_name} - #{@commit.title}", :class => "gfm gfm-commit "})" | |
24 | + end | |
25 | + | |
26 | + it "should not link with an invalid id" do | |
27 | + gfm("What happened in 12345678?").should == "What happened in 12345678?" | |
28 | + end | |
29 | + end | |
30 | + | |
31 | + describe "referencing a team member" do | |
32 | + it "should link using a simple name" do | |
33 | + user = Factory :user, name: "barry" | |
34 | + @project.users << user | |
35 | + member = @project.users_projects.where(:user_id => user).first | |
36 | + | |
37 | + gfm("@#{user.name} you are right").should == "#{link_to "@#{user.name}", project_team_member_path(@project, member), :class => "gfm gfm-team_member "} you are right" | |
38 | + end | |
39 | + | |
40 | + it "should link using a name with dots" do | |
41 | + user = Factory :user, name: "alphA.Beta" | |
42 | + @project.users << user | |
43 | + member = @project.users_projects.where(:user_id => user).first | |
44 | + | |
45 | + gfm("@#{user.name} you are right").should == "#{link_to "@#{user.name}", project_team_member_path(@project, member), :class => "gfm gfm-team_member "} you are right" | |
46 | + end | |
47 | + | |
48 | + it "should link using name with underscores" do | |
49 | + user = Factory :user, name: "ping_pong_king" | |
50 | + @project.users << user | |
51 | + member = @project.users_projects.where(:user_id => user).first | |
52 | + | |
53 | + gfm("@#{user.name} you are right").should == "#{link_to "@#{user.name}", project_team_member_path(@project, member), :class => "gfm gfm-team_member "} you are right" | |
54 | + end | |
55 | + | |
56 | + it "should link with adjecent text" do | |
57 | + user = Factory.create(:user, :name => "ace") | |
58 | + @project.users << user | |
59 | + member = @project.users_projects.where(:user_id => user).first | |
60 | + | |
61 | + gfm("Mail the Admin (@#{user.name})").should == "Mail the Admin (#{link_to "@#{user.name}", project_team_member_path(@project, member), :class => "gfm gfm-team_member "})" | |
62 | + end | |
63 | + | |
64 | + it "should add styles" do | |
65 | + user = Factory :user, name: "barry" | |
66 | + @project.users << user | |
67 | + gfm("@#{user.name} you are right").should have_selector(".gfm.gfm-team_member") | |
68 | + end | |
69 | + | |
70 | + it "should not link using a bogus name" do | |
71 | + gfm("What hapened to @foo?").should == "What hapened to @foo?" | |
72 | + end | |
73 | + end | |
74 | + | |
75 | + describe "referencing an issue" do | |
76 | + before do | |
77 | + @issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @project | |
78 | + @invalid_issue = Factory :issue, :assignee => @fake_user, :author => @fake_user, :project => @other_project | |
79 | + end | |
80 | + | |
81 | + it "should link using a correct id" do | |
82 | + gfm("Fixes ##{@issue.id}").should == "Fixes #{link_to "##{@issue.id}", project_issue_path(@project, @issue), :title => "Issue: #{@issue.title}", :class => "gfm gfm-issue "}" | |
83 | + end | |
84 | + | |
85 | + it "should link with adjecent text" do | |
86 | + gfm("This has already been discussed (see ##{@issue.id})").should == "This has already been discussed (see #{link_to "##{@issue.id}", project_issue_path(@project, @issue), :title => "Issue: #{@issue.title}", :class => "gfm gfm-issue "})" | |
87 | + end | |
88 | + | |
89 | + it "should add styles" do | |
90 | + gfm("Fixes ##{@issue.id}").should have_selector(".gfm.gfm-issue") | |
91 | + end | |
92 | + | |
93 | + it "should not link using an invalid id" do | |
94 | + gfm("##{@invalid_issue.id} has been marked duplicate of this").should == "##{@invalid_issue.id} has been marked duplicate of this" | |
95 | + end | |
96 | + end | |
97 | + | |
98 | + describe "referencing a merge request" do | |
99 | + before do | |
100 | + @merge_request = Factory :merge_request, :assignee => @fake_user, :author => @fake_user, :project => @project | |
101 | + @invalid_merge_request = Factory :merge_request, :assignee => @fake_user, :author => @fake_user, :project => @other_project | |
102 | + end | |
103 | + | |
104 | + it "should link using a correct id" do | |
105 | + gfm("Fixed in !#{@merge_request.id}").should == "Fixed in #{link_to "!#{@merge_request.id}", project_merge_request_path(@project, @merge_request), :title => "Merge Request: #{@merge_request.title}", :class => "gfm gfm-merge_request "}" | |
106 | + end | |
107 | + | |
108 | + it "should link with adjecent text" do | |
109 | + gfm("This has been fixed already (see !#{@merge_request.id})").should == "This has been fixed already (see #{link_to "!#{@merge_request.id}", project_merge_request_path(@project, @merge_request), :title => "Merge Request: #{@merge_request.title}", :class => "gfm gfm-merge_request "})" | |
110 | + end | |
111 | + | |
112 | + it "should add styles" do | |
113 | + gfm("Fixed in !#{@merge_request.id}").should have_selector(".gfm.gfm-merge_request") | |
114 | + end | |
115 | + | |
116 | + it "should not link using an invalid id" do | |
117 | + gfm("!#{@invalid_merge_request.id} violates our coding guidelines") | |
118 | + end | |
119 | + end | |
120 | + | |
121 | + describe "referencing a snippet" do | |
122 | + before do | |
123 | + @snippet = Factory.create(:snippet, | |
124 | + :title => "Render asset to string", | |
125 | + :author => @fake_user, | |
126 | + :project => @project) | |
127 | + end | |
128 | + | |
129 | + it "should link using a correct id" do | |
130 | + gfm("Check out $#{@snippet.id}").should == "Check out #{link_to "$#{@snippet.id}", project_snippet_path(@project, @snippet), :title => "Snippet: #{@snippet.title}", :class => "gfm gfm-snippet "}" | |
131 | + end | |
132 | + | |
133 | + it "should link with adjecent text" do | |
134 | + gfm("I have created a snippet for that ($#{@snippet.id})").should == "I have created a snippet for that (#{link_to "$#{@snippet.id}", project_snippet_path(@project, @snippet), :title => "Snippet: #{@snippet.title}", :class => "gfm gfm-snippet "})" | |
135 | + end | |
136 | + | |
137 | + it "should add styles" do | |
138 | + gfm("Check out $#{@snippet.id}").should have_selector(".gfm.gfm-snippet") | |
139 | + end | |
140 | + | |
141 | + it "should not link using an invalid id" do | |
142 | + gfm("Don't use $1234").should == "Don't use $1234" | |
143 | + end | |
144 | + end | |
145 | + | |
146 | + it "should link to multiple things" do | |
147 | + user = Factory :user, name: "barry" | |
148 | + @project.users << user | |
149 | + member = @project.users_projects.where(:user_id => user).first | |
150 | + | |
151 | + gfm("Let @#{user.name} fix the *mess* in #{@commit.id}").should == "Let #{link_to "@#{user.name}", project_team_member_path(@project, member), :class => "gfm gfm-team_member "} fix the *mess* in #{link_to @commit.id, project_commit_path(@project, :id => @commit.id), :title => "Commit: #{@commit.author_name} - #{@commit.title}", :class => "gfm gfm-commit "}" | |
152 | + end | |
153 | + | |
154 | + it "should not trip over other stuff", :focus => true do | |
155 | + gfm("_Please_ *stop* 'helping' and all the other b*$#%' you do.").should == "_Please_ *stop* 'helping' and all the other b*$#%' you do." | |
156 | + end | |
157 | + | |
158 | + it "should not touch HTML entities" do | |
159 | + gfm("We'll accept good pull requests.").should == "We'll accept good pull requests." | |
160 | + end | |
161 | + | |
162 | + it "should forward HTML options to links" do | |
163 | + gfm("fixed in #{@commit.id}", :class => "foo").should have_selector("a.foo") | |
164 | + end | |
165 | + end | |
166 | +end | ... | ... |