Commit 9304d049de0493de457fdec02114d5a23d116f9b

Authored by Dmitriy Zaporozhets
1 parent 470aa767

Fixed some tests and snippet colorize

app/controllers/admin/groups_controller.rb
... ... @@ -74,6 +74,6 @@ class Admin::GroupsController < AdminController
74 74 private
75 75  
76 76 def group
77   - @group = Group.find_by_code(params[:id])
  77 + @group = Group.find_by_path(params[:id])
78 78 end
79 79 end
... ...
app/controllers/groups_controller.rb
... ... @@ -50,7 +50,7 @@ class GroupsController < ApplicationController
50 50 protected
51 51  
52 52 def group
53   - @group ||= Group.find_by_code(params[:id])
  53 + @group ||= Group.find_by_path(params[:id])
54 54 end
55 55  
56 56 def projects
... ...
app/models/project.rb
... ... @@ -86,7 +86,7 @@ class Project < ActiveRecord::Base
86 86  
87 87 def create_by_user(params, user)
88 88 namespace_id = params.delete(:namespace_id)
89   - namespace_id ||= user.namespace_id
  89 + namespace_id ||= user.namespace.try(:id)
90 90  
91 91 project = Project.new params
92 92  
... ... @@ -222,6 +222,8 @@ class Project < ActiveRecord::Base
222 222 end
223 223 end
224 224  
225   - def move_repo
  225 + # For compatibility with old code
  226 + def code
  227 + path
226 228 end
227 229 end
... ...
app/views/snippets/show.html.haml
... ... @@ -15,8 +15,12 @@
15 15 %span.options
16 16 = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn very_small", target: "_blank"
17 17 .file_content.code
18   - %div{class: current_user.dark_scheme ? "black" : ""}
19   - = raw @snippet.colorize(options: { linenos: 'True'})
  18 + - unless @snippet.content.empty?
  19 + %div{class: current_user.dark_scheme ? "black" : "white"}
  20 + = preserve do
  21 + = raw Pygments.highlight(@snippet.content, formatter: :gitlab)
  22 + - else
  23 + %h4.nothing_here_message Empty file
20 24  
21 25  
22 26 %div
... ...
features/steps/admin/admin_groups.rb
... ... @@ -9,7 +9,7 @@ class AdminGroups < Spinach::FeatureSteps
9 9  
10 10 And 'submit form with new group info' do
11 11 fill_in 'group_name', :with => 'gitlab'
12   - fill_in 'group_code', :with => 'gitlab'
  12 + fill_in 'group_path', :with => 'gitlab'
