seanhussey-woulda 0.1.2 → 0.1.3

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/README.textile CHANGED
@@ -36,6 +36,7 @@ end
36
36
  # acts_as_taggable_on_steroids
37
37
  class PersonTest < Test::Unit::TestCase
38
38
  should_act_as_taggable_on_steroids
39
+ end
39
40
 
40
41
  # attachment_fu
41
42
  class ImageTest < Test::Unit::TestCase
@@ -43,7 +44,7 @@ class ImageTest < Test::Unit::TestCase
43
44
  end
44
45
 
45
46
  # enumeration_mixin
46
- class RoleTest < Test::Unit::
47
+ class RoleTest < Test::Unit::TestCase
47
48
  should_act_as_enumerated
48
49
  end
49
50
 
@@ -60,6 +61,11 @@ end
60
61
  # acts_as_solr
61
62
  class ProductTest < Test::Unit::TestCase
62
63
  should_act_as_solr :name, :price
64
+ end
65
+
66
+ # acts_as_state_machine
67
+ class OrderTest < Test::Unit::TestCase
68
+ should_act_as_state_machine :initial => :open, :states => [:closed], :events => {:close_order => {:to => :closed, :from :open}}
63
69
  end</code></pre>
64
70
 
65
71
  h2. The source
@@ -72,4 +78,4 @@ h2. Credit
72
78
 
73
79
  Written by "Sean Hussey":mailto:sean@seanhussey.com and "Josh Nichols":http://technicalpickles.com
74
80
 
75
- Copyright 2008 Sean Hussey and Josh Nichols.
81
+ Copyright 2008 Sean Hussey and Josh Nichols.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = "woulda"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
  s.summary = "woulda is a home for shoulda macros that don't belong in the main shoulda library"
10
10
  s.homepage = "http://github.com/seanhussey/woulda"
11
11
  s.rubyforge_project = "woulda"
@@ -0,0 +1,85 @@
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?(ScottBarron::Acts::StateMachine)
46
+ end
47
+
48
+ should "define ActsAsStateMachine class methods" do
49
+ assert klass.extended_by.include?(ScottBarron::Acts::StateMachine::ClassMethods), "#{klass} doesn't define ActsAsStateMachine class methods"
50
+ end
51
+
52
+ should "define ActsAsStateMachine instance methods" do
53
+ assert klass.include?(ScottBarron::Acts::StateMachine::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.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.states.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.transition_table.has_key?(event), "#{klass} does not define event #{event}"
70
+ end
71
+
72
+ to = transition[:to]
73
+ from = transition[:from]
74
+
75
+ should "transition to #{to} from #{from} on event #{event}" do
76
+ assert_not_nil klass.transition_table[event].detect { |t| t.to == to && t.from == from }, "#{event} does not transition to #{to} from #{from}"
77
+ end
78
+
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,6 @@
1
+ require 'shoulda'
2
+ require 'woulda/acts_as_state_machine/macros'
3
+
4
+ Test::Unit::TestCase.class_eval do
5
+ extend Woulda::ActsAsStateMachine::Macros
6
+ end
data/lib/woulda.rb CHANGED
@@ -6,4 +6,5 @@ require 'woulda/attachment_fu' if defined? Technoweenie::AttachmentFu
6
6
  require 'woulda/enumerations_mixin' if defined? ActiveRecord::Acts::Enumerated
7
7
  require 'woulda/paperclip' if defined? Paperclip
8
8
  require 'woulda/will_paginate' if defined? WillPaginate
9
- require 'woulda/acts_as_solr' if defined? ActsAsSolr
9
+ require 'woulda/acts_as_solr' if defined? ActsAsSolr
10
+ require 'woulda/acts_as_state_machine' if defined? ScottBarron::Acts::StateMachine
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Hussey
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-09-30 00:00:00 -07:00
13
+ date: 2008-10-04 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,9 @@ files:
50
50
  - lib/woulda/acts_as_solr
51
51
  - lib/woulda/acts_as_solr/macros.rb
52
52
  - lib/woulda/acts_as_solr.rb
53
+ - lib/woulda/acts_as_state_machine
54
+ - lib/woulda/acts_as_state_machine/macros.rb
55
+ - lib/woulda/acts_as_state_machine.rb
53
56
  - lib/woulda/acts_as_taggable_on_steroids
54
57
  - lib/woulda/acts_as_taggable_on_steroids/macros.rb
55
58
  - lib/woulda/acts_as_taggable_on_steroids.rb