summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-08-29 17:07:28 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-08-29 17:07:28 +0000
commitc8b3c8dfec4c768658be5482234c7a05808e6963 (patch)
tree16862470de00f6ce378d9303eb82cb37c1dd3ab0
parent603e11d7a5aa62f923e7b013cac6c66462131232 (diff)
downloadredmine-c8b3c8dfec4c768658be5482234c7a05808e6963.tar.gz
redmine-c8b3c8dfec4c768658be5482234c7a05808e6963.zip
Fix: error when posting to projects/add or users/add with no custom_fields parameter.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@675 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/projects_controller.rb2
-rw-r--r--app/controllers/users_controller.rb2
-rw-r--r--app/models/custom_value.rb2
-rw-r--r--test/integration/admin_test.rb6
4 files changed, 8 insertions, 4 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 2f5e24e28..6922c98ba 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -72,7 +72,7 @@ class ProjectsController < ApplicationController
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
else
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
- @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
+ @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
@project.custom_values = @custom_values
if params[:repository_enabled] && params[:repository_enabled] == "1"
@project.repository = Repository.factory(params[:repository_scm])
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 7e3abc75c..85579820f 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -58,7 +58,7 @@ class UsersController < ApplicationController
@user.admin = params[:user][:admin] || false
@user.login = params[:user][:login]
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
- @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
+ @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
@user.custom_values = @custom_values
if @user.save
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index e12c14376..6cc4d16bf 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -21,7 +21,7 @@ class CustomValue < ActiveRecord::Base
protected
def validate
- errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.empty?
+ errors.add(:value, :activerecord_error_blank) and return if custom_field.is_required? and value.blank?
errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
diff --git a/test/integration/admin_test.rb b/test/integration/admin_test.rb
index c51dc1bf1..a424247cc 100644
--- a/test/integration/admin_test.rb
+++ b/test/integration/admin_test.rb
@@ -45,7 +45,11 @@ class AdminTest < ActionController::IntegrationTest
get "projects/add"
assert_response :success
assert_template "projects/add"
- post "projects/add", :project => { :name => "blog", :description => "weblog", :identifier => "blog", :is_public => 1}
+ post "projects/add", :project => { :name => "blog",
+ :description => "weblog",
+ :identifier => "blog",
+ :is_public => 1 },
+ 'custom_fields[3]' => 'Beta'
assert_redirected_to "admin/projects"
assert_equal 'Successful creation.', flash[:notice]