yasm 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.0.11
2
+ -- bug fix: now, whether you're finding documents via get, find, or by_*, yasm state will be restored.
3
+ -- fixed a bug with namespaced action symbols
4
+ -- fixed a bug with two types of the same state getting loaded on initialization from the database
5
+
1
6
  v0.0.10
2
7
  -- you can now access the context from the state
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -14,9 +14,15 @@ Feature: CouchRest::Model Persistance
14
14
  When I save that context to CouchDB
15
15
  Then the states should be saved in the document
16
16
 
17
- Scenario: Loading state from CouchRest::Model::Base derived classes
17
+ @focus
18
+ Scenario Outline: Loading state from CouchRest::Model::Base derived classes
18
19
  Given a couchrest model context with state saved in the database
19
- When I load that context
20
+ When I load that context via "<method>"
20
21
  Then the states should be restored
21
22
  And the states should be fast forwarded
22
23
 
24
+ Examples:
25
+ |method|
26
+ |get|
27
+ |find|
28
+ |by_user|
@@ -53,7 +53,10 @@ end
53
53
 
54
54
  Given /^a couchrest model context with state saved in the database$/ do
55
55
  class CouchContext < CouchRest::Model::Base
56
+ use_database YASM_COUCH_DB
56
57
  include Yasm::Context
58
+ property :user
59
+ view_by :user
57
60
 
58
61
  start :couch_state1
59
62
  end
@@ -68,16 +71,22 @@ Given /^a couchrest model context with state saved in the database$/ do
68
71
  end
69
72
  class GoToState2; include Yasm::Action; triggers :couch_state2; end
70
73
  class GoToState3; include Yasm::Action; triggers :couch_state3; end
71
- @couch_context = CouchContext.new
74
+ @couch_context = CouchContext.new :user => "moonmaster9000"
72
75
  @couch_context.do! GoToState2
73
76
  @state_start_time = @couch_context.state.value.instantiated_at
74
77
  @couch_context.save
75
78
  end
76
79
 
77
- When /^I load that context$/ do
80
+ When /^I load that context via "([^\"]*)"$/ do |method|
78
81
  ten_minutes_from_now = 10.minutes.from_now
79
82
  Time.stub(:now).and_return ten_minutes_from_now
80
- @couch_context = CouchContext.find @couch_context.id
83
+
84
+ case method
85
+ when "get" then @couch_context = CouchContext.get @couch_context.id
86
+ when "find" then @couch_context = CouchContext.find @couch_context.id
87
+ when "by_user" then @couch_context = CouchContext.by_user(:key => @couch_context.user).first
88
+ else raise "Unknown Method!"
89
+ end
81
90
  end
82
91
 
83
92
  Then /^the states should be restored$/ do
@@ -6,14 +6,18 @@ module Yasm
6
6
  base.extend GetMethods
7
7
  base.before_save :save_yasm_states
8
8
  class << base
9
- alias_method_chain :get, :load_yasm_states
10
- alias_method_chain :find, :load_yasm_states
9
+ alias_method_chain :create_from_database, :load_yasm_states
11
10
  end
12
11
  end
13
12
 
14
13
  module GetMethods
15
- def get_with_load_yasm_states(id, db = database)
16
- doc = get_without_load_yasm_states id, db
14
+ def create_from_database_with_load_yasm_states(doc = {})
15
+ result = create_from_database_without_load_yasm_states doc
16
+ setup_document_state result
17
+ end
18
+
19
+ private
20
+ def setup_document_state(doc)
17
21
  doc.class.state_configurations.keys.each do |state_name|
18
22
  Yasm::Manager.change_state(
19
23
  :to => doc["yasm"]["states"][state_name.to_s]["class"].to_sym.to_class,
@@ -24,8 +28,6 @@ module Yasm
24
28
  doc.fast_forward if doc
25
29
  doc
26
30
  end
27
-
28
- alias :find_with_load_yasm_states :get_with_load_yasm_states
29
31
  end
30
32
 
31
33
  private
@@ -34,7 +36,7 @@ module Yasm
34
36
  self["yasm"]["states"] ||= {}
35
37
  self.class.state_configurations.keys.each do |state_name|
36
38
  container = state_container state_name
37
- self["yasm"]["states"][state_name] = {
39
+ self["yasm"]["states"][state_name.to_s] = {
38
40
  :class => container.value.class.to_s,
39
41
  :instantiated_at => container.value.instantiated_at
40
42
  }
@@ -15,7 +15,7 @@ module Yasm
15
15
 
16
16
  def is_allowed?(action)
17
17
  return true if @allowed_actions.nil?
18
- @allowed_actions.include? action.to_sym
18
+ @allowed_actions.map(&:to_class).include? action.to_class
19
19
  end
20
20
 
21
21
  def final!
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yasm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.10
5
+ version: 0.0.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Parker