|
71 | 71 | create(:condition, routing_page_id: pages.first.id, answer_value: "Yes", goto_page_id: pages.second.id) |
72 | 72 | end |
73 | 73 |
|
| 74 | + # Create a condition that shouldn't be removed |
| 75 | + let!(:healthy_condition) do |
| 76 | + create(:condition, routing_page_id: pages.second.id, answer_value: "Yes", goto_page_id: pages.third.id) |
| 77 | + end |
| 78 | + |
74 | 79 | # Provide a route that matches the stale condition's key, but is now a "default" route. |
75 | 80 | let(:routes) do |
76 | 81 | [ |
| 82 | + # Route for the first page, which is default so conditions are removed |
77 | 83 | build(:route_input, :default, page: pages.first, answer_value: "Yes"), |
| 84 | + # Two routes for the second page, which should not be removed |
| 85 | + build(:route_input, page: pages.second, goto: pages.third.id, answer_value: "Yes"), |
| 86 | + # This is default but has no conditions to remove |
| 87 | + build(:route_input, :default, page: pages.second, answer_value: "No"), |
78 | 88 | ] |
79 | 89 | end |
80 | 90 |
|
81 | 91 | it "destroys the condition that is now a default route" do |
82 | 92 | expect { service.sync_conditions_from_routes }.to change(Condition, :count).by(-1) |
83 | 93 | expect(Condition.exists?(stale_condition.id)).to be false |
84 | 94 | end |
| 95 | + |
| 96 | + it "does not destroy other page's conditions with the same answer value" do |
| 97 | + service.sync_conditions_from_routes |
| 98 | + expect(Condition.exists?(healthy_condition.id)).to be true |
| 99 | + end |
85 | 100 | end |
86 | 101 |
|
87 | 102 | context "with an answer_value of an empty string" do |
|
0 commit comments