project_routing_spec.rb 20.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
require 'spec_helper'

# Shared examples for a resource inside a Project
#
# By default it tests all the default REST actions: index, create, new, edit,
# show, update, and destroy. You can remove actions by customizing the
# `actions` variable.
#
# It also expects a `controller` variable to be available which defines both
# the path to the resource as well as the controller name.
#
# Examples
#
#   # Default behavior
#   it_behaves_like "RESTful project resources" do
#     let(:controller) { 'issues' }
#   end
#
#   # Customizing actions
#   it_behaves_like "RESTful project resources" do
#     let(:actions)    { [:index] }
#     let(:controller) { 'issues' }
#   end
shared_examples "RESTful project resources" do
  let(:actions) { [:index, :create, :new, :edit, :show, :update, :destroy] }

  it "to #index" do
    get("/gitlabhq/#{controller}").should route_to("#{controller}#index", project_id: 'gitlabhq') if actions.include?(:index)
  end

  it "to #create" do
    post("/gitlabhq/#{controller}").should route_to("#{controller}#create", project_id: 'gitlabhq') if actions.include?(:create)
  end

  it "to #new" do
    get("/gitlabhq/#{controller}/new").should route_to("#{controller}#new", project_id: 'gitlabhq') if actions.include?(:new)
  end

  it "to #edit" do
    get("/gitlabhq/#{controller}/1/edit").should route_to("#{controller}#edit", project_id: 'gitlabhq', id: '1') if actions.include?(:edit)
  end

  it "to #show" do
    get("/gitlabhq/#{controller}/1").should route_to("#{controller}#show", project_id: 'gitlabhq', id: '1') if actions.include?(:show)
  end

  it "to #update" do
    put("/gitlabhq/#{controller}/1").should route_to("#{controller}#update", project_id: 'gitlabhq', id: '1') if actions.include?(:update)
  end

  it "to #destroy" do
    delete("/gitlabhq/#{controller}/1").should route_to("#{controller}#destroy", project_id: 'gitlabhq', id: '1') if actions.include?(:destroy)
  end
end

#      projects POST   /projects(.:format)     projects#create
#   new_project GET    /projects/new(.:format) projects#new
#  wall_project GET    /:id/wall(.:format)     projects#wall
# files_project GET    /:id/files(.:format)    projects#files
#  edit_project GET    /:id/edit(.:format)     projects#edit
#       project GET    /:id(.:format)          projects#show
#               PUT    /:id(.:format)          projects#update
#               DELETE /:id(.:format)          projects#destroy
describe ProjectsController, "routing" do
  it "to #create" do
    post("/projects").should route_to('projects#create')
  end

  it "to #new" do
    get("/projects/new").should route_to('projects#new')
  end

  it "to #wall" do
D
Dmitriy Zaporozhets 已提交
74
    get("/gitlabhq/wall").should route_to('walls#show', project_id: 'gitlabhq')
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  end

  it "to #edit" do
    get("/gitlabhq/edit").should route_to('projects#edit', id: 'gitlabhq')
  end

  it "to #show" do
    get("/gitlabhq").should route_to('projects#show', id: 'gitlabhq')
  end

  it "to #update" do
    put("/gitlabhq").should route_to('projects#update', id: 'gitlabhq')
  end

  it "to #destroy" do
    delete("/gitlabhq").should route_to('projects#destroy', id: 'gitlabhq')
  end
end

#  pages_project_wikis GET    /:project_id/wikis/pages(.:format)       wikis#pages
# history_project_wiki GET    /:project_id/wikis/:id/history(.:format) wikis#history
#        project_wikis POST   /:project_id/wikis(.:format)             wikis#create
#    edit_project_wiki GET    /:project_id/wikis/:id/edit(.:format)    wikis#edit
#         project_wiki GET    /:project_id/wikis/:id(.:format)         wikis#show
#                      DELETE /:project_id/wikis/:id(.:format)         wikis#destroy
describe WikisController, "routing" do
  it "to #pages" do
    get("/gitlabhq/wikis/pages").should route_to('wikis#pages', project_id: 'gitlabhq')
  end

  it "to #history" do
    get("/gitlabhq/wikis/1/history").should route_to('wikis#history', project_id: 'gitlabhq', id: '1')
  end

  it_behaves_like "RESTful project resources" do
    let(:actions)    { [:create, :edit, :show, :destroy] }
    let(:controller) { 'wikis' }
  end
end

# branches_project_repository GET    /:project_id/repository/branches(.:format) repositories#branches
#     tags_project_repository GET    /:project_id/repository/tags(.:format)     repositories#tags
#  archive_project_repository GET    /:project_id/repository/archive(.:format)  repositories#archive
#          project_repository POST   /:project_id/repository(.:format)          repositories#create
#      new_project_repository GET    /:project_id/repository/new(.:format)      repositories#new
#     edit_project_repository GET    /:project_id/repository/edit(.:format)     repositories#edit
#                             GET    /:project_id/repository(.:format)          repositories#show
#                             PUT    /:project_id/repository(.:format)          repositories#update
#                             DELETE /:project_id/repository(.:format)          repositories#destroy
describe RepositoriesController, "routing" do
  it "to #branches" do
    get("/gitlabhq/repository/branches").should route_to('repositories#branches', project_id: 'gitlabhq')
  end

  it "to #tags" do
    get("/gitlabhq/repository/tags").should route_to('repositories#tags', project_id: 'gitlabhq')
  end

  it "to #archive" do
    get("/gitlabhq/repository/archive").should route_to('repositories#archive', project_id: 'gitlabhq')
  end

  it "to #create" do
    post("/gitlabhq/repository").should route_to('repositories#create', project_id: 'gitlabhq')
  end

  it "to #new" do
    get("/gitlabhq/repository/new").should route_to('repositories#new', project_id: 'gitlabhq')
  end

  it "to #edit" do
    get("/gitlabhq/repository/edit").should route_to('repositories#edit', project_id: 'gitlabhq')
  end

  it "to #show" do
    get("/gitlabhq/repository").should route_to('repositories#show', project_id: 'gitlabhq')
  end

  it "to #update" do
    put("/gitlabhq/repository").should route_to('repositories#update', project_id: 'gitlabhq')
  end

  it "to #destroy" do
    delete("/gitlabhq/repository").should route_to('repositories#destroy', project_id: 'gitlabhq')
  end
end

#     project_deploy_keys GET    /:project_id/deploy_keys(.:format)          deploy_keys#index
#                         POST   /:project_id/deploy_keys(.:format)          deploy_keys#create
#  new_project_deploy_key GET    /:project_id/deploy_keys/new(.:format)      deploy_keys#new
# edit_project_deploy_key GET    /:project_id/deploy_keys/:id/edit(.:format) deploy_keys#edit
#      project_deploy_key GET    /:project_id/deploy_keys/:id(.:format)      deploy_keys#show
#                         PUT    /:project_id/deploy_keys/:id(.:format)      deploy_keys#update
#                         DELETE /:project_id/deploy_keys/:id(.:format)      deploy_keys#destroy
describe DeployKeysController, "routing" do
  it_behaves_like "RESTful project resources" do
    let(:controller) { 'deploy_keys' }
  end
end

# project_protected_branches GET    /:project_id/protected_branches(.:format)     protected_branches#index
#                            POST   /:project_id/protected_branches(.:format)     protected_branches#create
#   project_protected_branch DELETE /:project_id/protected_branches/:id(.:format) protected_branches#destroy
describe ProtectedBranchesController, "routing" do
  it_behaves_like "RESTful project resources" do
    let(:actions)    { [:index, :create, :destroy] }
    let(:controller) { 'protected_branches' }
  end
end

D
Dmitriy Zaporozhets 已提交
185 186 187
#    switch_project_refs GET    /:project_id/refs/switch(.:format)              refs#switch
#  logs_tree_project_ref GET    /:project_id/refs/:id/logs_tree(.:format)       refs#logs_tree
#  logs_file_project_ref GET    /:project_id/refs/:id/logs_tree/:path(.:format) refs#logs_tree
188 189
describe RefsController, "routing" do
  it "to #switch" do
D
Dmitriy Zaporozhets 已提交
190
    get("/gitlabhq/refs/switch").should route_to('refs#switch', project_id: 'gitlabhq')
191 192 193
  end

  it "to #logs_tree" do
D
Dmitriy Zaporozhets 已提交
194 195
    get("/gitlabhq/refs/stable/logs_tree").should             route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable')
    get("/gitlabhq/refs/stable/logs_tree/foo/bar/baz").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
