ohm 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/test/model.rb CHANGED
@@ -61,7 +61,7 @@ test "customized ID" do
61
61
  inv = Invoice.create
62
62
  assert_equal "_custom_id", inv.id
63
63
 
64
- i = Invoice.create(id: "_diff_id")
64
+ i = Invoice.create(:id => "_diff_id")
65
65
  assert_equal "_diff_id", i.id
66
66
  assert_equal i, Invoice["_diff_id"]
67
67
  end
@@ -74,7 +74,7 @@ test "empty model is ok" do
74
74
  end
75
75
 
76
76
  test "counters are cleaned up during deletion" do
77
- e = Event.create(name: "Foo")
77
+ e = Event.create(:name => "Foo")
78
78
  e.incr :votes, 10
79
79
 
80
80
  assert_equal 10, e.votes
@@ -93,7 +93,7 @@ test "return false if the validation fails" do
93
93
  end
94
94
 
95
95
  test "get" do
96
- m = Meetup.create(name: "Foo")
96
+ m = Meetup.create(:name => "Foo")
97
97
  m.name = "Bar"
98
98
 
99
99
  assert_equal "Foo", m.get(:name)
@@ -101,7 +101,7 @@ test "get" do
101
101
  end
102
102
 
103
103
  test "set" do
104
- m = Meetup.create(name: "Foo")
104
+ m = Meetup.create(:name => "Foo")
105
105
 
106
106
  m.set :name, "Bar"
107
107
  assert_equal "Bar", m.name
@@ -411,7 +411,7 @@ test "work on lists" do
411
411
  post.related.key.rpush(Post.create(:body => "B").id)
412
412
  post.related.key.rpush(Post.create(:body => "A").id)
413
413
 
414
- res = post.related.sort_by(:body, order: "ALPHA ASC").map { |r| r.body }
414
+ res = post.related.sort_by(:body, :order => "ALPHA ASC").map { |r| r.body }
415
415
  assert_equal ["A", "B", "C"], res
416
416
  end
417
417
 
@@ -439,19 +439,19 @@ class Entry < Ohm::Model
439
439
  end
440
440
 
441
441
  setup do
442
- Entry.create(tags: "foo bar baz")
442
+ Entry.create(:tags => "foo bar baz")
443
443
  end
444
444
 
445
445
  test "finding by one entry in the enumerable" do |entry|
446
- assert Entry.find(tag: "foo").include?(entry)
447
- assert Entry.find(tag: "bar").include?(entry)
448
- assert Entry.find(tag: "baz").include?(entry)
446
+ assert Entry.find(:tag => "foo").include?(entry)
447
+ assert Entry.find(:tag => "bar").include?(entry)
448
+ assert Entry.find(:tag => "baz").include?(entry)
449
449
  end
450
450
 
451
451
  test "finding by multiple entries in the enumerable" do |entry|
452
- assert Entry.find(tag: ["foo", "bar"]).include?(entry)
453
- assert Entry.find(tag: ["bar", "baz"]).include?(entry)
454
- assert Entry.find(tag: ["baz", "oof"]).empty?
452
+ assert Entry.find(:tag => ["foo", "bar"]).include?(entry)
453
+ assert Entry.find(:tag => ["bar", "baz"]).include?(entry)
454
+ assert Entry.find(:tag => ["baz", "oof"]).empty?
455
455
  end
456
456
 
457
457
  # Attributes of type Set
@@ -562,12 +562,12 @@ test "sort the model instances by the values provided" do
562
562
  end
563
563
 
564
564
  test "accept a number in the limit parameter" do
565
- people = @event.attendees.sort_by(:name, limit: [0, 2], order: "ALPHA")
565
+ people = @event.attendees.sort_by(:name, :limit => [0, 2], :order => "ALPHA")
566
566
  assert %w[A B] == people.map { |person| person.name }
567
567
  end
568
568
 
569
569
  test "use the start parameter as an offset if the limit is provided" do
570
- people = @event.attendees.sort_by(:name, limit: [1, 2], order: "ALPHA")
570
+ people = @event.attendees.sort_by(:name, :limit => [1, 2], :order => "ALPHA")
571
571
  assert %w[B C] == people.map { |person| person.name }
572
572
  end
