aasm 5.1.0 → 5.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be8ee23b312066a6b90211161857cb2c461f20e9b1e3e93f955d6b8caeb6f497
4
- data.tar.gz: 47c63523fc92f0fdc823024f632f27cab4453c4c2c9c7e277c45dea0f170250f
3
+ metadata.gz: f2f4099a66f8d753c2bd7c06b3c378dcd37b47acf9b2f7487784e7762742c1c4
4
+ data.tar.gz: 8971b36f1b066c08d3a4d278a99d7c1e5386be72182da62b51a82db1e60e9e9f
5
5
  SHA512:
6
- metadata.gz: 258182cd645528de747eff39a70bcd697b5f965e49890ce369804aba0fb4c08739ff5259efef9cdde405b819765becb451ba4a6994f74dc89f0581c387d84ef1
7
- data.tar.gz: 9408e99df7783505a8a67d4d54b0d5f3660b991790db7bad46598734ed33d1d7f1b5e463f67d435c0de15d0d1ef020023f8900781a72a40bcc85c35d76c8cf22
6
+ metadata.gz: c24e544b82cfc4616f3e3ff033b7a5ab68bff7bd834b115797e9127ca361effe241ffb1adaedcdb595711a6757f2e0a8e0a8d606a9bc812c28707a1ee845ef40
7
+ data.tar.gz: 421636d1e59e52b8d6b4ddff7dd373fecd9a19ef67b90935e856b1ee980bae9a5a4a8526e62238de9ecc84a7783362e8d5b2005c53b9c7754368be79724c6255
@@ -12,7 +12,6 @@ before_install:
12
12
  - bundle _1.16.1_ install
13
13
 
14
14
  rvm:
15
- - 2.3.0
16
15
  - 2.5.0
17
16
  - 2.6.5
18
17
  - 2.7.0
@@ -47,16 +46,6 @@ script:
47
46
 
48
47
  matrix:
49
48
  exclude:
50
- - rvm: 2.3.0
51
- gemfile: gemfiles/norails.gemfile
52
- - rvm: 2.3.0
53
- gemfile: gemfiles/rails_5.0.gemfile
54
- # - rvm: 2.3.0
55
- # gemfile: gemfiles/rails_5.0_nobrainer.gemfile
56
- - rvm: 2.3.0
57
- gemfile: gemfiles/rails_5.1.gemfile
58
- - rvm: 2.3.0
59
- gemfile: gemfiles/rails_5.2.gemfile
60
49
  - rvm: 2.7.0
61
50
  gemfile: gemfiles/rails_5.2.gemfile
62
51
  - rvm: 2.6.5
@@ -4,6 +4,12 @@
4
4
 
5
5
  ## 5.1.0
6
6
 
