active_nomad 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/active_nomad/version.rb +1 -1
- data/lib/active_nomad.rb +17 -16
- data/spec/unit/active_nomad_spec.rb +26 -2
- metadata +4 -4
data/CHANGELOG
CHANGED
data/lib/active_nomad/version.rb
CHANGED
data/lib/active_nomad.rb
CHANGED
@@ -2,8 +2,6 @@ require 'active_record'
|
|
2
2
|
require 'cgi'
|
3
3
|
|
4
4
|
module ActiveNomad
|
5
|
-
NoPersistenceStrategy = Class.new(RuntimeError)
|
6
|
-
|
7
5
|
class Base < ActiveRecord::Base
|
8
6
|
#
|
9
7
|
# Tell this record how to save itself.
|
@@ -97,30 +95,33 @@ module ActiveNomad
|
|
97
95
|
from_serialized_attributes(serialized_attributes)
|
98
96
|
end
|
99
97
|
|
100
|
-
protected
|
101
|
-
|
102
98
|
#
|
103
|
-
#
|
99
|
+
# Destroy the object.
|
104
100
|
#
|
105
101
|
# The default is to call the block registered with
|
106
|
-
# #
|
102
|
+
# #to_destroy. Override if you don't want to use #to_destroy.
|
107
103
|
#
|
108
|
-
def
|
109
|
-
@
|
110
|
-
|
111
|
-
|
104
|
+
def destroy
|
105
|
+
if @destroy_proc
|
106
|
+
@destroy_proc.call(self)
|
107
|
+
end
|
108
|
+
self
|
112
109
|
end
|
113
110
|
|
111
|
+
protected
|
112
|
+
|
114
113
|
#
|
115
|
-
#
|
114
|
+
# Persist the object.
|
116
115
|
#
|
117
116
|
# The default is to call the block registered with
|
118
|
-
# #
|
117
|
+
# #to_save. Override if you don't want to use #to_save.
|
119
118
|
#
|
120
|
-
def
|
121
|
-
@
|
122
|
-
|
123
|
-
|
119
|
+
def persist
|
120
|
+
if @save_proc
|
121
|
+
@save_proc.call(self)
|
122
|
+
else
|
123
|
+
true
|
124
|
+
end
|
124
125
|
end
|
125
126
|
|
126
127
|
private
|
@@ -84,9 +84,9 @@ describe ActiveNomad::Base do
|
|
84
84
|
|
85
85
|
describe "#save" do
|
86
86
|
describe "when no save strategy has been defined" do
|
87
|
-
it "should
|
87
|
+
it "should return true" do
|
88
88
|
instance = ActiveNomad::Base.new
|
89
|
-
|
89
|
+
instance.save.should be_true
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -123,6 +123,30 @@ describe ActiveNomad::Base do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
describe "#destroy" do
|
127
|
+
describe "no destruction strategy has been defined" do
|
128
|
+
it "should return the object" do
|
129
|
+
instance = ActiveNomad::Base.new
|
130
|
+
instance.destroy.should equal(instance)
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "when a destruction strategy has been defined" do
|
134
|
+
before do
|
135
|
+
destroys = @destroys = []
|
136
|
+
@instance = ActiveNomad::Base.new
|
137
|
+
@instance.to_destroy do |*args|
|
138
|
+
destroys << args
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should call the destroy_proc with the record as an argument" do
|
143
|
+
@instance.destroy
|
144
|
+
@destroys.should == [[@instance]]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
126
150
|
describe "#to_serialized_attributes" do
|
127
151
|
it "should return a list of attribute names with serialized attributes, sorted by name" do
|
128
152
|
klass = Class.new(ActiveNomad::Base) do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_nomad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- George Ogata
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|