aasm 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/CODE_OF_CONDUCT.md +13 -0
  4. data/Gemfile +1 -1
  5. data/LICENSE +1 -1
  6. data/README.md +9 -0
  7. data/aasm.gemspec +1 -1
  8. data/lib/aasm/base.rb +12 -4
  9. data/lib/aasm/persistence/active_record_persistence.rb +1 -1
  10. data/lib/aasm/version.rb +1 -1
  11. data/spec/models/active_record/derivate_new_dsl.rb +3 -0
  12. data/spec/models/active_record/false_state.rb +17 -0
  13. data/spec/models/active_record/gate.rb +19 -0
  14. data/spec/models/active_record/localizer_test_model.rb +34 -0
  15. data/spec/models/active_record/no_direct_assignment.rb +10 -0
  16. data/spec/models/active_record/no_scope.rb +10 -0
  17. data/spec/models/active_record/persisted_state.rb +12 -0
  18. data/spec/models/active_record/provided_and_persisted_state.rb +24 -0
  19. data/spec/models/active_record/reader.rb +7 -0
  20. data/spec/models/active_record/simple_new_dsl.rb +8 -0
  21. data/spec/models/active_record/thief.rb +14 -0
  22. data/spec/models/active_record/transient.rb +6 -0
  23. data/spec/models/active_record/with_enum.rb +19 -0
  24. data/spec/models/active_record/with_false_enum.rb +15 -0
  25. data/spec/models/active_record/with_true_enum.rb +19 -0
  26. data/spec/models/active_record/writer.rb +6 -0
  27. data/spec/models/{auth_machine.rb → complex_example.rb} +1 -1
  28. data/spec/models/default_state.rb +12 -0
  29. data/spec/models/initial_state_proc.rb +15 -0
  30. data/spec/models/{bar.rb → no_initial_state.rb} +1 -4
  31. data/spec/models/provided_state.rb +24 -0
  32. data/spec/models/simple_example.rb +15 -0
  33. data/spec/models/state_machine_with_failed_event.rb +12 -0
  34. data/spec/models/sub_class.rb +3 -0
  35. data/spec/models/sub_class_with_more_states.rb +7 -0
  36. data/spec/models/super_class.rb +18 -0
  37. data/spec/models/{argument.rb → valid_state_name.rb} +1 -1
  38. data/spec/models/validator.rb +4 -4
  39. data/spec/spec_helper.rb +1 -1
  40. data/spec/unit/api_spec.rb +6 -1
  41. data/spec/unit/complex_example_spec.rb +2 -2
  42. data/spec/unit/event_naming_spec.rb +2 -15
  43. data/spec/unit/initial_state_spec.rb +3 -18
  44. data/spec/unit/inspection_spec.rb +7 -7
  45. data/spec/unit/localizer_spec.rb +0 -38
  46. data/spec/unit/persistence/active_record_persistence_spec.rb +21 -3
  47. data/spec/unit/simple_example_spec.rb +26 -42
  48. data/spec/unit/subclassing_spec.rb +10 -10
  49. metadata +60 -19
  50. data/spec/models/active_record/api.rb +0 -75
  51. data/spec/models/father.rb +0 -21
  52. data/spec/models/persistence.rb +0 -164
  53. data/spec/models/son.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e85a2c10a3cf49a548193c9634548eb38eb1578b
4
- data.tar.gz: 9b87e33663caa939dbf4eeefad57ea6ebde01fac
3
+ metadata.gz: cd80c470206244734a77fe540848e299e87dab9f
4
+ data.tar.gz: 28b464e9012345a46ddc5595d29541d52a358bf4
5
5
  SHA512:
