ohm-contrib 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/ohm/contrib/timestamping.rb +2 -2
- data/lib/ohm/contrib.rb +1 -1
- data/ohm-contrib.gemspec +4 -4
- data/test/test_ohm_boundaries.rb +2 -9
- data/test/test_ohm_timestamping.rb +5 -1
- data/test/test_ohm_to_hash.rb +2 -2
- data/test/test_ohm_typecast.rb +21 -21
- metadata +11 -4
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.27
|
data/lib/ohm/contrib.rb
CHANGED
data/ohm-contrib.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ohm-contrib}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.27"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril David"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-29}
|
13
13
|
s.description = %q{Highly decoupled drop-in functionality for Ohm models}
|
14
14
|
s.email = %q{cyx.ucron@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
s.homepage = %q{http://labs.sinefunc.com/ohm-contrib}
|
51
51
|
s.rdoc_options = ["--charset=UTF-8"]
|
52
52
|
s.require_paths = ["lib"]
|
53
|
-
s.rubygems_version = %q{1.3.
|
53
|
+
s.rubygems_version = %q{1.3.7}
|
54
54
|
s.summary = %q{A collection of ohm related modules}
|
55
55
|
s.test_files = [
|
56
56
|
"test/helper.rb",
|
@@ -70,7 +70,7 @@ Gem::Specification.new do |s|
|
|
70
70
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
71
|
s.specification_version = 3
|
72
72
|
|
73
|
-
if Gem::Version.new(Gem::
|
73
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
74
|
s.add_development_dependency(%q<contest>, [">= 0"])
|
75
75
|
s.add_development_dependency(%q<redis>, [">= 0"])
|
76
76
|
s.add_development_dependency(%q<ohm>, [">= 0"])
|
data/test/test_ohm_boundaries.rb
CHANGED
@@ -51,21 +51,15 @@ class TestOhmBoundaries < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
context "when searching name => matz" do
|
54
|
-
|
54
|
+
test "matz is the first and last" do
|
55
55
|
assert_equal @matz, Person.first(:name => "matz")
|
56
|
-
end
|
57
|
-
|
58
|
-
should "have matz as the last Person" do
|
59
56
|
assert_equal @matz, Person.last(:name => "matz")
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
60
|
context "when searching name => linus" do
|
64
|
-
|
61
|
+
test "linus is first and last" do
|
65
62
|
assert_equal @linus, Person.first(:name => "linus")
|
66
|
-
end
|
67
|
-
|
68
|
-
should "have matz as the last Person" do
|
69
63
|
assert_equal @linus, Person.last(:name => "linus")
|
70
64
|
end
|
71
65
|
end
|
@@ -76,6 +70,5 @@ class TestOhmBoundaries < Test::Unit::TestCase
|
|
76
70
|
assert_nil Person.last(:name => "quentin")
|
77
71
|
end
|
78
72
|
end
|
79
|
-
|
80
73
|
end
|
81
74
|
end
|
@@ -39,8 +39,11 @@ class TestOhmTimestamping < Test::Unit::TestCase
|
|
39
39
|
|
40
40
|
context "on update" do
|
41
41
|
setup do
|
42
|
+
Timecop.freeze(Time.utc(2010, 10, 30))
|
43
|
+
|
42
44
|
@person = Person.create
|
43
45
|
@old_created_at = @person.created_at.to_s
|
46
|
+
@old_updated_at = @person.updated_at.to_s
|
44
47
|
|
45
48
|
@now = Time.utc(2010, 10, 31)
|
46
49
|
Timecop.freeze(@now)
|
@@ -54,7 +57,8 @@ class TestOhmTimestamping < Test::Unit::TestCase
|
|
54
57
|
end
|
55
58
|
|
56
59
|
should "set updated_at to the current Time" do
|
60
|
+
assert_not_equal @old_updated_at, @person.updated_at
|
57
61
|
assert_equal @now.to_s, @person.updated_at
|
58
62
|
end
|
59
63
|
end
|
60
|
-
end
|
64
|
+
end
|
data/test/test_ohm_to_hash.rb
CHANGED
@@ -47,7 +47,7 @@ class TestOhmToHash < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context "when a comment has a reference to a person" do
|
50
|
-
Person = Class.new(Ohm::Model)
|
50
|
+
self::Person = Class.new(Ohm::Model)
|
51
51
|
|
52
52
|
class Comment < Ohm::Model
|
53
53
|
include Ohm::ToHash
|
@@ -64,4 +64,4 @@ class TestOhmToHash < Test::Unit::TestCase
|
|
64
64
|
assert_equal({ :id => '1', :person_id => '1' }, @comment.to_hash)
|
65
65
|
end
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
data/test/test_ohm_typecast.rb
CHANGED
@@ -38,29 +38,29 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
|
40
40
|
context "when using a decimal" do
|
41
|
-
class
|
41
|
+
class PostDecimal < Ohm::Model
|
42
42
|
include Ohm::Typecast
|
43
43
|
|
44
44
|
attribute :price, Decimal
|
45
45
|
end
|
46
46
|
|
47
47
|
test "handles nil case correctly" do
|
48
|
-
post =
|
49
|
-
post =
|
48
|
+
post = PostDecimal.create(:price => nil)
|
49
|
+
post = PostDecimal[post.id]
|
50
50
|
|
51
51
|
assert_nil post.price
|
52
52
|
end
|
53
53
|
|
54
54
|
test "handles empty string case correctly" do
|
55
|
-
post =
|
56
|
-
post =
|
55
|
+
post = PostDecimal.create(:price => "")
|
56
|
+
post = PostDecimal[post.id]
|
57
57
|
|
58
58
|
assert_equal "", post.price.to_s
|
59
59
|
end
|
60
60
|
|
61
61
|
test "allows for real arithmetic" do
|
62
|
-
post =
|
63
|
-
post =
|
62
|
+
post = PostDecimal.create(:price => "0.01")
|
63
|
+
post = PostDecimal[post.id]
|
64
64
|
|
65
65
|
assert_equal 0.02, post.price + post.price
|
66
66
|
assert_equal 0.0, post.price - post.price
|
@@ -69,8 +69,8 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
test "is accurate accdg to the decimal spec" do
|
72
|
-
post =
|
73
|
-
post =
|
72
|
+
post = PostDecimal.create(:price => "0.0001")
|
73
|
+
post = PostDecimal[post.id]
|
74
74
|
|
75
75
|
sum = 0
|
76
76
|
1_000.times { sum += post.price }
|
@@ -78,22 +78,22 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
78
78
|
end
|
79
79
|
|
80
80
|
test "using += with price" do
|
81
|
-
post =
|
82
|
-
post =
|
81
|
+
post = PostDecimal.create(:price => "0.0001")
|
82
|
+
post = PostDecimal[post.id]
|
83
83
|
|
84
84
|
post.price += 1
|
85
85
|
assert_equal 1.0001, post.price.to_f
|
86
86
|
end
|
87
87
|
|
88
88
|
test "assigning a raw BigDecimal" do
|
89
|
-
post =
|
90
|
-
post =
|
89
|
+
post = PostDecimal.create(:price => BigDecimal("399.50"))
|
90
|
+
post = PostDecimal[post.id]
|
91
91
|
|
92
92
|
assert_kind_of String, post.price.to_s
|
93
93
|
end
|
94
94
|
|
95
95
|
test "equality and comparable matching" do
|
96
|
-
post =
|
96
|
+
post = PostDecimal.create(:price => "399.50")
|
97
97
|
assert (post.price == "399.50")
|
98
98
|
assert (post.price < 399.51)
|
99
99
|
assert (post.price > 399.49)
|
@@ -104,7 +104,7 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
104
104
|
end
|
105
105
|
|
106
106
|
test "inspecting a Decimal" do
|
107
|
-
post =
|
107
|
+
post = PostDecimal.new(:price => 399.50)
|
108
108
|
assert_equal '"399.5"', post.price.inspect
|
109
109
|
|
110
110
|
post.price = 'FooBar'
|
@@ -544,15 +544,15 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
544
544
|
assert_equal addresses, post.addresses
|
545
545
|
end
|
546
546
|
|
547
|
-
class
|
548
|
-
def to_json
|
549
|
-
[city, country].to_json
|
547
|
+
class AddressArr < Class.new(Struct.new(:city, :country))
|
548
|
+
def to_json(*args)
|
549
|
+
[city, country].to_json(*args)
|
550
550
|
end
|
551
551
|
end
|
552
552
|
|
553
553
|
test "handles an arbitrary class as an element of the array" do
|
554
|
-
addresses = [
|
555
|
-
|
554
|
+
addresses = [AddressArr.new("Singapore", "SG"),
|
555
|
+
AddressArr.new("Philippines", "PH")]
|
556
556
|
|
557
557
|
post = Post.create(:addresses => addresses)
|
558
558
|
assert_equal [['Singapore', 'SG'], ['Philippines', 'PH']], post.addresses
|
@@ -612,7 +612,7 @@ class TestOhmTypecast < Test::Unit::TestCase
|
|
612
612
|
end
|
613
613
|
|
614
614
|
assert_raise TypeError do
|
615
|
-
Post.new(:addresses =>
|
615
|
+
Post.new(:addresses => AddressArr.new)
|
616
616
|
end
|
617
617
|
end
|
618
618
|
|
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
|
+
- 27
|
9
|
+
version: 0.0.27
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cyril David
|
@@ -14,13 +14,14 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-29 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: contest
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
@@ -33,6 +34,7 @@ dependencies:
|
|
33
34
|
name: redis
|
34
35
|
prerelease: false
|
35
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
36
38
|
requirements:
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
@@ -45,6 +47,7 @@ dependencies:
|
|
45
47
|
name: ohm
|
46
48
|
prerelease: false
|
47
49
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
48
51
|
requirements:
|
49
52
|
- - ">="
|
50
53
|
- !ruby/object:Gem::Version
|
@@ -57,6 +60,7 @@ dependencies:
|
|
57
60
|
name: timecop
|
58
61
|
prerelease: false
|
59
62
|
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
60
64
|
requirements:
|
61
65
|
- - ">="
|
62
66
|
- !ruby/object:Gem::Version
|
@@ -69,6 +73,7 @@ dependencies:
|
|
69
73
|
name: mocha
|
70
74
|
prerelease: false
|
71
75
|
requirement: &id005 !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
72
77
|
requirements:
|
73
78
|
- - ">="
|
74
79
|
- !ruby/object:Gem::Version
|
@@ -126,6 +131,7 @@ rdoc_options:
|
|
126
131
|
require_paths:
|
127
132
|
- lib
|
128
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
129
135
|
requirements:
|
130
136
|
- - ">="
|
131
137
|
- !ruby/object:Gem::Version
|
@@ -133,6 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
139
|
- 0
|
134
140
|
version: "0"
|
135
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
136
143
|
requirements:
|
137
144
|
- - ">="
|
138
145
|
- !ruby/object:Gem::Version
|
@@ -142,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
149
|
requirements: []
|
143
150
|
|
144
151
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.3.
|
152
|
+
rubygems_version: 1.3.7
|
146
153
|
signing_key:
|
147
154
|
specification_version: 3
|
148
155
|
summary: A collection of ohm related modules
|