ohm-contrib 0.0.31 → 0.0.33
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 -1
- data/README.markdown +2 -1
- data/Rakefile +4 -53
- data/lib/ohm/contrib.rb +2 -2
- data/lib/ohm/contrib/boundaries.rb +1 -0
- data/lib/ohm/contrib/callbacks.rb +5 -4
- data/lib/ohm/contrib/date_validations.rb +2 -1
- data/lib/ohm/contrib/extra_validations.rb +1 -0
- data/lib/ohm/contrib/length_validations.rb +1 -0
- data/lib/ohm/contrib/locking.rb +2 -1
- data/lib/ohm/contrib/lunar_macros.rb +5 -4
- data/lib/ohm/contrib/number_validations.rb +1 -0
- data/lib/ohm/contrib/slug.rb +1 -0
- data/lib/ohm/contrib/timestamping.rb +1 -0
- data/lib/ohm/contrib/typecast.rb +1 -0
- data/lib/ohm/contrib/web_validations.rb +2 -1
- data/test/autoload_test.rb +19 -0
- data/test/boundaries_test.rb +45 -0
- data/test/callbacks_lint.rb +105 -0
- data/test/date_validations_test.rb +29 -0
- data/test/helper.rb +19 -10
- data/test/instance_callbacks_test.rb +45 -0
- data/test/length_validations_test.rb +31 -0
- data/test/lunar_macros_test.rb +146 -0
- data/test/macro_callbacks_test.rb +57 -0
- data/test/membership_validation_test.rb +31 -0
- data/test/number_validations_test.rb +37 -0
- data/test/slug_test.rb +30 -0
- data/test/timestamping_test.rb +32 -0
- data/test/typecast_array_test.rb +154 -0
- data/test/typecast_boolean_test.rb +43 -0
- data/test/typecast_date_test.rb +77 -0
- data/test/typecast_decimal_test.rb +77 -0
- data/test/typecast_float_test.rb +52 -0
- data/test/typecast_hash_test.rb +117 -0
- data/test/typecast_integer_test.rb +66 -0
- data/test/typecast_string_test.rb +38 -0
- data/test/typecast_time_test.rb +67 -0
- data/test/typecast_timezone_test.rb +37 -0
- data/test/web_validations_test.rb +79 -0
- metadata +47 -56
- data/.document +0 -5
- data/.gitignore +0 -25
- data/VERSION +0 -1
- data/lib/ohm/contrib/to_hash.rb +0 -39
- data/ohm-contrib.gemspec +0 -103
- data/test/test_ohm_boundaries.rb +0 -74
- data/test/test_ohm_contrib.rb +0 -70
- data/test/test_ohm_contrib_callbacks.rb +0 -375
- data/test/test_ohm_date_validations.rb +0 -30
- data/test/test_ohm_extra_validations.rb +0 -32
- data/test/test_ohm_length_validations.rb +0 -32
- data/test/test_ohm_lunar_macros.rb +0 -165
- data/test/test_ohm_number_validations.rb +0 -59
- data/test/test_ohm_slug.rb +0 -29
- data/test/test_ohm_timestamping.rb +0 -64
- data/test/test_ohm_to_hash.rb +0 -67
- data/test/test_ohm_typecast.rb +0 -707
- data/test/test_ohm_web_validations.rb +0 -114
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
class Post < Ohm::Model
|
6
|
+
include Ohm::Typecast
|
7
|
+
|
8
|
+
attribute :price, Integer
|
9
|
+
end
|
10
|
+
|
11
|
+
test "handles nil case correctly" do
|
12
|
+
post = Post.create(:price => nil)
|
13
|
+
post = Post[post.id]
|
14
|
+
|
15
|
+
assert nil == post.price
|
16
|
+
end
|
17
|
+
|
18
|
+
test "handles empty string case correctly" do
|
19
|
+
post = Post.create(:price => "")
|
20
|
+
post = Post[post.id]
|
21
|
+
|
22
|
+
assert "" == post.price.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
test "allows respond_to on an invalid integer" do
|
26
|
+
post = Post.new(:price => "FooBar")
|
27
|
+
|
28
|
+
assert_nothing_raised ArgumentError do
|
29
|
+
post.price.respond_to?(:**)
|
30
|
+
end
|
31
|
+
|
32
|
+
assert ! post.price.respond_to?(:**)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "falls back to String#respond_to? when invalid" do
|
36
|
+
post = Post.new(:price => "FooBar")
|
37
|
+
assert post.price.respond_to?(:capitalize)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "allows for real arithmetic" do
|
41
|
+
post = Post.create(:price => "3")
|
42
|
+
post = Post[post.id]
|
43
|
+
|
44
|
+
assert 6 == post.price + post.price
|
45
|
+
assert 0 == post.price - post.price
|
46
|
+
assert 9 == post.price * post.price
|
47
|
+
assert 1 == post.price / post.price
|
48
|
+
end
|
49
|
+
|
50
|
+
test "raises when trying to do arithmetic ops on a non-int" do
|
51
|
+
post = Post.create(:price => "FooBar")
|
52
|
+
post = Post[post.id]
|
53
|
+
|
54
|
+
assert_raise ArgumentError do
|
55
|
+
post.price * post.price
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "inspecting" do
|
60
|
+
post = Post.new(:price => "50000")
|
61
|
+
assert '"50000"' == post.price.inspect
|
62
|
+
|
63
|
+
post.price = 'FooBar'
|
64
|
+
assert '"FooBar"' == post.price.inspect
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
class Post < Ohm::Model
|
6
|
+
include Ohm::Typecast
|
7
|
+
|
8
|
+
attribute :content
|
9
|
+
end
|
10
|
+
|
11
|
+
test "handles nil case correctly" do
|
12
|
+
post = Post.create(:content => nil)
|
13
|
+
post = Post[post.id]
|
14
|
+
|
15
|
+
assert nil == post.content
|
16
|
+
end
|
17
|
+
|
18
|
+
test "still responds to string methods properly" do
|
19
|
+
post = Post.create(:content => "FooBar")
|
20
|
+
post = Post[post.id]
|
21
|
+
|
22
|
+
assert "foobar" == post.content.downcase
|
23
|
+
end
|
24
|
+
|
25
|
+
test "mutating methods like upcase!" do
|
26
|
+
post = Post.create(:content => "FooBar")
|
27
|
+
post = Post[post.id]
|
28
|
+
|
29
|
+
post.content.upcase!
|
30
|
+
|
31
|
+
assert "FOOBAR" == post.content.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
test "inspecting" do
|
35
|
+
post = Post.new(:content => "FooBar")
|
36
|
+
assert 'FooBar' == post.content
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
class Post < Ohm::Model
|
6
|
+
include Ohm::Typecast
|
7
|
+
|
8
|
+
attribute :created_at, Time
|
9
|
+
|
10
|
+
def now
|
11
|
+
Time.now
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_time
|
15
|
+
Time.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test "still able to access top level Time" do
|
20
|
+
assert Post.new.now.to_s == Time.now.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should be able to use Time.new inside the class" do
|
24
|
+
assert Post.new.new_time.to_s == Time.new.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
test "handles nil case correctly" do
|
28
|
+
post = Post.create(:created_at => nil)
|
29
|
+
post = Post[post.id]
|
30
|
+
|
31
|
+
assert nil == post.created_at
|
32
|
+
end
|
33
|
+
|
34
|
+
test "handles empty string case correctly" do
|
35
|
+
post = Post.create(:created_at => "")
|
36
|
+
post = Post[post.id]
|
37
|
+
|
38
|
+
assert "" == post.created_at.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
test "allows for real time operations" do
|
42
|
+
post = Post.create(:created_at => "2010-05-10T00:00Z")
|
43
|
+
post = Post[post.id]
|
44
|
+
|
45
|
+
assert post.created_at.respond_to?(:strftime)
|
46
|
+
assert "2010-05-10" == post.created_at.strftime('%Y-%m-%d')
|
47
|
+
end
|
48
|
+
|
49
|
+
test "raises when trying to do non-time operations" do
|
50
|
+
post = Post.create(:created_at => "FooBar")
|
51
|
+
post = Post[post.id]
|
52
|
+
|
53
|
+
assert ! post.created_at.respond_to?(:abs)
|
54
|
+
|
55
|
+
assert_raise NoMethodError do
|
56
|
+
post.created_at.abs
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test "inspecting" do
|
61
|
+
post = Post.create(:created_at => Time.utc(2010, 05, 05))
|
62
|
+
assert '"2010-05-05 00:00:00 UTC"' == post.created_at.inspect
|
63
|
+
|
64
|
+
post.created_at = 'FooBar'
|
65
|
+
assert '"FooBar"' == post.created_at.inspect
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
class Post < Ohm::Model
|
6
|
+
include Ohm::Typecast
|
7
|
+
|
8
|
+
attribute :printed_at, Time
|
9
|
+
end
|
10
|
+
|
11
|
+
test "2010-08-07T00:00Z is parsed as 2010-08-07 00:00:00 UTC" do
|
12
|
+
post = Post.new(:printed_at => "2010-08-07T00:00Z")
|
13
|
+
assert Time.utc(2010, 8, 7).to_s == post.printed_at.utc.to_s
|
14
|
+
|
15
|
+
post.save
|
16
|
+
post = Post[post.id]
|
17
|
+
assert Time.utc(2010, 8, 7).to_s == post.printed_at.utc.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
test "2010-08-07 18:29Z is parsed as 2010-08-07 18:29:00 UTC" do
|
21
|
+
post = Post.new(:printed_at => "2010-08-07 18:29Z")
|
22
|
+
assert Time.utc(2010, 8, 7, 18, 29).to_s == post.printed_at.utc.to_s
|
23
|
+
|
24
|
+
post.save
|
25
|
+
post = Post[post.id]
|
26
|
+
assert Time.utc(2010, 8, 7, 18, 29).to_s == post.printed_at.utc.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
test "2010-08-07T18:29:31Z is parsed as 2010-08-07 18:29:31 UTC" do
|
30
|
+
post = Post.new(:printed_at => "2010-08-07T18:29:31Z")
|
31
|
+
assert Time.utc(2010, 8, 7, 18, 29, 31).to_s == post.printed_at.utc.to_s
|
32
|
+
|
33
|
+
post.save
|
34
|
+
post = Post[post.id]
|
35
|
+
assert Time.utc(2010, 8, 7, 18, 29, 31).to_s == post.printed_at.utc.to_s
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
class BlogPost < Ohm::Model
|
6
|
+
include Ohm::WebValidations
|
7
|
+
|
8
|
+
attribute :slug
|
9
|
+
|
10
|
+
index :slug
|
11
|
+
|
12
|
+
def validate
|
13
|
+
assert_slug :slug
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Comment < Ohm::Model
|
18
|
+
include Ohm::WebValidations
|
19
|
+
|
20
|
+
attribute :ip_address
|
21
|
+
attribute :homepage
|
22
|
+
attribute :email
|
23
|
+
|
24
|
+
def validate
|
25
|
+
assert_ipaddr :ip_address
|
26
|
+
assert_url :homepage
|
27
|
+
assert_email :email
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test "invalid slug scenario" do
|
32
|
+
p = BlogPost.new(:slug => "This is a title, not a SLUG")
|
33
|
+
assert ! p.valid?
|
34
|
+
assert [[:slug, :not_slug]] == p.errors
|
35
|
+
end
|
36
|
+
|
37
|
+
test "valid slug scenario" do
|
38
|
+
p = BlogPost.new(:slug => "this-is-a-valid-slug")
|
39
|
+
assert p.valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
test "slug uniqueness validation" do
|
43
|
+
p1 = BlogPost.create(:slug => "this-is-a-valid-slug")
|
44
|
+
p2 = BlogPost.create(:slug => "this-is-a-valid-slug")
|
45
|
+
|
46
|
+
assert ! p2.valid?
|
47
|
+
assert [[:slug, :not_unique]] == p2.errors
|
48
|
+
end
|
49
|
+
|
50
|
+
test "ip address validation" do
|
51
|
+
c = Comment.new(:ip_address => "400.500.600.700")
|
52
|
+
assert ! c.valid?
|
53
|
+
assert c.errors.include?([:ip_address, :not_ipaddr])
|
54
|
+
end
|
55
|
+
|
56
|
+
test "email address validation" do
|
57
|
+
c = Comment.new(:email => "something.com")
|
58
|
+
assert ! c.valid?
|
59
|
+
assert c.errors.include?([:email, :not_email])
|
60
|
+
|
61
|
+
c = Comment.new(:email => "john@doe.com")
|
62
|
+
c.valid?
|
63
|
+
assert ! c.errors.include?([:email, :not_email])
|
64
|
+
end
|
65
|
+
|
66
|
+
test "url validaiton" do
|
67
|
+
c = Comment.new(:homepage => "somehing")
|
68
|
+
assert ! c.valid?
|
69
|
+
assert c.errors.include?([:homepage, :not_url])
|
70
|
+
|
71
|
+
c = Comment.new(:homepage => "irc://irc.freenode.net/something")
|
72
|
+
assert ! c.valid?
|
73
|
+
assert c.errors.include?([:homepage, :not_url])
|
74
|
+
|
75
|
+
c = Comment.new(:homepage => "http://test.com")
|
76
|
+
c.valid?
|
77
|
+
assert ! c.errors.include?([:homepage, :not_url])
|
78
|
+
end
|
79
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 33
|
9
|
+
version: 0.0.33
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril David
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-12 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: ohm
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
@@ -28,10 +28,10 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
|
-
type: :
|
31
|
+
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: cutest
|
35
35
|
prerelease: false
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
type: :development
|
45
45
|
version_requirements: *id002
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: redis
|
48
48
|
prerelease: false
|
49
49
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id003
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: lunar
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id004 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
type: :development
|
71
71
|
version_requirements: *id004
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
73
|
+
name: override
|
74
74
|
prerelease: false
|
75
75
|
requirement: &id005 !ruby/object:Gem::Requirement
|
76
76
|
none: false
|
@@ -82,23 +82,15 @@ dependencies:
|
|
82
82
|
version: "0"
|
83
83
|
type: :development
|
84
84
|
version_requirements: *id005
|
85
|
-
description:
|
85
|
+
description:
|
86
86
|
email: cyx.ucron@gmail.com
|
87
87
|
executables: []
|
88
88
|
|
89
89
|
extensions: []
|
90
90
|
|
91
|
-
extra_rdoc_files:
|
92
|
-
|
93
|
-
- README.markdown
|
91
|
+
extra_rdoc_files: []
|
92
|
+
|
94
93
|
files:
|
95
|
-
- .document
|
96
|
-
- .gitignore
|
97
|
-
- LICENSE
|
98
|
-
- README.markdown
|
99
|
-
- Rakefile
|
100
|
-
- VERSION
|
101
|
-
- lib/ohm/contrib.rb
|
102
94
|
- lib/ohm/contrib/boundaries.rb
|
103
95
|
- lib/ohm/contrib/callbacks.rb
|
104
96
|
- lib/ohm/contrib/date_validations.rb
|
@@ -109,31 +101,43 @@ files:
|
|
109
101
|
- lib/ohm/contrib/number_validations.rb
|
110
102
|
- lib/ohm/contrib/slug.rb
|
111
103
|
- lib/ohm/contrib/timestamping.rb
|
112
|
-
- lib/ohm/contrib/to_hash.rb
|
113
104
|
- lib/ohm/contrib/typecast.rb
|
114
105
|
- lib/ohm/contrib/web_validations.rb
|
115
|
-
- ohm
|
106
|
+
- lib/ohm/contrib.rb
|
107
|
+
- README.markdown
|
108
|
+
- LICENSE
|
109
|
+
- Rakefile
|
110
|
+
- test/autoload_test.rb
|
111
|
+
- test/boundaries_test.rb
|
112
|
+
- test/callbacks_lint.rb
|
113
|
+
- test/date_validations_test.rb
|
116
114
|
- test/helper.rb
|
117
|
-
- test/
|
118
|
-
- test/
|
119
|
-
- test/
|
120
|
-
- test/
|
121
|
-
- test/
|
122
|
-
- test/
|
123
|
-
- test/
|
124
|
-
- test/
|
125
|
-
- test/
|
126
|
-
- test/
|
127
|
-
- test/
|
128
|
-
- test/
|
129
|
-
- test/
|
115
|
+
- test/instance_callbacks_test.rb
|
116
|
+
- test/length_validations_test.rb
|
117
|
+
- test/lunar_macros_test.rb
|
118
|
+
- test/macro_callbacks_test.rb
|
119
|
+
- test/membership_validation_test.rb
|
120
|
+
- test/number_validations_test.rb
|
121
|
+
- test/slug_test.rb
|
122
|
+
- test/timestamping_test.rb
|
123
|
+
- test/typecast_array_test.rb
|
124
|
+
- test/typecast_boolean_test.rb
|
125
|
+
- test/typecast_date_test.rb
|
126
|
+
- test/typecast_decimal_test.rb
|
127
|
+
- test/typecast_float_test.rb
|
128
|
+
- test/typecast_hash_test.rb
|
129
|
+
- test/typecast_integer_test.rb
|
130
|
+
- test/typecast_string_test.rb
|
131
|
+
- test/typecast_time_test.rb
|
132
|
+
- test/typecast_timezone_test.rb
|
133
|
+
- test/web_validations_test.rb
|
130
134
|
has_rdoc: true
|
131
|
-
homepage: http://
|
135
|
+
homepage: http://github.com/cyx/ohm-contrib
|
132
136
|
licenses: []
|
133
137
|
|
134
138
|
post_install_message:
|
135
|
-
rdoc_options:
|
136
|
-
|
139
|
+
rdoc_options: []
|
140
|
+
|
137
141
|
require_paths:
|
138
142
|
- lib
|
139
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -154,23 +158,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
158
|
version: "0"
|
155
159
|
requirements: []
|
156
160
|
|
157
|
-
rubyforge_project:
|
161
|
+
rubyforge_project: ohm-contrib
|
158
162
|
rubygems_version: 1.3.7
|
159
163
|
signing_key:
|
160
|
-
specification_version:
|
161
|
-
summary: A collection of
|
162
|
-
test_files:
|
163
|
-
|
164
|
-
- test/test_ohm_boundaries.rb
|
165
|
-
- test/test_ohm_contrib.rb
|
166
|
-
- test/test_ohm_contrib_callbacks.rb
|
167
|
-
- test/test_ohm_date_validations.rb
|
168
|
-
- test/test_ohm_extra_validations.rb
|
169
|
-
- test/test_ohm_length_validations.rb
|
170
|
-
- test/test_ohm_lunar_macros.rb
|
171
|
-
- test/test_ohm_number_validations.rb
|
172
|
-
- test/test_ohm_slug.rb
|
173
|
-
- test/test_ohm_timestamping.rb
|
174
|
-
- test/test_ohm_to_hash.rb
|
175
|
-
- test/test_ohm_typecast.rb
|
176
|
-
- test/test_ohm_web_validations.rb
|
164
|
+
specification_version: 2
|
165
|
+
summary: A collection of decoupled drop-in modules for Ohm
|
166
|
+
test_files: []
|
167
|
+
|