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]