aasm 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.sw?
2
+ *~
3
+ .DS_Store
4
+ .idea
5
+ coverage
6
+ pkg
7
+ rdoc
8
+ Gemfile.lock
9
+ spec/debug.log
10
+ spec/*.db
data/Gemfile CHANGED
@@ -1,16 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- # Add dependencies to develop your gem here.
4
- # Include everything needed to run rake, tests, features, etc.
5
- group :development do
6
- gem "rspec", ">= 2.0.0"
7
- gem "shoulda"
8
- gem "sdoc"
9
- gem "bundler", ">= 1.0.0"
10
- gem "jeweler", ">= 1.5.1"
11
- gem "rcov", ">= 0"
12
- gem "rr"
13
- gem "reek", "~> 1.2.8"
14
- gem "roodi", "~> 2.1.0"
15
- gem "activerecord"
16
- end
3
+ gemspec
@@ -1,74 +1,64 @@
1
- = Alternatives
2
-
3
- This project is essentially abandoned. Thorsten Böttger has volunteered to take over maintenance: https://github.com/alto/aasm
4
-
5
- If you are looking for an alternative to AASM, I would highly suggest transitions: http://github.com/qoobaa/transitions
6
-
7
- = AASM - Ruby state machines
1
+ # AASM - Ruby state machines #
8
2
 
9
3
  This package contains AASM, a library for adding finite state machines to Ruby classes.
10
4
 
11
5
  AASM started as the acts_as_state_machine plugin but has evolved into a more generic library that no longer targets only ActiveRecord models.
12
6
 
13
- AASM has the following features:
7
+ ## Features ##
14
8
 
15
9
  * States
16
10
  * Machines
17
11
  * Events
18
12
  * Transitions
19
13
 
20
- == New Callbacks
14
+ ## New Callbacks ##
21
15
 
22
16
  The callback chain & order on a successful event looks like:
23
17
 
24
- oldstate:exit*
25
- event:before
26
- __find transition, if possible__
27
- transition:on_transition*
28
- oldstate:before_exit
29
- newstate:before_enter
30
- newstate:enter*
31
- __update state__
32
- event:success*
33
- oldstate:after_exit
34
- newstate:after_enter
35
- event:after
36
- obj:aasm_event_fired*
18
+ oldstate:exit*
19
+ event:before
20
+ __find transition, if possible__
21
+ transition:on_transition*
22
+ oldstate:before_exit
23
+ newstate:before_enter
24
+ newstate:enter*
25
+ __update state__
26
+ event:success*
27
+ oldstate:after_exit
28
+ newstate:after_enter
29
+ event:after
30
+ obj:aasm_event_fired*
37
31
 
38
- (*) marks old callbacks
32
+ (*) marks old callbacks
39
33
 
40
34
 
41
- == Download
35
+ ## Download ##
42
36
 
43
37
  The latest AASM can currently be pulled from the git repository on github.
44
38
 
45
39
  * http://github.com/rubyist/aasm/tree/master
46
40
 
47
41
 
48
- == Installation
49
-
50
- === From gemcutter
51
-
52
- % sudo gem install gemcutter
53
- % sudo gem tumble
54
- % sudo gem install aasm
55
-
56
- === From GitHub hosted gems (only older releases are available)
42
+ ## Installation ##
57
43
 
58
- % sudo gem sources -a http://gems.github.com # (you only need to do this once)
59
- % sudo gem install rubyist-aasm
44
+ ### From RubyGems.org ###
60
45
 
61
- === Building your own gems
46
+ ```sh
47
+ % gem install aasm
48
+ ```
62
49
 
63
- % rake gemspec
64
- % rake build
65
- % sudo gem install pkg/aasm-2.1.gem
50
+ ### Building your own gems ###
66
51
 
52
+ ```sh
53
+ % rake build
54
+ % sudo gem install pkg/aasm-x.y.z.gem
55
+ ```
67
56
 
68
- == Simple Example
57
+ ## Simple Example ##
69
58
 
70
59
  Here's a quick example highlighting some of the features.
71
60
 
61
+ ```ruby
72
62
  class Conversation
73
63
  include AASM
74
64
 
@@ -89,11 +79,13 @@ Here's a quick example highlighting some of the features.
89
79
  transitions :to => :closed, :from => [:read, :unread]
90
80
  end
91
81
  end
82
+ ```
92
83
 
93
- == A Slightly More Complex Example
84
+ ## A Slightly More Complex Example ##
94
85
 
95
86
  This example uses a few of the more complex features available.
96
87
 
88
+ ```ruby
97
89
  class Relationship
98
90
  include AASM
99
91
 
@@ -123,15 +115,16 @@ This example uses a few of the more complex features available.
123
115
  def give_up_intimacy; end
124
116
  def buy_exotic_car_and_wear_a_combover; end
125
117
  end
118
+ ```
126
119
 
127
- = Other Stuff
120
+ # Other Stuff #
128
121
 
129
122
  Author:: Scott Barron <scott at elitists dot net>
130
123
  License:: Original code Copyright 2006, 2007, 2008 by Scott Barron.
131
124
  Released under an MIT-style license. See the LICENSE file
132
125
  included in the distribution.
133
126
 
134
- == Warranty
127
+ ## Warranty ##
135
128
 
136
129
  This software is provided "as is" and without any express or
137
130
  implied warranties, including, without limitation, the implied
data/Rakefile CHANGED
@@ -1,30 +1,11 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
1
+ require 'bundler/gem_tasks'
11
2
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- gem.name = "aasm"
15
- gem.summary = %Q{State machine mixin for Ruby objects}
16
- gem.description = %Q{AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.}
17
- gem.homepage = "http://rubyist.github.com/aasm/"
18
- gem.authors = ["Scott Barron", "Scott Petersen", "Travis Tilley"]
19
- gem.email = "scott@elitists.net, ttilley@gmail.com"
20
- gem.add_development_dependency "rspec"
21
- gem.add_development_dependency "shoulda"
22
- gem.add_development_dependency 'sdoc'
23
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
24
7
  end
25
- Jeweler::RubygemsDotOrgTasks.new
26
8
 
27
- require 'rspec/core/rake_task'
28
9
  require 'rake/testtask'
29
10
  Rake::TestTask.new(:test) do |test|
30
11
  test.libs << 'lib' << 'test'
@@ -32,48 +13,15 @@ Rake::TestTask.new(:test) do |test|
32
13
  test.verbose = true
33
14
  end
34
15
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new(:rcov_shoulda) do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/*_test.rb'
39
- test.verbose = true
40
- end
41
-
42
- RSpec::Core::RakeTask.new(:spec) do |spec|
43
- spec.pattern = 'spec/**/*_spec.rb'
44
- spec.rspec_opts = ['-cfs']
45
- end
46
-
47
- RSpec::Core::RakeTask.new(:rcov_rspec) do |spec|
48
- spec.pattern = 'spec/**/*_spec.rb'
49
- spec.rcov = true
50
- end
51
-
52
- require 'reek/rake/task'
53
- Reek::Rake::Task.new do |t|
54
- t.fail_on_error = true
55
- t.verbose = false
56
- t.source_files = 'lib/**/*.rb'
57
- end
58
-
59
- require 'roodi'
60
- require 'roodi_task'
61
- RoodiTask.new do |t|
62
- t.verbose = false
63
- end
64
-
65
16
  task :default => :test
