ohm-expire 0.1.3.1 → 0.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ohm/expire.rb +2 -1
  2. data/test/expire-test.rb +14 -1
  3. metadata +2 -3
@@ -49,9 +49,10 @@ module Ohm
49
49
  #
50
50
  # * self
51
51
  def create(*args)
52
+ args = [{}] if args.empty?
52
53
  args.first.merge!(:_default_expire => @expire)
53
54
  object = super(*args)
54
- if !object.new? && @expire
55
+ if object && !object.new? && @expire
55
56
  Ohm.redis.expire(object.key, @expire)
56
57
  Ohm.redis.expire("#{object.key}:_indices", @expire)
57
58
  end
@@ -8,17 +8,22 @@ class Model < Ohm::Model
8
8
  TTL = 5
9
9
 
10
10
  attribute :hash
11
+ attribute :required_attr
11
12
  index :hash
12
13
 
13
14
  expire TTL
14
15
 
15
16
  attribute :data
17
+
18
+ def validate
19
+ assert_present :required_attr
20
+ end
16
21
  end
17
22
 
18
23
  test do
19
24
  Ohm.flush
20
25
 
21
- m = Model.create(:hash => "123")
26
+ m = Model.create(:hash => "123", :required_attr => "1")
22
27
  assert_equal Model::TTL, m.get_ttl
23
28
 
24
29
  m.update_ttl 3
@@ -37,4 +42,12 @@ test do
37
42
 
38
43
  m = Model.find(:hash => "123").first
39
44
  assert m.hash.nil?
45
+
46
+ # invalid model should not raise undefined method for nil:NilClass
47
+ invalid_model = Model.create(:hash => "123")
48
+ assert invalid_model.nil?
49
+
50
+ # invalid model should not raise undefined method for nil:NilClass
51
+ empty_model = Model.create
52
+ assert invalid_model.nil?
40
53
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ohm-expire
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3.1
5
+ version: 0.1.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Jos\xC3\xA9 P. Airosa"
@@ -72,10 +72,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements: []
73
73
 
74
74
  rubyforge_project: ohm-expire
75
- rubygems_version: 1.8.24
75
+ rubygems_version: 1.8.9
76
76
  signing_key:
77
77
  specification_version: 3
78
78
  summary: Ohm Expire Plugin
79
79
  test_files: []
80
80
 
81
- has_rdoc: