diff --git a/spec/lib/rate_time_entry_patch_spec.rb b/spec/lib/rate_time_entry_patch_spec.rb deleted file mode 100644 index 56469fd..0000000 --- a/spec/lib/rate_time_entry_patch_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' - -describe TimeEntry, 'cost' do - before(:each) do - @user = mock_model(User) - @project = mock_model(Project) - @date = Date.today.to_s - @time_entry = TimeEntry.new({:user => @user, :project => @project, :spent_on => @date, :hours => 10.0}) - end - - it 'should return 0.0 if there are no rates for the user' do - Rate.should_receive(:amount_for).with(@user, @project, @date).and_return(nil) - @time_entry.cost.should eql(0.0) - end - - describe 'should return the product of hours by' do - it 'the results of Rate.amount_for' do - Rate.should_receive(:amount_for).with(@user, @project, @date).and_return(200.0) - @time_entry.cost.should eql(200.0 * @time_entry.hours) - end - - it 'the assigned rate' do - rate = mock_model(Rate, :amount => 100.0) - @time_entry.should_receive(:rate).at_least(:twice).and_return(rate) - @time_entry.cost.should eql(rate.amount * @time_entry.hours) - end - - end -end diff --git a/test/unit/lib/rate_time_entry_patch_test.rb b/test/unit/lib/rate_time_entry_patch_test.rb new file mode 100644 index 0000000..1945ac7 --- /dev/null +++ b/test/unit/lib/rate_time_entry_patch_test.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class RateTimeEntryPatchTest < ActiveSupport::TestCase + def setup + @user = User.generate! + @project = Project.generate! + @date = Date.today.to_s + @time_entry = TimeEntry.new({:user => @user, :project => @project, :spent_on => @date, :hours => 10.0}) + end + + should 'should return 0.0 if there are no rates for the user' do + assert_equal 0.0, @time_entry.cost + end + + context 'should return the product of hours by' do + should 'the results of Rate.amount_for' do + Rate.generate!(:user => @user, :project => @project, :date_in_effect => @date, :amount => 200.0) + assert_equal((200.0 * @time_entry.hours), @time_entry.cost) + end + + should 'the assigned rate' do + rate = Rate.generate!(:user => @user, :project => @project, :date_in_effect => @date, :amount => 100.0) + @time_entry.rate = rate + assert_equal rate.amount * @time_entry.hours, @time_entry.cost + end + + end + +end