ohm 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohm.rb +6 -1
- data/test/model_test.rb +3 -4
- 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
|
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 "
|
98
|
-
|
99
|
-
|
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.
|
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-
|
13
|
+
date: 2009-06-27 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|