|
8 | 8 | it { is_expected.to have_many :recommendations }
|
9 | 9 | it { is_expected.to have_many :users }
|
10 | 10 | it { is_expected.to have_many :measures }
|
11 |
| - it { is_expected.to have_many :indicators } |
12 |
| - it { is_expected.to have_many :progress_reports } |
13 |
| - it { is_expected.to have_many :due_dates } |
14 | 11 | it { is_expected.to have_many :categories }
|
15 |
| - it { is_expected.to have_many :children_due_dates } |
16 | 12 |
|
17 | 13 | context "Sub-relation validations" do
|
18 | 14 | it "will not allow guest users to be assigned" do
|
|
85 | 81 | expect { sub_category.save! }.to raise_exception(/Validation failed: Parent Taxonomy does not have parent category's taxonomy as parent./)
|
86 | 82 | end
|
87 | 83 | end
|
| 84 | + |
| 85 | + describe "indicators" do |
| 86 | + subject { FactoryBot.create(:category) } |
| 87 | + |
| 88 | + let(:indicator_traits) { [] } |
| 89 | + |
| 90 | + let(:child_taxonomy) { FactoryBot.create(:taxonomy, parent_id: subject.taxonomy.id) } |
| 91 | + let(:child_category) { FactoryBot.create(:category, parent_id: subject.id, title: "Child Category", taxonomy: child_taxonomy) } |
| 92 | + |
| 93 | + let(:first_recommendation) { FactoryBot.create(:recommendation, title: "First Recommendation") } |
| 94 | + let(:second_recommendation) { FactoryBot.create(:recommendation, title: "Second Recommendation") } |
| 95 | + let(:child_category_recommendation) { FactoryBot.create(:recommendation, title: "Child Category Recommendation") } |
| 96 | + |
| 97 | + let(:first_direct_indicator) { FactoryBot.create(:indicator, *indicator_traits, title: "First Direct Indicator") } |
| 98 | + let(:second_direct_indicator) { FactoryBot.create(:indicator, *indicator_traits, title: "Second Direct Indicator") } |
| 99 | + let(:third_direct_indicator) { FactoryBot.create(:indicator, *indicator_traits, title: "Second Direct Indicator") } |
| 100 | + |
| 101 | + let(:indicator_via_first_measure) { FactoryBot.create(:indicator, *indicator_traits, title: "Indicator via First Measure") } |
| 102 | + let(:indicator_via_second_measure) { FactoryBot.create(:indicator, *indicator_traits, title: "Indicator via Second Measure") } |
| 103 | + |
| 104 | + let(:first_shared_indicator) { FactoryBot.create(:indicator, *indicator_traits, title: "First Shared Indicator") } |
| 105 | + let(:second_shared_indicator) { FactoryBot.create(:indicator, *indicator_traits, title: "Second Shared Indicator") } |
| 106 | + |
| 107 | + let(:first_measure) { FactoryBot.create(:measure) } |
| 108 | + let(:second_measure) { FactoryBot.create(:measure) } |
| 109 | + |
| 110 | + let(:all_unique_indicators) do |
| 111 | + [ |
| 112 | + first_direct_indicator, |
| 113 | + second_direct_indicator, |
| 114 | + third_direct_indicator, |
| 115 | + indicator_via_first_measure, |
| 116 | + indicator_via_second_measure, |
| 117 | + first_shared_indicator, |
| 118 | + second_shared_indicator |
| 119 | + ] |
| 120 | + end |
| 121 | + |
| 122 | + before do |
| 123 | + # Create direct indicators: two for the first recommendation, one for the second, and one for the child category recommendation |
| 124 | + FactoryBot.create(:recommendation_indicator, recommendation: first_recommendation, indicator: first_direct_indicator) |
| 125 | + FactoryBot.create(:recommendation_indicator, recommendation: first_recommendation, indicator: second_direct_indicator) |
| 126 | + |
| 127 | + FactoryBot.create(:recommendation_indicator, recommendation: second_recommendation, indicator: second_direct_indicator) |
| 128 | + |
| 129 | + FactoryBot.create(:recommendation_indicator, recommendation: child_category_recommendation, indicator: third_direct_indicator) |
| 130 | + |
| 131 | + # Create indicators via measures |
| 132 | + FactoryBot.create(:measure_indicator, measure: first_measure, indicator: indicator_via_first_measure) |
| 133 | + FactoryBot.create(:measure_indicator, measure: second_measure, indicator: indicator_via_second_measure) |
| 134 | + |
| 135 | + # Associate measures with the recommendation: one for the first recommendation, two for the second, and one for the child category recommendation |
| 136 | + FactoryBot.create(:recommendation_measure, recommendation: first_recommendation, measure: first_measure) |
| 137 | + |
| 138 | + FactoryBot.create(:recommendation_measure, recommendation: second_recommendation, measure: first_measure) |
| 139 | + FactoryBot.create(:recommendation_measure, recommendation: second_recommendation, measure: second_measure) |
| 140 | + |
| 141 | + FactoryBot.create(:recommendation_measure, recommendation: child_category_recommendation, measure: second_measure) |
| 142 | + |
| 143 | + # Create shared indicators: both linked to every recommendation |
| 144 | + FactoryBot.create(:measure_indicator, measure: first_measure, indicator: first_shared_indicator) |
| 145 | + FactoryBot.create(:recommendation_indicator, recommendation: first_recommendation, indicator: first_shared_indicator) |
| 146 | + FactoryBot.create(:recommendation_indicator, recommendation: second_recommendation, indicator: first_shared_indicator) |
| 147 | + FactoryBot.create(:recommendation_indicator, recommendation: child_category_recommendation, indicator: first_shared_indicator) |
| 148 | + |
| 149 | + FactoryBot.create(:measure_indicator, measure: second_measure, indicator: second_shared_indicator) |
| 150 | + FactoryBot.create(:recommendation_indicator, recommendation: first_recommendation, indicator: second_shared_indicator) |
| 151 | + FactoryBot.create(:recommendation_indicator, recommendation: second_recommendation, indicator: second_shared_indicator) |
| 152 | + FactoryBot.create(:recommendation_indicator, recommendation: child_category_recommendation, indicator: second_shared_indicator) |
| 153 | + |
| 154 | + # Associate recommendations to the category |
| 155 | + FactoryBot.create(:recommendation_category, recommendation: first_recommendation, category: subject) |
| 156 | + FactoryBot.create(:recommendation_category, recommendation: second_recommendation, category: subject) |
| 157 | + |
| 158 | + # Associate child category |
| 159 | + FactoryBot.create(:recommendation_category, recommendation: child_category_recommendation, category: child_category) |
| 160 | + end |
| 161 | + |
| 162 | + describe "#combined_indicator_ids" do |
| 163 | + it "contains the IDs of all distinct indicators from recommendations and the recommendations of child categories" do |
| 164 | + expect(subject.combined_indicator_ids).not_to be_empty |
| 165 | + expect(subject.combined_indicator_ids).to match_array(all_unique_indicators.map(&:id)) |
| 166 | + end |
| 167 | + end |
| 168 | + |
| 169 | + describe "#due_dates" do |
| 170 | + let(:indicator_traits) { [:with_12_due_dates] } |
| 171 | + |
| 172 | + it "contains the due dates for all distinct indicators from recommendations and the recommendations of child categories" do |
| 173 | + expect(subject.due_dates.to_a).not_to be_empty |
| 174 | + expect(subject.due_dates.to_a).to match_array(all_unique_indicators.flat_map(&:due_dates)) |
| 175 | + end |
| 176 | + end |
| 177 | + end |
88 | 178 | end
|
0 commit comments