7
+ * Fix Depreciation message for after_commit_everywhere [#695](https://github.com/aasm/aasm/issues/695) in PR [#696](https://github.com/aasm/aasm/pull/696)
8
+ * Fix human_state to use display option [#684](https://github.com/aasm/aasm/issues/684) in PR [#697](https://github.com/aasm/aasm/pull/697)
9
+ * Remove support for ruby 2.3
10
+
11
+ ## 5.1.0
12
+
7
13
  * Fix after_commit in nested transactions [#536](https://github.com/aasm/aasm/issues/536) without explicit AR dependency in PR [#668](https://github.com/aasm/aasm/pull/668), thanks to [stokarenko](https://github.com/stokarenko)
8
14
  * Remove support for Rails 3.2
9
15
 
data/README.md CHANGED
@@ -434,6 +434,25 @@ job.stage1_completed
434
434
  job.aasm.current_state # stage3
435
435
  ```
436
436
 
437
+ ### Display name for state
438
+
439
+ You can define display name for state using :display option
440
+
441
+ ```ruby
442
+ class Job
443
+ include AASM
444
+
445
+ aasm do
446
+ state :stage1, initial: true, display: 'First Stage'
447
+ state :stage2
448
+ state :stage3
449
+ end
450
+ end
451
+
452
+ job = Job.new
453
+ job.aasm.human_state
454
+
455
+ ```
437
456
 
438
457
  ### Multiple state machines per class
439
458
 
@@ -1,5 +1,3 @@
1
- require 'ostruct'
2
-
3
1
  require 'aasm/version'
4
2
  require 'aasm/errors'
5
3
  require 'aasm/configuration'
@@ -28,7 +28,7 @@ module AASM
28
28
  end
29
29
 
30
30
  def human_state
31
- AASM::Localizer.new.human_state_name(@instance.class, state_object_for_name(current_state))
31
+ state_object_for_name(current_state).display_name
32
32
  end
33
33
 
34
34
  def states(options={}, *args)
@@ -28,19 +28,6 @@ module AASM
28
28
  # end
29
29
  #
30
30
  def self.included(base)
31
- begin
32
- require 'after_commit_everywhere'
33
- raise LoadError unless Gem::Version.new(::AfterCommitEverywhere::VERSION) >= Gem::Version.new('0.1.5')
34
-
35
- base.send(:include, ::AfterCommitEverywhere) unless base.include?(::AfterCommitEverywhere)
36
- base.send(:alias_method, :aasm_execute_after_commit, :after_commit)
37
- rescue LoadError
38
- warn <<-MSG
39
- [DEPRECATION] :after_commit AASM callback is not safe in terms of race conditions and redundant calls.
40
- Please add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'` to your Gemfile in order to fix that.
41
- MSG
42
- end
43
-
44
31
  base.send(:include, AASM::Persistence::Base)
45
32
  base.send(:include, AASM::Persistence::ORM)
46
33
  base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
@@ -74,6 +61,24 @@ module AASM
74
61
 
75
62
  private
76
63
 
64
+ def aasm_execute_after_commit
65
+ begin
66
+ require 'after_commit_everywhere'
67
+ raise LoadError unless Gem::Version.new(::AfterCommitEverywhere::VERSION) >= Gem::Version.new('0.1.5')
68
+
69
+ self.extend ::AfterCommitEverywhere
70
+ after_commit do
71
+ yield
72
+ end
73
+ rescue LoadError
74
+ warn <<-MSG
75
+ [DEPRECATION] :after_commit AASM callback is not safe in terms of race conditions and redundant calls.
76
+ Please add `gem 'after_commit_everywhere', '~> 0.1', '>= 0.1.5'` to your Gemfile in order to fix that.
77
+ MSG
78
+ yield
79
+ end
80
+ end
81
+
77
82
  def aasm_raise_invalid_record
78
83
  raise ActiveRecord::RecordInvalid.new(self)
79
84
  end
@@ -135,7 +135,7 @@ module AASM
135
135
  super
136
136
  end
137
137
 
138
- if success
138
+ if success && !(event.options.keys & [:after_commit, :after_all_commits]).empty?
139
139
  aasm_execute_after_commit do
140
140
  event.fire_callbacks(:after_commit, self, *args)
141
141
  event.fire_global_callbacks(:after_all_commits, self, *args)
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "5.1.0"
2
+ VERSION = "5.1.1"
3
3
  end
@@ -4,9 +4,6 @@ en:
4
4
  localizer_test_model:
5
5
  close: "Let's close it!"
6
6
 
7
- attributes:
8
- localizer_test_model:
9
- aasm_state/opened: "It's open now!"
10
7
  errors:
11
8
  messages:
12
9
  record_invalid: "Invalid record"
@@ -1,9 +1,5 @@
1
1
  en:
2
2
  activerecord:
3
- events:
4
- localizer_test_model:
5
- close: "Let's close it!"
6
-
7
3
  attributes:
8
4
  localizer_test_model:
9
5
  aasm_state:
@@ -0,0 +1,5 @@
1
+ en:
2
+ activerecord:
3
+ attributes:
4
+ localizer_test_model:
5
+ aasm_state/opened: "It's open now!"
@@ -11,13 +11,13 @@ end
11
11
 
12
12
  describe 'localized state names' do
13
13
  before(:all) do
14
- I18n.load_path << 'spec/en.yml'
15
- I18n.default_locale = :en
14
+ I18n.load_path << 'spec/localizer_test_model_new_style.yml'
16
15
  I18n.reload!
17
16
  end
18
17
 
19
18
  after(:all) do
20
- I18n.load_path.clear
19
+ I18n.load_path.delete('spec/localizer_test_model_new_style.yml')
20
+ I18n.backend.load_translations
21
21
  end
22
22
 
23
23
  it 'should localize' do
@@ -2,7 +2,7 @@ class DefaultState
2
2
  attr_accessor :transient_store, :persisted_store
3
3
  include AASM
4
4
  aasm do
5
- state :alpha, :initial => true
5
+ state :alpha, :initial => true, display: 'ALPHA'
6
6
  state :beta
7
7
  state :gamma
8
8
  event :release do
@@ -13,6 +13,7 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib
13
13
  require 'aasm'
14
14
  require 'rspec'
15
15
  require 'aasm/rspec'
16
+ require 'i18n'
16
17
  require 'pry'
17
18
 
18
19
  # require 'ruby-debug'; Debugger.settings[:autoeval] = true; debugger; rubys_debugger = 'annoying'
@@ -34,3 +35,7 @@ Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].sort.each { |f| require Fi
34
35
 
35
36
  # example model classes
36
37
  Dir[File.dirname(__FILE__) + "/models/*.rb"].sort.each { |f| require File.expand_path(f) }
38
+
39
+ I18n.load_path << 'spec/en.yml'
40
+ I18n.enforce_available_locales = false
41
+ I18n.default_locale = :en
@@ -13,6 +13,10 @@ if defined?(ActiveRecord)
13
13
  expect(DefaultState.new.aasm.current_state).to eql :alpha
14
14
  end
15
15
 
16
+ it "uses display option" do
17
+ expect(DefaultState.new.aasm.human_state).to eql "ALPHA"
18
+ end
19
+
16
20
  it "uses the provided method" do
17
21
  expect(ProvidedState.new.aasm.current_state).to eql :beta
18
22
  end
@@ -166,11 +166,15 @@ describe "special cases" do
166
166
  end
167
167
 
168
168
  describe 'aasm.states_for_select' do
169
- it "should return a select friendly array of states" do
170
- expect(FooMultiple.aasm(:left)).to respond_to(:states_for_select)
171
- expect(FooMultiple.aasm(:left).states_for_select).to eq(
172
- [['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']]
173
- )
169
+ context 'without I18n' do
170
+ before { allow(Module).to receive(:const_defined?).with(:I18n).and_return(nil) }
171
+
172
+ it "should return a select friendly array of states" do
173
+ expect(FooMultiple.aasm(:left)).to respond_to(:states_for_select)
174
+ expect(FooMultiple.aasm(:left).states_for_select).to eq(
175
+ [['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']]
176
+ )
177
+ end
174
178
  end
175
179
  end
176
180
 
@@ -102,9 +102,13 @@ describe "special cases" do
102
102
  end
103
103
 
104
104
  describe 'aasm.states_for_select' do
105
- it "should return a select friendly array of states" do
106
- expect(Foo.aasm).to respond_to(:states_for_select)
107
- expect(Foo.aasm.states_for_select).to eq([['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']])
105
+ context 'without I18n' do
106
+ before { allow(Module).to receive(:const_defined?).with(:I18n).and_return(nil) }
107
+
108
+ it "should return a select friendly array of states" do
109
+ expect(Foo.aasm).to respond_to(:states_for_select)
110
+ expect(Foo.aasm.states_for_select).to eq([['Open', 'open'], ['Closed', 'closed'], ['Final', 'final']])
111
+ end
108
112
  end
109
113
  end
110
114
 
@@ -1,20 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- if defined?(ActiceRecord)
4
- require 'i18n'
5
-
6
- I18n.enforce_available_locales = false
3
+ if defined?(ActiveRecord)
4
+ require 'models/active_record/localizer_test_model'
7
5
  load_schema
8
6
 
9
7
  describe AASM::Localizer, "new style" do
10
8
  before(:all) do
11
- I18n.load_path << 'spec/en.yml'
12
- I18n.default_locale = :en
9
+ I18n.load_path << 'spec/localizer_test_model_new_style.yml'
13
10
  I18n.reload!
14
11
  end
15
12
 
16
13
  after(:all) do
17
- I18n.load_path.clear
14
+ I18n.load_path.delete('spec/localizer_test_model_new_style.yml')
15
+ I18n.backend.load_translations
18
16
  end
19
17
 
20
18
  let (:foo_opened) { LocalizerTestModel.new }
@@ -43,13 +41,14 @@ if defined?(ActiceRecord)
43
41
 
44
42
  describe AASM::Localizer, "deprecated style" do
45
43
  before(:all) do
46
- I18n.load_path << 'spec/en_deprecated_style.yml'
47
- I18n.default_locale = :en
44
+ I18n.load_path << 'spec/localizer_test_model_deprecated_style.yml'
48
45
  I18n.reload!
46
+ I18n.backend.load_translations
49
47
  end
50
48
 
51
49
  after(:all) do
52
- I18n.load_path.clear
50
+ I18n.load_path.delete('spec/localizer_test_model_deprecated_style.yml')
51
+ I18n.backend.load_translations
53
52
  end
54
53
 
55
54
  let (:foo_opened) { LocalizerTestModel.new }
@@ -17,12 +17,28 @@ describe AASM::Core::State do
17
17
  expect(state.name).to eq(:astate)
18
18
  end
19
19
 
20
- it 'should set the display_name from name' do
21
- expect(new_state.display_name).to eq('Astate')
22
- end
20
+ describe '#display_name' do
21
+ subject(:display_name) { new_state(options).display_name }
22
+
23
+ context 'without options' do
24
+ let(:options) { {} }
25
+
26
+ context 'without I18n' do
27
+ before { allow(Module).to receive(:const_defined?).with(:I18n).and_return(nil) }
28
+
29
+ it 'should set the display_name from name' do
30
+ expect(display_name).to eq('Astate')
31
+ end
32
+ end
33
+ end
34
+
35
+ context 'with :display option' do
36
+ let(:options) { { display: "A State" } }
23
37
 
24
- it 'should set the display_name from options' do
25
- expect(new_state(:display => "A State").display_name).to eq('A State')
38
+ it 'should set the display_name from options' do
39
+ expect(display_name).to eq('A State')
40
+ end
41
+ end
26
42
  end
27
43
 
28
44
  it 'should set the options and expose them as options' do
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.1.0
4
+ version: 5.1.1
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: 2020-08-01 00:00:00.000000000 Z
12
+ date: 2020-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -232,10 +232,11 @@ files:
232
232
  - spec/database.rb
233
233
  - spec/database.yml
234
234
  - spec/en.yml
235
- - spec/en_deprecated_style.yml
236
235
  - spec/generators/active_record_generator_spec.rb
237
236
  - spec/generators/mongoid_generator_spec.rb
238
237
  - spec/generators/no_brainer_generator_spec.rb
238
+ - spec/localizer_test_model_deprecated_style.yml
239
+ - spec/localizer_test_model_new_style.yml
239
240
  - spec/models/active_record/active_record_callback.rb
240
241
  - spec/models/active_record/basic_active_record_two_state_machines_example.rb
241
242
  - spec/models/active_record/complex_active_record_example.rb
@@ -436,10 +437,11 @@ test_files:
436
437
  - spec/database.rb
437
438
  - spec/database.yml
438
439
  - spec/en.yml
439
- - spec/en_deprecated_style.yml
440
440
  - spec/generators/active_record_generator_spec.rb
441
441
  - spec/generators/mongoid_generator_spec.rb
442
442
  - spec/generators/no_brainer_generator_spec.rb
443
+ - spec/localizer_test_model_deprecated_style.yml
444
+ - spec/localizer_test_model_new_style.yml
443
445
  - spec/models/active_record/active_record_callback.rb
444
446
  - spec/models/active_record/basic_active_record_two_state_machines_example.rb
445
447
  - spec/models/active_record/complex_active_record_example.rb