sidestate 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sidestate/hook.rb +6 -1
- data/spec/sidestate/hook_spec.rb +5 -0
- metadata +3 -3
data/lib/sidestate/hook.rb
CHANGED
@@ -4,7 +4,8 @@ module Sidestate::Hook
|
|
4
4
|
extend Sidestate::Hook::ClassMethods
|
5
5
|
has_many aasm_state_collection
|
6
6
|
|
7
|
-
|
7
|
+
after_create :save_aasm_state_object_for_new_record
|
8
|
+
after_update :save_aasm_state_object
|
8
9
|
|
9
10
|
define_method(aasm_state_object) do
|
10
11
|
aasm_state_collection.last
|
@@ -47,6 +48,10 @@ module Sidestate::Hook
|
|
47
48
|
aasm_state_collection.create! :name => new_state.to_s, self.class.name.underscore.to_sym => self
|
48
49
|
end
|
49
50
|
|
51
|
+
def save_aasm_state_object_for_new_record
|
52
|
+
aasm_state_collection.create! :name => aasm_current_state.to_s, self.class.name.underscore.to_sym => self
|
53
|
+
end
|
54
|
+
|
50
55
|
def aasm_state_collection
|
51
56
|
send(self.class.aasm_state_collection)
|
52
57
|
end
|
data/spec/sidestate/hook_spec.rb
CHANGED
@@ -7,6 +7,11 @@ describe Sidestate::Hook do
|
|
7
7
|
article.article_state.should_not be_nil
|
8
8
|
end
|
9
9
|
|
10
|
+
it "should only create one state object when the model is created" do
|
11
|
+
article = Article.create
|
12
|
+
article.article_states.length.should == 1
|
13
|
+
end
|
14
|
+
|
10
15
|
it "should set the state accordingly" do
|
11
16
|
Article.create.article_state.name.should == 'draft'
|
12
17
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pat Allan
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-29 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|