summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/project.rb8
-rw-r--r--test/functional/projects_controller_test.rb9
-rw-r--r--test/unit/project_test.rb6
3 files changed, 21 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 25f0d3fc5..2138773cf 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -332,8 +332,12 @@ class Project < ActiveRecord::Base
end
def to_param
- # id is used for projects with a numeric identifier (compatibility)
- @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id.to_s : identifier)
+ if new_record?
+ nil
+ else
+ # id is used for projects with a numeric identifier (compatibility)
+ @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id.to_s : identifier)
+ end
end
def active?
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 2efb98ccd..0bf3cf9a5 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -118,6 +118,15 @@ class ProjectsControllerTest < ActionController::TestCase
end
end
+ def test_new_should_not_display_invalid_search_link
+ @request.session[:user_id] = 1
+
+ get :new
+ assert_response :success
+ assert_select '#quick-search form[action=?]', '/search'
+ assert_select '#quick-search a[href=?]', '/search'
+ end
+
test "#create by admin user should create a new project" do
@request.session[:user_id] = 1
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index c76272e7b..ffb514aa3 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -142,6 +142,12 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal true, Project.find(1).identifier_frozen?
end
+ def test_to_param_should_be_nil_for_new_records
+ project = Project.new
+ project.identifier = "foo"
+ assert_nil project.to_param
+ end
+
def test_members_should_be_active_users
Project.all.each do |project|
assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }