ohm 0.0.21 → 0.0.22

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/lib/ohm.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require "base64"
2
4
  require File.join(File.dirname(__FILE__), "ohm", "redis")
3
5
  require File.join(File.dirname(__FILE__), "ohm", "validations")
@@ -473,8 +475,8 @@ module Ohm
473
475
 
474
476
  mutex do
475
477
  create_model_membership
476
- add_to_indices
477
478
  write
479
+ add_to_indices
478
480
  end
479
481
  end
480
482
 
@@ -483,8 +485,8 @@ module Ohm
483
485
  return unless valid?
484
486
 
485
487
  mutex do
486
- update_indices
487
488
  write
489
+ update_indices
488
490
  end
489
491
  end
490
492
 
@@ -563,7 +565,6 @@ module Ohm
563
565
 
564
566
  def write
565
567
  attributes.each { |att| write_remote(att, send(att)) }
566
- self
567
568
  end
568
569
 
569
570
  private
@@ -648,7 +649,9 @@ module Ohm
648
649
  end
649
650
 
650
651
  def write_remote(att, value)
651
- db.set(key(att), value)
652
+ value.nil? ?
653
+ db.del(key(att)) :
654
+ db.set(key(att), value)
652
655
  end
653
656
 
654
657
  def read_locals(attrs)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'socket'
2
4
 
3
5
  begin
@@ -238,7 +240,7 @@ module Ohm
238
240
  def format_bulk_reply(line)
239
241
  bulklen = line.to_i
240
242
  return nil if bulklen == -1
241
- reply = @sock.read(bulklen)
243
+ reply = @sock.read(bulklen).encode("UTF-8")
242
244
  @sock.read(2) # Discard CRLF.
243
245
  reply
244
246
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module Ohm
2
4
  module Validations
3
5
  class Presenter
@@ -8,11 +8,13 @@ class IndicesTest < Test::Unit::TestCase
8
8
  class User < Ohm::Model
9
9
  attribute :email
10
10
  attribute :update
11
+ attribute :activation_code
11
12
 
12
13
  index :email
13
14
  index :email_provider
14
15
  index :working_days
15
16
  index :update
17
+ index :activation_code
16
18
 
17
19
  def email_provider
18
20
  email.split("@").last
@@ -21,6 +23,11 @@ class IndicesTest < Test::Unit::TestCase
21
23
  def working_days
22
24
  @working_days ||= []
23
25
  end
26
+
27
+ def write
28
+ self.activation_code ||= "user:#{id}"
29
+ super
30
+ end
24
31
  end
25
32
 
26
33
  context "A model with an indexed attribute" do
@@ -69,6 +76,10 @@ class IndicesTest < Test::Unit::TestCase
69
76
  assert_equal [@user1, @user2], User.find(:email_provider, "gmail.com").to_a.sort_by { |u| u.id }
70
77
  assert_equal [@user3], User.find(:email_provider, "yahoo.com")
71
78
  end
79
+
80
+ should "allow indexing by an attribute that is lazily set" do
81
+ assert_equal [@user1], User.find(:activation_code, "user:1").to_a
82
+ end
72
83
  end
73
84
 
74
85
  context "Indexing enumerables" do
@@ -55,6 +55,7 @@ class TestRedis < Test::Unit::TestCase
55
55
  context "An event updated from a hash of attributes" do
56
56
  class Meetup < Ohm::Model
57
57
  attribute :name
58
+ attribute :location
58
59
 
59
60
  def validate
60
61
  assert_present :name
@@ -71,6 +72,18 @@ class TestRedis < Test::Unit::TestCase
71
72
  event = Meetup.create(:name => "Ruby Tuesday")
72
73
  assert !event.update(:name => nil)
73
74
  end
75
+
76
+ should "save the attributes in UTF8" do
77
+ event = Meetup.create(:name => "Ruby Tuesday")
78
+ assert_equal "UTF-8", Meetup[event.id].name.encoding.to_s
79
+ end
80
+
81
+ should "delete the attribute if set to nil" do
82
+ event = Meetup.create(:name => "Ruby Tuesday", :location => "Los Angeles")
83
+ assert_equal "Los Angeles", Meetup[event.id].location
84
+ assert event.update(:location => nil)
85
+ assert_equal nil, Meetup[event.id].location
86
+ end
74
87
  end
75
88
 
76
89
  context "Finding an event" do
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: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-21 00:00:00 -03:00
13
+ date: 2009-09-25 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies: []
16
16