573
573
 
@@ -742,7 +742,7 @@ test "typecast attributes" do
742
742
  end
743
743
 
744
744
  option = Option.create :votes => 20
745
- option.update(votes: option.votes + 1)
745
+ option.update(:votes => option.votes + 1)
746
746
 
747
747
  assert_equal 21, option.votes
748
748
  end
@@ -758,7 +758,7 @@ test "poster-example for overriding writers" do
758
758
  end
759
759
  end
760
760
 
761
- a = Advertiser.new(email: " FOO@BAR.COM ")
761
+ a = Advertiser.new(:email => " FOO@BAR.COM ")
762
762
  assert_equal "foo@bar.com", a.email
763
763
  end
764
764
 
@@ -1,4 +1,6 @@
1
- require_relative "helper"
1
+ # encoding: UTF-8
2
+
3
+ require File.expand_path("./helper", File.dirname(__FILE__))
2
4
 
3
5
  Ohm.flush
4
6
 
@@ -14,14 +16,14 @@ class User < Ohm::Model
14
16
  end
15
17
 
16
18
  create = lambda do |i|
17
- User.new(fname: "John#{i}",
18
- lname: "Doe#{i}",
19
- bday: Time.now.to_s,
20
- gender: "Male",
21
- city: "Los Angeles",
22
- state: "CA",
23
- country: "US",
24
- zip: "90210").save
19
+ User.new(:fname => "John#{i}",
20
+ :lname => "Doe#{i}",
21
+ :bday => Time.now.to_s,
22
+ :gender => "Male",
23
+ :city => "Los Angeles",
24
+ :state => "CA",
25
+ :country => "US",
26
+ :zip => "90210").save
25
27
  end
26
28
 
27
29
  10.times(&create)
@@ -29,7 +31,7 @@ end
29
31
  require "benchmark"
30
32
 
31
33
  t1 = Benchmark.realtime do
32
- User.all.sort_by(:fname, order: "DESC ALPHA").each do |user|
34
+ User.all.sort_by(:fname, :order => "DESC ALPHA").each do |user|
33
35
  end
34
36
  end
35
37
 
@@ -48,7 +50,7 @@ end
48
50
  90.times(&create)
49
51
 
50
52
  t1 = Benchmark.realtime do
51
- User.all.sort_by(:fname, order: "DESC ALPHA").each do |user|
53
+ User.all.sort_by(:fname, :order => "DESC ALPHA").each do |user|
52
54
  end
53
55
  end
54
56
 
data/test/transactions.rb CHANGED
@@ -45,11 +45,11 @@ end
45
45
  test "transaction local storage" do |db|
46
46
  t1 = Ohm::Transaction.new do |t|
47
47
  t.read do |s|
48
- s.foo = db.type("foo")
48
+ s[:foo] = db.type("foo")
49
49
  end
50
50
 
51
51
  t.write do |s|
52
- db.set("foo", s.foo.reverse)
52
+ db.set("foo", s[:foo].reverse)
53
53
  end
54
54
  end
55
55
 
@@ -62,7 +62,7 @@ test "composed transaction" do |db|
62
62
  t1 = Ohm::Transaction.new do |t|
63
63
  t.watch("foo")
64
64
 
65
- t.write do |s|
65
+ t.write do
66
66
  db.set("foo", "bar")
67
67
  end
68
68
  end
@@ -70,7 +70,7 @@ test "composed transaction" do |db|
70
70
  t2 = Ohm::Transaction.new do |t|
71
71
  t.watch("foo")
72
72
 
73
- t.write do |s|
73
+ t.write do
74
74
  db.set("foo", "baz")
75
75
  end
76
76
  end
@@ -158,13 +158,13 @@ end
158
158
  test "storage in composed transactions" do |db|
159
159
  t1 = Ohm::Transaction.new do |t|
160
160
  t.read do |s|
161
- s.foo = db.type("foo")
161
+ s[:foo] = db.type("foo")
162
162
  end
163
163
  end
164
164
 
165
165
  t2 = Ohm::Transaction.new do |t|
166
166
  t.write do |s|
167
- db.set("foo", s.foo.reverse)
167
+ db.set("foo", s[:foo].reverse)
168
168
  end
169
169
  end
