aasm 5.0.2 → 5.0.3

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: 972a54f67c50af93041d8c104cb61069ad8ae6f4
4
- data.tar.gz: e4004fe73c08fdcf208afb45fa4e91904d2d97e0
3
+ metadata.gz: 90423050620c1cd3228e8f5f67b76be213c9c491
4
+ data.tar.gz: 8d583eb68700900b6e0a8c22d6e8b7b0e8714ce7
5
5
  SHA512:
6
- metadata.gz: 3e2da17ffaa34ca4a299b3c9b7e7d8832c7fb09cfb07fbfe1315092fbea01cbdb4ee7b7ceca3847533b421a60db97c151b71a57a8c75f42c0e4627881ad5b9f0
7
- data.tar.gz: f759c915e858f503d4b168c93b909aa497ba6ac4a3327ad51593dcbe44301e485166f76a5d09a4cd5c470c75cbb98b0085a675c2767e5267cfc0925ad32b777b
6
+ metadata.gz: fb3ca30cbb4d415e5fc9905ae1b9e9ace0b7145ff97f29ce8639a57a99df3df43f3b1626dd9029421e54326085a8e4f5853dfbd21e231c778b3dca058cc980b9
7
+ data.tar.gz: 72996c355abefda14839e009f50bdcf900b0acd6d43f3d9eabb4e587390dd67b16be0a9eb66119f7e9d394993d266a0af823dedd6b54ad3e20049d7794fe9bfa
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## 5.0.3
6
+
7
+ * Fix Abstract class issue, [#619](https://github.com/aasm/aasm/pull/619)
8
+
5
9
  ## 5.0.2
6
10
 
7
11
  * Clear failed callbacks, [#600](https://github.com/aasm/aasm/pull/600), thanks to
data/README.md CHANGED
@@ -70,19 +70,19 @@ class Job
70
70
  include AASM
71
71
 
72
72
  aasm do
73
- state :sleeping, :initial => true
73
+ state :sleeping, initial: true
74
74
  state :running, :cleaning
75
75
 
76
76
  event :run do
77
- transitions :from => :sleeping, :to => :running
77
+ transitions from: :sleeping, to: :running
78
78
  end
79
79
 
80
80
  event :clean do
81
- transitions :from => :running, :to => :cleaning
81
+ transitions from: :running, to: :cleaning
82
82
  end
83
83
 
84
84
  event :sleep do
85
- transitions :from => [:running, :cleaning], :to => :sleeping
85
+ transitions from: [:running, :cleaning], to: :sleeping
86
86
  end
87
87
  end
88
88
 
@@ -108,7 +108,7 @@ AASM not to be *whiny*:
108
108
  ```ruby
109
109
  class Job
110
110
  ...
111
- aasm :whiny_transitions => false do
111
+ aasm whiny_transitions: false do
112
112
  ...
113
113
  end
114
114
  end
@@ -137,19 +137,19 @@ class Job
137
137
  include AASM
138
138
 
139
139
  aasm do
140
- state :sleeping, :initial => true, :before_enter => :do_something
140
+ state :sleeping, initial: true, before_enter: :do_something
141
141
  state :running, before_enter: Proc.new { do_something && notify_somebody }
142
142
  state :finished
143
143
 
144
144
  after_all_transitions :log_status_change
145
145
 
146
- event :run, :after => :notify_somebody do
146
+ event :run, after: :notify_somebody do
147
147
  before do
148
148
  log('Preparing to run')
149
149
  end
150
150
 
151
- transitions :from => :sleeping, :to => :running, :after => Proc.new {|*args| set_process(*args) }
152
- transitions :from => :running, :to => :finished, :after => LogRunTime
151
+ transitions from: :sleeping, to: :running, after: Proc.new {|*args| set_process(*args) }
152
+ transitions from: :running, to: :finished, after: LogRunTime
153
153
  end
154
154
 
155
155
  event :sleep do
@@ -159,7 +159,7 @@ class Job
159
159
  error do |e|
160
160
  ...
161
161
  end
162
- transitions :from => :running, :to => :sleeping
162
+ transitions from: :running, to: :sleeping
163
163
  end
164
164
  end
165
165
 
@@ -312,24 +312,24 @@ class Cleaner
312
312
  include AASM
313
313
 
314
314
  aasm do
315
- state :idle, :initial => true
315
+ state :idle, initial: true
316
316
  state :cleaning
317
317
 
318
318
  event :clean do
319
- transitions :from => :idle, :to => :cleaning, :guard => :cleaning_needed?
319
+ transitions from: :idle, to: :cleaning, guard: :cleaning_needed?
320
320
  end
321
321
 
322
322
  event :clean_if_needed do
323
- transitions :from => :idle, :to => :cleaning do
323
+ transitions from: :idle, to: :cleaning do
324
324
  guard do
325
325
  cleaning_needed?
326
326
  end
327
327
  end
328
- transitions :from => :idle, :to => :idle
328
+ transitions from: :idle, to: :idle
329
329
  end
330
330
 
331
331
  event :clean_if_dirty do
332
- transitions :from => :idle, :to => :cleaning, :guard => :if_dirty?
332
+ transitions from: :idle, to: :cleaning, guard: :if_dirty?
333
333
  end
334
334
  end
335
335
 
@@ -358,16 +358,16 @@ You can even provide a number of guards, which all have to succeed to proceed
358
358
  def walked_the_dog?; ...; end
359
359
 
360
360
  event :sleep do
361
- transitions :from => :running, :to => :sleeping, :guards => [:cleaning_needed?, :walked_the_dog?]
361
+ transitions from: :running, to: :sleeping, guards: [:cleaning_needed?, :walked_the_dog?]
362
362
  end
363
363
  ```
364
364
 
365
365
  If you want to provide guards for all transitions within an event, you can use event guards
366
366
 
367
367
  ```ruby
368
- event :sleep, :guards => [:walked_the_dog?] do
369
- transitions :from => :running, :to => :sleeping, :guards => [:cleaning_needed?]
370
- transitions :from => :cleaning, :to => :sleeping
368
+ event :sleep, guards: [:walked_the_dog?] do
369
+ transitions from: :running, to: :sleeping, guards: [:cleaning_needed?]
370
+ transitions from: :cleaning, to: :sleeping
371
371
  end
372
372
  ```
373
373
 
@@ -375,20 +375,20 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we
375
375
 
376
376
  ```ruby
377
377
  event :clean do
378
- transitions :from => :running, :to => :cleaning, :if => :cleaning_needed?
378
+ transitions from: :running, to: :cleaning, if: :cleaning_needed?
379
379
  end
380
380
 
381
381
  event :sleep do
382
- transitions :from => :running, :to => :sleeping, :unless => :cleaning_needed?
382
+ transitions from: :running, to: :sleeping, unless: :cleaning_needed?
383
383
  end
384
384
  end
385
385
  ```
386
386
 
387
- You can invoke a Class instead a method since this Class responds to `call`
387
+ You can invoke a Class instead a method since this Class responds to `call`
388
388
 
389
389
  ```ruby
390
390
  event :sleep do
391
- transitions :from => :running, :to => :sleeping, :guards => Dog
391
+ transitions from: :running, to: :sleeping, guards: Dog
392
392
  end
393
393
  ```
394
394
  ```ruby
@@ -411,7 +411,7 @@ class Job
411
411
  include AASM
412
412
 
413
413
  aasm do
414
- state :stage1, :initial => true
414
+ state :stage1, initial: true
415
415
  state :stage2
416
416
  state :stage3
417
417
  state :completed
@@ -442,30 +442,30 @@ built with one state machine per class in mind. Nonetheless, here's how to do it
442
442
  class SimpleMultipleExample
443
443
  include AASM
444
444
  aasm(:move) do
445
- state :standing, :initial => true
445
+ state :standing, initial: true
446
446
  state :walking
447
447
  state :running
448
448
 
449
449
  event :walk do
450
- transitions :from => :standing, :to => :walking
450
+ transitions from: :standing, to: :walking
451
451
  end
452
452
  event :run do
453
- transitions :from => [:standing, :walking], :to => :running
453
+ transitions from: [:standing, :walking], to: :running
454
454
  end
455
455
  event :hold do
456
- transitions :from => [:walking, :running], :to => :standing
456
+ transitions from: [:walking, :running], to: :standing
457
457
  end
458
458
  end
459
459
 
460
460
  aasm(:work) do
461
- state :sleeping, :initial => true
461
+ state :sleeping, initial: true
462
462
  state :processing
463
463
 
464
464
  event :start do
465
- transitions :from => :sleeping, :to => :processing
465
+ transitions from: :sleeping, to: :processing
466
466
  end
467
467
  event :stop do
468
- transitions :from => :processing, :to => :sleeping
468
+ transitions from: :processing, to: :sleeping
469
469
  end
470
470
  end
471
471
  end
@@ -498,28 +498,28 @@ Alternatively, you can provide a namespace for each state machine:
498
498
  class NamespacedMultipleExample
499
499
  include AASM
500
500
  aasm(:status) do
501
- state :unapproved, :initial => true
501
+ state :unapproved, initial: true
502
502
  state :approved
503
503
 
504
504
  event :approve do
505
- transitions :from => :unapproved, :to => :approved
505
+ transitions from: :unapproved, to: :approved
506
506
  end
507
507
 
508
508
  event :unapprove do
509
- transitions :from => :approved, :to => :unapproved
509
+ transitions from: :approved, to: :unapproved
510
510
  end
511
511
  end
512
512
 
513
513
  aasm(:review_status, namespace: :review) do
514
- state :unapproved, :initial => true
514
+ state :unapproved, initial: true
515
515
  state :approved
516
516
 
517
517
  event :approve do
518
- transitions :from => :unapproved, :to => :approved
518
+ transitions from: :unapproved, to: :approved
519
519
  end
520
520
 
521
521
  event :unapprove do
522
- transitions :from => :approved, :to => :unapproved
522
+ transitions from: :approved, to: :unapproved
523
523
  end
524
524
  end
525
525
  end
@@ -551,26 +551,26 @@ class Example
551
551
  include AASM
552
552
 
553
553
  aasm(:work) do
554
- state :sleeping, :initial => true
554
+ state :sleeping, initial: true
555
555
  state :processing
556
556
 
557
557
  event :start do
558
- transitions :from => :sleeping, :to => :processing
558
+ transitions from: :sleeping, to: :processing
559
559
  end
560
560
  event :stop do
561
- transitions :from => :processing, :to => :sleeping
561
+ transitions from: :processing, to: :sleeping
562
562
  end
563
563
  end
564
564
 
565
565
  aasm(:question) do
566
- state :answered, :initial => true
566
+ state :answered, initial: true
567
567
  state :asked
568
568
 
569
- event :ask, :binding_event => :start do
570
- transitions :from => :answered, :to => :asked
569
+ event :ask, binding_event: :start do
570
+ transitions from: :answered, to: :asked
571
571
  end
572
- event :answer, :binding_event => :stop do
573
- transitions :from => :asked, :to => :answered
572
+ event :answer, binding_event: :stop do
573
+ transitions from: :asked, to: :answered
574
574
  end
575
575
  end
576
576
  end
@@ -616,7 +616,7 @@ class CustomAASMBase < AASM::Base
616
616
  # A custom transiton that we want available across many AASM models.
617
617
  def count_transitions!
618
618
  klass.class_eval do
619
- aasm :with_klass => CustomAASMBase do
619
+ aasm with_klass: CustomAASMBase do
620
620
  after_all_transitions :increment_transition_count
621
621
  end
622
622
  end
@@ -653,19 +653,19 @@ class SimpleCustomExample
653
653
  include AASM
654
654
 
655
655
  # Let's build an AASM state machine with our custom class.
656
- aasm :with_klass => CustomAASMBase do
656
+ aasm with_klass: CustomAASMBase do
657
657
  requires_guards!
658
658
  count_transitions!
659
659
 
660
- state :initialised, :initial => true
660
+ state :initialised, initial: true
661
661
  state :filled_out
662
662
  state :authorised
663
663
 
664
664
  event :fill_out do
665
- transitions :from => :initialised, :to => :filled_out, :guard => :fillable?
665
+ transitions from: :initialised, to: :filled_out, guard: :fillable?
666
666
  end
667
667
  event :authorise do
668
- transitions :from => :filled_out, :to => :authorised, :guard => :authorizable?
668
+ transitions from: :filled_out, to: :authorised, guard: :authorizable?
669
669
  end
670
670
  end
671
671
  end
@@ -682,15 +682,15 @@ class Job < ActiveRecord::Base
682
682
  include AASM
683
683
 
684
684
  aasm do # default column: aasm_state
685
- state :sleeping, :initial => true
685
+ state :sleeping, initial: true
686
686
  state :running
687
687
 
688
688
  event :run do
689
- transitions :from => :sleeping, :to => :running
689
+ transitions from: :sleeping, to: :running
690
690
  end
691
691
 
692
692
  event :sleep do
693
- transitions :from => :running, :to => :sleeping
693
+ transitions from: :running, to: :sleeping
694
694
  end
695
695
  end
696
696
 
@@ -725,16 +725,16 @@ be updated in the database (just like ActiveRecord `update_column` is working).
725
725
  class Job < ActiveRecord::Base
726
726
  include AASM
727
727
 
728
- aasm :skip_validation_on_save => true do
729
- state :sleeping, :initial => true
728
+ aasm skip_validation_on_save: true do
729
+ state :sleeping, initial: true
730
730
  state :running
731
731
 
732
732
  event :run do
733
- transitions :from => :sleeping, :to => :running
733
+ transitions from: :sleeping, to: :running
734
734
  end
735
735
 
736
736
  event :sleep do
737
- transitions :from => :running, :to => :sleeping
737
+ transitions from: :running, to: :sleeping
738
738
  end
739
739
  end
740
740
 
@@ -748,12 +748,12 @@ configure _AASM_ to not allow direct assignment, like this:
748
748
  class Job < ActiveRecord::Base
749
749
  include AASM
750
750
 
751
- aasm :no_direct_assignment => true do
752
- state :sleeping, :initial => true
751
+ aasm no_direct_assignment: true do
752
+ state :sleeping, initial: true
753
753
  state :running
754
754
 
755
755
  event :run do
756
- transitions :from => :sleeping, :to => :running
756
+ transitions from: :sleeping, to: :running
757
757
  end
758
758
  end
759
759
 
@@ -784,8 +784,8 @@ class Job < ActiveRecord::Base
784
784
  running: 99
785
785
  }
786
786
 
787
- aasm :column => :state, :enum => true do
788
- state :sleeping, :initial => true
787
+ aasm column: :state, enum: true do
788
+ state :sleeping, initial: true
789
789
  state :running
790
790
  end
791
791
  end
@@ -884,7 +884,7 @@ class Job < ActiveRecord::Base
884
884
  include AASM
885
885
 
886
886
  aasm do
887
- state :sleeping, :initial => true
887
+ state :sleeping, initial: true
888
888
  state :running
889
889
  state :cleaning
890
890
  end
@@ -913,8 +913,8 @@ defining the `AASM` states, like this:
913
913
  class Job < ActiveRecord::Base
914
914
  include AASM
915
915
 
916
- aasm :create_scopes => false do
917
- state :sleeping, :initial => true
916
+ aasm create_scopes: false do
917
+ state :sleeping, initial: true
918
918
  state :running
919
919
  state :cleaning
920
920
  end
@@ -947,11 +947,11 @@ class Job < ActiveRecord::Base
947
947
  include AASM
948
948
 
949
949
  aasm do
950
- state :sleeping, :initial => true
950
+ state :sleeping, initial: true
951
951
  state :running
952
952
 
953
- event :run, :after_commit => :notify_about_running_job do
954
- transitions :from => :sleeping, :to => :running
953
+ event :run, after_commit: :notify_about_running_job do
954
+ transitions from: :sleeping, to: :running
955
955
  end
956
956
  end
957
957
 
@@ -977,14 +977,14 @@ If you want to encapsulate state changes within an own transaction, the behavior
977
977
  of this nested transaction might be confusing. Take a look at
978
978
  [ActiveRecord Nested Transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html)
979
979
  if you want to know more about this. Nevertheless, AASM by default requires a new transaction
980
- `transaction(:requires_new => true)`. You can override this behavior by changing
980
+ `transaction(requires_new: true)`. You can override this behavior by changing
981
981
  the configuration
982
982
 
983
983
  ```ruby
984
984
  class Job < ActiveRecord::Base
985
985
  include AASM
986
986
 
987
- aasm :requires_new_transaction => false do
987
+ aasm requires_new_transaction: false do
988
988
  ...
989
989
  end
990
990
 
@@ -992,7 +992,7 @@ class Job < ActiveRecord::Base
992
992
  end
993
993
  ```
994
994
 
995
- which then leads to `transaction(:requires_new => false)`, the Rails default.
995
+ which then leads to `transaction(requires_new: false)`, the Rails default.
996
996
 
997
997
  Additionally, if you do not want any of your active record actions to be
998
998
  wrapped in a transaction, you can specify the `use_transactions` flag. This can
@@ -1004,7 +1004,7 @@ result of a transaction or callback, even when some error occurs. The
1004
1004
  class Job < ActiveRecord::Base
1005
1005
  include AASM
1006
1006
 
1007
- aasm :use_transactions => false do
1007
+ aasm use_transactions: false do
1008
1008
  ...
1009
1009
  end
1010
1010
 
@@ -1027,7 +1027,7 @@ AASM supports [Active Record pessimistic locking via `with_lock`](http://api.rub
1027
1027
  class Job < ActiveRecord::Base
1028
1028
  include AASM
1029
1029
 
1030
- aasm :requires_lock => true do
1030
+ aasm requires_lock: true do
1031
1031
  ...
1032
1032
  end
1033
1033
 
@@ -1039,7 +1039,7 @@ end
1039
1039
  class Job < ActiveRecord::Base
1040
1040
  include AASM
1041
1041
 
1042
- aasm :requires_lock => 'FOR UPDATE NOWAIT' do
1042
+ aasm requires_lock: 'FOR UPDATE NOWAIT' do
1043
1043
  ...
1044
1044
  end
1045
1045
 
@@ -1057,7 +1057,7 @@ this by defining your favorite column name, using `:column` like this:
1057
1057
  class Job < ActiveRecord::Base
1058
1058
  include AASM
1059
1059
 
1060
- aasm :column => 'my_state' do
1060
+ aasm column: 'my_state' do
1061
1061
  ...
1062
1062
  end
1063
1063
 
@@ -1093,19 +1093,19 @@ class Job
1093
1093
  include AASM
1094
1094
 
1095
1095
  aasm do
1096
- state :sleeping, :initial => true
1096
+ state :sleeping, initial: true
1097
1097
  state :running, :cleaning
1098
1098
 
1099
1099
  event :run do
1100
- transitions :from => :sleeping, :to => :running
1100
+ transitions from: :sleeping, to: :running
1101
1101
  end
1102
1102
 
1103
1103
  event :clean do
1104
- transitions :from => :running, :to => :cleaning, :guard => :cleaning_needed?
1104
+ transitions from: :running, to: :cleaning, guard: :cleaning_needed?
1105
1105
  end
1106
1106
 
1107
1107
  event :sleep do
1108
- transitions :from => [:running, :cleaning], :to => :sleeping
1108
+ transitions from: [:running, :cleaning], to: :sleeping
1109
1109
  end
1110
1110
  end
1111
1111
 
@@ -1123,15 +1123,15 @@ Job.aasm.states.map(&:name)
1123
1123
  job = Job.new
1124
1124
 
1125
1125
  # show all permitted states (from initial state)
1126
- job.aasm.states(:permitted => true).map(&:name)
1126
+ job.aasm.states(permitted: true).map(&:name)
1127
1127
  #=> [:running]
1128
1128
 
1129
1129
  job.run
1130
- job.aasm.states(:permitted => true).map(&:name)
1130
+ job.aasm.states(permitted: true).map(&:name)
1131
1131
  #=> [:sleeping]
1132
1132
 
1133
1133
  # show all non permitted states
1134
- job.aasm.states(:permitted => false).map(&:name)
1134
+ job.aasm.states(permitted: false).map(&:name)
1135
1135
  #=> [:cleaning]
1136
1136
 
1137
1137
  # show all possible (triggerable) events from the current state
@@ -1139,23 +1139,23 @@ job.aasm.events.map(&:name)
1139
1139
  #=> [:clean, :sleep]
1140
1140
 
1141
1141
  # show all permitted events
1142
- job.aasm.events(:permitted => true).map(&:name)
1142
+ job.aasm.events(permitted: true).map(&:name)
1143
1143
  #=> [:sleep]
1144
1144
 
1145
1145
  # show all non permitted events
1146
- job.aasm.events(:permitted => false).map(&:name)
1146
+ job.aasm.events(permitted: false).map(&:name)
1147
1147
  #=> [:clean]
1148
1148
 
1149
1149
  # show all possible events except a specific one
1150
- job.aasm.events(:reject => :sleep).map(&:name)
1150
+ job.aasm.events(reject: :sleep).map(&:name)
1151
1151
  #=> [:clean]
1152
1152
 
1153
1153
  # list states for select
1154
1154
  Job.aasm.states_for_select
1155
- => [["Sleeping", "sleeping"], ["Running", "running"], ["Cleaning", "cleaning"]]
1155
+ #=> [["Sleeping", "sleeping"], ["Running", "running"], ["Cleaning", "cleaning"]]
1156
1156
 
1157
1157
  # show permitted states with guard parameter
1158
- job.aasm.states({:permitted => true}, guard_parameter).map(&:name)
1158
+ job.aasm.states({permitted: true}, guard_parameter).map(&:name)
1159
1159
  ```
1160
1160
 
1161
1161
 
@@ -1168,7 +1168,7 @@ use
1168
1168
  class Job
1169
1169
  include AASM
1170
1170
 
1171
- aasm :logger => Rails.logger do
1171
+ aasm logger: Rails.logger do
1172
1172
  ...
1173
1173
  end
1174
1174
  end
@@ -1192,12 +1192,12 @@ the 'instance method symbol / string' way whenever possible when defining guardi
1192
1192
 
1193
1193
  #### RSpec
1194
1194
 
1195
- AASM provides some matchers for [RSpec](http://rspec.info):
1196
- *`transition_from`,
1195
+ AASM provides some matchers for [RSpec](http://rspec.info):
1196
+ *`transition_from`,
1197
1197
  * `have_state`, `allow_event`
1198
- * and `allow_transition_to`.
1198
+ * and `allow_transition_to`.
1199
1199
 
1200
- ##### Installation Instructions:
1200
+ ##### Installation Instructions:
1201
1201
  * Add `require 'aasm/rspec'` to your `spec_helper.rb` file.
1202
1202
 
1203
1203
  ##### Examples Of Usage in Rspec:
@@ -54,6 +54,7 @@ module AASM
54
54
  # make sure to raise an error if no_direct_assignment is enabled
55
55
  # and attribute is directly assigned though
56
56
  aasm_name = @name
57
+ return true if should_not_define_method(klass) && !@state_machine.config.no_direct_assignment
57
58
  klass.send :define_method, "#{@state_machine.config.column}=", ->(state_name) do
58
59
  if self.class.aasm(:"#{aasm_name}").state_machine.config.no_direct_assignment
59
60
  raise AASM::NoDirectAssignmentError.new(
@@ -65,6 +66,13 @@ module AASM
65
66
  end
66
67
  end
67
68
 
69
+ def should_not_define_method(klass)
70
+ (klass.methods.include?(:abstract_class) &&
71
+ klass.abstract_class) ||
72
+ (klass.superclass.methods.include?(:abstract_class) &&
73
+ klass.superclass.abstract_class)
74
+ end
75
+
68
76
  # This method is both a getter and a setter
69
77
  def attribute_name(column_name=nil)
70
78
  if column_name
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "5.0.2"
2
+ VERSION = "5.0.3"
3
3
  end
@@ -14,6 +14,9 @@ ActiveRecord::Migration.suppress_messages do
14
14
  ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t|
15
15
  t.string "status"
16
16
  end
17
+ ActiveRecord::Migration.create_table "users", :force => true do |t|
18
+ t.string "status"
19
+ end
17
20
 
18
21
  ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
19
22
  t.string "left"
@@ -0,0 +1,23 @@
1
+ class Base < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ self.table_name = 'users'
4
+
5
+ include AASM
6
+
7
+ aasm column: 'status' do
8
+ state :inactive, initial: true
9
+ state :active
10
+
11
+ event :activate do
12
+ transitions from: :inactive, to: :active
13
+ end
14
+
15
+ event :deactivate do
16
+ transitions from: :active, to: :inactive
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ class Person < Base
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ if defined?(ActiveRecord)
3
+ require 'models/active_record/person'
4
+
5
+ load_schema
6
+ describe 'Abstract subclassing' do
7
+
8
+ it 'should have the parent states' do
9
+ Person.aasm.states.each do |state|
10
+ expect(Base.aasm.states).to include(state)
11
+ end
12
+ expect(Person.aasm.states).to eq(Base.aasm.states)
13
+ end
14
+
15
+ it 'should have the same events as its parent' do
16
+ expect(Base.aasm.events).to eq(Person.aasm.events)
17
+ end
18
+
19
+ it 'should not break aasm methods when super class is abstract_class' do
20
+ person = Person.new
21
+ person.status = 'active'
22
+ person.deactivate!
23
+ expect(person.aasm.current_state).to eq(:inactive)
24
+ end
25
+
26
+ end
27
+ end
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: 5.0.2
4
+ version: 5.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Boettger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-08 00:00:00.000000000 Z
12
+ date: 2019-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -210,6 +210,7 @@ files:
210
210
  - spec/models/active_record/no_direct_assignment.rb
211
211
  - spec/models/active_record/no_scope.rb
212
212
  - spec/models/active_record/persisted_state.rb
213
+ - spec/models/active_record/person.rb
213
214
  - spec/models/active_record/provided_and_persisted_state.rb
214
215
  - spec/models/active_record/reader.rb
215
216
  - spec/models/active_record/readme_job.rb
@@ -312,6 +313,7 @@ files:
312
313
  - spec/spec_helpers/redis.rb
313
314
  - spec/spec_helpers/remove_warnings.rb
314
315
  - spec/spec_helpers/sequel.rb
316
+ - spec/unit/abstract_class_spec.rb
315
317
  - spec/unit/api_spec.rb
316
318
  - spec/unit/basic_two_state_machines_example_spec.rb
317
319
  - spec/unit/callback_multiple_spec.rb
@@ -411,6 +413,7 @@ test_files:
411
413
  - spec/models/active_record/no_direct_assignment.rb
412
414
  - spec/models/active_record/no_scope.rb
413
415
  - spec/models/active_record/persisted_state.rb
416
+ - spec/models/active_record/person.rb
414
417
  - spec/models/active_record/provided_and_persisted_state.rb
415
418
  - spec/models/active_record/reader.rb
416
419
  - spec/models/active_record/readme_job.rb
@@ -513,6 +516,7 @@ test_files:
513
516
  - spec/spec_helpers/redis.rb
514
517
  - spec/spec_helpers/remove_warnings.rb
515
518
  - spec/spec_helpers/sequel.rb
519
+ - spec/unit/abstract_class_spec.rb
516
520
  - spec/unit/api_spec.rb
517
521
  - spec/unit/basic_two_state_machines_example_spec.rb
518
522
  - spec/unit/callback_multiple_spec.rb