13 13 click_button "Save group"
14 14 end
15 15  
... ...
features/steps/project/create_project.rb
... ... @@ -4,8 +4,6 @@ class CreateProject < Spinach::FeatureSteps
4 4  
5 5 And 'fill project form with valid data' do
6 6 fill_in 'project_name', :with => 'NewProject'
7   - fill_in 'project_code', :with => 'NPR'
8   - fill_in 'project_path', :with => 'newproject'
9 7 click_button "Create project"
10 8 end
11 9  
... ...
lib/api/projects.rb
... ... @@ -40,8 +40,7 @@ module Gitlab
40 40 post do
41 41 params[:code] ||= params[:name]
42 42 params[:path] ||= params[:name]
43   - attrs = attributes_for_keys [:code,
44   - :path,
  43 + attrs = attributes_for_keys [:path,
45 44 :name,
46 45 :description,
47 46 :default_branch,
... ...
spec/requests/admin/admin_projects_spec.rb
... ... @@ -2,9 +2,7 @@ require 'spec_helper'
2 2  
3 3 describe "Admin::Projects" do
4 4 before do
5   - @project = create(:project,
6   - name: "LeGiT",
7   - code: "LGT")
  5 + @project = create(:project)
8 6 login_as :admin
9 7 end
10 8  
... ... @@ -29,7 +27,7 @@ describe "Admin::Projects" do
29 27 end
30 28  
31 29 it "should have project info" do
32   - page.should have_content(@project.code)
  30 + page.should have_content(@project.path)
33 31 page.should have_content(@project.name)
34 32 end
35 33 end
... ... @@ -48,19 +46,16 @@ describe "Admin::Projects" do
48 46 describe "Update project" do
49 47 before do
50 48 fill_in "project_name", with: "Big Bang"
51   - fill_in "project_code", with: "BB1"
52 49 click_button "Save Project"
53 50 @project.reload
54 51 end
55 52  
56 53 it "should show page with new data" do
57   - page.should have_content("BB1")
58 54 page.should have_content("Big Bang")
59 55 end
60 56  
61 57 it "should change project entry" do
62 58 @project.name.should == "Big Bang"
63   - @project.code.should == "BB1"
64 59 end
65 60 end
66 61 end
... ... @@ -77,8 +72,6 @@ describe "Admin::Projects" do
77 72  
78 73 it "should have labels for new project" do
79 74 page.should have_content("Project name is")
80   - page.should have_content("Git Clone")
81   - page.should have_content("URL")
82 75 end
83 76 end
84 77  
... ... @@ -86,8 +79,6 @@ describe "Admin::Projects" do
86 79 before do
87 80 visit new_admin_project_path
88 81 fill_in 'project_name', with: 'NewProject'
89   - fill_in 'project_code', with: 'NPR'
90   - fill_in 'project_path', with: 'gitlabhq_1'
91 82 expect { click_button "Create project" }.to change { Project.count }.by(1)
92 83 @project = Project.last
93 84 end
... ...
spec/requests/api/issues_spec.rb
... ... @@ -28,7 +28,7 @@ describe Gitlab::API do
28 28  
29 29 describe "GET /projects/:id/issues" do
30 30 it "should return project issues" do
31   - get api("/projects/#{project.code}/issues", user)
  31 + get api("/projects/#{project.path}/issues", user)
32 32 response.status.should == 200
33 33 json_response.should be_an Array
34 34 json_response.first['title'].should == issue.title
... ... @@ -37,7 +37,7 @@ describe Gitlab::API do
37 37  
38 38 describe "GET /projects/:id/issues/:issue_id" do
39 39 it "should return a project issue by id" do
40   - get api("/projects/#{project.code}/issues/#{issue.id}", user)
  40 + get api("/projects/#{project.path}/issues/#{issue.id}", user)
41 41 response.status.should == 200
42 42 json_response['title'].should == issue.title
43 43 end
... ... @@ -45,7 +45,7 @@ describe Gitlab::API do
45 45  
46 46 describe "POST /projects/:id/issues" do
47 47 it "should create a new project issue" do
48   - post api("/projects/#{project.code}/issues", user),
  48 + post api("/projects/#{project.path}/issues", user),
49 49 title: 'new issue', labels: 'label, label2'
50 50 response.status.should == 201
51 51 json_response['title'].should == 'new issue'
... ... @@ -56,7 +56,7 @@ describe Gitlab::API do
56 56  
57 57 describe "PUT /projects/:id/issues/:issue_id" do
58 58 it "should update a project issue" do
59   - put api("/projects/#{project.code}/issues/#{issue.id}", user),
  59 + put api("/projects/#{project.path}/issues/#{issue.id}", user),
60 60 title: 'updated title', labels: 'label2', closed: 1
61 61 response.status.should == 200
62 62 json_response['title'].should == 'updated title'
... ... @@ -67,7 +67,7 @@ describe Gitlab::API do
67 67  
68 68 describe "DELETE /projects/:id/issues/:issue_id" do
69 69 it "should delete a project issue" do
70   - delete api("/projects/#{project.code}/issues/#{issue.id}", user)
  70 + delete api("/projects/#{project.path}/issues/#{issue.id}", user)
71 71 response.status.should == 405
72 72 end
73 73 end
... ...
spec/requests/api/merge_requests_spec.rb
... ... @@ -11,14 +11,14 @@ describe Gitlab::API do
11 11 describe "GET /projects/:id/merge_requests" do
12 12 context "when unauthenticated" do
13 13 it "should return authentication error" do
14   - get api("/projects/#{project.code}/merge_requests")
  14 + get api("/projects/#{project.path}/merge_requests")
15 15 response.status.should == 401
16 16 end
17 17 end
18 18  
19 19 context "when authenticated" do
20 20 it "should return an array of merge_requests" do
21   - get api("/projects/#{project.code}/merge_requests", user)
  21 + get api("/projects/#{project.path}/merge_requests", user)
22 22 response.status.should == 200
23 23 json_response.should be_an Array
24 24 json_response.first['title'].should == merge_request.title
... ... @@ -28,7 +28,7 @@ describe Gitlab::API do
28 28  
29 29 describe "GET /projects/:id/merge_request/:merge_request_id" do
30 30 it "should return merge_request" do
31   - get api("/projects/#{project.code}/merge_request/#{merge_request.id}", user)
  31 + get api("/projects/#{project.path}/merge_request/#{merge_request.id}", user)
32 32 response.status.should == 200
33 33 json_response['title'].should == merge_request.title
34 34 end
... ... @@ -36,7 +36,7 @@ describe Gitlab::API do
36 36  
37 37 describe "POST /projects/:id/merge_requests" do
38 38 it "should return merge_request" do
39   - post api("/projects/#{project.code}/merge_requests", user),
  39 + post api("/projects/#{project.path}/merge_requests", user),
40 40 title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user
41 41 response.status.should == 201
42 42 json_response['title'].should == 'Test merge_request'
... ... @@ -45,7 +45,7 @@ describe Gitlab::API do
45 45  
46 46 describe "PUT /projects/:id/merge_request/:merge_request_id" do
47 47 it "should return merge_request" do
48   - put api("/projects/#{project.code}/merge_request/#{merge_request.id}", user), title: "New title"
  48 + put api("/projects/#{project.path}/merge_request/#{merge_request.id}", user), title: "New title"
49 49 response.status.should == 200
50 50 json_response['title'].should == 'New title'
51 51 end
... ... @@ -53,7 +53,7 @@ describe Gitlab::API do
53 53  
54 54 describe "POST /projects/:id/merge_request/:merge_request_id/comments" do
55 55 it "should return comment" do
56   - post api("/projects/#{project.code}/merge_request/#{merge_request.id}/comments", user), note: "My comment"
  56 + post api("/projects/#{project.path}/merge_request/#{merge_request.id}/comments", user), note: "My comment"
57 57 response.status.should == 201
58 58 json_response['note'].should == 'My comment'
59 59 end
... ...
spec/requests/api/projects_spec.rb
... ... @@ -33,7 +33,7 @@ describe Gitlab::API do
33 33 end
34 34  
35 35 describe "POST /projects" do
36   - it "should create new project without code and path" do
  36 + it "should create new project without path" do
37 37 expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
38 38 end
39 39  
... ... @@ -53,8 +53,7 @@ describe Gitlab::API do
53 53  
54 54 it "should assign attributes to project" do
55 55 project = attributes_for(:project, {
56   - path: 'path',
57   - code: 'code',
  56 + path: project.name.parameterize,
58 57 description: Faker::Lorem.sentence,
59 58 default_branch: 'stable',
60 59 issues_enabled: false,
... ... @@ -79,8 +78,8 @@ describe Gitlab::API do
79 78 json_response['owner']['email'].should == user.email
80 79 end
81 80  
82   - it "should return a project by code name" do
83   - get api("/projects/#{project.code}", user)
  81 + it "should return a project by path name" do
  82 + get api("/projects/#{project.path}", user)
84 83 response.status.should == 200
85 84 json_response['name'].should == project.name
86 85 end
... ... @@ -94,7 +93,7 @@ describe Gitlab::API do
94 93  
95 94 describe "GET /projects/:id/repository/branches" do
96 95 it "should return an array of project branches" do
97   - get api("/projects/#{project.code}/repository/branches", user)
  96 + get api("/projects/#{project.path}/repository/branches", user)
98 97 response.status.should == 200
99 98 json_response.should be_an Array
100 99 json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name
... ... @@ -103,7 +102,7 @@ describe Gitlab::API do
103 102  
104 103 describe "GET /projects/:id/repository/branches/:branch" do
105 104 it "should return the branch information for a single branch" do
106   - get api("/projects/#{project.code}/repository/branches/new_design", user)
  105 + get api("/projects/#{project.path}/repository/branches/new_design", user)
107 106 response.status.should == 200
108 107  
109 108 json_response['name'].should == 'new_design'
... ... @@ -113,7 +112,7 @@ describe Gitlab::API do
113 112  
114 113 describe "GET /projects/:id/members" do
115 114 it "should return project team members" do
116   - get api("/projects/#{project.code}/members", user)
  115 + get api("/projects/#{project.path}/members", user)
117 116 response.status.should == 200
118 117 json_response.should be_an Array
119 118 json_response.count.should == 2
... ... @@ -123,7 +122,7 @@ describe Gitlab::API do
123 122  
124 123 describe "GET /projects/:id/members/:user_id" do
125 124 it "should return project team member" do
126   - get api("/projects/#{project.code}/members/#{user.id}", user)
  125 + get api("/projects/#{project.path}/members/#{user.id}", user)
127 126 response.status.should == 200
128 127 json_response['email'].should == user.email
129 128 json_response['access_level'].should == UsersProject::MASTER
... ... @@ -133,7 +132,7 @@ describe Gitlab::API do
133 132 describe "POST /projects/:id/members" do
134 133 it "should add user to project team" do
135 134 expect {
136   - post api("/projects/#{project.code}/members", user), user_id: user2.id,
  135 + post api("/projects/#{project.path}/members", user), user_id: user2.id,
137 136 access_level: UsersProject::DEVELOPER
138 137 }.to change { UsersProject.count }.by(1)
139 138  
... ... @@ -145,7 +144,7 @@ describe Gitlab::API do
145 144  
146 145 describe "PUT /projects/:id/members/:user_id" do
147 146 it "should update project team member" do
148   - put api("/projects/#{project.code}/members/#{user3.id}", user), access_level: UsersProject::MASTER
  147 + put api("/projects/#{project.path}/members/#{user3.id}", user), access_level: UsersProject::MASTER
149 148 response.status.should == 200
150 149 json_response['email'].should == user3.email
151 150 json_response['access_level'].should == UsersProject::MASTER
... ... @@ -155,14 +154,14 @@ describe Gitlab::API do
155 154 describe "DELETE /projects/:id/members/:user_id" do
156 155 it "should remove user from project team" do
157 156 expect {
158   - delete api("/projects/#{project.code}/members/#{user3.id}", user)
  157 + delete api("/projects/#{project.path}/members/#{user3.id}", user)
159 158 }.to change { UsersProject.count }.by(-1)
160 159 end
161 160 end
162 161  
163 162 describe "GET /projects/:id/hooks" do
164 163 it "should return project hooks" do
165   - get api("/projects/#{project.code}/hooks", user)
  164 + get api("/projects/#{project.path}/hooks", user)
166 165  
167 166 response.status.should == 200
168 167  
... ... @@ -174,7 +173,7 @@ describe Gitlab::API do
174 173  
175 174 describe "GET /projects/:id/hooks/:hook_id" do
176 175 it "should return a project hook" do
177   - get api("/projects/#{project.code}/hooks/#{hook.id}", user)
  176 + get api("/projects/#{project.path}/hooks/#{hook.id}", user)
178 177 response.status.should == 200
179 178 json_response['url'].should == hook.url
180 179 end
... ... @@ -183,7 +182,7 @@ describe Gitlab::API do
183 182 describe "POST /projects/:id/hooks" do
184 183 it "should add hook to project" do
185 184 expect {
186   - post api("/projects/#{project.code}/hooks", user),
  185 + post api("/projects/#{project.path}/hooks", user),
187 186 "url" => "http://example.com"
188 187 }.to change {project.hooks.count}.by(1)
189 188 end
... ... @@ -191,7 +190,7 @@ describe Gitlab::API do
191 190  
192 191 describe "PUT /projects/:id/hooks/:hook_id" do
193 192 it "should update an existing project hook" do
194   - put api("/projects/#{project.code}/hooks/#{hook.id}", user),
  193 + put api("/projects/#{project.path}/hooks/#{hook.id}", user),
195 194 url: 'http://example.org'
196 195 response.status.should == 200
197 196 json_response['url'].should == 'http://example.org'
... ... @@ -202,7 +201,7 @@ describe Gitlab::API do
202 201 describe "DELETE /projects/:id/hooks" do
203 202 it "should delete hook from project" do
204 203 expect {
205   - delete api("/projects/#{project.code}/hooks", user),
  204 + delete api("/projects/#{project.path}/hooks", user),
206 205 hook_id: hook.id
207 206 }.to change {project.hooks.count}.by(-1)
208 207 end
... ... @@ -210,7 +209,7 @@ describe Gitlab::API do
210 209  
211 210 describe "GET /projects/:id/repository/tags" do
212 211 it "should return an array of project tags" do
213   - get api("/projects/#{project.code}/repository/tags", user)
  212 + get api("/projects/#{project.path}/repository/tags", user)
214 213 response.status.should == 200
215 214 json_response.should be_an Array
216 215 json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name
... ... @@ -222,7 +221,7 @@ describe Gitlab::API do
222 221 before { project.add_access(user2, :read) }
223 222  
224 223 it "should return project commits" do
225   - get api("/projects/#{project.code}/repository/commits", user)
  224 + get api("/projects/#{project.path}/repository/commits", user)
226 225 response.status.should == 200
227 226  
228 227 json_response.should be_an Array
... ... @@ -232,7 +231,7 @@ describe Gitlab::API do
232 231  
233 232 context "unauthorized user" do
234 233 it "should not return project commits" do
235   - get api("/projects/#{project.code}/repository/commits")
  234 + get api("/projects/#{project.path}/repository/commits")
236 235 response.status.should == 401
237 236 end
238 237 end
... ... @@ -240,7 +239,7 @@ describe Gitlab::API do
240 239  
241 240 describe "GET /projects/:id/snippets" do
242 241 it "should return an array of project snippets" do
243   - get api("/projects/#{project.code}/snippets", user)
  242 + get api("/projects/#{project.path}/snippets", user)
244 243 response.status.should == 200
245 244 json_response.should be_an Array
246 245 json_response.first['title'].should == snippet.title
... ... @@ -249,7 +248,7 @@ describe Gitlab::API do
249 248  
250 249 describe "GET /projects/:id/snippets/:snippet_id" do
251 250 it "should return a project snippet" do
252   - get api("/projects/#{project.code}/snippets/#{snippet.id}", user)
  251 + get api("/projects/#{project.path}/snippets/#{snippet.id}", user)
253 252 response.status.should == 200
254 253 json_response['title'].should == snippet.title
255 254 end
... ... @@ -257,8 +256,8 @@ describe Gitlab::API do
257 256  
258 257 describe "POST /projects/:id/snippets" do
259 258 it "should create a new project snippet" do
260   - post api("/projects/#{project.code}/snippets", user),
261   - title: 'api test', file_name: 'sample.rb', code: 'test'
  259 + post api("/projects/#{project.path}/snippets", user),
  260 + title: 'api test', file_name: 'sample.rb', path: 'test'
262 261 response.status.should == 201
263 262 json_response['title'].should == 'api test'
264 263 end
... ... @@ -266,42 +265,42 @@ describe Gitlab::API do
266 265  
267 266 describe "PUT /projects/:id/snippets/:shippet_id" do
268 267 it "should update an existing project snippet" do
269   - put api("/projects/#{project.code}/snippets/#{snippet.id}", user),
270   - code: 'updated code'
  268 + put api("/projects/#{project.path}/snippets/#{snippet.id}", user),
  269 + path: 'updated path'
271 270 response.status.should == 200
272 271 json_response['title'].should == 'example'
273   - snippet.reload.content.should == 'updated code'
  272 + snippet.reload.content.should == 'updated path'
274 273 end
275 274 end
276 275  
277 276 describe "DELETE /projects/:id/snippets/:snippet_id" do
278 277 it "should delete existing project snippet" do
279 278 expect {
280   - delete api("/projects/#{project.code}/snippets/#{snippet.id}", user)
  279 + delete api("/projects/#{project.path}/snippets/#{snippet.id}", user)
281 280 }.to change { Snippet.count }.by(-1)
282 281 end
283 282 end
284 283  
285 284 describe "GET /projects/:id/snippets/:snippet_id/raw" do
286 285 it "should get a raw project snippet" do
287   - get api("/projects/#{project.code}/snippets/#{snippet.id}/raw", user)
  286 + get api("/projects/#{project.path}/snippets/#{snippet.id}/raw", user)
288 287 response.status.should == 200
289 288 end
290 289 end
291 290  
292 291 describe "GET /projects/:id/:sha/blob" do
293 292 it "should get the raw file contents" do
294   - get api("/projects/#{project.code}/repository/commits/master/blob?filepath=README.md", user)
  293 + get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.md", user)
295 294 response.status.should == 200
296 295 end
297 296  
298 297 it "should return 404 for invalid branch_name" do
299   - get api("/projects/#{project.code}/repository/commits/invalid_branch_name/blob?filepath=README.md", user)
  298 + get api("/projects/#{project.path}/repository/commits/invalid_branch_name/blob?filepath=README.md", user)
300 299 response.status.should == 404
301 300 end
302 301  
303 302 it "should return 404 for invalid file" do
304   - get api("/projects/#{project.code}/repository/commits/master/blob?filepath=README.invalid", user)
  303 + get api("/projects/#{project.path}/repository/commits/master/blob?filepath=README.invalid", user)
305 304 response.status.should == 404
306 305 end
307 306 end
... ...
spec/requests/projects_spec.rb
... ... @@ -8,8 +8,6 @@ describe "Projects" do
8 8 visit new_project_path
9 9  
10 10 fill_in 'project_name', with: 'Awesome'
11   - find("#project_path").value.should == 'awesome'
12   - find("#project_code").value.should == 'awesome'
13 11 end
14 12 end
15 13  
... ... @@ -53,7 +51,6 @@ describe "Projects" do
53 51 visit edit_project_path(@project)
54 52  
55 53 fill_in 'project_name', with: 'Awesome'
56   - fill_in 'project_code', with: 'gitlabhq'
57 54 click_button "Save"
58 55 @project = @project.reload
59 56 end
... ...
spec/support/stubbed_repository.rb
... ... @@ -28,4 +28,10 @@ module StubbedRepository
28 28 end
29 29 end
30 30  
  31 +class Namespace
  32 + def ensure_dir_exist
  33 + true
  34 + end
  35 +end
  36 +
31 37 Project.send(:include, StubbedRepository)
... ...