Commit c8b3c8df authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

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
parent 603e11d7
......@@ -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])
......
......@@ -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]
......
......@@ -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
......
......@@ -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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment