OSDN Git Service

project path & code regexp validation
authorgitlabhq <m@gitlabhq.com>
Sat, 15 Oct 2011 16:30:56 +0000 (19:30 +0300)
committergitlabhq <m@gitlabhq.com>
Sat, 15 Oct 2011 16:30:56 +0000 (19:30 +0300)
app/models/project.rb
config/initializers/rails_footnotes.rb
config/routes.rb
spec/requests/admin/admin_projects_spec.rb
spec/requests/projects_spec.rb

index 17b556c..0d90af8 100644 (file)
@@ -16,6 +16,8 @@ class Project < ActiveRecord::Base
   validates :path,
             :uniqueness => true,
             :presence => true,
+            :format => { :with => /^[a-zA-Z0-9_\-]*$/,
+                         :message => "only letters, digits & '_' '-' allowed" },
             :length   => { :within => 0..255 }
   
   validates :description,
@@ -24,14 +26,15 @@ class Project < ActiveRecord::Base
   validates :code,
             :presence => true,
             :uniqueness => true,
-            :length   => { :within => 3..12 }
+            :format => { :with => /^[a-zA-Z0-9_\-]*$/,
+                         :message => "only letters, digits & '_' '-' allowed"  },
+            :length   => { :within => 3..16 }
 
   validates :owner,
             :presence => true
 
   validate :check_limit
   
-  before_save :format_code
   after_destroy :destroy_gitosis_project
   after_save :update_gitosis_project
 
@@ -47,10 +50,6 @@ class Project < ActiveRecord::Base
     notes.where(:noteable_type => ["", nil])
   end
 
-  def format_code
-    read_attribute(:code).downcase.strip.gsub(' ', '')
-  end
-
   def update_gitosis_project
     Gitosis.new.configure do |c|
       c.update_project(path, gitosis_writers)
index da9d58e..2e578ec 100644 (file)
@@ -1,5 +1,5 @@
 if defined?(Footnotes) && Rails.env.development?
-  Footnotes.run! # first of all
+  #Footnotes.run! # first of all
 
   # ... other init code
 end
index 00106b1..cd8dc4c 100644 (file)
@@ -32,7 +32,7 @@ Gitlab::Application.routes.draw do
       get "tree/:commit_id/:path" => "projects#tree",
       :as => :tree_file,
       :constraints => { 
-        :id => /[a-zA-Z0-9]+/,
+        :id => /[a-zA-Z0-9_\-]+/,
         :commit_id => /[a-zA-Z0-9]+/,
         :path => /.*/
       }
index 8aa311e..e36ee44 100644 (file)
@@ -88,7 +88,7 @@ describe "Admin::Projects" do
       visit new_admin_project_path
       fill_in 'Name', :with => 'NewProject'
       fill_in 'Code', :with => 'NPR'
-      fill_in 'Path', :with => '/tmp/legit_test/legit'
+      fill_in 'Path', :with => 'legit_1'
       expect { click_button "Save" }.to change { Project.count }.by(1)
       @project = Project.last
     end
index 329f0a5..2825a6a 100644 (file)
@@ -39,7 +39,7 @@ describe "Projects" do
       visit new_project_path
       fill_in 'Name', :with => 'NewProject'
       fill_in 'Code', :with => 'NPR'
-      fill_in 'Path', :with => '/tmp/legit_test/legit'
+      fill_in 'Path', :with => 'newproject'
       expect { click_button "Create Project" }.to change { Project.count }.by(1)
       @project = Project.last
     end