ohm-contrib 0.0.24 → 0.0.25

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.24
1
+ 0.0.25
@@ -20,14 +20,13 @@ module Ohm
20
20
  end
21
21
 
22
22
  module ClassMethods
23
- def first
24
- all.first
23
+ def first(opts = {})
24
+ find(opts).sort(:start => 0, :limit => 1).first
25
25
  end
26
26
 
27
- # @todo Add support for passing in conditions
28
- def last
29
- self[db.get(key(:id))]
27
+ def last(opts = {})
28
+ find(opts).sort(:start => 0, :limit => 1, :order => "DESC").first
30
29
  end
31
30
  end
32
31
  end
33
- end
32
+ end
@@ -32,7 +32,8 @@ module Ohm
32
32
  extend ::Forwardable
33
33
 
34
34
  @@delegation_blacklist = [
35
- :==, :to_s, :initialize, :inspect, :object_id, :__send__, :__id__
35
+ :==, :to_s, :initialize, :inspect, :object_id, :__send__, :__id__,
36
+ :respond_to?
36
37
  ]
37
38
 
38
39
  def self.[](value)
@@ -68,6 +69,12 @@ module Ohm
68
69
  to_s == other.to_s
69
70
  end
70
71
 
72
+ def respond_to?(method)
73
+ object.respond_to?(method)
74
+ rescue ::ArgumentError
75
+ @raw.respond_to?(method)
76
+ end
77
+
71
78
  protected
72
79
  def object
73
80
  @raw
@@ -161,6 +168,10 @@ module Ohm
161
168
  object.to_json
162
169
  end
163
170
  alias :inspect :to_s
171
+
172
+ def respond_to?(method)
173
+ object.respond_to?(method)
174
+ end
164
175
  end
165
176
 
166
177
  class Hash < Serialized
data/lib/ohm/contrib.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ohm
2
2
  module Contrib
3
- VERSION = '0.0.24'
3
+ VERSION = '0.0.26'
4
4
  end
5
5
 
6
6
  autoload :Boundaries, "ohm/contrib/boundaries"
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.24"
8
+ s.version = "0.0.25"
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-11}
12
+ s.date = %q{2010-06-19}
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 = [
data/test/helper.rb CHANGED
@@ -6,11 +6,11 @@ require 'ohm'
6
6
  require 'timecop'
7
7
  require 'mocha'
8
8
 
9
- Ohm.connect :host => "localhost", :port => "6380"
9
+ Ohm.connect :host => "localhost", :port => "6379"
10
10
 
11
11
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
12
  $LOAD_PATH.unshift(File.dirname(__FILE__))
13
13
  require 'ohm/contrib'
14
14
 
15
15
  class Test::Unit::TestCase
16
- end
16
+ end
@@ -9,6 +9,7 @@ class TestOhmBoundaries < Test::Unit::TestCase
9
9
  include Ohm::Boundaries
10
10
 
11
11
  attribute :name
12
+ index :name
12
13
  end
13
14
 
14
15
  context "when there are no People" do
@@ -48,5 +49,33 @@ class TestOhmBoundaries < Test::Unit::TestCase
48
49
  should "have linus as the last Person" do
49
50
  assert_equal @linus, Person.last
50
51
  end
52
+
53
+ context "when searching name => matz" do
54
+ should "have matz as the first Person" do
55
+ assert_equal @matz, Person.first(:name => "matz")
56
+ end
57
+
58
+ should "have matz as the last Person" do
59
+ assert_equal @matz, Person.last(:name => "matz")
60
+ end
61
+ end
62
+
63
+ context "when searching name => linus" do
64
+ should "have matz as the first Person" do
65
+ assert_equal @linus, Person.first(:name => "linus")
66
+ end
67
+
68
+ should "have matz as the last Person" do
69
+ assert_equal @linus, Person.last(:name => "linus")
70
+ end
71
+ end
72
+
73
+ context "when searching name => quentin" do
74
+ should "have nil as first and last" do
75
+ assert_nil Person.first(:name => "quentin")
76
+ assert_nil Person.last(:name => "quentin")
77
+ end
78
+ end
79
+
51
80
  end
52
- end
81
+ end
@@ -133,6 +133,20 @@ class TestOhmTypecast < Test::Unit::TestCase
133
133
  assert_equal "", post.price.to_s
134
134
  end
135
135
 
136
+ test "allows respond_to on an invalid integer" do
137
+ post = Post.new(:price => "FooBar")
138
+ assert_nothing_raised ArgumentError do
139
+ post.price.respond_to?(:**)
140
+ end
141
+
142
+ assert ! post.price.respond_to?(:**)
143
+ end
144
+
145
+ test "falls back to String#respond_to? when invalid" do
146
+ post = Post.new(:price => "FooBar")
147
+ assert post.price.respond_to?(:capitalize)
148
+ end
149
+
136
150
  test "allows for real arithmetic" do
137
151
  post = Post.create(:price => "3")
138
152
  post = Post[post.id]
@@ -259,10 +273,10 @@ class TestOhmTypecast < Test::Unit::TestCase
259
273
  post = Post.create(:created_at => "FooBar")
260
274
  post = Post[post.id]
261
275
 
262
- assert ! post.created_at.respond_to?(:slice)
276
+ assert ! post.created_at.respond_to?(:abs)
263
277
 
264
278
  assert_raise NoMethodError do
265
- post.created_at.slice
279
+ post.created_at.abs
266
280
  end
267
281
  end
268
282
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 24
9
- version: 0.0.24
8
+ - 25
9
+ version: 0.0.25
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-11 00:00:00 +08:00
17
+ date: 2010-06-19 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency