Fix dot in project name routes. Refactor and write basic route specs. Refs #454
This commit is contained in:
parent
5fcf9c3ffa
commit
f335863881
|
@ -2,6 +2,7 @@
|
|||
class Project < ActiveRecord::Base
|
||||
VISIBILITIES = ['open', 'hidden']
|
||||
MAX_OWN_PROJECTS = 32000
|
||||
NAME_REGEXP = /[a-zA-Z0-9_\-\+\.]+/
|
||||
|
||||
belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count
|
||||
|
||||
|
@ -19,7 +20,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
has_many :advisories
|
||||
|
||||
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/}
|
||||
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^#{NAME_REGEXP}$/}
|
||||
validates :owner, :presence => true
|
||||
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ Rosa::Application.routes.draw do
|
|||
|
||||
resources :projects, :only => [:index, :new, :create]
|
||||
|
||||
scope ':owner_name/:project_name' do # project
|
||||
scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project
|
||||
scope :as => 'project' do
|
||||
resources :wiki do
|
||||
collection do
|
||||
|
|
|
@ -12,20 +12,20 @@ describe Projects::Git::TreesController do
|
|||
|
||||
@project = FactoryGirl.create(:project)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@params = {:owner_name => @project.owner.uname, :project_name => @project.name, :format => 'tar'}
|
||||
@params = {:owner_name => @project.owner.uname, :project_name => @project.name}
|
||||
end
|
||||
|
||||
context 'for guest' do
|
||||
if APP_CONFIG['anonymous_access']
|
||||
it 'should be able to perform archive action with anonymous acccess' do
|
||||
fill_project
|
||||
get :archive, @params
|
||||
get :archive, @params.merge(:format => 'tar')
|
||||
response.should be_success
|
||||
end
|
||||
else
|
||||
it 'should not be able to perform archive action without anonymous acccess' do
|
||||
fill_project
|
||||
get :archive, @params
|
||||
get :archive, @params.merge(:format => 'tar')
|
||||
response.code.should == '401'
|
||||
end
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ describe Projects::Git::TreesController do
|
|||
it 'should not be able to archive empty project' do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
expect { get :archive, @params }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'should not be able to injection code with format' do
|
||||
|
@ -56,7 +56,7 @@ describe Projects::Git::TreesController do
|
|||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
fill_project
|
||||
get :archive, @params
|
||||
get :archive, @params.merge(:format => 'tar')
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require "spec_helper"
|
||||
|
||||
describe Projects::ProjectsController do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #index" do
|
||||
get("/projects").should route_to("projects/projects#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
get("/projects/new").should route_to("projects/projects#new")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
get("/import/glib2.0-mib/edit").should route_to("projects/projects#edit", :owner_name => 'import', :project_name => 'glib2.0-mib')
|
||||
end
|
||||
|
||||
it "routes to #create" do
|
||||
post("/projects").should route_to("projects/projects#create")
|
||||
end
|
||||
|
||||
it "routes to #update" do
|
||||
put("/import/glib2.0-mib").should route_to("projects/projects#update", :owner_name => 'import', :project_name => 'glib2.0-mib')
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
delete("/import/glib2.0-mib").should route_to("projects/projects#destroy", :owner_name => 'import', :project_name => 'glib2.0-mib')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe Projects::Git::TreesController do
|
||||
describe "routing" do
|
||||
|
||||
it "routes to #show" do
|
||||
get("/import/glib2.0-mib").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib')
|
||||
get("/import/glib2.0-mib/tree/branch").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch')
|
||||
get("/import/glib2.0-mib/tree/branch/some/path.to").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch', :path => 'some/path.to')
|
||||
end
|
||||
|
||||
# TODO write more specs also with slash in branch name!
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue