Require that a Rate be unlocked before saving it. #1919
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user