File: test_dirty.rb

package info (click to toggle)
ruby-activeldap 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,588 kB
  • sloc: ruby: 18,143; sh: 12; makefile: 5
file content (98 lines) | stat: -rw-r--r-- 2,394 bytes parent folder | download | duplicates (4)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'al-test-utils'

class TestDirty < Test::Unit::TestCase
  include AlTestUtils

  priority :must

  priority :normal
  def test_clean_after_load
    make_temporary_user do |user, password|
      attributes = (user.must + user.may).collect(&:name) - ['objectClass']
      _wrap_assertion do
        attributes.each do |name|
          assert_false(user.send("#{name}_changed?"))
        end
      end
    end
  end

  def test_clean_after_reload
    make_temporary_user do |user, password|
      attributes = (user.must + user.may).collect(&:name) - ['objectClass']

      user.cn = 'New cn'
      assert_true(user.cn_changed?)
      user.reload
      assert_false(user.cn_changed?)

      _wrap_assertion do
        attributes.each do |name|
          assert_false(user.send("#{name}_changed?"))
        end
      end
    end
  end

  def test_setter
    make_temporary_user do |user, password|
      attributes = (user.must + user.may).collect(&:name) - ['objectClass', 'cn']
      user.cn = 'New cn'
      assert_true(user.cn_changed?)

      _wrap_assertion do
        (attributes - ['cn']).each do |name|
          assert_false(user.send("#{name}_changed?"))
        end

        assert_true(user.cn_changed?)
      end
    end
  end

  def test_save
    make_temporary_user do |user, password|
      attributes = (user.must + user.may).collect(&:name) - ['objectClass', 'cn']
      user.cn = 'New cn'
      assert_true(user.cn_changed?)
      user.save
      assert_false(user.cn_changed?)

      _wrap_assertion do
        attributes.each do |name|
          assert_false(user.send("#{name}_changed?"))
        end
      end
    end
  end

  def test_save!
    make_temporary_user do |user, password|
      attributes = (user.must + user.may).collect(&:name) - ['objectClass', 'cn']
      user.cn = 'New cn'
      assert_true(user.cn_changed?)
      user.save!
      assert_false(user.cn_changed?)

      _wrap_assertion do
        attributes.each do |name|
          assert_false(user.send("#{name}_changed?"))
        end
      end
    end
  end

  class TestDNChange
    def test_direct_base_use
      leaf = ActiveLdap::Base.create
      leaf.add_class("organizationalUnit")
      leaf_dn = "ou=addressbook,#{user.dn}"
      leaf.dn = leaf_dn
      begin
        leaf.save
      ensure
        ActiveLdap::Base.delete_entry(leaf_dn) if leaf.exists?
      end
    end
  end
end