ohm-contrib 1.0.0.rc2 → 1.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohm/contrib.rb +8 -8
- data/lib/ohm/scope.rb +1 -1
- data/lib/ohm/slug.rb +2 -2
- data/lib/ohm/timestamps.rb +1 -1
- data/ohm-contrib.gemspec +2 -2
- data/test/instance_callbacks.rb +2 -2
- data/test/plugin.rb +19 -19
- data/test/scope.rb +1 -1
- data/test/slug.rb +4 -4
- data/test/versioned.rb +4 -4
- metadata +11 -11
data/lib/ohm/contrib.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
require File.expand_path("../callbacks", __FILE__)
|
2
|
+
require File.expand_path("../datatypes", __FILE__)
|
3
|
+
require File.expand_path("../locking", __FILE__)
|
4
|
+
require File.expand_path("../scope", __FILE__)
|
5
|
+
require File.expand_path("../slug", __FILE__)
|
6
|
+
require File.expand_path("../softdelete", __FILE__)
|
7
|
+
require File.expand_path("../timestamps", __FILE__)
|
8
|
+
require File.expand_path("../versioned", __FILE__)
|
9
9
|
|
10
10
|
module Ohm
|
11
11
|
module Contrib
|
data/lib/ohm/scope.rb
CHANGED
data/lib/ohm/slug.rb
CHANGED
@@ -13,7 +13,7 @@ module Ohm
|
|
13
13
|
def slug(str = to_s)
|
14
14
|
ret = transcode(str)
|
15
15
|
ret.gsub!("'", "")
|
16
|
-
ret.gsub!(
|
16
|
+
ret.gsub!(/[^0-9A-Za-z]/u, " ")
|
17
17
|
ret.strip!
|
18
18
|
ret.gsub!(/\s+/, "-")
|
19
19
|
ret.downcase
|
@@ -40,4 +40,4 @@ module Ohm
|
|
40
40
|
"#{ id }-#{ slug }"
|
41
41
|
end
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
data/lib/ohm/timestamps.rb
CHANGED
data/ohm-contrib.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "ohm-contrib"
|
3
|
-
s.version = "1.0.0.
|
3
|
+
s.version = "1.0.0.rc3"
|
4
4
|
s.summary = %{A collection of decoupled drop-in modules for Ohm.}
|
5
5
|
s.description = %{Includes a couple of core functions such as callbacks, timestamping, typecasting and lots of generic validation routines.}
|
6
6
|
s.author = "Cyril David"
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.rubyforge_project = "ohm-contrib"
|
23
23
|
|
24
24
|
s.has_rdoc = false
|
25
|
-
s.add_dependency "ohm", "1.0.0.
|
25
|
+
s.add_dependency "ohm", "1.0.0.rc2"
|
26
26
|
|
27
27
|
s.add_development_dependency "cutest"
|
28
28
|
s.add_development_dependency "redis"
|
data/test/instance_callbacks.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require File.expand_path("../helper", __FILE__)
|
4
4
|
|
5
5
|
class Post < Ohm::Model
|
6
6
|
include Ohm::Callbacks
|
@@ -40,4 +40,4 @@ protected
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
load File.expand_path('lint/callbacks.rb', File.dirname(__FILE__))
|
43
|
+
load File.expand_path('lint/callbacks.rb', File.dirname(__FILE__))
|
data/test/plugin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require File.expand_path("../helper", __FILE__)
|
4
4
|
|
5
5
|
class Comment < Ohm::Model
|
6
6
|
include Ohm::Timestamps
|
@@ -39,7 +39,7 @@ private
|
|
39
39
|
end
|
40
40
|
|
41
41
|
test "class-level, instance level callbacks" do
|
42
|
-
a = Article.create(title
|
42
|
+
a = Article.create(:title => "Foo<br>Bar")
|
43
43
|
|
44
44
|
assert_equal "Foo Bar", a.title
|
45
45
|
assert_equal 1, a.comments.size
|
@@ -56,10 +56,10 @@ class Post < Ohm::Model
|
|
56
56
|
end
|
57
57
|
|
58
58
|
test "slugging" do
|
59
|
-
post = Post.create(title
|
59
|
+
post = Post.create(:title => "Foo Bar Baz")
|
60
60
|
assert_equal "1-foo-bar-baz", post.to_param
|
61
61
|
|
62
|
-
post = Post.create(title
|
62
|
+
post = Post.create(:title => "Décor")
|
63
63
|
assert_equal "2-decor", post.to_param
|
64
64
|
end
|
65
65
|
|
@@ -74,22 +74,22 @@ class Order < Ohm::Model
|
|
74
74
|
|
75
75
|
scope do
|
76
76
|
def paid
|
77
|
-
find(state
|
77
|
+
find(:state => "paid")
|
78
78
|
end
|
79
79
|
|
80
80
|
def deleted
|
81
|
-
find(deleted
|
81
|
+
find(:deleted => 1)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
test "scope" do
|
87
|
-
paid = Order.create(state
|
87
|
+
paid = Order.create(:state => "paid", :deleted => nil)
|
88
88
|
|
89
89
|
assert Order.all.paid.include?(paid)
|
90
90
|
assert_equal 0, Order.all.paid.deleted.size
|
91
91
|
|
92
|
-
paid.update(deleted
|
92
|
+
paid.update(:deleted => 1)
|
93
93
|
assert Order.all.paid.deleted.include?(paid)
|
94
94
|
end
|
95
95
|
|
@@ -101,12 +101,12 @@ class User < Ohm::Model
|
|
101
101
|
end
|
102
102
|
|
103
103
|
test "soft delete" do
|
104
|
-
user = User.create(email
|
104
|
+
user = User.create(:email => "a@a.com")
|
105
105
|
user.delete
|
106
106
|
|
107
107
|
assert User.all.empty?
|
108
108
|
assert User.deleted.include?(user)
|
109
|
-
assert User.find(email
|
109
|
+
assert User.find(:email => "a@a.com").include?(user)
|
110
110
|
|
111
111
|
assert user.deleted?
|
112
112
|
assert User[user.id] == user
|
@@ -134,7 +134,7 @@ class Product < Ohm::Model
|
|
134
134
|
end
|
135
135
|
|
136
136
|
test "datatypes" do
|
137
|
-
p = Product.new(stock
|
137
|
+
p = Product.new(:stock => "1")
|
138
138
|
|
139
139
|
assert_equal 1, p.stock
|
140
140
|
p.save
|
@@ -143,7 +143,7 @@ test "datatypes" do
|
|
143
143
|
assert_equal 1, p.stock
|
144
144
|
|
145
145
|
time = Time.now.utc
|
146
|
-
p = Product.new(bought_at
|
146
|
+
p = Product.new(:bought_at => time)
|
147
147
|
assert p.bought_at.kind_of?(Time)
|
148
148
|
|
149
149
|
p.save
|
@@ -152,11 +152,11 @@ test "datatypes" do
|
|
152
152
|
assert p.bought_at.kind_of?(Time)
|
153
153
|
assert_equal time, p.bought_at
|
154
154
|
|
155
|
-
p = Product.new(date_released
|
155
|
+
p = Product.new(:date_released => Date.today)
|
156
156
|
|
157
157
|
assert p.date_released.kind_of?(Date)
|
158
158
|
|
159
|
-
p = Product.new(date_released
|
159
|
+
p = Product.new(:date_released => "2011-11-22")
|
160
160
|
assert p.date_released.kind_of?(Date)
|
161
161
|
|
162
162
|
p.save
|
@@ -166,7 +166,7 @@ test "datatypes" do
|
|
166
166
|
|
167
167
|
sizes = { "XS" => 1, "S" => 2, "L" => 3 }
|
168
168
|
|
169
|
-
p = Product.new(sizes
|
169
|
+
p = Product.new(:sizes => sizes)
|
170
170
|
assert p.sizes.kind_of?(Hash)
|
171
171
|
p.save
|
172
172
|
|
@@ -174,7 +174,7 @@ test "datatypes" do
|
|
174
174
|
assert_equal sizes, p.sizes
|
175
175
|
|
176
176
|
stores = ["walmart", "marshalls", "jcpenny"]
|
177
|
-
p = Product.new(stores
|
177
|
+
p = Product.new(:stores => stores)
|
178
178
|
assert p.stores.kind_of?(Array)
|
179
179
|
|
180
180
|
p.save
|
@@ -182,7 +182,7 @@ test "datatypes" do
|
|
182
182
|
p = Product[p.id]
|
183
183
|
assert_equal stores, p.stores
|
184
184
|
|
185
|
-
p = Product.new(price
|
185
|
+
p = Product.new(:price => 0.001)
|
186
186
|
|
187
187
|
x = 0
|
188
188
|
1000.times { x += p.price }
|
@@ -193,14 +193,14 @@ test "datatypes" do
|
|
193
193
|
p = Product[p.id]
|
194
194
|
assert_equal 0.001, p.price
|
195
195
|
|
196
|
-
p = Product.new(rating
|
196
|
+
p = Product.new(:rating => 4.5)
|
197
197
|
assert p.rating.kind_of?(Float)
|
198
198
|
|
199
199
|
p.save
|
200
200
|
p = Product[p.id]
|
201
201
|
assert_equal 4.5, p.rating
|
202
202
|
|
203
|
-
p = Product.new(published
|
203
|
+
p = Product.new(:published => 1)
|
204
204
|
assert_equal true, p.published
|
205
205
|
|
206
206
|
p.save
|
data/test/scope.rb
CHANGED
data/test/slug.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require File.expand_path("../helper", __FILE__)
|
4
4
|
|
5
5
|
class Article < Ohm::Model
|
6
6
|
include Ohm::Slug
|
@@ -12,13 +12,13 @@ class Article < Ohm::Model
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test "to_param" do
|
15
|
-
article = Article.create(title
|
15
|
+
article = Article.create(:title => "A very Unique and Interesting String?'")
|
16
16
|
|
17
17
|
assert '1-a-very-unique-and-interesting-string' == article.to_param
|
18
18
|
end
|
19
19
|
|
20
20
|
test "finding" do
|
21
|
-
article = Article.create(title
|
21
|
+
article = Article.create(:title => "A very Unique and Interesting String?'")
|
22
22
|
|
23
23
|
assert 1 == Article["1-a-very-unique-and-interesting-string"].id
|
24
|
-
end
|
24
|
+
end
|
data/test/versioned.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require File.expand_path("../helper", __FILE__)
|
2
2
|
|
3
3
|
class Article < Ohm::Model
|
4
4
|
include Ohm::Versioned
|
@@ -8,17 +8,17 @@ class Article < Ohm::Model
|
|
8
8
|
end
|
9
9
|
|
10
10
|
test do
|
11
|
-
a1 = Article.create(title
|
11
|
+
a1 = Article.create(:title => "Foo Bar", :content => "Lorem ipsum")
|
12
12
|
a2 = Article[a1.id]
|
13
13
|
|
14
14
|
a1.update({})
|
15
15
|
|
16
16
|
begin
|
17
|
-
a2.update(title
|
17
|
+
a2.update(:title => "Bar Baz")
|
18
18
|
rescue Ohm::VersionConflict => ex
|
19
19
|
end
|
20
20
|
|
21
|
-
expected = { title
|
21
|
+
expected = { :title => "Bar Baz", :_version => "1", :content => "Lorem ipsum" }
|
22
22
|
|
23
23
|
assert_equal expected, ex.attributes
|
24
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ohm
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152132380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.0.0.
|
21
|
+
version: 1.0.0.rc2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152132380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cutest
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152154260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152154260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: redis
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152153580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152153580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: override
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152152620 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152152620
|
58
58
|
description: Includes a couple of core functions such as callbacks, timestamping,
|
59
59
|
typecasting and lots of generic validation routines.
|
60
60
|
email: cyx.ucron@gmail.com
|