File: test_no_update_for_scope_destruction.rb

package info (click to toggle)
ruby-acts-as-list 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 388 kB
  • sloc: ruby: 2,493; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 2,164 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'helper'

class DestructionTodoList < ActiveRecord::Base
  has_many :destruction_todo_items, dependent: :destroy
  has_many :destruction_tada_items, dependent: :destroy
end

class DestructionTodoItem < ActiveRecord::Base
  belongs_to :destruction_todo_list
  acts_as_list scope: :destruction_todo_list
end

class DestructionTadaItem < ActiveRecord::Base
  belongs_to :destruction_todo_list
  acts_as_list scope: [:destruction_todo_list_id, :enabled]
end

class NoUpdateForScopeDestructionTestCase < Minitest::Test
  def setup
    ActiveRecord::Base.connection.create_table :destruction_todo_lists do |t|
    end

    ActiveRecord::Base.connection.create_table :destruction_todo_items do |t|
      t.column :position, :integer
      t.column :destruction_todo_list_id, :integer
    end

    ActiveRecord::Base.connection.create_table :destruction_tada_items do |t|
      t.column :position, :integer
      t.column :destruction_todo_list_id, :integer
      t.column :enabled, :boolean
    end

    ActiveRecord::Base.connection.schema_cache.clear!
    [DestructionTodoList, DestructionTodoItem, DestructionTadaItem].each(&:reset_column_information)
    super
  end

  def teardown
    teardown_db
    super
  end

  class NoUpdateForScopeDestructionTest < NoUpdateForScopeDestructionTestCase
    def setup
      super
      @list = DestructionTodoList.create!

      @todo_item_1 = DestructionTodoItem.create! position: 1, destruction_todo_list_id: @list.id
      @tada_item_1 = DestructionTadaItem.create! position: 1, destruction_todo_list_id: @list.id, enabled: true
    end

    def test_no_update_children_when_parent_destroyed
      DestructionTodoItem.any_instance.expects(:decrement_positions_on_lower_items).never
      DestructionTadaItem.any_instance.expects(:decrement_positions_on_lower_items).never
      assert @list.destroy
    end

    def test_update_children_when_sibling_destroyed
      @todo_item_1.expects(:decrement_positions_on_lower_items).once
      @tada_item_1.expects(:decrement_positions_on_lower_items).once
      assert @todo_item_1.destroy
      assert @tada_item_1.destroy
    end

  end
end