diff options
Diffstat (limited to 'script12.rb')
| -rw-r--r-- | script12.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/script12.rb b/script12.rb new file mode 100644 index 0000000..659557c --- /dev/null +++ b/script12.rb | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | require 'timeout' | ||
| 2 | |||
| 3 | a = Node.root.children.create!(:slug => "cycle_test_a") | ||
| 4 | b = a.children.create!(:slug => "cycle_test_b") | ||
| 5 | |||
| 6 | a.staged_parent_id = b.id | ||
| 7 | a.publish_draft! | ||
| 8 | a.reload | ||
| 9 | |||
| 10 | puts "a.parent_id after staging a under its own child b: #{a.parent_id.inspect} (b.id = #{b.id})" | ||
| 11 | puts "Node.valid? => #{Node.valid?}" | ||
| 12 | |||
| 13 | begin | ||
| 14 | Timeout.timeout(3) { puts "a.level => #{a.level}" } | ||
| 15 | rescue Timeout::Error | ||
| 16 | puts "TIMED OUT after 3s -- a real cycle and a real infinite loop, confirmed" | ||
| 17 | end | ||
| 18 | |||
| 19 | # Break any cycle before cleanup -- delete_descendants does its own BFS | ||
| 20 | # the same way #level does, and would hang on a real cycle too. | ||
| 21 | Node.where(id: a.id).update_all(parent_id: nil) | ||
| 22 | b.destroy | ||
| 23 | a.destroy | ||
