aasm 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88085e60d048a49a0b7d88c73810dbed9e028926
4
- data.tar.gz: 86b196aee05e522b0235cbf0d8ed6b2f66cde027
3
+ metadata.gz: 3953eaa965802447de8e3783a35c91dcc89e87a4
4
+ data.tar.gz: 1b70e517fc29f1fad325a0a46d126cab2eebf029
5
5
  SHA512:
6
- metadata.gz: b339bead8353bed92cfe761bf0fedab3aa48ee24edb030e1f992ab0de1342ec5d8228f185ed81cd3f45519a778db110edc41baa885dc549624fe7408ea3205ac
7
- data.tar.gz: 10433114be6eec38b4eb0ebc191b7f093cb25d5f45215f172354cbfbfc5cbcebc5b8e0ead5d8cc42a19731e40ee5e65ea29ac76f5a501405fac427d3ea836e67
6
+ metadata.gz: 220319a5169ac9f1928a5beaaacf81c72d47ab3cf972dea079633fcc82ac8bfa3d42c97c0ffa38b9526e1a50b729ba331cc7ae29a1267dddd4d3e9ae52a7cd70
7
+ data.tar.gz: 0eff6b102e298af64e76e6f71cff21989d260c626efada6ed5dc763d092d351fac20a9696f1882ab8110e535b20897def8c5c7d2c013d7df82e4b6c437590a2f
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ TODO
15
15
  .ruby-gemset
16
16
  alto
17
17
  .rspec
18
+ .bundle
19
+
@@ -4,6 +4,10 @@
4
4
 
5
5
  * deprecated old aasm_* class methods (old-style DSL), in preparation for AASM v4.0.0
6
6
 