196
    get("/gitlab/gitlabhq/refs/stable/logs_tree/files.scss").should route_to('refs#logs_tree', project_id: 'gitlab/gitlabhq', id: 'stable', path: 'files.scss')
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
  end
end

#           diffs_project_merge_request GET    /:project_id/merge_requests/:id/diffs(.:format)           merge_requests#diffs
#       automerge_project_merge_request GET    /:project_id/merge_requests/:id/automerge(.:format)       merge_requests#automerge
# automerge_check_project_merge_request GET    /:project_id/merge_requests/:id/automerge_check(.:format) merge_requests#automerge_check
#    branch_from_project_merge_requests GET    /:project_id/merge_requests/branch_from(.:format)         merge_requests#branch_from
#      branch_to_project_merge_requests GET    /:project_id/merge_requests/branch_to(.:format)           merge_requests#branch_to
#                project_merge_requests GET    /:project_id/merge_requests(.:format)                     merge_requests#index
#                                       POST   /:project_id/merge_requests(.:format)                     merge_requests#create
#             new_project_merge_request GET    /:project_id/merge_requests/new(.:format)                 merge_requests#new
#            edit_project_merge_request GET    /:project_id/merge_requests/:id/edit(.:format)            merge_requests#edit
#                 project_merge_request GET    /:project_id/merge_requests/:id(.:format)                 merge_requests#show
#                                       PUT    /:project_id/merge_requests/:id(.:format)                 merge_requests#update
#                                       DELETE /:project_id/merge_requests/:id(.:format)                 merge_requests#destroy
describe MergeRequestsController, "routing" do
  it "to #diffs" do
    get("/gitlabhq/merge_requests/1/diffs").should route_to('merge_requests#diffs', project_id: 'gitlabhq', id: '1')
  end

  it "to #automerge" do
    get("/gitlabhq/merge_requests/1/automerge").should route_to('merge_requests#automerge', project_id: 'gitlabhq', id: '1')
  end

  it "to #automerge_check" do
    get("/gitlabhq/merge_requests/1/automerge_check").should route_to('merge_requests#automerge_check', project_id: 'gitlabhq', id: '1')
  end

  it "to #branch_from" do
    get("/gitlabhq/merge_requests/branch_from").should route_to('merge_requests#branch_from', project_id: 'gitlabhq')
  end

  it "to #branch_to" do
    get("/gitlabhq/merge_requests/branch_to").should route_to('merge_requests#branch_to', project_id: 'gitlabhq')
  end

233 234 235 236 237
  it "to #show" do
    get("/gitlabhq/merge_requests/1.diff").should route_to('merge_requests#show', project_id: 'gitlabhq', id: '1', format: 'diff')
    get("/gitlabhq/merge_requests/1.patch").should route_to('merge_requests#show', project_id: 'gitlabhq', id: '1', format: 'patch')
  end

238 239
  it_behaves_like "RESTful project resources" do
    let(:controller) { 'merge_requests' }
240
    let(:actions) { [:index, :create, :new, :edit, :show, :update] }
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
  end
end

#  raw_project_snippet GET    /:project_id/snippets/:id/raw(.:format)  snippets#raw
#     project_snippets GET    /:project_id/snippets(.:format)          snippets#index
#                      POST   /:project_id/snippets(.:format)          snippets#create
#  new_project_snippet GET    /:project_id/snippets/new(.:format)      snippets#new
# edit_project_snippet GET    /:project_id/snippets/:id/edit(.:format) snippets#edit
#      project_snippet GET    /:project_id/snippets/:id(.:format)      snippets#show
#                      PUT    /:project_id/snippets/:id(.:format)      snippets#update
#                      DELETE /:project_id/snippets/:id(.:format)      snippets#destroy
describe SnippetsController, "routing" do
  it "to #raw" do
    get("/gitlabhq/snippets/1/raw").should route_to('snippets#raw', project_id: 'gitlabhq', id: '1')
  end

  it_behaves_like "RESTful project resources" do
    let(:controller) { 'snippets' }
  end
end

# test_project_hook GET    /:project_id/hooks/:id/test(.:format) hooks#test
#     project_hooks GET    /:project_id/hooks(.:format)          hooks#index
#                   POST   /:project_id/hooks(.:format)          hooks#create
#      project_hook DELETE /:project_id/hooks/:id(.:format)      hooks#destroy
describe HooksController, "routing" do
  it "to #test" do
    get("/gitlabhq/hooks/1/test").should route_to('hooks#test', project_id: 'gitlabhq', id: '1')
  end

  it_behaves_like "RESTful project resources" do
    let(:actions)    { [:index, :create, :destroy] }
    let(:controller) { 'hooks' }
  end
