Permalink
Browse files

wip

  • Loading branch information...
1 parent 545cf91 commit 28bfbfb45f055ca40087d2ab8fde64a3aefece86 @nackd committed with Apr 2, 2012
Showing with 24 additions and 14 deletions.
  1. +11 −6 app/models/cmi_checkpoint.rb
  2. +13 −8 app/models/cmi_project_info.rb
@@ -45,12 +45,17 @@ def init_journal(user, notes = "")
# Role effort validation
def role_effort
User.roles.each do |role|
- if scheduled_role_effort[role] =~ /\A[+-]?\d+\Z/
- scheduled_role_effort[role] = scheduled_role_effort[role].to_i
- elsif !scheduled_role_effort[role].is_a? Integer
- error = [I18n.translate(:"cmi.label_scheduled_role_effort", :role => role),
- I18n.translate(:"activerecord.errors.messages.not_a_number")].join " "
- errors.add_to_base(error)
+ next if scheduled_role_effort.nil?
+ begin
+ scheduled_role_effort[role] = Kernel.Integer scheduled_role_effort[role]
+ rescue ArgumentError
+ begin
+ scheduled_role_effort[role] = Kernel.Float scheduled_role_effort[role]
+ rescue ArgumentError
+ error = [I18n.translate(:"cmi.label_scheduled_role_effort", :role => role),
+ I18n.translate(:"activerecord.errors.messages.not_a_number")].join " "
+ errors.add_to_base(error)
+ end
end
end
end
@@ -3,9 +3,9 @@ class CmiProjectInfo < ActiveRecord::Base
belongs_to :project
- validates_presence_of :project, :group
+ validates_presence_of :project #, :group
- validates_format_of :actual_start_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => false
+ validates_format_of :actual_start_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
validates_format_of :scheduled_start_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => false
validates_format_of :scheduled_finish_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => false
@@ -25,12 +25,17 @@ def scheduled_role_effort
# Role effort validation
def role_effort
User.roles.each do |role|
- if scheduled_role_effort[role] =~ /\A[+-]?\d+\Z/
- scheduled_role_effort[role] = scheduled_role_effort[role].to_i
- elsif !scheduled_role_effort[role].is_a? Integer
- error = [I18n.translate(:"cmi.label_scheduled_role_effort", :role => role),
- I18n.translate(:"activerecord.errors.messages.not_a_number")].join " "
- errors.add_to_base(error)
+ next if scheduled_role_effort.nil?
+ begin
+ scheduled_role_effort[role] = Kernel.Integer scheduled_role_effort[role]
+ rescue ArgumentError
+ begin
+ scheduled_role_effort[role] = Kernel.Float scheduled_role_effort[role]
+ rescue ArgumentError
+ error = [I18n.translate(:"cmi.label_scheduled_role_effort", :role => role),
+ I18n.translate(:"activerecord.errors.messages.not_a_number")].join " "
+ errors.add_to_base(error)
+ end
end
end
end

0 comments on commit 28bfbfb

Please sign in to comment.