ohm-contrib 2.0.0.alpha5 → 2.0.0.rc1
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.
- checksums.yaml +4 -4
- data/.gems +4 -0
- data/.gitignore +29 -0
- data/CHANGELOG.md +45 -0
- data/README.markdown +3 -23
- data/lib/ohm/contrib.rb +8 -8
- data/lib/ohm/datatypes.rb +11 -20
- data/lib/ohm/locking.rb +7 -9
- data/lib/ohm/slug.rb +3 -2
- data/lib/ohm/softdelete.rb +12 -15
- data/lib/ohm/timestamps.rb +1 -1
- data/lib/ohm/versioned.rb +1 -1
- data/makefile +4 -0
- data/ohm-contrib.gemspec +5 -15
- data/test/callbacks.rb +119 -0
- data/test/contrib.rb +13 -0
- data/test/datatypes.rb +151 -0
- data/test/helper.rb +1 -16
- data/test/locking.rb +10 -0
- data/test/scope.rb +10 -12
- data/test/slug.rb +13 -7
- data/test/{soft_delete.rb → softdelete.rb} +15 -20
- data/test/timestamp.rb +19 -10
- data/test/versioned.rb +6 -5
- metadata +34 -13
- data/test/instance_callbacks.rb +0 -43
- data/test/plugin.rb +0 -299
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril David
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ohm
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.0.
|
19
|
+
version: 2.0.0.rc1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.0.
|
26
|
+
version: 2.0.0.rc1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cutest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: iconv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: override
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +73,9 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- .gems
|
77
|
+
- .gitignore
|
78
|
+
- CHANGELOG.md
|
62
79
|
- LICENSE
|
63
80
|
- README.markdown
|
64
81
|
- lib/ohm/callbacks.rb
|
@@ -70,17 +87,21 @@ files:
|
|
70
87
|
- lib/ohm/softdelete.rb
|
71
88
|
- lib/ohm/timestamps.rb
|
72
89
|
- lib/ohm/versioned.rb
|
90
|
+
- makefile
|
73
91
|
- ohm-contrib.gemspec
|
92
|
+
- test/callbacks.rb
|
93
|
+
- test/contrib.rb
|
94
|
+
- test/datatypes.rb
|
74
95
|
- test/helper.rb
|
75
|
-
- test/
|
76
|
-
- test/plugin.rb
|
96
|
+
- test/locking.rb
|
77
97
|
- test/scope.rb
|
78
98
|
- test/slug.rb
|
79
|
-
- test/
|
99
|
+
- test/softdelete.rb
|
80
100
|
- test/timestamp.rb
|
81
101
|
- test/versioned.rb
|
82
102
|
homepage: http://github.com/cyx/ohm-contrib
|
83
|
-
licenses:
|
103
|
+
licenses:
|
104
|
+
- MIT
|
84
105
|
metadata: {}
|
85
106
|
post_install_message:
|
86
107
|
rdoc_options: []
|
@@ -97,9 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
118
|
- !ruby/object:Gem::Version
|
98
119
|
version: 1.3.1
|
99
120
|
requirements: []
|
100
|
-
rubyforge_project:
|
101
|
-
rubygems_version: 2.0.
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.0.14
|
102
123
|
signing_key:
|
103
|
-
specification_version:
|
124
|
+
specification_version: 4
|
104
125
|
summary: A collection of decoupled drop-in modules for Ohm.
|
105
126
|
test_files: []
|
data/test/instance_callbacks.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("../helper", __FILE__)
|
4
|
-
|
5
|
-
class Post < Ohm::Model
|
6
|
-
include Ohm::Callbacks
|
7
|
-
|
8
|
-
attribute :body
|
9
|
-
|
10
|
-
def validate
|
11
|
-
super
|
12
|
-
|
13
|
-
assert_present :body
|
14
|
-
end
|
15
|
-
|
16
|
-
def did?(action)
|
17
|
-
instance_variable_get("@#{ action }")
|
18
|
-
end
|
19
|
-
|
20
|
-
def count(action)
|
21
|
-
instance_variable_get("@#{ action }")
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
def before_create() incr(:do_before_create) end
|
26
|
-
def after_create() incr(:do_after_create) end
|
27
|
-
def before_save() incr(:do_before_save) end
|
28
|
-
def after_save() incr(:do_after_save) end
|
29
|
-
def before_update() incr(:do_before_update) end
|
30
|
-
def after_update() incr(:do_after_update) end
|
31
|
-
def before_delete() incr(:do_before_delete) end
|
32
|
-
def after_delete() incr(:do_after_delete) end
|
33
|
-
|
34
|
-
def incr(action)
|
35
|
-
val = instance_variable_get("@#{ action }")
|
36
|
-
val ||= 0
|
37
|
-
val += 1
|
38
|
-
|
39
|
-
instance_variable_set("@#{ action }", val)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
load File.expand_path('lint/callbacks.rb', File.dirname(__FILE__))
|
data/test/plugin.rb
DELETED
@@ -1,299 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path("../helper", __FILE__)
|
4
|
-
require 'set'
|
5
|
-
|
6
|
-
class Comment < Ohm::Model
|
7
|
-
include Ohm::Timestamps
|
8
|
-
end
|
9
|
-
|
10
|
-
test "timestamps are added during creation" do
|
11
|
-
e = Comment.new
|
12
|
-
e.save
|
13
|
-
|
14
|
-
assert e.created_at
|
15
|
-
assert e.updated_at
|
16
|
-
end
|
17
|
-
|
18
|
-
class Server < Ohm::Model
|
19
|
-
include Ohm::Locking
|
20
|
-
end
|
21
|
-
|
22
|
-
test "mutex method is added at instance and class level" do
|
23
|
-
assert Server.new.respond_to?(:mutex)
|
24
|
-
end
|
25
|
-
|
26
|
-
class Article < Ohm::Model
|
27
|
-
include Ohm::Callbacks
|
28
|
-
|
29
|
-
attribute :title
|
30
|
-
set :comments, Comment
|
31
|
-
|
32
|
-
private
|
33
|
-
def before_save
|
34
|
-
self.title = title.gsub("<br>", " ")
|
35
|
-
end
|
36
|
-
|
37
|
-
def after_save
|
38
|
-
redis.call("SADD", comments.key, Comment.create.id)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
test "class-level, instance level callbacks" do
|
43
|
-
a = Article.create(:title => "Foo<br>Bar")
|
44
|
-
|
45
|
-
assert_equal "Foo Bar", a.title
|
46
|
-
assert_equal 1, a.comments.size
|
47
|
-
end
|
48
|
-
|
49
|
-
# slugging
|
50
|
-
scope do
|
51
|
-
class Post < Ohm::Model
|
52
|
-
attribute :title
|
53
|
-
|
54
|
-
include Ohm::Slug
|
55
|
-
|
56
|
-
def to_s
|
57
|
-
title
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
test "slugging" do
|
62
|
-
post = Post.create(:title => "Foo Bar Baz 1.0")
|
63
|
-
assert_equal "1-foo-bar-baz-1-0", post.to_param
|
64
|
-
|
65
|
-
post = Post.create(:title => "Décor")
|
66
|
-
assert_equal "2-decor", post.to_param
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Ohm::Scope
|
71
|
-
scope do
|
72
|
-
class Order < Ohm::Model
|
73
|
-
include Ohm::Scope
|
74
|
-
|
75
|
-
attribute :state
|
76
|
-
index :state
|
77
|
-
|
78
|
-
attribute :deleted
|
79
|
-
index :deleted
|
80
|
-
|
81
|
-
scope do
|
82
|
-
def paid
|
83
|
-
find(:state => "paid")
|
84
|
-
end
|
85
|
-
|
86
|
-
def deleted
|
87
|
-
find(:deleted => 1)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
test "scoping" do
|
93
|
-
paid = Order.create(:state => "paid", :deleted => nil)
|
94
|
-
|
95
|
-
assert Order.all.paid.include?(paid)
|
96
|
-
assert_equal 0, Order.all.paid.deleted.size
|
97
|
-
|
98
|
-
paid.update(:deleted => 1)
|
99
|
-
assert Order.all.paid.deleted.include?(paid)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# soft delete
|
104
|
-
scope do
|
105
|
-
class User < Ohm::Model
|
106
|
-
include Ohm::SoftDelete
|
107
|
-
|
108
|
-
attribute :email
|
109
|
-
index :email
|
110
|
-
end
|
111
|
-
|
112
|
-
setup do
|
113
|
-
user = User.create(:email => "a@a.com")
|
114
|
-
user.delete
|
115
|
-
|
116
|
-
user
|
117
|
-
end
|
118
|
-
|
119
|
-
test "removes from User.all" do |user|
|
120
|
-
assert User.all.empty?
|
121
|
-
end
|
122
|
-
|
123
|
-
test "adds to User.deleted" do |user|
|
124
|
-
assert User.deleted.include?(user)
|
125
|
-
end
|
126
|
-
|
127
|
-
test "doesn't remove from indices" do |user|
|
128
|
-
assert User.find(:email => "a@a.com").include?(user)
|
129
|
-
end
|
130
|
-
|
131
|
-
test "makes it deleted?" do |user|
|
132
|
-
assert user.deleted?
|
133
|
-
end
|
134
|
-
|
135
|
-
test "is still retrievable" do |user|
|
136
|
-
assert_equal user, User[user.id]
|
137
|
-
end
|
138
|
-
|
139
|
-
test "restore" do |user|
|
140
|
-
user.restore
|
141
|
-
|
142
|
-
assert User.all.include?(user)
|
143
|
-
assert User.deleted.empty?
|
144
|
-
|
145
|
-
assert ! user.deleted?
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# datatypes
|
150
|
-
scope do
|
151
|
-
class Product < Ohm::Model
|
152
|
-
include Ohm::DataTypes
|
153
|
-
|
154
|
-
attribute :name
|
155
|
-
attribute :stock, Type::Integer
|
156
|
-
attribute :price, Type::Decimal
|
157
|
-
attribute :rating, Type::Float
|
158
|
-
attribute :bought_at, Type::Time
|
159
|
-
attribute :date_released, Type::Date
|
160
|
-
attribute :sizes, Type::Hash
|
161
|
-
attribute :stores, Type::Array
|
162
|
-
attribute :published, Type::Boolean
|
163
|
-
attribute :state, Type::Symbol
|
164
|
-
attribute :comments, Type::Set
|
165
|
-
end
|
166
|
-
|
167
|
-
test "Type::Integer" do
|
168
|
-
p = Product.new(:stock => "1")
|
169
|
-
|
170
|
-
assert_equal 1, p.stock
|
171
|
-
p.save
|
172
|
-
|
173
|
-
p = Product[p.id]
|
174
|
-
assert_equal 1, p.stock
|
175
|
-
end
|
176
|
-
|
177
|
-
test "Type::Time" do
|
178
|
-
time = Time.utc(2011, 11, 22)
|
179
|
-
p = Product.new(:bought_at => time)
|
180
|
-
assert p.bought_at.kind_of?(Time)
|
181
|
-
|
182
|
-
p.save
|
183
|
-
|
184
|
-
p = Product[p.id]
|
185
|
-
assert p.bought_at.kind_of?(Time)
|
186
|
-
assert_equal time, p.bought_at
|
187
|
-
|
188
|
-
assert_equal "2011-11-22 00:00:00 UTC", p.get(:bought_at)
|
189
|
-
assert_equal "2011-11-22 00:00:00 UTC", p.bought_at.to_s
|
190
|
-
end
|
191
|
-
|
192
|
-
test "Type::Date" do
|
193
|
-
p = Product.new(:date_released => Date.today)
|
194
|
-
|
195
|
-
assert p.date_released.kind_of?(Date)
|
196
|
-
|
197
|
-
p = Product.new(:date_released => "2011-11-22")
|
198
|
-
assert p.date_released.kind_of?(Date)
|
199
|
-
|
200
|
-
p.save
|
201
|
-
|
202
|
-
p = Product[p.id]
|
203
|
-
assert_equal Date.new(2011, 11, 22), p.date_released
|
204
|
-
assert_equal "2011-11-22", p.get(:date_released)
|
205
|
-
assert_equal "2011-11-22", p.date_released.to_s
|
206
|
-
end
|
207
|
-
|
208
|
-
test "Type::Hash" do
|
209
|
-
sizes = { "XS" => 1, "S" => 2, "L" => 3 }
|
210
|
-
|
211
|
-
p = Product.new(:sizes => sizes)
|
212
|
-
assert p.sizes.kind_of?(Hash)
|
213
|
-
p.save
|
214
|
-
|
215
|
-
p = Product[p.id]
|
216
|
-
assert_equal sizes, p.sizes
|
217
|
-
assert_equal %Q[{"XS":1,"S":2,"L":3}], p.get(:sizes)
|
218
|
-
assert_equal %Q[{"XS":1,"S":2,"L":3}], p.sizes.to_s
|
219
|
-
end
|
220
|
-
|
221
|
-
test "Type::Array" do
|
222
|
-
stores = ["walmart", "marshalls", "jcpenny"]
|
223
|
-
p = Product.new(:stores => stores)
|
224
|
-
assert p.stores.kind_of?(Array)
|
225
|
-
|
226
|
-
p.save
|
227
|
-
|
228
|
-
p = Product[p.id]
|
229
|
-
assert_equal stores, p.stores
|
230
|
-
assert_equal %Q(["walmart","marshalls","jcpenny"]), p.get(:stores)
|
231
|
-
assert_equal %Q(["walmart","marshalls","jcpenny"]), p.stores.to_s
|
232
|
-
end
|
233
|
-
|
234
|
-
test "Type::Decimal" do
|
235
|
-
p = Product.new(:price => 0.001)
|
236
|
-
|
237
|
-
# This fails if 0.001 is a float.
|
238
|
-
x = 0
|
239
|
-
1000.times { x += p.price }
|
240
|
-
assert_equal 1, x
|
241
|
-
|
242
|
-
p.save
|
243
|
-
|
244
|
-
p = Product[p.id]
|
245
|
-
assert_equal 0.001, p.price
|
246
|
-
assert_equal "0.1E-2", p.get(:price)
|
247
|
-
end
|
248
|
-
|
249
|
-
test "Type::Float" do
|
250
|
-
p = Product.new(:rating => 4.5)
|
251
|
-
assert p.rating.kind_of?(Float)
|
252
|
-
|
253
|
-
p.save
|
254
|
-
p = Product[p.id]
|
255
|
-
assert_equal 4.5, p.rating
|
256
|
-
assert_equal "4.5", p.get(:rating)
|
257
|
-
end
|
258
|
-
|
259
|
-
test "Type::Boolean" do
|
260
|
-
p = Product.new(:published => 1)
|
261
|
-
assert_equal true, p.published
|
262
|
-
|
263
|
-
p.save
|
264
|
-
|
265
|
-
p = Product[p.id]
|
266
|
-
assert_equal true, p.published
|
267
|
-
|
268
|
-
p.published = false
|
269
|
-
p.save
|
270
|
-
|
271
|
-
p = Product[p.id]
|
272
|
-
assert_equal nil, p.get(:published)
|
273
|
-
assert_equal false, p.published
|
274
|
-
end
|
275
|
-
|
276
|
-
test "Type::Symbol" do
|
277
|
-
p = Product.new(:state => 'available')
|
278
|
-
|
279
|
-
assert_equal :available, p.state
|
280
|
-
p.save
|
281
|
-
|
282
|
-
p = Product[p.id]
|
283
|
-
assert_equal :available, p.state
|
284
|
-
end
|
285
|
-
|
286
|
-
test "Type::Set" do
|
287
|
-
comments = ::Set.new(["Good product", "Awesome!", "Great."])
|
288
|
-
p = Product.new(:comments => comments)
|
289
|
-
assert p.comments.kind_of?(::Set)
|
290
|
-
|
291
|
-
p.save
|
292
|
-
|
293
|
-
p = Product[p.id]
|
294
|
-
|
295
|
-
assert_equal comments, p.comments
|
296
|
-
assert_equal %Q(["Awesome!","Good product","Great."]), p.get(:comments)
|
297
|
-
assert_equal %Q(["Awesome!","Good product","Great."]), p.comments.to_s
|
298
|
-
end
|
299
|
-
end
|