end

277 278 279 280
# project_commit GET    /:project_id/commit/:id(.:format) commit#show {:id=>/[[:alnum:]]{6,40}/, :project_id=>/[^\/]+/}
describe CommitController, "routing" do
  it "to #show" do
    get("/gitlabhq/commit/4246fb").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fb')
R
Riyad Preukschas 已提交
281
    get("/gitlabhq/commit/4246fb.diff").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fb', format: 'diff')
R
Robert Speicher 已提交
282
    get("/gitlabhq/commit/4246fb.patch").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fb', format: 'patch')
283 284 285 286
    get("/gitlabhq/commit/4246fbd13872934f72a8fd0d6fb1317b47b59cb5").should route_to('commit#show', project_id: 'gitlabhq', id: '4246fbd13872934f72a8fd0d6fb1317b47b59cb5')
  end
end

287 288 289 290 291 292
#    patch_project_commit GET    /:project_id/commits/:id/patch(.:format) commits#patch
#         project_commits GET    /:project_id/commits(.:format)           commits#index
#                         POST   /:project_id/commits(.:format)           commits#create
#          project_commit GET    /:project_id/commits/:id(.:format)       commits#show
describe CommitsController, "routing" do
  it_behaves_like "RESTful project resources" do
R
Robert Speicher 已提交
293
    let(:actions)    { [:show] }
294 295
    let(:controller) { 'commits' }
  end
296 297 298 299

  it "to #show" do
    get("/gitlab/gitlabhq/commits/master.atom").should route_to('commits#show', project_id: 'gitlab/gitlabhq', id: "master", format: "atom")
  end
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
end

#     project_team_members GET    /:project_id/team_members(.:format)          team_members#index
#                          POST   /:project_id/team_members(.:format)          team_members#create
#  new_project_team_member GET    /:project_id/team_members/new(.:format)      team_members#new
# edit_project_team_member GET    /:project_id/team_members/:id/edit(.:format) team_members#edit
#      project_team_member GET    /:project_id/team_members/:id(.:format)      team_members#show
#                          PUT    /:project_id/team_members/:id(.:format)      team_members#update
#                          DELETE /:project_id/team_members/:id(.:format)      team_members#destroy
describe TeamMembersController, "routing" do
  it_behaves_like "RESTful project resources" do
    let(:controller) { 'team_members' }
  end
end

#     project_milestones GET    /:project_id/milestones(.:format)          milestones#index
#                        POST   /:project_id/milestones(.:format)          milestones#create
#  new_project_milestone GET    /:project_id/milestones/new(.:format)      milestones#new
# edit_project_milestone GET    /:project_id/milestones/:id/edit(.:format) milestones#edit
#      project_milestone GET    /:project_id/milestones/:id(.:format)      milestones#show
#                        PUT    /:project_id/milestones/:id(.:format)      milestones#update
#                        DELETE /:project_id/milestones/:id(.:format)      milestones#destroy
describe MilestonesController, "routing" do
  it_behaves_like "RESTful project resources" do
    let(:controller) { 'milestones' }
325
    let(:actions) { [:index, :create, :new, :edit, :show, :update] }
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
  end
end

# project_labels GET    /:project_id/labels(.:format) labels#index
describe LabelsController, "routing" do
  it "to #index" do
    get("/gitlabhq/labels").should route_to('labels#index', project_id: 'gitlabhq')
  end
end

#        sort_project_issues POST   /:project_id/issues/sort(.:format)        issues#sort
# bulk_update_project_issues POST   /:project_id/issues/bulk_update(.:format) issues#bulk_update
#      search_project_issues GET    /:project_id/issues/search(.:format)      issues#search
#             project_issues GET    /:project_id/issues(.:format)             issues#index
#                            POST   /:project_id/issues(.:format)             issues#create
#          new_project_issue GET    /:project_id/issues/new(.:format)         issues#new
#         edit_project_issue GET    /:project_id/issues/:id/edit(.:format)    issues#edit
#              project_issue GET    /:project_id/issues/:id(.:format)         issues#show
#                            PUT    /:project_id/issues/:id(.:format)         issues#update
#                            DELETE /:project_id/issues/:id(.:format)         issues#destroy
describe IssuesController, "routing" do
  it "to #bulk_update" do
    post("/gitlabhq/issues/bulk_update").should route_to('issues#bulk_update', project_id: 'gitlabhq')
  end

  it_behaves_like "RESTful project resources" do
    let(:controller) { 'issues' }
