-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathtest_simple_model.rb
More file actions
92 lines (78 loc) · 2.69 KB
/
test_simple_model.rb
File metadata and controls
92 lines (78 loc) · 2.69 KB
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
require 'test_helper'
require '01_simple_model'
require 'securerandom'
class TestSimpleModel < Minitest::Test
class Product
include SimpleModel
attr_accessor :name, :description
end
def test_accessor
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
assert_equal 'SmarterHR', obj.name
assert_equal 'more smart SmartHR', obj.description
end
def test_writer
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
obj.name = 'Ultra SmarterHR'
obj.description = 'more smart SmarterHR'
assert_equal 'Ultra SmarterHR', obj.name
assert_equal 'more smart SmarterHR', obj.description
end
def test_watching_not_changes_attrs
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
assert_equal false, obj.changed?
end
def test_watching_changes_attrs
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
obj.name = 'SuperSmarterHR'
assert_equal true, obj.changed?
end
def test_watching_changes_each_attrs
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
obj.name = 'SuperSmarterHR'
assert_equal true, obj.name_changed?
assert_equal false, obj.description_changed?
end
def test_restore_changes
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
obj.name = 'Ultra SmarterHR'
obj.description = 'more smart SmarterHR'
obj.restore!
assert_equal 'SmarterHR', obj.name
assert_equal 'more smart SmartHR', obj.description
assert_equal false, obj.changed?
end
def test_random_read
name = SecureRandom.hex
desc = SecureRandom.hex
obj = Product.new(name: name, description: desc)
assert_equal name, obj.name
assert_equal desc, obj.description
end
def test_random_write
name = SecureRandom.hex
desc = SecureRandom.hex
obj = Product.new(name: 'SmarterHR', description: 'more smart SmartHR')
obj.name = name
obj.description = desc
assert_equal name, obj.name
assert_equal desc, obj.description
end
class MultipleAccessorsProduct
include SimpleModel
attr_accessor :name
attr_accessor :description
end
def test_multiple_accessors
obj = MultipleAccessorsProduct.new(name: 'SmarterHR', description: 'more smart SmartHR')
assert_equal 'SmarterHR', obj.name
assert_equal 'more smart SmartHR', obj.description
end
def test_multiple_accessors_writer
obj = MultipleAccessorsProduct.new(name: 'SmarterHR', description: 'more smart SmartHR')
obj.name = 'Ultra SmarterHR'
obj.description = 'more smart SmarterHR'
assert_equal 'Ultra SmarterHR', obj.name
assert_equal 'more smart SmarterHR', obj.description
end
end