diff --git a/spec/models/cost_entry_spec.rb b/spec/models/cost_entry_spec.rb index a6dfbb6716..5b4cdd11be 100644 --- a/spec/models/cost_entry_spec.rb +++ b/spec/models/cost_entry_spec.rb @@ -79,5 +79,17 @@ describe CostEntry do @example.reload @example.costs.should == rates("cheap_five").rate end + + it "should be able to change order of rates (sorted by valid_from)" do + cheap_one = rates("cheap_one") + cheap_three = rates("cheap_three") + @example.spent_on = cheap_one.valid_from + @example.save! + @example.rate.should == cheap_one + cheap_one.valid_from = cheap_three.valid_from - 1.day + cheap_one.save! + @example.reload + @example.rate.should == cheap_three + end end \ No newline at end of file diff --git a/spec/models/time_entry_spec.rb b/spec/models/time_entry_spec.rb index e118c52c1e..26e1dbbb8a 100644 --- a/spec/models/time_entry_spec.rb +++ b/spec/models/time_entry_spec.rb @@ -42,7 +42,7 @@ describe TimeEntry do @example.save! @example.costs.should == rates("hourly_one").rate hourly = HourlyRate.create! :valid_from => 1.day.ago, :rate => 1.0, - :user => User.current, :project => rates("hourly_one").project + :user => User.current, :project => rates("hourly_one").project @example.reload @example.rate.should_not == rates("hourly_one") @example.costs.should == hourly.rate @@ -55,7 +55,7 @@ describe TimeEntry do @example.save! @example.costs.should == rates("hourly_three").rate hourly = HourlyRate.create! :valid_from => 3.days.ago.to_date, :rate => 1.0, - :user => User.current, :project => rates("hourly_one").project + :user => User.current, :project => rates("hourly_one").project @example.reload @example.rate.should_not == rates("hourly_three") @example.costs.should == hourly.rate @@ -84,6 +84,18 @@ describe TimeEntry do @example.costs.should == rates("hourly_five").rate end + it "should be able to change order of rates (sorted by valid_from)" do + hourly_one = rates("hourly_one") + hourly_three = rates("hourly_three") + @example.spent_on = hourly_one.valid_from + @example.save! + @example.rate.should == hourly_one + hourly_one.valid_from = hourly_three.valid_from - 1.day + hourly_one.save! + @example.reload + @example.rate.should == hourly_three + end + end describe "default rate" do @@ -142,12 +154,12 @@ describe TimeEntry do @default_example.reload @default_example.costs.should == rates("default_hourly_five").rate end - + it "shoud be able to switch between default hourly rate and hourly rate" do user = users("john") @default_example.rate.should == rates("default_hourly_one") rate = HourlyRate.create! :valid_from => 10.days.ago.to_date, :rate => 1337.0, :user => user, - :project => rates("hourly_one").project + :project => rates("hourly_one").project @default_example.reload @default_example.rate.should == rate rate.destroy