353
    let(:actions) { [:index, :create, :new, :edit, :show, :update] }
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
  end
end

# preview_project_notes POST   /:project_id/notes/preview(.:format) notes#preview
#         project_notes GET    /:project_id/notes(.:format)         notes#index
#                       POST   /:project_id/notes(.:format)         notes#create
#          project_note DELETE /:project_id/notes/:id(.:format)     notes#destroy
describe NotesController, "routing" do
  it "to #preview" do
    post("/gitlabhq/notes/preview").should route_to('notes#preview', project_id: 'gitlabhq')
  end

  it_behaves_like "RESTful project resources" do
    let(:actions)    { [:index, :create, :destroy] }
    let(:controller) { 'notes' }
  end
end
371

R
Robert Speicher 已提交
372
# project_blame GET    /:project_id/blame/:id(.:format) blame#show {:id=>/.+/, :project_id=>/[^\/]+/}
373 374 375
describe BlameController, "routing" do
  it "to #show" do
    get("/gitlabhq/blame/master/app/models/project.rb").should route_to('blame#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
376
    get("/gitlab/gitlabhq/blame/master/files.scss").should route_to('blame#show', project_id: 'gitlab/gitlabhq', id: 'master/files.scss')
377 378 379
  end
end

R
Robert Speicher 已提交
380
# project_blob GET    /:project_id/blob/:id(.:format) blob#show {:id=>/.+/, :project_id=>/[^\/]+/}
381 382 383
describe BlobController, "routing" do
  it "to #show" do
    get("/gitlabhq/blob/master/app/models/project.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
384
    get("/gitlabhq/blob/master/app/models/compare.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/compare.rb')
385
    get("/gitlab/gitlabhq/blob/master/files.scss").should route_to('blob#show', project_id: 'gitlab/gitlabhq', id: 'master/files.scss')
386 387 388
  end
end

R
Robert Speicher 已提交
389
# project_tree GET    /:project_id/tree/:id(.:format) tree#show {:id=>/.+/, :project_id=>/[^\/]+/}
390 391 392
describe TreeController, "routing" do
  it "to #show" do
    get("/gitlabhq/tree/master/app/models/project.rb").should route_to('tree#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
393
    get("/gitlab/gitlabhq/tree/master/files.scss").should route_to('tree#show', project_id: 'gitlab/gitlabhq', id: 'master/files.scss')
394 395 396
  end
end

R
Robert Speicher 已提交
397
# project_compare_index GET    /:project_id/compare(.:format)             compare#index {:id=>/[^\/]+/, :project_id=>/[^\/]+/}
398
#                       POST   /:project_id/compare(.:format)             compare#create {:id=>/[^\/]+/, :project_id=>/[^\/]+/}
R
Robert Speicher 已提交
399
#       project_compare        /:project_id/compare/:from...:to(.:format) compare#show {:from=>/.+/, :to=>/.+/, :id=>/[^\/]+/, :project_id=>/[^\/]+/}
400
describe CompareController, "routing" do
R
Robert Speicher 已提交
401 402 403 404
  it "to #index" do
    get("/gitlabhq/compare").should route_to('compare#index', project_id: 'gitlabhq')
  end

405 406 407 408
  it "to #compare" do
    post("/gitlabhq/compare").should route_to('compare#create', project_id: 'gitlabhq')
  end

409 410 411 412 413
  it "to #show" do
    get("/gitlabhq/compare/master...stable").should     route_to('compare#show', project_id: 'gitlabhq', from: 'master', to: 'stable')
    get("/gitlabhq/compare/issue/1234...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable')
  end
end
414 415 416 417 418 419 420

describe GraphController, "routing" do
  it "to #show" do
    get("/gitlabhq/graph/master").should route_to('graph#show', project_id: 'gitlabhq', id: 'master')
    get("/gitlabhq/graph/master.json").should route_to('graph#show', project_id: 'gitlabhq', id: 'master', format: "json")
  end
end