Add pending test for the great-grandparent touching bug from #19324

This commit is contained in:
David Heinemeier Hansson 2015-06-25 14:23:06 +02:00
parent 41568f8c07
commit 5f5e6d9249
6 changed files with 72 additions and 0 deletions

View File

@ -2,8 +2,11 @@ require 'cases/helper'
require 'models/invoice'
require 'models/line_item'
require 'models/topic'
require 'models/node'
require 'models/tree'
class TouchLaterTest < ActiveRecord::TestCase
fixtures :nodes, :trees
def test_touch_laster_raise_if_non_persisted
invoice = Invoice.new
@ -90,4 +93,22 @@ class TouchLaterTest < ActiveRecord::TestCase
invoice.touch_later
end
end
def test_touching_three_deep
skip "Pending from #19324"
previous_tree_updated_at = trees(:root).updated_at
previous_grandparent_updated_at = nodes(:grandparent).updated_at
previous_parent_updated_at = nodes(:parent_a).updated_at
previous_child_updated_at = nodes(:child_one_of_a).updated_at
travel 5.seconds
Node.create! parent: nodes(:child_one_of_a), tree: trees(:root)
assert_not_equal nodes(:child_one_of_a).reload.updated_at, previous_child_updated_at
assert_not_equal nodes(:parent_a).reload.updated_at, previous_parent_updated_at
assert_not_equal nodes(:grandparent).reload.updated_at, previous_grandparent_updated_at
assert_not_equal trees(:root).reload.updated_at, previous_tree_updated_at
end
end

29
activerecord/test/fixtures/nodes.yml vendored Normal file
View File

@ -0,0 +1,29 @@
grandparent:
id: 1
tree_id: 1
name: Grand Parent
parent_a:
id: 2
tree_id: 1
parent_id: 1
name: Parent A
parent_b:
id: 3
tree_id: 1
parent_id: 1
name: Parent B
child_one_of_a:
id: 4
tree_id: 1
parent_id: 2
name: Child one
child_two_of_b:
id: 5
tree_id: 1
parent_id: 2
name: Child two

3
activerecord/test/fixtures/trees.yml vendored Normal file
View File

@ -0,0 +1,3 @@
root:
id: 1
name: The Root

View File

@ -0,0 +1,5 @@
class Node < ActiveRecord::Base
belongs_to :tree, touch: true
belongs_to :parent, class_name: 'Node', touch: true, optional: true
has_many :children, class_name: 'Node', foreign_key: :parent_id, dependent: :destroy
end

View File

@ -0,0 +1,3 @@
class Tree < ActiveRecord::Base
has_many :nodes, dependent: :destroy
end

View File

@ -867,6 +867,17 @@ ActiveRecord::Schema.define do
t.string 'from'
end
create_table :nodes, force: true do |t|
t.integer :tree_id
t.integer :parent_id
t.string :name
t.datetime :updated_at
end
create_table :trees, force: true do |t|
t.string :name
t.datetime :updated_at
end
create_table :hotels, force: true do |t|
end
create_table :departments, force: true do |t|