File: shared_no_addition.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 (38 lines) | stat: -rw-r--r-- 868 bytes parent folder | download | duplicates (3)
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
# frozen_string_literal: true

module Shared
  module NoAddition
    def setup
      (1..4).each { |counter| NoAdditionMixin.create! pos: counter, parent_id: 5 }
    end

    def test_insert
      new = NoAdditionMixin.create(parent_id: 20)
      assert_nil new.pos
      assert !new.in_list?

      new = NoAdditionMixin.create(parent_id: 20)
      assert_nil new.pos
    end

    def test_update_does_not_add_to_list
      new = NoAdditionMixin.create(parent_id: 20)
      new.update_attribute(:updated_at, Time.now) # force some change
      new.reload

      assert !new.in_list?
    end

    def test_update_scope_does_not_add_to_list
      new = NoAdditionMixin.create

      new.update_attribute(:parent_id, 20)
      new.reload
      assert !new.in_list?

      new.update_attribute(:parent_id, 5)
      new.reload
      assert !new.in_list?
    end
  end
end