ohm 0.0.6 → 0.0.7

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.rb +6 -1
  2. data/test/model_test.rb +3 -4
  3. metadata +2 -2
data/lib/ohm.rb CHANGED
@@ -158,6 +158,10 @@ module Ohm
158
158
  end
159
159
  end
160
160
 
161
+ def new?
162
+ !id
163
+ end
164
+
161
165
  def create
162
166
  return unless valid?
163
167
  initialize_id
@@ -167,6 +171,7 @@ module Ohm
167
171
  end
168
172
 
169
173
  def save
174
+ create if new?
170
175
  return unless valid?
171
176
  update_indices
172
177
  save!
@@ -201,7 +206,7 @@ module Ohm
201
206
  protected
202
207
 
203
208
  def key(*args)
204
- raise ModelIsNew unless id
209
+ raise ModelIsNew if new?
205
210
  self.class.key(id, *args)
206
211
  end
207
212
 
data/test/model_test.rb CHANGED
@@ -94,10 +94,9 @@ class TestRedis < Test::Unit::TestCase
94
94
  end
95
95
 
96
96
  context "Saving a model" do
97
- should "not save a new model" do
98
- assert_raise Ohm::Model::ModelIsNew do
99
- Event.new.save
100
- end
97
+ should "create the model if it's new" do
98
+ event = Event.new(:name => "Foo").save
99
+ assert_equal "Foo", Event[event.id].name
101
100
  end
102
101
 
103
102
  should "save it only if it was previously created" 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.6
4
+ version: 0.0.7
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-06-22 00:00:00 -03:00
13
+ date: 2009-06-27 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies: []
16
16