Converted RateTimeEntryPatch test to Test::Unit.

This commit is contained in:
Eric Davis
2010-07-23 08:14:22 -07:00
parent 22cbcdf847
commit 0c3d83fe62
2 changed files with 29 additions and 29 deletions

View File

@@ -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

View File

@@ -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