7
+ ## 3.2.1
8
+
9
+ * bugfix: permissible_events and events did not contain events with an empty "from" transition (see [issue #140](https://github.com/aasm/aasm/issues/140) and [issue #141](https://github.com/aasm/aasm/issues/141), thanks to [@daniel-rikowski](https://github.com/daniel-rikowski))
10
+
7
11
  ## 3.2.0
8
12
 
9
13
  * support [Sequel](http://sequel.jeremyevans.net/) (see [issue #119](https://github.com/aasm/aasm/issues/119), thanks to [@godfat](https://github.com/godfat))
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  # s.add_development_dependency 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
20
20
  s.add_development_dependency 'rake'
21
21
  s.add_development_dependency 'sdoc'
22
- s.add_development_dependency 'rspec', '>= 2.14'
22
+ s.add_development_dependency 'rspec', '~> 2.14'
23
23
  s.add_development_dependency 'rr'
24
24
  # s.add_development_dependency 'sqlite3'
25
25
  s.add_development_dependency 'minitest'
@@ -5,7 +5,7 @@ module AASM
5
5
 
6
6
  # do not overwrite existing state machines, which could have been created by
7
7
  # inheritance, see class method inherited
8
- AASM::StateMachine[base] ||= AASM::StateMachine.new('')
8
+ AASM::StateMachine[base] ||= AASM::StateMachine.new
9
9
 
10
10
  AASM::Persistence.load_persistence(base)
11
11
  super
@@ -1,9 +1,9 @@
1
1
  module AASM
2
2
  class Base
3
3
 
4
- def initialize(clazz, options={}, &block)
5
- @clazz = clazz
6
- @state_machine = AASM::StateMachine[@clazz]
4
+ def initialize(klass, options={}, &block)
5
+ @klass = klass
6
+ @state_machine = AASM::StateMachine[@klass]
7
7
  @state_machine.config.column = options[:column].to_sym if options[:column]
8
8
  @options = options
9
9
 
@@ -30,15 +30,14 @@ module AASM
30
30
 
31
31
  # define a state
32
32
  def state(name, options={})
33
- @state_machine.add_state(name, @clazz, options)
34
- @state_machine.initial_state = name if options[:initial] || !@state_machine.initial_state
33
+ @state_machine.add_state(name, @klass, options)
35
34
 
36
- @clazz.send(:define_method, "#{name.to_s}?") do
35
+ @klass.send(:define_method, "#{name.to_s}?") do
37
36
  aasm.current_state == name
38
37
  end
39
38
 
40
- unless @clazz.const_defined?("STATE_#{name.to_s.upcase}")
41
- @clazz.const_set("STATE_#{name.to_s.upcase}", name)
39
+ unless @klass.const_defined?("STATE_#{name.to_s.upcase}")
40
+ @klass.const_set("STATE_#{name.to_s.upcase}", name)
42
41
  end
43
42
  end
44
43
 
@@ -49,15 +48,15 @@ module AASM
49
48
  # an addition over standard aasm so that, before firing an event, you can ask
50
49
  # may_event? and get back a boolean that tells you whether the guard method
51
50
  # on the transition will let this happen.
52
- @clazz.send(:define_method, "may_#{name.to_s}?") do |*args|
51
+ @klass.send(:define_method, "may_#{name.to_s}?") do |*args|
53
52
  aasm.may_fire_event?(name, *args)
54
53
  end
55
54
 
56
- @clazz.send(:define_method, "#{name.to_s}!") do |*args, &block|
55
+ @klass.send(:define_method, "#{name.to_s}!") do |*args, &block|
57
56
  aasm_fire_event(name, {:persist => true}, *args, &block)
58
57
  end
59
58
 
60
- @clazz.send(:define_method, "#{name.to_s}") do |*args, &block|
59
+ @klass.send(:define_method, "#{name.to_s}") do |*args, &block|
61
60
  aasm_fire_event(name, {:persist => false}, *args, &block)
62
61
  end
63
62
  end
@@ -26,7 +26,7 @@ module AASM
26
26
  end
27
27
 
28
28
  def transitions_from_state(state)
29
- @transitions.select { |t| t.from == state }
29
+ @transitions.select { |t| t.from.nil? or t.from == state }
30
30
  end
31
31
 
32
32
  def transitions_to_state?(state)
@@ -87,26 +87,26 @@ module AASM
87
87
  # make sure to create a (named) scope for each state
88
88
  def state_with_scope(name, *args)
89
89
  state_without_scope(name, *args)
90
- if AASM::StateMachine[@clazz].config.create_scopes && !@clazz.respond_to?(name)
91
- if @clazz.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
90
+ if AASM::StateMachine[@klass].config.create_scopes && !@klass.respond_to?(name)
91
+ if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
92
92
 
93
- conditions = {"#{@clazz.table_name}.#{@clazz.aasm_column}" => name.to_s}
93
+ conditions = {"#{@klass.table_name}.#{@klass.aasm_column}" => name.to_s}
94
94
  if ActiveRecord::VERSION::MAJOR >= 4
95
- @clazz.class_eval do
95
+ @klass.class_eval do
96
96
  scope name, lambda { where(conditions) }
97
97
  end
98
98
  elsif ActiveRecord::VERSION::MAJOR >= 3
99
- @clazz.class_eval do
99
+ @klass.class_eval do
100
100
  scope name, where(conditions)
101
101
  end
102
102
  else
103
- @clazz.class_eval do
103
+ @klass.class_eval do
104
104
  named_scope name, :conditions => conditions
105
105
  end
106
106
  end
107
- elsif @clazz.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document")
108
- scope_options = lambda { @clazz.send(:where, {@clazz.aasm_column.to_sym => name.to_s}) }
109
- @clazz.send(:scope, name, scope_options)
107
+ elsif @klass.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document")
108
+ scope_options = lambda { @klass.send(:where, {@klass.aasm_column.to_sym => name.to_s}) }
109
+ @klass.send(:scope, name, scope_options)
110
110
  end
111
111
  end
112
112
  end
@@ -2,9 +2,9 @@ module AASM
2
2
  class State
3
3
  attr_reader :name, :options
4
4
 
5
- def initialize(name, clazz, options={})
5
+ def initialize(name, klass, options={})
6
6
  @name = name
7
- @clazz = clazz
7
+ @klass = klass
8
8
  update(options)
9
9
  end
10
10
 
@@ -48,7 +48,7 @@ module AASM
48
48
  end
49
49
 
50
50
  def localized_name
51
- AASM::Localizer.new.human_state_name(@clazz, self)
51
+ AASM::Localizer.new.human_state_name(@klass, self)
52
52
  end
53
53
  alias human_name localized_name
54
54
 
@@ -2,20 +2,17 @@ module AASM
2
2
  class StateMachine
3
3
 
4
4
  # the following two methods provide the storage of all state machines
5
- def self.[](clazz)
6
- (@machines ||= {})[clazz.to_s]
5
+ def self.[](klass)
6
+ (@machines ||= {})[klass.to_s]
7
7
  end
8
8
 
9
- def self.[]=(clazz, machine)
10
- (@machines ||= {})[clazz.to_s] = machine
9
+ def self.[]=(klass, machine)
10
+ (@machines ||= {})[klass.to_s] = machine
11
11
  end
12
12
 
13
13
  attr_accessor :states, :events, :initial_state, :config
14
- attr_reader :name
15
14
 
16
- # QUESTION: what's the name for? [alto, 2012-11-28]
17
- def initialize(name)
18
- @name = name
15
+ def initialize
19
16
  @initial_state = nil
20
17
  @states = []
21
18
  @events = {}
@@ -29,8 +26,15 @@ module AASM
29
26
  @events = @events.dup
30
27
  end
31
28
 
32
- def add_state(name, clazz, options)
33
- @states << AASM::State.new(name, clazz, options) unless @states.include?(name)
29
+ def add_state(name, klass, options)
30
+ set_initial_state(name, options)
31
+ @states << AASM::State.new(name, klass, options) unless @states.include?(name)
32
+ end
33
+
34
+ private
35
+
36
+ def set_initial_state(name, options)
37
+ @initial_state = name if options[:initial] || !initial_state
34
38
  end
35
39
 
36
40
  end # StateMachine
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "3.2.0"
2
+ VERSION = "3.2.1"
3
3
  end
@@ -58,6 +58,23 @@ describe 'transition inspection' do
58
58
  end
59
59
  end
60
60
 
61
+ describe 'transition inspection without from' do
62
+ let(:event) do
63
+ AASM::Event.new(:run) do
64
+ transitions :to => :running
65
+ end
66
+ end
67
+
68
+ it 'should support inspecting transitions from other states' do
69
+ expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
70
+ expect(event.transitions_from_state?(:sleeping)).to be_true
71
+
72
+ expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([:running])
73
+ expect(event.transitions_from_state?(:cleaning)).to be_true
74
+ end
75
+
76
+ end
77
+
61
78
  describe 'firing an event' do
62
79
  it 'should return nil if the transitions are empty' do
63
80
  obj = double('object', :aasm => double('aasm', :current_state => 'open'))
@@ -2,8 +2,8 @@
2
2
 
3
3
  # describe "state machines" do
4
4
 
5
- # def number_of_objects(clazz)
6
- # ObjectSpace.each_object(clazz) {}
5
+ # def number_of_objects(klass)
6
+ # ObjectSpace.each_object(klass) {}
7
7
  # end
8
8
 
9
9
  # def machines
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Barron
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-05-16 00:00:00.000000000 Z
14
+ date: 2014-06-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -45,14 +45,14 @@ dependencies:
45
45
  name: rspec
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - ">="
48
+ - - "~>"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '2.14'
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - ">="
55
+ - - "~>"
56
56
  - !ruby/object:Gem::Version
57
57
  version: '2.14'
58
58
  - !ruby/object:Gem::Dependency