|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe BillReport, :type => :presenter do |
4 | | - let :billable_projects do |
5 | | - FactoryGirl.create_list(:project, 3, :billable => true) |
6 | | - end |
| 4 | + describe "with a mix of project types" do |
| 5 | + let :billable_projects do |
| 6 | + FactoryGirl.create_list(:project, 3, :billable => true) |
| 7 | + end |
7 | 8 |
|
8 | | - let :unbillable_projects do |
9 | | - FactoryGirl.create_list(:project, 3, :billable => false) |
10 | | - end |
| 9 | + let :unbillable_projects do |
| 10 | + FactoryGirl.create_list(:project, 3, :billable => false) |
| 11 | + end |
11 | 12 |
|
12 | | - let :unclockable_projects do |
13 | | - FactoryGirl.create_list(:project, 2, :billable => false, :clockable => false) |
14 | | - end |
| 13 | + let :unclockable_projects do |
| 14 | + FactoryGirl.create_list(:project, 2, :billable => false, :clockable => false) |
| 15 | + end |
15 | 16 |
|
16 | | - let :clockable_projects do |
17 | | - billable_projects + unbillable_projects |
18 | | - end |
| 17 | + let :clockable_projects do |
| 18 | + billable_projects + unbillable_projects |
| 19 | + end |
19 | 20 |
|
20 | | - let :projects do |
21 | | - (clockable_projects + unclockable_projects).shuffle |
22 | | - end |
| 21 | + let :projects do |
| 22 | + (clockable_projects + unclockable_projects).shuffle |
| 23 | + end |
23 | 24 |
|
24 | | - let :bill do |
25 | | - FactoryGirl.create(:bill) |
26 | | - end |
| 25 | + let :bill do |
| 26 | + FactoryGirl.create(:bill) |
| 27 | + end |
27 | 28 |
|
28 | | - let :unbillable_wus do |
29 | | - (1..17).zip(projects.cycle).map do |num, project| |
30 | | - FactoryGirl.create(:work_unit, :billable => false, :hours => 1, :project => project, :bill => bill) |
| 29 | + let :unbillable_wus do |
| 30 | + (1..17).zip(projects.cycle).map do |num, project| |
| 31 | + FactoryGirl.create(:work_unit, :billable => false, :hours => 1, :project => project, :bill => bill) |
| 32 | + end |
31 | 33 | end |
32 | | - end |
33 | 34 |
|
34 | | - let :billable_wus do |
35 | | - (1..17).zip(projects.cycle).map do |num, project| |
36 | | - FactoryGirl.create(:work_unit, :billable => true, :hours => 1, :project => project, :bill => bill) |
| 35 | + let :billable_wus do |
| 36 | + (1..17).zip(projects.cycle).map do |num, project| |
| 37 | + FactoryGirl.create(:work_unit, :billable => true, :hours => 1, :project => project, :bill => bill) |
| 38 | + end |
37 | 39 | end |
38 | | - end |
39 | 40 |
|
40 | | - let :billable_clockable do |
41 | | - billable_wus.find_all do |wu| |
42 | | - wu.project.clockable? |
| 41 | + let :billable_clockable do |
| 42 | + billable_wus.find_all do |wu| |
| 43 | + wu.project.clockable? |
| 44 | + end |
43 | 45 | end |
44 | | - end |
45 | 46 |
|
46 | | - let! :work_units do |
47 | | - unbillable_wus + billable_wus |
48 | | - end |
| 47 | + let! :work_units do |
| 48 | + unbillable_wus + billable_wus |
| 49 | + end |
49 | 50 |
|
50 | | - let :total_billable_hours do |
51 | | - billable_wus.inject(0) do |total, wu| |
52 | | - total + wu.hours |
| 51 | + let :total_billable_hours do |
| 52 | + billable_wus.inject(0) do |total, wu| |
| 53 | + total + wu.hours |
| 54 | + end |
53 | 55 | end |
54 | | - end |
55 | 56 |
|
56 | | - subject :bill_report do |
57 | | - BillReport.new(bill) |
58 | | - end |
| 57 | + subject :bill_report do |
| 58 | + BillReport.new(bill) |
| 59 | + end |
59 | 60 |
|
60 | | - it "should total hours consistently" do |
61 | | - expect(bill_report.total_hours).to eql(billable_clockable.length * 1.0) |
62 | | - end |
| 61 | + it "should total hours consistently" do |
| 62 | + expect(bill_report.total_hours).to eql(billable_clockable.length * 1.0) |
| 63 | + end |
| 64 | + |
| 65 | + it "should have all the projects in #projects_and_hours" do |
| 66 | + expect(bill_report.projects_and_hours.length).to eql(clockable_projects.length) |
| 67 | + end |
| 68 | + |
| 69 | + it "should have all the billable WUs in #work_units_and_hours" do |
| 70 | + expect(bill_report.work_units_and_hours.length).to eql(billable_clockable.length) |
| 71 | + expect(bill_report.work_units_and_hours.map(&:notes).sort).to eql(billable_clockable.map(&:notes).sort) |
| 72 | + end |
63 | 73 |
|
64 | | - it "should have all the projects in #projects_and_hours" do |
65 | | - expect(bill_report.projects_and_hours.length).to eql(clockable_projects.length) |
66 | 74 | end |
| 75 | + describe "with child projects" do |
| 76 | + |
| 77 | + let! :project do FactoryGirl.create(:project, :name => "Topmost") end |
| 78 | + let! :child_project do FactoryGirl.create(:project, :name => "Middle", :parent_id => project.id) end |
| 79 | + let! :grandchild_project do FactoryGirl.create(:project, :name => "Bottom", :parent_id => child_project.id) end |
| 80 | + let! :bill do FactoryGirl.create(:bill) end |
| 81 | + |
| 82 | + 2.times do |idx| |
| 83 | + let! "project_work_unit_#{idx}" do |
| 84 | + FactoryGirl.create(:work_unit, :project => project, :hours => 2, :bill => bill) |
| 85 | + end |
| 86 | + let! "child_project_work_unit_#{idx}" do |
| 87 | + FactoryGirl.create(:work_unit, :project => child_project, :hours => 4, :bill => bill) |
| 88 | + end |
| 89 | + let! "grandchild_project_work_unit_#{idx}" do |
| 90 | + FactoryGirl.create(:work_unit, :project => grandchild_project, :hours => 6, :bill => bill) |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + subject :bill_report do |
| 95 | + BillReport.new(bill) |
| 96 | + end |
| 97 | + |
| 98 | + it "should total hours consistently" do |
| 99 | + expect(bill_report.total_hours.to_f).to eql((2 * 2 + 2 * 4 + 2 * 6) * 1.0) |
| 100 | + end |
| 101 | + |
| 102 | + it "should not accumulate hours to parent projects" do |
| 103 | + expect(bill_report.projects_and_hours.length).to eql(3) |
| 104 | + expect(bill_report.projects_and_hours.map(&:hours).map(&:to_f)).to include(4.0, 8.0, 12.0) |
| 105 | + end |
| 106 | + |
| 107 | + it "should have all the billable WUs in #work_units_and_hours" do |
| 108 | + expect(bill_report.work_units_and_hours.length).to eql(6) |
| 109 | + end |
67 | 110 |
|
68 | | - it "should have all the billable WUs in #work_units_and_hours" do |
69 | | - expect(bill_report.work_units_and_hours.length).to eql(billable_clockable.length) |
70 | | - expect(bill_report.work_units_and_hours.map(&:notes).sort).to eql(billable_clockable.map(&:notes).sort) |
71 | 111 | end |
72 | 112 |
|
73 | 113 | end |
0 commit comments