yssk22-couch_resource 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +2 -0
- data/MIT_LICENSE +8 -0
- data/README.rdoc +7 -0
- data/lib/couch_resource.rb +25 -0
- data/lib/couch_resource/base.rb +705 -0
- data/lib/couch_resource/callbacks.rb +103 -0
- data/lib/couch_resource/connection.rb +194 -0
- data/lib/couch_resource/error.rb +3 -0
- data/lib/couch_resource/struct.rb +340 -0
- data/lib/couch_resource/validations.rb +520 -0
- data/lib/couch_resource/view.rb +228 -0
- data/test/test_base.rb +384 -0
- data/test/test_callbacks.rb +115 -0
- data/test/test_connection.rb +39 -0
- data/test/test_struct.rb +332 -0
- data/test/test_validations.rb +186 -0
- metadata +70 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), "../lib/couch_resource/validations")
|
4
|
+
|
5
|
+
class ValidatesEachTest
|
6
|
+
include CouchResource::Struct
|
7
|
+
include CouchResource::Validations
|
8
|
+
string :first_name, :validates => [
|
9
|
+
[:each , {
|
10
|
+
:proc => Proc.new do |record, attr, value|
|
11
|
+
record.errors.add attr, "starts with z." if value[0] == ?z
|
12
|
+
end
|
13
|
+
}]
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
class ValidatesConfirmationOfTest
|
18
|
+
include CouchResource::Struct
|
19
|
+
include CouchResource::Validations
|
20
|
+
string :password, :validates => [:confirmation_of]
|
21
|
+
end
|
22
|
+
|
23
|
+
class ValidatesPresenseOfTest
|
24
|
+
include CouchResource::Struct
|
25
|
+
include CouchResource::Validations
|
26
|
+
string :title, :validates => [ :presense_of ]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class ValidatesLengthOfTest
|
31
|
+
include CouchResource::Struct
|
32
|
+
include CouchResource::Validations
|
33
|
+
string :title, :validates => [[:length_of, { :minimum => 2 } ]]
|
34
|
+
end
|
35
|
+
|
36
|
+
class ValidatesFormatOfTest
|
37
|
+
include CouchResource::Struct
|
38
|
+
include CouchResource::Validations
|
39
|
+
string :title, :validates => [[:format_of, { :with => /^\d+$/ } ]]
|
40
|
+
end
|
41
|
+
|
42
|
+
class ValidatesInclusionOfTest
|
43
|
+
include CouchResource::Struct
|
44
|
+
include CouchResource::Validations
|
45
|
+
number :age, :validates => [[ :inclusion_of, { :in => 1..10 } ]]
|
46
|
+
end
|
47
|
+
|
48
|
+
class ValidatesExclusionOfTest
|
49
|
+
include CouchResource::Struct
|
50
|
+
include CouchResource::Validations
|
51
|
+
number :age, :validates => [[ :exclusion_of, { :in => 1..10 } ]]
|
52
|
+
end
|
53
|
+
|
54
|
+
class ValidatesNumericalityOfTest
|
55
|
+
include CouchResource::Struct
|
56
|
+
include CouchResource::Validations
|
57
|
+
number :age, :validates =>
|
58
|
+
[[ :numericality_of, {
|
59
|
+
:greater_than => 1,
|
60
|
+
:odd => true
|
61
|
+
} ]]
|
62
|
+
end
|
63
|
+
|
64
|
+
class MultiValidationTest
|
65
|
+
include CouchResource::Struct
|
66
|
+
include CouchResource::Validations
|
67
|
+
string :title, :validates => [[:each, { :proc => Proc.new{|record, attr, value|
|
68
|
+
if value && value.length > 10
|
69
|
+
record.errors.add(attr, "exceed 10 length")
|
70
|
+
end
|
71
|
+
} }],
|
72
|
+
[:length_of, { :minimum => 5 } ],
|
73
|
+
[:format_of, { :with => /^\d+$/ }]]
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
class ValidatesChildrenOfTest
|
78
|
+
include CouchResource::Struct
|
79
|
+
include CouchResource::Validations
|
80
|
+
string :title, :validates => [[:length_of, { :maximum => 10 }]]
|
81
|
+
class NestedClass
|
82
|
+
include CouchResource::Struct
|
83
|
+
include CouchResource::Validations
|
84
|
+
number :age, :validates =>
|
85
|
+
[[ :numericality_of, {
|
86
|
+
:greater_than => 10,
|
87
|
+
:odd => true
|
88
|
+
} ]]
|
89
|
+
end
|
90
|
+
object :nest, :is_a => NestedClass, :validates => [[:children_of, { :allow_nil => true }]]
|
91
|
+
end
|
92
|
+
|
93
|
+
class TestValidations < Test::Unit::TestCase
|
94
|
+
def test_validates_each
|
95
|
+
obj = ValidatesEachTest.new
|
96
|
+
obj.first_name = "z"
|
97
|
+
assert_equal false, obj.valid?
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_validates_confirmation_of
|
101
|
+
obj = ValidatesConfirmationOfTest.new
|
102
|
+
obj.password = "z"
|
103
|
+
obj.password_confirmation = "y"
|
104
|
+
assert_equal false, obj.valid?
|
105
|
+
obj.password_confirmation = "z"
|
106
|
+
assert_equal true, obj.valid?
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_validates_presense_of
|
110
|
+
obj = ValidatesPresenseOfTest.new
|
111
|
+
obj.title = nil
|
112
|
+
assert_equal false, obj.valid?
|
113
|
+
obj.title = "title"
|
114
|
+
assert_equal true, obj.valid?
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_validates_length_of
|
118
|
+
obj = ValidatesLengthOfTest.new
|
119
|
+
obj.title = "1"
|
120
|
+
assert_equal false, obj.valid?
|
121
|
+
obj.title = "123"
|
122
|
+
assert_equal true, obj.valid?
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_validates_format_of
|
126
|
+
obj = ValidatesFormatOfTest.new
|
127
|
+
obj.title = "1a"
|
128
|
+
assert_equal false, obj.valid?
|
129
|
+
obj.title = "11"
|
130
|
+
assert_equal true, obj.valid?
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_validates_inclusion_of
|
134
|
+
obj = ValidatesInclusionOfTest.new
|
135
|
+
obj.age = 5
|
136
|
+
assert_equal true, obj.valid?
|
137
|
+
obj.age = 11
|
138
|
+
assert_equal false, obj.valid?
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_validates_exclusion_of
|
142
|
+
obj = ValidatesExclusionOfTest.new
|
143
|
+
obj.age = 5
|
144
|
+
assert_equal false, obj.valid?
|
145
|
+
obj.age = 11
|
146
|
+
assert_equal true, obj.valid?
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_validates_numericality_of
|
150
|
+
obj = ValidatesNumericalityOfTest.new
|
151
|
+
obj.age = 2
|
152
|
+
assert_equal false, obj.valid?
|
153
|
+
obj.age = 3
|
154
|
+
assert_equal true, obj.valid?
|
155
|
+
obj.age = 1
|
156
|
+
assert_equal false, obj.valid?
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_multivalidation
|
160
|
+
obj = MultiValidationTest.new
|
161
|
+
obj.title = "a"
|
162
|
+
assert_equal false, obj.valid?
|
163
|
+
obj.title = "1"
|
164
|
+
assert_equal false, obj.valid?
|
165
|
+
obj.title = "aaaaaa"
|
166
|
+
assert_equal false, obj.valid?
|
167
|
+
obj.title = "111111"
|
168
|
+
assert_equal true, obj.valid?
|
169
|
+
obj.title = "11111111111"
|
170
|
+
assert_equal false, obj.valid?
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_validates_children_of
|
174
|
+
obj = ValidatesChildrenOfTest.new
|
175
|
+
obj.title = "1" * 15
|
176
|
+
assert_equal false, obj.valid?
|
177
|
+
obj.title = "1" * 5
|
178
|
+
assert_equal true, obj.valid?
|
179
|
+
obj.nest = ValidatesChildrenOfTest::NestedClass.new()
|
180
|
+
obj.nest.age = 9
|
181
|
+
assert_equal false, obj.valid?
|
182
|
+
obj.nest.age = 11
|
183
|
+
assert_equal true, obj.valid?
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yssk22-couch_resource
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yohei Sasaki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: yssk22@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- MIT_LICENSE
|
27
|
+
- lib/couch_resource/base.rb
|
28
|
+
- lib/couch_resource/callbacks.rb
|
29
|
+
- lib/couch_resource/connection.rb
|
30
|
+
- lib/couch_resource/error.rb
|
31
|
+
- lib/couch_resource/struct.rb
|
32
|
+
- lib/couch_resource/validations.rb
|
33
|
+
- lib/couch_resource/view.rb
|
34
|
+
- lib/couch_resource.rb
|
35
|
+
- test/test_base.rb
|
36
|
+
- test/test_callbacks.rb
|
37
|
+
- test/test_connection.rb
|
38
|
+
- test/test_struct.rb
|
39
|
+
- test/test_validations.rb
|
40
|
+
- README.rdoc
|
41
|
+
- LICENSE
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/yssk22/couch_resource
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --inline-source
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: ActiveRecord style data mapper for CouchDB
|
69
|
+
test_files: []
|
70
|
+
|