Permalink
Browse files

Add number validation

Closes #65
  • Loading branch information...
1 parent 7721d8d commit 9247941d1f92f0dfc44094a3368c7c1595aaad78 @potomak potomak committed Nov 29, 2012
Showing with 8 additions and 4 deletions.
  1. +5 −3 app/models/project.rb
  2. +2 −0 app/models/user.rb
  3. +1 −1 app/views/projects/show.html.erb
View
@@ -13,13 +13,15 @@ class Project
belongs_to :user
validates_presence_of :name
+ validates_numericality_of :money_budget, greater_than: 0, allow_blank: true
+ validates_numericality_of :time_budget, greater_than: 0, allow_blank: true
def estimated_work_time
- (time_budget*60*60 * Workable::WORK_TIME_FACTOR if time_budget).to_i
+ (time_budget.to_i*60*60 * Workable::WORK_TIME_FACTOR if time_budget).to_i
end
def estimated_hourly_rate
- money_budget / (estimated_work_time/60/60).to_f if money_budget && estimated_work_time
+ money_budget.to_f / (estimated_work_time/60/60).to_f if money_budget && estimated_work_time
end
def any_of_conditions
@@ -31,7 +33,7 @@ def tomatoes
end
def effective_hourly_rate
- money_budget.to_f / effective_work_time*60*60 if money_budget
+ money_budget.to_f / (effective_work_time*60*60).to_f if money_budget
end
def hourly_rate_delta
View
@@ -41,6 +41,8 @@ class User
validate :color_update_grant, :unless => Proc.new { read_attribute(:color).nil? }
validates_inclusion_of :currency, :in => CURRENCIES.keys
+ validates_numericality_of :work_hours_per_day, greater_than: 0, allow_blank: true
+ validates_numericality_of :average_hourly_rate, greater_than: 0, allow_blank: true
embeds_many :authorizations
has_many :tomatoes
@@ -52,7 +52,7 @@
<% end %>
<% if @project.effective_work_time && @project.estimated_work_time %>
- <%= render partial: 'shared/counter', locals: {css_class: "delta #{@project.work_time_delta > 0 ? 'red' : 'green'}", value: "#{@project.work_time_delta > 0 ? '+' : '-'} #{distance_of_time_in_words(@project.work_time_delta)}", label: 'Effective/estimated work time'} %>
+ <%= render partial: 'shared/counter', locals: {css_class: "delta #{@project.work_time_delta > 0 ? 'red' : 'green'}", value: "#{@project.work_time_delta > 0 ? '+' : '-'} #{distance_of_time_in_words(@project.work_time_delta.abs)}", label: 'Effective/estimated work time'} %>
<% else %>
<%= render partial: 'shared/counter', locals: {css_class: nil, value: 'n/a', label: 'Effective/estimated work time'} %>
<% end %>

0 comments on commit 9247941

Please sign in to comment.