170
170
 
@@ -176,11 +176,11 @@ end
176
176
  test "reading an storage entries that doesn't exist raises" do |db|
177
177
  t1 = Ohm::Transaction.new do |t|
178
178
  t.read do |s|
179
- s.foo
179
+ s[:foo]
180
180
  end
181
181
  end
182
182
 
183
- assert_raise NoMethodError do
183
+ assert_raise Ohm::Transaction::Store::NoEntryError do
184
184
  t1.commit(db)
185
185
  end
186
186
  end
@@ -188,13 +188,13 @@ end
188
188
  test "storage entries can't be overriden" do |db|
189
189
  t1 = Ohm::Transaction.new do |t|
190
190
  t.read do |s|
191
- s.foo = db.type("foo")
191
+ s[:foo] = db.type("foo")
192
192
  end
193
193
  end
194
194
 
195
195
  t2 = Ohm::Transaction.new do |t|
196
196
  t.read do |s|
197
- s.foo = db.exists("foo")
197
+ s[:foo] = db.exists("foo")
198
198
  end
199
199
  end
200
200
 
@@ -203,51 +203,38 @@ test "storage entries can't be overriden" do |db|
203
203
  end
204
204
  end
205
205
 
206
- __END__
207
- # We leave this here to indicate what the past behavior was with
208
- # model transactions.
209
-
210
- class Post < Ohm::Model
211
- attribute :body
212
- attribute :state
213
- index :state
214
-
215
- def before_save
216
- self.body = body.to_s.strip
206
+ test "banking transaction" do |db|
207
+ class A < Ohm::Model
208
+ attribute :amount
217
209
  end
218
210
 
219
- def before_create
220
- self.state = "draft"
211
+ class B < Ohm::Model
212
+ attribute :amount
221
213
  end
222
- end
223
-
224
- test "transactions in models" do |db|
225
- p = Post.new(body: " foo ")
226
214
 
227
- db.set "csv:foo", "A,B"
215
+ def transfer(amount, account1, account2)
216
+ Ohm.transaction do |t|
228
217
 
229
- t1 = Ohm::Transaction.define do |t|
230
- t.watch("csv:foo")
218
+ t.watch(account1.key, account2.key)
231
219
 
232
- t.read do |s|
233
- s.csv = db.get("csv:foo")
234
- end
220
+ t.read do |s|
221
+ s[:available] = account1.get(:amount).to_i
222
+ end
235
223
 
236
- t.write do |s|
237
- db.set("csv:foo", s.csv + "," + "C")
224
+ t.write do |s|
225
+ if s[:available] >= amount
226
+ account1.key.hincrby(:amount, - amount)
227
+ account2.key.hincrby(:amount, amount)
228
+ end
229
+ end
238
230
  end
239
231
  end
240
232
 
241
- main = Ohm::Transaction.new(p.transaction_for_create, t1)
242
- main.commit(db)
243
-
244
- # Verify the Post transaction proceeded without a hitch
245
- p = Post[p.id]
233
+ a = A.create :amount => 100
234
+ b = B.create :amount => 0
246
235
 
247
- assert_equal "draft", p.state
248
- assert_equal "foo", p.body
249
- assert Post.find(state: "draft").include?(p)
236
+ transfer(100, a, b).commit(db)
250
237
 
251
- # Verify that the second transaction happened
252
- assert_equal "A,B,C", db.get("csv:foo")
238
+ assert_equal a.get(:amount), "0"
239
+ assert_equal b.get(:amount), "100"
253
240
  end
data/test/uniques.rb CHANGED
@@ -17,7 +17,7 @@ class User < Ohm::Model
17
17
  end
18
18
 
19
19
  setup do
20
- User.create(email: "a@a.com")
20
+ User.create(:email => "a@a.com")
21
21
  end
22
22
 
23
23
  test "findability" do |u|
@@ -26,12 +26,12 @@ end
26
26
 
27
27
  test "raises when it already exists during create" do
28
28
  assert_raise Ohm::UniqueIndexViolation do
29
- User.create(email: "a@a.com")
29
+ User.create(:email => "a@a.com")
30
30
  end
31
31
  end
32
32
 
33
33
  test "raises when it already exists during save" do