6
- metadata.gz: 1e2b255e2cae2cfae4a13c14ef8bd89f20c132ae5acf8260e68319f40646008304f05870e5cfbb2e4402b7cedc588552b777407c613b30f7e8b1787b9eac8faf
7
- data.tar.gz: 41843dcb1cfa5c1147abea4420951ae3217349abd7a7918a1ef0014671218a520957c61d2d7f70ae5634514df5722466e83deb64549b463a5d3d51a323049da3
6
+ metadata.gz: 46d54cc3e2e66387916f7f1edfe03f3de9cb09578a8b485ea084bd68ba854f9003d1fd00de18a6d7c40984a0b0d2fe1b2d7bc4b3610e7d421c724e2f5af7a9f1
7
+ data.tar.gz: cb2506c237a22fc3dc04869791d15f85614ac33096ccff60fa5a6dd40830d2325375ed13cdc3abf2adc02c958a336362027393c6ee0351bc463cf47cb0b9020f
@@ -1,6 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 4.2.0 (not yet released)
3
+ ## 4.3.0 (not yet released)
4
+
5
+ ## 4.2.0
6
+
7
+ * support turning off and on the configuration option for `no_direct_assignment` (see [issue #223](https://github.com/aasm/aasm/issues/223) for details)
8
+ * event arguments are now passed to `:after_commit` callbacks as well (see [issue #238](https://github.com/aasm/aasm/pull/238), thanks to [@kuinak](https://github.com/kuinak))
4
9
 
5
10
  ## 4.1.1
6
11
 
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gem "sqlite3", :platforms => :ruby
4
4
  gem 'rubysl', :platforms => :rbx
5
5
  gem "jruby-openssl", :platforms => :jruby
6
6
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
7
- gem "rails", "~>4.1"
7
+ gem "rails", "~>4.2"
8
8
  gem 'mongoid', '~>4.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
9
9
  gem 'sequel'
10
10
  # Since mongoid V4 requires incompatible bson V2, cannot have mongoid (V4 or greater)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2014 Scott Barron
1
+ Copyright (c) 2006-2015 Scott Barron
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -679,6 +679,15 @@ Feel free to
679
679
  * [Thorsten Böttger](http://github.com/alto) (since 2011)
680
680
 
681
681
 
682
+ ## Contributing ##
683
+
684
+ 1. Read the [Contributor Code of Conduct](https://github.com/aasm/aasm/blob/master/CODE_OF_CONDUCT.md)
685
+ 2. Fork it
686
+ 3. Create your feature branch (git checkout -b my-new-feature)
687
+ 4. Commit your changes (git commit -am 'Added some feature')
688
+ 5. Push to the branch (git push origin my-new-feature)
689
+ 6. Create new Pull Request
690
+
682
691
  ## Warranty ##
683
692
 
684
693
  This software is provided "as is" and without any express or
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_development_dependency 'rake'
20
20
  s.add_development_dependency 'sdoc'
21
- s.add_development_dependency 'rspec'
21
+ s.add_development_dependency 'rspec', ">= 3"
22
22
 
23
23
  # debugging
24
24
  # s.add_development_dependency 'debugger'
@@ -27,11 +27,19 @@ module AASM
27
27
 
28
28
  configure :enum, nil
29
29
 
30
- if @state_machine.config.no_direct_assignment
31
- @klass.send(:define_method, "#{@state_machine.config.column}=") do |state_name|
32
- raise AASM::NoDirectAssignmentError.new('direct assignment of AASM column has been disabled (see AASM configuration for this class)')
30
+ # make sure to raise an error if no_direct_assignment is enabled
31
+ # and attribute is directly assigned though
32
+ @klass.class_eval %Q(
33
+ def #{@state_machine.config.column}=(state_name)
34
+ if self.class.aasm.state_machine.config.no_direct_assignment
35
+ raise AASM::NoDirectAssignmentError.new(
36
+ 'direct assignment of AASM column has been disabled (see AASM configuration for this class)'
37
+ )
38
+ else
39
+ super
40
+ end
33
41
  end
34
- end
42
+ )
35
43
  end
36
44
 
37
45
  # This method is both a getter and a setter
@@ -176,7 +176,7 @@ module AASM
176
176
 
177
177
  if success && options[:persist]
178
178
  event = self.class.aasm.state_machine.events[name]
179
- event.fire_callbacks(:after_commit, self)
179
+ event.fire_callbacks(:after_commit, self, *args)
180
180
  end
181
181
 
182
182
  success
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "4.1.1"
2
+ VERSION = "4.2.0"
3
3
  end
@@ -0,0 +1,3 @@
1
+ require_relative 'simple_new_dsl'
2
+ class DerivateNewDsl < SimpleNewDsl
3
+ end
@@ -0,0 +1,17 @@
1
+ class FalseState < ActiveRecord::Base
2
+ include AASM
3
+
4
+ def initialize(*args)
5
+ super
6
+ self.aasm_state = false
7
+ end
8
+
9
+ aasm do
10
+ state :opened
11
+ state :closed
12
+
13
+ event :view do
14
+ transitions :to => :read, :from => [:needs_attention]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ class Gate < ActiveRecord::Base
2
+ include AASM
3
+
4
+ # Fake this column for testing purposes
5
+ # attr_accessor :aasm_state
6
+
7
+ def value
8
+ 'value'
9
+ end
10
+
11
+ aasm do
12
+ state :opened
13
+ state :closed
14
+
15
+ event :view do
16
+ transitions :to => :read, :from => [:needs_attention]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ class LocalizerTestModel < ActiveRecord::Base
2
+ include AASM
3
+
4
+ aasm do
5
+ state :opened, :initial => true
6
+ state :closed
7
+ event :close
8
+ event :open
9
+ end
10
+ end
11
+
12
+ describe 'localized state names' do
13
+ before(:all) do
14
+ I18n.load_path << 'spec/en.yml'
15
+ I18n.default_locale = :en
16
+ I18n.reload!
17
+ end
18
+
19
+ after(:all) do
20
+ I18n.load_path.clear
21
+ end
22
+
23
+ it 'should localize' do
24
+ state = LocalizerTestModel.aasm.states.detect {|s| s == :opened}
25
+ expect(state.localized_name).to eq("It's open now!")
26
+ expect(state.human_name).to eq("It's open now!")
27
+ end
28
+
29
+ it 'should use fallback' do
30
+ state = LocalizerTestModel.aasm.states.detect {|s| s == :closed}
31
+ expect(state.localized_name).to eq('Closed')
32
+ expect(state.human_name).to eq('Closed')
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ class NoDirectAssignment < ActiveRecord::Base
2
+ include AASM
3
+ aasm :no_direct_assignment => true do
4
+ state :pending, :initial => true
5
+ state :running
6
+ event :run do
7
+ transitions :from => :pending, :to => :running
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class NoScope < ActiveRecord::Base
2
+ include AASM
3
+ aasm :create_scopes => false do
4
+ state :pending, :initial => true
5
+ state :running
6
+ event :run do
7
+ transitions :from => :pending, :to => :running
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class PersistedState < ActiveRecord::Base
2
+ attr_accessor :transient_store, :persisted_store
3
+ include AASM
4
+ aasm do
5
+ state :alpha, :initial => true
6
+ state :beta
7
+ state :gamma
8
+ event :release do
9
+ transitions :from => [:alpha, :beta, :gamma], :to => :beta
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ class ProvidedAndPersistedState < ActiveRecord::Base
2
+ attr_accessor :transient_store, :persisted_store
3
+ include AASM
4
+ aasm do
5
+ state :alpha, :initial => true
6
+ state :beta
7
+ state :gamma
8
+ event :release do
9
+ transitions :from => [:alpha, :beta, :gamma], :to => :beta
10
+ end
11
+ end
12
+
13
+ def aasm_read_state
14
+ :gamma
15
+ end
16
+
17
+ def aasm_write_state(new_state)
18
+ @persisted_store = new_state
19
+ end
20
+
21
+ def aasm_write_state_without_persistence(new_state)
22
+ @transient_store = new_state
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ class Reader < ActiveRecord::Base
2
+ include AASM
3
+
4
+ def aasm_read_state
5
+ "fi"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class SimpleNewDsl < ActiveRecord::Base
2
+ include AASM
3
+ aasm :column => :status
4
+ aasm do
5
+ state :unknown_scope
6
+ state :new
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ class Thief < ActiveRecord::Base
2
+ if ActiveRecord::VERSION::MAJOR >= 3
3
+ self.table_name = 'thieves'
4
+ else
5
+ set_table_name "thieves"
6
+ end
7
+ include AASM
8
+ aasm do
9
+ state :rich
10
+ state :jailed
11
+ initial_state Proc.new {|thief| thief.skilled ? :rich : :jailed }
12
+ end
13
+ attr_accessor :skilled, :aasm_state
14
+ end
@@ -0,0 +1,6 @@
1
+ class Transient < ActiveRecord::Base
2
+ def aasm_write_state_without_persistence(state)
3
+ "fum"
4
+ end
5
+ include AASM
6
+ end
@@ -0,0 +1,19 @@
1
+ class WithEnum < ActiveRecord::Base
2
+ include AASM
3
+
4
+ # Fake this column for testing purposes
5
+ attr_accessor :aasm_state
6
+
7
+ def self.test
8
+ {}
9
+ end
10
+
11
+ aasm :enum => :test do
12
+ state :opened
13
+ state :closed
14
+
15
+ event :view do
16
+ transitions :to => :read, :from => [:needs_attention]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ class WithFalseEnum < ActiveRecord::Base
2
+ include AASM
3
+
4
+ # Fake this column for testing purposes
5
+ attr_accessor :aasm_state
6
+
7
+ aasm :enum => false do
8
+ state :opened
9
+ state :closed
10
+
11
+ event :view do
12
+ transitions :to => :read, :from => [:needs_attention]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ class WithTrueEnum < ActiveRecord::Base
2
+ include AASM
3
+
4
+ # Fake this column for testing purposes
5
+ attr_accessor :aasm_state
6
+
7
+ def value
8
+ 'value'
9
+ end
10
+
11
+ aasm :enum => true do
12
+ state :opened
13
+ state :closed
14
+
15
+ event :view do
16
+ transitions :to => :read, :from => [:needs_attention]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ class Writer < ActiveRecord::Base
2
+ def aasm_write_state(state)
3
+ "fo"
4
+ end
5
+ include AASM
6
+ end
@@ -1,4 +1,4 @@
1
- class AuthMachine
1
+ class ComplexExample
2
2
  include AASM
3
3
 
4
4
  attr_accessor :activation_code, :activated_at, :deleted_at
@@ -0,0 +1,12 @@
1
+ class DefaultState
2
+ attr_accessor :transient_store, :persisted_store
3
+ include AASM
4
+ aasm do
5
+ state :alpha, :initial => true
6
+ state :beta
7
+ state :gamma
8
+ event :release do
9
+ transitions :from => [:alpha, :beta, :gamma], :to => :beta
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ class InitialStateProc
2
+ RICH = 1_000_000
3
+
4
+ attr_accessor :balance
5
+
6
+ include AASM
7
+ aasm do
8
+ state :retired
9
+ state :selling_bad_mortgages
10
+ initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
11
+ end
12
+
13
+ def initialize(balance = 0); self.balance = balance; end
14
+ def rich?; self.balance >= RICH; end
15
+ end
@@ -1,4 +1,4 @@
1
- class Bar
1
+ class NoInitialState
2
2
  include AASM
3
3
 
4
4
  aasm do
@@ -10,6 +10,3 @@ class Bar
10
10
  end
11
11
  end
12
12
  end
13
-
14
- class Baz < Bar
15
- end
@@ -0,0 +1,24 @@
1
+ class ProvidedState
2
+ attr_accessor :transient_store, :persisted_store
3
+ include AASM
4
+ aasm do
5
+ state :alpha, :initial => true
6
+ state :beta
7
+ state :gamma
8
+ event :release do
9
+ transitions :from => [:alpha, :beta, :gamma], :to => :beta
10
+ end
11
+ end
12
+
13
+ def aasm_read_state
14
+ :beta
15
+ end
16
+
17
+ def aasm_write_state(new_state)
18
+ @persisted_store = new_state
19
+ end
20
+
21
+ def aasm_write_state_without_persistence(new_state)
22
+ @transient_store = new_state
23
+ end
24
+ end