seanhussey-woulda 0.2.0 → 0.2.1
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/VERSION.yml
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
module Woulda
|
2
|
+
module ActsAsStateMachine
|
3
|
+
module Macros
|
4
|
+
# Example:
|
5
|
+
#
|
6
|
+
# class Order < ActiveRecord::Base
|
7
|
+
# acts_as_state_machine :initial => :open
|
8
|
+
#
|
9
|
+
# state :open
|
10
|
+
# state :closed
|
11
|
+
#
|
12
|
+
# event :close_order do
|
13
|
+
# transitions :to => :closed, :from => :open
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# class OrderTest < Test::Unit::TestCase
|
18
|
+
#
|
19
|
+
# # check the inital state
|
20
|
+
# should_act_as_state_machine :initial => :open
|
21
|
+
#
|
22
|
+
# # check states in addition to :initial
|
23
|
+
# should_act_as_state_machine :initial => :open, :states => [:closed]
|
24
|
+
#
|
25
|
+
# # check events and transitions
|
26
|
+
# should_act_as_state_machine :events => {:close_order => {:to => :closed, :from :open}}
|
27
|
+
#
|
28
|
+
# should_act_as_state_machine :initial => :open, :states => [:closed], :events => {:close_order => {:to => :closed, :from :open}}
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
def should_act_as_state_machine(opts={})
|
32
|
+
klass = model_class
|
33
|
+
|
34
|
+
initial_state, states, events, db_column = get_options!([opts], :initial, :states, :events, :column)
|
35
|
+
|
36
|
+
states ||= []
|
37
|
+
events ||= {}
|
38
|
+
db_column ||= :state
|
39
|
+
|
40
|
+
context "A #{klass.name}" do
|
41
|
+
|
42
|
+
should_have_db_column db_column
|
43
|
+
|
44
|
+
should "include the ActsAsStateMachine module" do
|
45
|
+
assert klass.included_modules.include?(AASM)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "define ActsAsStateMachine class methods" do
|
49
|
+
assert klass.extended_by.include?(AASM::ClassMethods), "#{klass} doesn't define ActsAsStateMachine class methods"
|
50
|
+
end
|
51
|
+
|
52
|
+
should "define ActsAsStateMachine instance methods" do
|
53
|
+
assert klass.include?(AASM::InstanceMethods), "#{klass} doesn't define ActsAsStateMachine instance methods"
|
54
|
+
end
|
55
|
+
|
56
|
+
should "have an intital state of #{initial_state}" do
|
57
|
+
assert_equal initial_state, klass.aasm_initial_state, "#{klass} does not have an initial state of #{initial_state}"
|
58
|
+
end
|
59
|
+
|
60
|
+
states.each do |state|
|
61
|
+
should "include state #{state}" do
|
62
|
+
assert klass.aasm_states.map { |state| state.name}.include?(state), "#{klass} does not include state #{state}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
events.each do |event, transition|
|
67
|
+
|
68
|
+
should "define an event #{event}" do
|
69
|
+
assert klass.aasm_events.has_key?(event), "#{klass} does not define event #{event}"
|
70
|
+
end
|
71
|
+
|
72
|
+
to = transition[:to]
|
73
|
+
from = transition[:from].is_a?(Symbol) ? [transition[:from]] : transition[:from]
|
74
|
+
|
75
|
+
from.each do |from_state|
|
76
|
+
should "transition to #{to} from #{from_state} on event #{event}" do
|
77
|
+
assert_not_nil klass.aasm_events[event].instance_variable_get("@transitions").detect { |t| t.to == to && t.from == from_state }, "#{event} does not transition to #{to} from #{from_state}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
File without changes
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'shoulda'
|
2
|
-
require File.dirname(__FILE__) + '/acts_as_state_machine/
|
2
|
+
require File.dirname(__FILE__) + '/acts_as_state_machine/macros_old' unless const_defined?(AASM)
|
3
|
+
require File.dirname(__FILE__) + '/acts_as_state_machine/macros_new' if const_defined?(AASM)
|
3
4
|
|
4
5
|
Test::Unit::TestCase.class_eval do
|
5
6
|
extend Woulda::ActsAsStateMachine::Macros
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seanhussey-woulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Hussey
|
@@ -10,11 +10,12 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-02-24 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: thoughtbot-shoulda
|
18
|
+
type: :runtime
|
18
19
|
version_requirement:
|
19
20
|
version_requirements: !ruby/object:Gem::Requirement
|
20
21
|
requirements:
|
@@ -52,7 +53,8 @@ files:
|
|
52
53
|
- lib/woulda/acts_as_solr/macros.rb
|
53
54
|
- lib/woulda/acts_as_solr.rb
|
54
55
|
- lib/woulda/acts_as_state_machine
|
55
|
-
- lib/woulda/acts_as_state_machine/
|
56
|
+
- lib/woulda/acts_as_state_machine/macros_new.rb
|
57
|
+
- lib/woulda/acts_as_state_machine/macros_old.rb
|
56
58
|
- lib/woulda/acts_as_state_machine.rb
|
57
59
|
- lib/woulda/acts_as_taggable_on_steroids
|
58
60
|
- lib/woulda/acts_as_taggable_on_steroids/macros.rb
|