66
17
 
67
- require 'rake/rdoctask'
18
+ require 'rdoc/task'
19
+ require 'aasm/version'
68
20
  require 'sdoc'
69
- Rake::RDocTask.new do |rdoc|
70
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
71
21
 
22
+ Rake::RDocTask.new do |rdoc|
72
23
  rdoc.rdoc_dir = 'rdoc'
73
- rdoc.title = "aasm #{version}"
24
+ rdoc.title = "aasm #{AASM::VERSION}"
74
25
  rdoc.rdoc_files.include('README*')
75
26
  rdoc.rdoc_files.include('lib/**/*.rb')
76
-
77
- rdoc.options << '--fmt' << 'shtml'
78
- rdoc.template = 'direct'
79
- end
27
+ end
data/aasm.gemspec CHANGED
@@ -1,126 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "aasm/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{aasm}
8
- s.version = "2.2.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Scott Barron", "Scott Petersen", "Travis Tilley"]
12
- s.date = %q{2011-08-31}
6
+ s.name = "aasm"
7
+ s.version = AASM::VERSION
8
+ s.authors = ["Scott Barron", "Scott Petersen", "Travis Tilley", "Thorsten Böttger"]
9
+ s.email = %q{scott@elitists.net, ttilley@gmail.com}
10
+ s.homepage = %q{http://rubyist.github.com/aasm/}
11
+ s.summary = %q{State machine mixin for Ruby objects}
13
12
  s.description = %q{AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.}
14
- s.email = %q{scott@elitists.net, ttilley@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "aasm.gemspec",
27
- "lib/aasm.rb",
28
- "lib/aasm/aasm.rb",
29
- "lib/aasm/event.rb",
30
- "lib/aasm/persistence.rb",
31
- "lib/aasm/persistence/active_record_persistence.rb",
32
- "lib/aasm/state.rb",
33
- "lib/aasm/state_machine.rb",
34
- "lib/aasm/state_transition.rb",
35
- "lib/aasm/supporting_classes.rb",
36
- "spec/functional/conversation.rb",
37
- "spec/functional/conversation_spec.rb",
38
- "spec/spec_helper.rb",
39
- "spec/unit/aasm_spec.rb",
40
- "spec/unit/active_record_persistence_spec.rb",
41
- "spec/unit/before_after_callbacks_spec.rb",
42
- "spec/unit/event_spec.rb",
43
- "spec/unit/state_spec.rb",
44
- "spec/unit/state_transition_spec.rb",
45
- "test/functional/auth_machine_test.rb",
46
- "test/models/process.rb",
47
- "test/test_helper.rb",
48
- "test/unit/aasm_test.rb",
49
- "test/unit/event_test.rb",
50
- "test/unit/state_machine_test.rb",
51
- "test/unit/state_test.rb",
52
- "test/unit/state_transition_test.rb"
53
- ]
54
- s.homepage = %q{http://rubyist.github.com/aasm/}
55
- s.require_paths = ["lib"]
56
- s.rubygems_version = %q{1.6.2}
57
- s.summary = %q{State machine mixin for Ruby objects}
58
- s.test_files = [
59
- "spec/functional/conversation.rb",
60
- "spec/functional/conversation_spec.rb",
61
- "spec/spec_helper.rb",
62
- "spec/unit/aasm_spec.rb",
63
- "spec/unit/active_record_persistence_spec.rb",
64
- "spec/unit/before_after_callbacks_spec.rb",
65
- "spec/unit/event_spec.rb",
66
- "spec/unit/state_spec.rb",
67
- "spec/unit/state_transition_spec.rb",
68
- "test/functional/auth_machine_test.rb",
69
- "test/models/process.rb",
70
- "test/test_helper.rb",
71
- "test/unit/aasm_test.rb",
72
- "test/unit/event_test.rb",
73
- "test/unit/state_machine_test.rb",
74
- "test/unit/state_test.rb",
75
- "test/unit/state_transition_test.rb"
76
- ]
77
13
 
78
- if s.respond_to? :specification_version then
79
- s.specification_version = 3
14
+ s.add_dependency 'activerecord'
15
+ s.add_development_dependency 'rake'
16
+ s.add_development_dependency 'sdoc'
17
+ s.add_development_dependency 'rspec', '~> 2.0'
18
+ s.add_development_dependency 'rr'
19
+ s.add_development_dependency 'shoulda'
20
+ s.add_development_dependency 'sqlite3'
21
+ s.add_development_dependency 'minitest'
80
22
 
81
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
- s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
83
- s.add_development_dependency(%q<shoulda>, [">= 0"])
84
- s.add_development_dependency(%q<sdoc>, [">= 0"])
85
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
86
- s.add_development_dependency(%q<jeweler>, [">= 1.5.1"])
87
- s.add_development_dependency(%q<rcov>, [">= 0"])
88
- s.add_development_dependency(%q<rr>, [">= 0"])
89
- s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
90
- s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
91
- s.add_development_dependency(%q<activerecord>, [">= 0"])
92
- s.add_development_dependency(%q<rspec>, [">= 0"])
93
- s.add_development_dependency(%q<shoulda>, [">= 0"])
94
- s.add_development_dependency(%q<sdoc>, [">= 0"])
95
- else
96
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
97
- s.add_dependency(%q<shoulda>, [">= 0"])
98
- s.add_dependency(%q<sdoc>, [">= 0"])
99
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
100
- s.add_dependency(%q<jeweler>, [">= 1.5.1"])
101
- s.add_dependency(%q<rcov>, [">= 0"])
102
- s.add_dependency(%q<rr>, [">= 0"])
103
- s.add_dependency(%q<reek>, ["~> 1.2.8"])
104
- s.add_dependency(%q<roodi>, ["~> 2.1.0"])
105
- s.add_dependency(%q<activerecord>, [">= 0"])
106
- s.add_dependency(%q<rspec>, [">= 0"])
107
- s.add_dependency(%q<shoulda>, [">= 0"])
108
- s.add_dependency(%q<sdoc>, [">= 0"])
109
- end
110
- else
111
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
112
- s.add_dependency(%q<shoulda>, [">= 0"])
113
- s.add_dependency(%q<sdoc>, [">= 0"])
114
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
115
- s.add_dependency(%q<jeweler>, [">= 1.5.1"])
116
- s.add_dependency(%q<rcov>, [">= 0"])
117
- s.add_dependency(%q<rr>, [">= 0"])
118
- s.add_dependency(%q<reek>, ["~> 1.2.8"])
119
- s.add_dependency(%q<roodi>, ["~> 2.1.0"])
120
- s.add_dependency(%q<activerecord>, [">= 0"])
121
- s.add_dependency(%q<rspec>, [">= 0"])
122
- s.add_dependency(%q<shoulda>, [">= 0"])
123
- s.add_dependency(%q<sdoc>, [">= 0"])
124
- end
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
125
27
  end
126
-
data/lib/aasm.rb CHANGED
@@ -7,3 +7,4 @@ require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes')
7
7
  require File.join(File.dirname(__FILE__), 'aasm', 'state_machine')
8
8
  require File.join(File.dirname(__FILE__), 'aasm', 'persistence')
9
9
  require File.join(File.dirname(__FILE__), 'aasm', 'aasm')
10
+ require File.join(File.dirname(__FILE__), 'aasm', 'i18n')
data/lib/aasm/aasm.rb CHANGED
@@ -7,6 +7,7 @@ module AASM
7
7
 
8
8
  def self.included(base) #:nodoc:
9
9
  base.extend AASM::ClassMethods
10
+
10
11
  AASM::Persistence.set_persistence(base)
11
12
  unless AASM::StateMachine[base]
12
13
  AASM::StateMachine[base] = AASM::StateMachine.new('')
@@ -41,7 +42,7 @@ module AASM
41
42
  aasm_current_state == name
42
43
  end
43
44
  end
44
-
45
+
45
46
  def aasm_event(name, options = {}, &block)
46
47
  sm = AASM::StateMachine[self]
47
48
 
@@ -70,8 +71,11 @@ module AASM
70
71
  AASM::StateMachine[self].states.map { |state| state.for_select }
71
72
  end
72
73
 
74
+ def human_event_name(event)
75
+ AASM::I18n.new.human_event_name(self, event)
76
+ end
73
77
  end
74
-
78
+
75
79
  # Instance methods
76
80
  def aasm_current_state
77
81
  return @aasm_current_state if @aasm_current_state
@@ -105,6 +109,10 @@ module AASM
105
109
  events.map {|event| event.name}
106
110
  end
107
111
 
112
+ def human_state
113
+ AASM::I18n.new.human_state(self)
114
+ end
115
+
108
116
  private
109
117
 
110
118
  def set_aasm_current_state_with_persistence(state)
data/lib/aasm/i18n.rb ADDED
@@ -0,0 +1,36 @@
1
+ class AASM::I18n
2
+ def human_event_name(klass, event)
3
+ defaults = ancestors_list(klass).map do |ancestor|
4
+ :"#{i18n_scope(klass)}.events.#{i18n_klass(ancestor)}.#{event}"
5
+ end << event.to_s.humanize
6
+
7
+ I18n.translate(defaults.shift, :default => defaults, :raise => true)
8
+ end
9
+
10
+ def human_state(obj)
11
+ klass = obj.class
12
+ defaults = ancestors_list(klass).map do |ancestor|
13
+ :"#{i18n_scope(klass)}.attributes.#{i18n_klass(ancestor)}.#{klass.aasm_column}.#{obj.aasm_current_state}"
14
+ end << obj.aasm_current_state.to_s.humanize
15
+
16
+ I18n.translate(defaults.shift, :default => defaults, :raise => true)
17
+ end
18
+
19
+ private
20
+
21
+ # added for rails 2.x compatibility
22
+ def i18n_scope(klass)
23
+ klass.respond_to?(:i18n_scope) ? klass.i18n_scope : :activerecord
24
+ end
25
+
26
+ # added for rails < 3.0.3 compatibility
27
+ def i18n_klass(klass)
28
+ klass.model_name.respond_to?(:i18n_key) ? klass.model_name.i18n_key : klass.name.underscore
29
+ end
30
+
31
+ def ancestors_list(klass)
32
+ klass.ancestors.select do |ancestor|
33
+ ancestor.respond_to?(:model_name) unless ancestor == ActiveRecord::Base
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module AASM
2
+ VERSION = "2.3.0"
3
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,3 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: spec/aasm.sqlite3.db
data/spec/en.yml ADDED
@@ -0,0 +1,10 @@
1
+ en:
2
+ activerecord:
3
+ events:
4
+ i18n_test_model:
5
+ close: "Let's close it!"
6
+
7
+ attributes:
8
+ i18n_test_model:
9
+ aasm_state:
10
+ open: "It's opened now!"
data/spec/schema.rb ADDED
@@ -0,0 +1,7 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ %w{gates readers writers transients simples thieves i18n_test_models}.each do |table_name|
4
+ create_table table_name, :force => true
5
+ end
6
+
7
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,9 @@ require 'aasm'
5
5
  require 'rspec'
6
6
  require 'rspec/autorun'
7
7
 
8
- RSpec.configure do |config|
9
-
8
+ def load_schema
9
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
10
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
11
+ ActiveRecord::Base.establish_connection(config['sqlite3'])
12
+ load(File.dirname(__FILE__) + "/schema.rb")
10
13
  end
@@ -2,20 +2,18 @@ begin
2
2
  require 'rubygems'
3
3
  require 'active_record'
4
4
  require 'logger'
5
-
6
- ActiveRecord::Base.logger = Logger.new(STDERR)
7
5
 
8
- # A dummy class for mocking the activerecord connection class
9
- class Connection
10
- end
6
+ load_schema
11
7
 
12
- class FooBar < ActiveRecord::Base
8
+ ActiveRecord::Base.logger = Logger.new(STDERR)
9
+
10
+ class Gate < ActiveRecord::Base
13
11
  include AASM
14
12
 
15
13
  # Fake this column for testing purposes
16
14
  attr_accessor :aasm_state
17
15
 
18
- aasm_state :open
16
+ aasm_state :opened
19
17
  aasm_state :closed
20
18
 
21
19
  aasm_event :view do
@@ -23,36 +21,37 @@ begin
23
21
  end
24
22
  end
25
23
 
26
- class Fi < ActiveRecord::Base
24
+ class Reader < ActiveRecord::Base
27
25
  def aasm_read_state
28
26
  "fi"
29
27
  end
30
28
  include AASM
31
29
  end
32
30
 
33
- class Fo < ActiveRecord::Base
31
+ class Writer < ActiveRecord::Base
34
32
  def aasm_write_state(state)
35
33
  "fo"
36
34
  end
37
35
  include AASM
38
36
  end
39
37
 
40
- class Fum < ActiveRecord::Base
38
+ class Transient < ActiveRecord::Base
41
39
  def aasm_write_state_without_persistence(state)
42
40
  "fum"
43
41
  end
44
42
  include AASM
45
43
  end
46
44
 
47
- class June < ActiveRecord::Base
45
+ class Simple < ActiveRecord::Base
48
46
  include AASM
49
47
  aasm_column :status
50
48
  end
51
49
 
52
- class Beaver < June
50
+ class Derivate < Simple
53
51
  end
54
52
 
55
53
  class Thief < ActiveRecord::Base
54
+ set_table_name "thieves"
56
55
  include AASM
57
56
  aasm_initial_state Proc.new { |thief| thief.skilled ? :rich : :jailed }
58
57
  aasm_state :rich
@@ -69,9 +68,9 @@ begin
69
68
  end
70
69
  end
71
70
 
72
- describe FooBar, "class methods" do
71
+ describe Gate, "class methods" do
73
72
  before(:each) do
74
- @klass = FooBar
73
+ @klass = Gate
75
74
  end
76
75
  it_should_behave_like "aasm model"
77
76
  it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
@@ -85,9 +84,9 @@ begin
85
84
  end
86
85
  end
87
86
 
88
- describe Fi, "class methods" do
87
+ describe Reader, "class methods" do
89
88
  before(:each) do
90
- @klass = Fi
89
+ @klass = Reader
91
90
  end
92
91
  it_should_behave_like "aasm model"
93
92
  it "should not include AASM::Persistence::ActiveRecordPersistence::ReadState" do
@@ -101,9 +100,9 @@ begin
101
100
  end
102
101
  end
103
102
 
104
- describe Fo, "class methods" do
103
+ describe Writer, "class methods" do
105
104
  before(:each) do
106
- @klass = Fo
105
+ @klass = Writer
107
106
  end
108
107
  it_should_behave_like "aasm model"
109
108
  it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
@@ -117,9 +116,9 @@ begin
117
116
  end
118
117
  end
119
118
 
120
- describe Fum, "class methods" do
119
+ describe Transient, "class methods" do
121
120
  before(:each) do
122
- @klass = Fum
121
+ @klass = Transient
123
122
  end
124
123
  it_should_behave_like "aasm model"
125
124
  it "should include AASM::Persistence::ActiveRecordPersistence::ReadState" do
@@ -133,61 +132,57 @@ begin
133
132
  end
134
133
  end
135
134
 
136
- describe FooBar, "instance methods" do
137
- before(:each) do
138
- connection = mock(Connection, :columns => [])
139
- FooBar.stub!(:connection).and_return(connection)
140
- end
135
+ describe Gate, "instance methods" do
141
136
 
142
137
  it "should respond to aasm read state when not previously defined" do
143
- FooBar.new.should respond_to(:aasm_read_state)
138
+ Gate.new.should respond_to(:aasm_read_state)
144
139
  end
145
140
 
146
141
  it "should respond to aasm write state when not previously defined" do
147
- FooBar.new.should respond_to(:aasm_write_state)
142
+ Gate.new.should respond_to(:aasm_write_state)
148
143
  end
149
144
 
150
145
  it "should respond to aasm write state without persistence when not previously defined" do
151
- FooBar.new.should respond_to(:aasm_write_state_without_persistence)
146
+ Gate.new.should respond_to(:aasm_write_state_without_persistence)
152
147
  end
153
148
 
154
149
  it "should return the initial state when new and the aasm field is nil" do
155
- FooBar.new.aasm_current_state.should == :open
150
+ Gate.new.aasm_current_state.should == :opened
156
151
  end
157
152
 
158
153
  it "should return the aasm column when new and the aasm field is not nil" do
159
- foo = FooBar.new
154
+ foo = Gate.new
160
155
  foo.aasm_state = "closed"
161
156
  foo.aasm_current_state.should == :closed
162
157
  end
163
158
 
164
159
  it "should return the aasm column when not new and the aasm_column is not nil" do
165
- foo = FooBar.new
160
+ foo = Gate.new
166
161
  foo.stub!(:new_record?).and_return(false)
167
162
  foo.aasm_state = "state"
168
163
  foo.aasm_current_state.should == :state
169
164
  end
170
165
 
171
166
  it "should allow a nil state" do
172
- foo = FooBar.new
167
+ foo = Gate.new
173
168
  foo.stub!(:new_record?).and_return(false)
174
169
  foo.aasm_state = nil
175
170
  foo.aasm_current_state.should be_nil
176
171
  end
177
172
 
178
173
  it "should have aasm_ensure_initial_state" do
179
- foo = FooBar.new
174
+ foo = Gate.new
180
175
  foo.send :aasm_ensure_initial_state
181
176
  end
182
177
 
183
178
  it "should call aasm_ensure_initial_state on validation before create" do
184
- foo = FooBar.new
179
+ foo = Gate.new
185
180
  foo.should_receive(:aasm_ensure_initial_state).and_return(true)
186
181
  foo.valid?
187
182
  end
188
183
 
189
184
  it "should call aasm_ensure_initial_state on validation before create" do
190
- foo = FooBar.new
185
+ foo = Gate.new
191
186
  foo.stub!(:new_record?).and_return(false)
192
187
  foo.should_not_receive(:aasm_ensure_initial_state)
193
188
  foo.valid?
@@ -195,45 +190,41 @@ begin
195
190
 
196
191
  end
197
192
 
198
- describe 'Beavers' do
193
+ describe 'Derivates' do
199
194
  it "should have the same states as it's parent" do
200
- Beaver.aasm_states.should == June.aasm_states
195
+ Derivate.aasm_states.should == Simple.aasm_states
201
196
  end
202
197
 
203
198
  it "should have the same events as it's parent" do
204
- Beaver.aasm_events.should == June.aasm_events
199
+ Derivate.aasm_events.should == Simple.aasm_events
205
200
  end
206
201
 
207
202
  it "should have the same column as it's parent" do
208
- Beaver.aasm_column.should == :status
203
+ Derivate.aasm_column.should == :status
209
204
  end
210
205
  end
211
206
 
212
207
  describe AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods do
213
- class NamedScopeExample < ActiveRecord::Base
214
- include AASM
215
- end
216
208
 
217
209
  context "Does not already respond_to? the scope name" do
218
210
  it "should add a scope" do
219
- NamedScopeExample.aasm_state :unknown_scope
220
- NamedScopeExample.scopes.keys.should include(:unknown_scope)
211
+ Simple.should_not respond_to(:unknown_scope)
212
+ Simple.aasm_state :unknown_scope
213
+ Simple.should respond_to(:unknown_scope)
214
+ Simple.unknown_scope.class.should == ActiveRecord::Relation
221
215
  end
222
216
  end
223
217
 
224
218
  context "Already respond_to? the scope name" do
225
219
  it "should not add a scope" do
226
- NamedScopeExample.aasm_state :new
227
- NamedScopeExample.scopes.keys.should_not include(:new)
220
+ Simple.aasm_state :new
221
+ Simple.should respond_to(:new)
222
+ Simple.new.class.should == Simple
228
223
  end
229
224
  end
230
225
  end
231
226
 
232
227
  describe 'Thieves' do
233
- before(:each) do
234
- connection = mock(Connection, :columns => [])
235
- Thief.stub!(:connection).and_return(connection)
236
- end
237
228
 
238
229
  it 'should be rich if they\'re skilled' do
239
230
  Thief.new(:skilled => true).aasm_current_state.should == :rich
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'active_record'
3
+ require 'logger'
4
+ require 'i18n'
5
+
6
+ ActiveRecord::Base.logger = Logger.new(STDERR)
7
+
8
+ class I18nTestModel < ActiveRecord::Base
9
+ include AASM
10
+
11
+ attr_accessor :aasm_state
12
+
13
+ aasm_initial_state :open
14
+ aasm_state :opened
15
+ aasm_state :closed
16
+
17
+ aasm_event :close
18
+ aasm_event :open
19
+ end
20
+
21
+ describe AASM::I18n do
22
+ before(:all) do
23
+ I18n.load_path << 'spec/en.yml'
24
+ I18n.default_locale = :en
25
+ end
26
+
27
+ after(:all) { I18n.load_path.clear }
28
+
29
+ let (:foo_opened) { I18nTestModel.new }
30
+ let (:foo_closed) { I18nTestModel.new.tap { |x| x.aasm_state = :closed } }
31
+
32
+ context '.human_state' do
33
+ it 'should return translated state value' do
34
+ foo_opened.human_state.should == "It's opened now!"
35
+ end
36
+
37
+ it 'should return humanized value if not localized' do
38
+ foo_closed.human_state.should == "Closed"
39
+ end
40
+ end
41
+
42
+ context '.human_event_name' do
43
+ it 'should return translated event name' do
44
+ I18nTestModel.human_event_name(:close).should == "Let's close it!"
45
+ end
46
+
47
+ it 'should return humanized event name' do
48
+ I18nTestModel.human_event_name(:open).should == "Open"
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,44 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 2
9
- - 1
10
- version: 2.2.1
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Barron
14
14
  - Scott Petersen
15
15
  - Travis Tilley
16
+ - "Thorsten B\xC3\xB6ttger"
16
17
  autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2011-08-31 00:00:00 +02:00
21
+ date: 2011-09-02 00:00:00 +02:00
21
22
  default_executable:
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency
25
+ name: activerecord
24
26
  prerelease: false
25
- type: :development
26
27
  requirement: &id001 !ruby/object:Gem::Requirement
27
28
  none: false
28
29
  requirements:
29
30
  - - ">="
30
31
  - !ruby/object:Gem::Version
31
- hash: 15
32
+ hash: 3
32
33
  segments:
33
- - 2
34
- - 0
35
34
  - 0
36
- version: 2.0.0
37
- name: rspec
35
+ version: "0"
36
+ type: :runtime
38
37
  version_requirements: *id001
39
38
  - !ruby/object:Gem::Dependency
39
+ name: rake
40
40
  prerelease: false
41
- type: :development
42
41
  requirement: &id002 !ruby/object:Gem::Requirement
43
42
  none: false
44
43
  requirements:
@@ -48,11 +47,11 @@ dependencies:
48
47
  segments:
49
48
  - 0
50
49
  version: "0"
51
- name: shoulda
50
+ type: :development
52
51
  version_requirements: *id002
53
52
  - !ruby/object:Gem::Dependency
53
+ name: sdoc
54
54
  prerelease: false
55
- type: :development
56
55
  requirement: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
57
  requirements:
@@ -62,43 +61,40 @@ dependencies:
62
61
  segments:
63
62
  - 0
64
63
  version: "0"
65
- name: sdoc
64
+ type: :development
66
65
  version_requirements: *id003
67
66
  - !ruby/object:Gem::Dependency
67
+ name: rspec
68
68
  prerelease: false
69
- type: :development
70
69
  requirement: &id004 !ruby/object:Gem::Requirement
71
70
  none: false
72
71
  requirements:
73
- - - ">="
72
+ - - ~>
74
73
  - !ruby/object:Gem::Version
75
- hash: 23
74
+ hash: 3
76
75
  segments:
77
- - 1
78
- - 0
76
+ - 2
79
77
  - 0
80
- version: 1.0.0
81
- name: bundler
78
+ version: "2.0"
79
+ type: :development
82
80
  version_requirements: *id004
83
81
  - !ruby/object:Gem::Dependency
82
+ name: rr
84
83
  prerelease: false
85
- type: :development
86
84
  requirement: &id005 !ruby/object:Gem::Requirement
87
85
  none: false
88
86
  requirements:
89
87
  - - ">="
90
88
  - !ruby/object:Gem::Version
91
- hash: 1
89
+ hash: 3
92
90
  segments:
93
- - 1
94
- - 5
95
- - 1
96
- version: 1.5.1
97
- name: jeweler
91
+ - 0
92
+ version: "0"
93
+ type: :development
98
94
  version_requirements: *id005
99
95
  - !ruby/object:Gem::Dependency
96
+ name: shoulda
100
97
  prerelease: false
101
- type: :development
102
98
  requirement: &id006 !ruby/object:Gem::Requirement
103
99
  none: false
104
100
  requirements:
@@ -108,11 +104,11 @@ dependencies:
108
104
  segments:
109
105
  - 0
110
106
  version: "0"
111
- name: rcov
107
+ type: :development
112
108
  version_requirements: *id006
113
109
  - !ruby/object:Gem::Dependency
110
+ name: sqlite3
114
111
  prerelease: false
115
- type: :development
116
112
  requirement: &id007 !ruby/object:Gem::Requirement
117
113
  none: false
118
114
  requirements:
@@ -122,58 +118,12 @@ dependencies:
122
118
  segments:
123
119
  - 0
124
120
  version: "0"
125
- name: rr
121
+ type: :development
126
122
  version_requirements: *id007
127
123
  - !ruby/object:Gem::Dependency
124
+ name: minitest
128
125
  prerelease: false
129
- type: :development
130
126
  requirement: &id008 !ruby/object:Gem::Requirement
131
- none: false
132
- requirements:
133
- - - ~>
134
- - !ruby/object:Gem::Version
135
- hash: 15
136
- segments:
137
- - 1
138
- - 2
139
- - 8
140
- version: 1.2.8
141
- name: reek
142
- version_requirements: *id008
143
- - !ruby/object:Gem::Dependency
144
- prerelease: false
145
- type: :development
146
- requirement: &id009 !ruby/object:Gem::Requirement
147
- none: false
148
- requirements:
149
- - - ~>
150
- - !ruby/object:Gem::Version
151
- hash: 11
152
- segments:
153
- - 2
154
- - 1
155
- - 0
156
- version: 2.1.0
157
- name: roodi
158
- version_requirements: *id009
159
- - !ruby/object:Gem::Dependency
160
- prerelease: false
161
- type: :development
162
- requirement: &id010 !ruby/object:Gem::Requirement
163
- none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- hash: 3
168
- segments:
169
- - 0
170
- version: "0"
171
- name: activerecord
172
- version_requirements: *id010
173
- - !ruby/object:Gem::Dependency
174
- prerelease: false
175
- type: :development
176
- requirement: &id011 !ruby/object:Gem::Requirement
177
127
  none: false
178
128
  requirements:
179
129
  - - ">="
@@ -182,69 +132,46 @@ dependencies:
182
132
  segments:
183
133
  - 0
184
134
  version: "0"
185
- name: rspec
186
- version_requirements: *id011
187
- - !ruby/object:Gem::Dependency
188
- prerelease: false
189
135
  type: :development
190
- requirement: &id012 !ruby/object:Gem::Requirement
191
- none: false
192
- requirements:
193
- - - ">="
194
- - !ruby/object:Gem::Version
195
- hash: 3
196
- segments:
197
- - 0
198
- version: "0"
199
- name: shoulda
200
- version_requirements: *id012
201
- - !ruby/object:Gem::Dependency
202
- prerelease: false
203
- type: :development
204
- requirement: &id013 !ruby/object:Gem::Requirement
205
- none: false
206
- requirements:
207
- - - ">="
208
- - !ruby/object:Gem::Version
209
- hash: 3
210
- segments:
211
- - 0
212
- version: "0"
213
- name: sdoc
214
- version_requirements: *id013
136
+ version_requirements: *id008
215
137
  description: AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.
216
138
  email: scott@elitists.net, ttilley@gmail.com
217
139
  executables: []
218
140
 
219
141
  extensions: []
220
142
 
221
- extra_rdoc_files:
222
- - LICENSE
223
- - README.rdoc
143
+ extra_rdoc_files: []
144
+
224
145
  files:
225
146
  - .document
147
+ - .gitignore
226
148
  - Gemfile
227
149
  - LICENSE
228
- - README.rdoc
150
+ - README.md
229
151
  - Rakefile
230
- - VERSION
231
152
  - aasm.gemspec
232
153
  - lib/aasm.rb
233
154
  - lib/aasm/aasm.rb
234
155
  - lib/aasm/event.rb
156
+ - lib/aasm/i18n.rb
235
157
  - lib/aasm/persistence.rb
236
158
  - lib/aasm/persistence/active_record_persistence.rb
237
159
  - lib/aasm/state.rb
238
160
  - lib/aasm/state_machine.rb
239
161
  - lib/aasm/state_transition.rb
240
162
  - lib/aasm/supporting_classes.rb
163
+ - lib/aasm/version.rb
164
+ - spec/database.yml
165
+ - spec/en.yml
241
166
  - spec/functional/conversation.rb
242
167
  - spec/functional/conversation_spec.rb
168
+ - spec/schema.rb
243
169
  - spec/spec_helper.rb
244
170
  - spec/unit/aasm_spec.rb
245
171
  - spec/unit/active_record_persistence_spec.rb
246
172
  - spec/unit/before_after_callbacks_spec.rb
247
173
  - spec/unit/event_spec.rb
174
+ - spec/unit/i18n_spec.rb
248
175
  - spec/unit/state_spec.rb
249
176
  - spec/unit/state_transition_spec.rb
250
177
  - test/functional/auth_machine_test.rb
@@ -290,13 +217,17 @@ signing_key:
290
217
  specification_version: 3
291
218
  summary: State machine mixin for Ruby objects
292
219
  test_files:
220
+ - spec/database.yml
221
+ - spec/en.yml
293
222
  - spec/functional/conversation.rb
294
223
  - spec/functional/conversation_spec.rb
224
+ - spec/schema.rb
295
225
  - spec/spec_helper.rb
296
226
  - spec/unit/aasm_spec.rb
297
227
  - spec/unit/active_record_persistence_spec.rb
298
228
  - spec/unit/before_after_callbacks_spec.rb
299
229
  - spec/unit/event_spec.rb
230
+ - spec/unit/i18n_spec.rb
300
231
  - spec/unit/state_spec.rb
301
232
  - spec/unit/state_transition_spec.rb
302
233
  - test/functional/auth_machine_test.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.2.1