34
- u = User.create(email: "b@b.com")
34
+ u = User.create(:email => "b@b.com")
35
35
  u.email = "a@a.com"
36
36
 
37
37
  assert_raise Ohm::UniqueIndexViolation do
@@ -52,8 +52,8 @@ test "doesn't raise when saving again and again" do |u|
52
52
  end
53
53
 
54
54
  test "removes the previous index when changing" do
55
- u = User.create(email: "c@c.com")
56
- u.update(email: "d@d.com")
55
+ u = User.create(:email => "c@c.com")
56
+ u.update(:email => "d@d.com")
57
57
 
58
58
  assert_equal nil, User.with(:email, "c@c.com")
59
59
  assert_equal nil, User.key[:unique][:email].hget("c@c.com")
@@ -68,20 +68,20 @@ test "removes the previous index when deleting" do |u|
68
68
  end
69
69
 
70
70
  test "unique virtual attribute" do
71
- u = User.create(email: "foo@yahoo.com")
71
+ u = User.create(:email => "foo@yahoo.com")
72
72
 
73
73
  assert_equal u, User.with(:provider, "yahoo")
74
74
 
75
75
  # Yahoo should be allowed because this user is the one reserved for it.
76
- u.update(email: "bar@yahoo.com")
76
+ u.update(:email => "bar@yahoo.com")
77
77
 
78
78
  # `a` is not allowed though.
79
79
  assert_raise Ohm::UniqueIndexViolation do
80
- u.update(email: "bar@a.com")
80
+ u.update(:email => "bar@a.com")
81
81
  end
82
82
 
83
83
  # And so is yahoo if we try creating a different user.
84
84
  assert_raise Ohm::UniqueIndexViolation do
85
- User.create(email: "baz@yahoo.com")
85
+ User.create(:email => "baz@yahoo.com")
86
86
  end
87
87
  end
data/test/validations.rb CHANGED
@@ -68,7 +68,7 @@ scope do
68
68
  event.save
69
69
 
70
70
  assert event.new?
71
- assert_equal({capacity: [:not_numeric]}, event.errors)
71
+ assert_equal({:capacity => [:not_numeric]}, event.errors)
72
72
  end
73
73
 
74
74
  test "fail when the value is not numeric" do |event|
@@ -82,7 +82,7 @@ scope do
82
82
  event.save
83
83
 
84
84
  assert event.new?
85
- assert_equal({capacity: [:not_numeric]}, event.errors)
85
+ assert_equal({:capacity => [:not_numeric]}, event.errors)
86
86
  end
87
87
 
88
88
  test "succeed when the value is numeric" do |event|
@@ -182,14 +182,14 @@ scope do
182
182
  test "fail when the attribute is nil" do |target|
183
183
  target.validate
184
184
 
185
- assert_equal({ name: [:not_present] }, target.errors)
185
+ assert_equal({ :name => [:not_present] }, target.errors)
186
186
  end
187
187
 
188
188
  test "fail when the attribute is empty" do |target|
189
189
  target.name = ""
190
190
  target.validate
191
191
 
192
- assert_equal({ name: [:not_present] }, target.errors)
192
+ assert_equal({ :name => [:not_present] }, target.errors)
193
193
  end
194
194
  end
195
195
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-03 00:00:00.000000000 Z
13
+ date: 2012-04-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nest
17
- requirement: &2155966540 !ruby/object:Gem::Requirement
17
+ requirement: &2151942880 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '1.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2155966540
25
+ version_requirements: *2151942880
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: scrivener
28
- requirement: &2155963980 !ruby/object:Gem::Requirement
28
+ requirement: &2151941460 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.0.3
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2155963980
36
+ version_requirements: *2151941460
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cutest
39
- requirement: &2155978980 !ruby/object:Gem::Requirement
39
+ requirement: &2151940600 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0.1'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2155978980
47
+ version_requirements: *2151940600
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: batch
50
- requirement: &2155978440 !ruby/object:Gem::Requirement
50
+ requirement: &2151936780 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 0.0.1
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2155978440
58
+ version_requirements: *2151936780
59
59
  description: Ohm is a library that allows to store an object in Redis, a persistent
60
60
  key-value database. It includes an extensible list of validations and has very good
61
61
  performance.