Require that a Rate be unlocked before saving it. #1919

This commit is contained in:
Eric Davis
2009-01-16 15:28:34 -08:00
parent 9b0332bf78
commit 3ffb31fafc
2 changed files with 36 additions and 0 deletions
+6
View File
@@ -6,6 +6,8 @@ class Rate < ActiveRecord::Base
validates_presence_of :user_id
validates_presence_of :date_in_effect
before_save :unlocked?
named_scope :history_for_user, lambda { |user|
{
:conditions => { :user_id => user.id },
@@ -16,4 +18,8 @@ class Rate < ActiveRecord::Base
def locked?
return self.time_entries.length > 0
end
def unlocked?
return !self.locked?
end
end
+30
View File
@@ -70,3 +70,33 @@ describe Rate, 'locked?' do
end
end
describe Rate, 'locked?' do
it 'should be false if a Time Entry is associated' do
rate = Rate.new
rate.time_entries << mock_model(TimeEntry)
rate.unlocked?.should be_false
end
it 'should be true if no Time Entries are associated' do
rate = Rate.new
rate.unlocked?.should be_true
end
end
describe Rate, 'save' do
include RateSpecHelper
it 'should save normally if a Rate is not locked' do
rate = Rate.new(rate_valid_attributes)
rate.stub!(:locked?).and_return(false)
rate.save.should eql(true)
end
it 'should not save if a Rate is locked' do
rate = Rate.new(rate_valid_attributes)
rate.stub!(:locked?).and_return(true)
rate.save.should eql(false)
end
end