Allow project name, path etc start with number. Fixed specs

This commit is contained in:
Dmitriy Zaporozhets 2013-08-13 12:24:10 +03:00
parent a36195bd28
commit 7825830ca5
4 changed files with 11 additions and 10 deletions

View File

@ -73,11 +73,11 @@ class Project < ActiveRecord::Base
validates :description, length: { within: 0..2000 }
validates :name, presence: true, length: { within: 0..255 },
format: { with: Gitlab::Regex.project_name_regex,
message: "only letters, digits, spaces & '_' '-' '.' allowed. Letter should be first" }
message: "only letters, digits, spaces & '_' '-' '.' allowed. Letter or digit should be first" }
validates :path, presence: true, length: { within: 0..255 },
exclusion: { in: Gitlab::Blacklist.path },
format: { with: Gitlab::Regex.path_regex,
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
message: "only letters, digits & '_' '-' '.' allowed. Letter or digit should be first" }
validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, inclusion: { in: [true, false] }
validates :issues_tracker_id, length: { within: 0..255 }

View File

@ -7,7 +7,7 @@ module Gitlab
end
def project_name_regex
/\A[a-zA-Z][a-zA-Z0-9_\-\. ]*\z/
/\A[a-zA-Z0-9][a-zA-Z0-9_\-\. ]*\z/
end
def name_regex
@ -21,7 +21,7 @@ module Gitlab
protected
def default_regex
/\A[a-zA-Z][a-zA-Z0-9_\-\.]*\z/
/\A[a-zA-Z0-9][a-zA-Z0-9_\-\.]*\z/
end
end
end

View File

@ -9,11 +9,11 @@ describe Commit do
commit.title.should == "--no commit message"
end
it "truncates a message without a newline at 70 characters" do
it "truncates a message without a newline at 80 characters" do
message = commit.safe_message * 10
commit.stub(:safe_message).and_return(message)
commit.title.should == "#{message[0..69]}&hellip;"
commit.title.should == "#{message[0..79]}&hellip;"
end
it "truncates a message with a newline before 80 characters at the newline" do
@ -27,7 +27,7 @@ describe Commit do
message = (commit.safe_message * 10) + "\n"
commit.stub(:safe_message).and_return(message)
commit.title.should == "#{message[0..69]}&hellip;"
commit.title.should == "#{message[0..79]}&hellip;"
end
end

View File

@ -68,9 +68,10 @@ describe Project do
it { should ensure_length_of(:issues_tracker_id).is_within(0..255) }
it "should not allow new projects beyond user limits" do
project.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 1))
project.should_not be_valid
project.errors[:limit_reached].first.should match(/Your own projects limit is 1/)
project2 = build(:project)
project2.stub(:creator).and_return(double(can_create_project?: false, projects_limit: 0))
project2.should_not be_valid
project2.errors[:limit_reached].first.should match(/Your own projects limit is 0/)
end
end