state_machines-activemodel 0.6.0 → 0.9.0

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: 6c0c2ff3f596aa6cef5995e482bcebf703eae4a12b69ab74eab03808bd11c6d6
4
- data.tar.gz: f52f715a48845c350ddb25d84ea7a9e17ec9d95ea333cd57c329175cb9dcf01f
3
+ metadata.gz: c8bb31a6d52d73caf948365731b8670f86a57814d839c4606cd12c88b178f48f
4
+ data.tar.gz: c3f2f12fc7077f4fb230b08908314684fbbe7c59153cd12cc35dbacd767dd386
5
5
  SHA512:
6
- metadata.gz: 8585ea04188c0f058c5ac7673ff9df179222c0419a51b9f82d76bf38bd42a25409def954d0bfc2dbf54c2fb24830f02d13ae0307f2879b56c7c36e7aca27c3dd
7
- data.tar.gz: 06e2b22e4c65b8a0f10052d73891b1f54016cb00952829320e65a4ce9ea1fc8fbb0427bff6fbdfb58cd3095e65f4f9a63a775916957d2fb8ca7b89eabc60608c
6
+ metadata.gz: 8dd82a7786ea47d62fb36e04fd85be1451d1d37666702545bf9db2c0b13601d61ca65c1ab0b28844f64e7cdab82e62a1ea8221706b5d8342b003caa1fb8d9f08
7
+ data.tar.gz: 944d5c9ce3320e1f46e638c120ee2fcf4bd97f4c98ab3fad8e1598bc2fe2cd0a80ed2db61dc86535b551366c38108c4a007729eaeef4703e5a9e51c874921a2a
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2006-2012 Aaron Pfeifer
2
- Copyright (c) 2014-2015 Abdelkader Boudih
2
+ Copyright (c) 2014-2023 Abdelkader Boudih
3
3
 
4
4
  MIT License
5
5
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://travis-ci.org/state-machines/state_machines-activemodel.svg?branch=master)](https://travis-ci.org/state-machines/state_machines-activemodel)
2
- [![Code Climate](https://codeclimate.com/github/state-machines/state_machines-activemodel.png)](https://codeclimate.com/github/state-machines/state_machines-activemodel)
1
+ ![Build Status](https://github.com/state-machines/state_machines-activemodel/actions/workflows/ruby.yml/badge.svg)
2
+ [![Code Climate](https://codeclimate.com/github/state-machines/state_machines-activemodel.svg)](https://codeclimate.com/github/state-machines/state_machines-activemodel)
3
3
 
4
4
  # StateMachines ActiveModel Integration
5
5
 
@@ -21,6 +21,10 @@ Or install it yourself as:
21
21
 
22
22
  $ gem install state_machines-activemodel
23
23
 
24
+ ## Dependencies
25
+
26
+ Active Model 5.1+
27
+
24
28
  ## Usage
25
29
 
26
30
  ```ruby
@@ -78,11 +82,6 @@ end
78
82
 
79
83
  ```
80
84
 
81
- Dependencies
82
-
83
- Active Model 4.1+
84
-
85
-
86
85
  ## Contributing
87
86
 
88
87
  1. Fork it ( https://github.com/state-machines/state_machines-activemodel/fork )
@@ -1,7 +1,7 @@
1
1
  module StateMachines
2
2
  module Integrations
3
3
  module ActiveModel
4
- VERSION = '0.6.0'
4
+ VERSION = '0.9.0'
5
5
  end
6
6
  end
7
7
  end
@@ -184,7 +184,9 @@ module StateMachines
184
184
  # == Observers
185
185
  #
186
186
  # In order to hook in observer support for your application, the
187
- # ActiveModel::Observing feature must be included. Because of the way
187
+ # ActiveModel::Observing feature must be included. This can be added by including the
188
+ # https://github.com/state-machines/state_machines-activemodel-observers gem in your
189
+ # Gemfile. Because of the way
188
190
  # ActiveModel observers are designed, there is less flexibility around the
189
191
  # specific transitions that can be hooked in. However, a large number of
190
192
  # hooks *are* supported. For example, if a transition for a object's
@@ -380,7 +382,7 @@ module StateMachines
380
382
  end
381
383
 
382
384
  default_options = default_error_message_options(object, attribute, message)
383
- object.errors.add(attribute, message, options.merge(default_options))
385
+ object.errors.add(attribute, message, **options, **default_options)
384
386
  end
385
387
  end
386
388
 
@@ -405,6 +407,10 @@ module StateMachines
405
407
  def define_state_initializer
406
408
  define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
407
409
  def initialize(params = {})
410
+ params.transform_keys! do |key|
411
+ self.class.attribute_aliases[key.to_s] || key.to_s
412
+ end if self.class.respond_to?(:attribute_aliases)
413
+
408
414
  self.class.state_machines.initialize_states(self, {}, params) { super }
409
415
  end
410
416
  end_eval
@@ -0,0 +1,33 @@
1
+ require_relative 'test_helper'
2
+
3
+ class MachineWithInitializedAliasedAttributeTest < BaseTestCase
4
+ def test_should_match_original_attribute_value_with_attribute_methods
5
+ model = new_model do
6
+ include ActiveModel::AttributeMethods
7
+ alias_attribute :custom_status, :state
8
+ end
9
+
10
+ machine = StateMachines::Machine.new(model, initial: :parked, integration: :active_model)
11
+ machine.other_states(:started)
12
+
13
+ record = model.new(custom_status: 'started')
14
+
15
+ refute record.state?(:parked)
16
+ assert record.state?(:started)
17
+ end
18
+
19
+ def test_should_not_match_original_attribute_value_without_attribute_methods
20
+ model = new_model do
21
+ alias_attribute :custom_status, :state
22
+ end
23
+
24
+ machine = StateMachines::Machine.new(model, initial: :parked, integration: :active_model)
25
+ machine.other_states(:started)
26
+
27
+ record = model.new(custom_status: 'started')
28
+
29
+ assert record.state?(:parked)
30
+ refute record.state?(:started)
31
+ end
32
+ end
33
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines-activemodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-09 00:00:00.000000000 Z
12
+ date: 2023-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: state_machines
@@ -17,22 +17,19 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.5.0
20
+ version: 0.6.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 0.5.0
27
+ version: 0.6.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activemodel
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '4.1'
35
- - - "<"
36
33
  - !ruby/object:Gem::Version
37
34
  version: '6.0'
38
35
  type: :runtime
@@ -40,9 +37,6 @@ dependencies:
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
38
  requirements:
42
39
  - - ">="
43
- - !ruby/object:Gem::Version
44
- version: '4.1'
45
- - - "<"
46
40
  - !ruby/object:Gem::Version
47
41
  version: '6.0'
48
42
  - !ruby/object:Gem::Dependency
@@ -123,26 +117,12 @@ executables: []
123
117
  extensions: []
124
118
  extra_rdoc_files: []
125
119
  files:
126
- - ".gitignore"
127
- - ".travis.yml"
128
- - Appraisals
129
- - Gemfile
130
120
  - LICENSE.txt
131
121
  - README.md
132
- - Rakefile
133
- - gemfiles/active_model_4.1.gemfile
134
- - gemfiles/active_model_4.2.gemfile
135
- - gemfiles/active_model_5.0.gemfile
136
- - gemfiles/active_model_5.1.gemfile
137
- - gemfiles/active_model_5.2.gemfile
138
- - gemfiles/active_model_6.0.gemfile
139
- - gemfiles/active_model_edge.gemfile
140
122
  - lib/state_machines-activemodel.rb
141
123
  - lib/state_machines/integrations/active_model.rb
142
124
  - lib/state_machines/integrations/active_model/locale.rb
143
125
  - lib/state_machines/integrations/active_model/version.rb
144
- - state_machines-activemodel.gemspec
145
- - test/files/en.yml
146
126
  - test/integration_test.rb
147
127
  - test/machine_by_default_test.rb
148
128
  - test/machine_errors_test.rb
@@ -157,6 +137,7 @@ files:
157
137
  - test/machine_with_events_test.rb
158
138
  - test/machine_with_failed_after_callbacks_test.rb
159
139
  - test/machine_with_failed_before_callbacks_test.rb
140
+ - test/machine_with_initialized_aliased_attribute_test.rb
160
141
  - test/machine_with_initialized_state_test.rb
161
142
  - test/machine_with_internationalization_test.rb
162
143
  - test/machine_with_model_state_attribute_test.rb
@@ -166,7 +147,6 @@ files:
166
147
  - test/machine_with_static_initial_state_test.rb
167
148
  - test/machine_with_validations_and_custom_attribute_test.rb
168
149
  - test/machine_with_validations_test.rb
169
- - test/test_helper.rb
170
150
  homepage: https://github.com/state-machines/state_machines-activemodel
171
151
  licenses:
172
152
  - MIT
@@ -179,19 +159,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
159
  requirements:
180
160
  - - ">="
181
161
  - !ruby/object:Gem::Version
182
- version: 2.0.0
162
+ version: 3.0.0
183
163
  required_rubygems_version: !ruby/object:Gem::Requirement
184
164
  requirements:
185
165
  - - ">="
186
166
  - !ruby/object:Gem::Version
187
167
  version: '0'
188
168
  requirements: []
189
- rubygems_version: 3.0.1
169
+ rubygems_version: 3.4.10
190
170
  signing_key:
191
171
  specification_version: 4
192
172
  summary: ActiveModel integration for State Machines
193
173
  test_files:
194
- - test/files/en.yml
195
174
  - test/integration_test.rb
196
175
  - test/machine_by_default_test.rb
197
176
  - test/machine_errors_test.rb
@@ -206,6 +185,7 @@ test_files:
206
185
  - test/machine_with_events_test.rb
207
186
  - test/machine_with_failed_after_callbacks_test.rb
208
187
  - test/machine_with_failed_before_callbacks_test.rb
188
+ - test/machine_with_initialized_aliased_attribute_test.rb
209
189
  - test/machine_with_initialized_state_test.rb
210
190
  - test/machine_with_internationalization_test.rb
211
191
  - test/machine_with_model_state_attribute_test.rb
@@ -215,4 +195,3 @@ test_files:
215
195
  - test/machine_with_static_initial_state_test.rb
216
196
  - test/machine_with_validations_and_custom_attribute_test.rb
217
197
  - test/machine_with_validations_test.rb
218
- - test/test_helper.rb
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- tmp
16
- *.bundle
17
- *.so
18
- *.o
19
- *.a
20
- mkmf.log
21
- .idea/
22
- *.lock
data/.travis.yml DELETED
@@ -1,70 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
-
5
- rvm:
6
- - 2.1
7
- - 2.2.9
8
- - 2.3.8
9
- - 2.4.6
10
- - 2.5.5
11
- - 2.6.2
12
- - jruby
13
- - rbx-2
14
-
15
- gemfile:
16
- - gemfiles/active_model_4.2.gemfile
17
-
18
- matrix:
19
- include:
20
- - gemfile: gemfiles/active_model_4.1.gemfile
21
- rvm: 2.1
22
- - gemfile: gemfiles/active_model_4.1.gemfile
23
- rvm: 2.2.9
24
- - gemfile: gemfiles/active_model_4.1.gemfile
25
- rvm: 2.3.8
26
- - gemfile: gemfiles/active_model_5.0.gemfile
27
- rvm: 2.2.9
28
- - gemfile: gemfiles/active_model_5.0.gemfile
29
- rvm: 2.3.8
30
- - gemfile: gemfiles/active_model_5.0.gemfile
31
- rvm: 2.4.6
32
- - gemfile: gemfiles/active_model_5.0.gemfile
33
- rvm: 2.5.5
34
- - gemfile: gemfiles/active_model_5.0.gemfile
35
- rvm: 2.6.2
36
- - gemfile: gemfiles/active_model_5.1.gemfile
37
- rvm: 2.2.9
38
- - gemfile: gemfiles/active_model_5.1.gemfile
39
- rvm: 2.3.8
40
- - gemfile: gemfiles/active_model_5.1.gemfile
41
- rvm: 2.4.6
42
- - gemfile: gemfiles/active_model_5.1.gemfile
43
- rvm: 2.5.5
44
- - gemfile: gemfiles/active_model_5.1.gemfile
45
- rvm: 2.6.2
46
- - gemfile: gemfiles/active_model_5.2.gemfile
47
- rvm: 2.2.9
48
- - gemfile: gemfiles/active_model_5.2.gemfile
49
- rvm: 2.3.8
50
- - gemfile: gemfiles/active_model_5.2.gemfile
51
- rvm: 2.4.6
52
- - gemfile: gemfiles/active_model_5.2.gemfile
53
- rvm: 2.5.5
54
- - gemfile: gemfiles/active_model_5.2.gemfile
55
- rvm: 2.6.2
56
- - gemfile: gemfiles/active_model_6.0.gemfile
57
- rvm: 2.5.5
58
- - gemfile: gemfiles/active_model_6.0.gemfile
59
- rvm: 2.6.2
60
- - gemfile: gemfiles/active_model_edge.gemfile
61
- rvm: 2.6.2
62
- - gemfile: gemfiles/active_model_edge.gemfile
63
- rvm: 2.5.5
64
- allow_failures:
65
- - rvm: jruby
66
- - rvm: rbx-2
67
- - gemfile: gemfiles/active_model_edge.gemfile
68
- rvm: 2.5.5
69
- - gemfile: gemfiles/active_model_edge.gemfile
70
- rvm: 2.6.2
data/Appraisals DELETED
@@ -1,24 +0,0 @@
1
- # ActiveModel integrations
2
- appraise 'active_model_4.1' do
3
- gem 'activemodel', github: 'rails/rails', branch: '4-1-stable'
4
- end
5
-
6
- appraise 'active_model_4.2' do
7
- gem 'activemodel', github: 'rails/rails', branch: '4-2-stable'
8
- end
9
-
10
- appraise 'active_model_5.0' do
11
- gem 'activemodel', github: 'rails/rails', branch: '5-0-stable'
12
- end
13
-
14
- appraise 'active_model_5.1' do
15
- gem 'activemodel', github: 'rails/rails', branch: '5-1-stable'
16
- end
17
-
18
- appraise 'active_model_5.2' do
19
- gem 'activemodel', github: 'rails/rails', branch: '5-2-stable'
20
- end
21
-
22
- appraise 'active_model_edge' do
23
- gem 'activemodel', github: 'rails/rails', branch: 'master'
24
- end
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in state_machine2_activemodel.gemspec
4
- gemspec
5
-
6
- platforms :mri_20, :mri_21 do
7
- gem 'pry-byebug'
8
- end
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.test_files = FileList['test/*_test.rb']
6
- end
7
-
8
- desc 'Default: run all tests.'
9
- task default: :test
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", :github => "rails/rails", :branch => "4-1-stable"
6
-
7
- platforms :mri_20, :mri_21 do
8
- gem "pry-byebug"
9
- end
10
-
11
- gemspec :path => "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", :github => "rails/rails", :branch => "4-2-stable"
6
-
7
- platforms :mri_20, :mri_21 do
8
- gem "pry-byebug"
9
- end
10
-
11
- gemspec :path => "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", :github => "rails/rails", :branch => "5-0-stable"
6
-
7
- platforms :mri_20, :mri_21 do
8
- gem "pry-byebug"
9
- end
10
-
11
- gemspec :path => "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", github: "rails/rails", branch: "5-1-stable"
6
-
7
- platforms :mri_20, :mri_21 do
8
- gem "pry-byebug"
9
- end
10
-
11
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", github: "rails/rails", branch: "5-2-stable"
6
-
7
- platforms :mri_20, :mri_21 do
8
- gem "pry-byebug"
9
- end
10
-
11
- gemspec path: "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", github: "rails/rails", branch: "master"
6
-
7
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", :github => "rails/rails", :branch => "master"
6
-
7
- platforms :mri_20, :mri_21 do
8
- gem "pry-byebug"
9
- end
10
-
11
- gemspec :path => "../"
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'state_machines/integrations/active_model/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'state_machines-activemodel'
8
- spec.version = StateMachines::Integrations::ActiveModel::VERSION
9
- spec.authors = ['Abdelkader Boudih', 'Aaron Pfeifer']
10
- spec.email = %w(terminale@gmail.com aaron@pluginaweek.org)
11
- spec.summary = 'ActiveModel integration for State Machines'
12
- spec.description = 'Adds support for creating state machines for attributes on ActiveModel'
13
- spec.homepage = 'https://github.com/state-machines/state_machines-activemodel'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.test_files = spec.files.grep(/^test\//)
18
- spec.require_paths = ['lib']
19
- spec.required_ruby_version = '>= 2.0.0'
20
- spec.add_dependency 'state_machines', '>= 0.5.0'
21
- spec.add_dependency 'activemodel', '>= 4.1', '< 6.0'
22
-
23
- spec.add_development_dependency 'bundler', '>= 1.6'
24
- spec.add_development_dependency 'rake', '>= 10'
25
- spec.add_development_dependency 'appraisal', '>= 1'
26
- spec.add_development_dependency 'minitest', '~> 5.4'
27
- spec.add_development_dependency 'minitest-reporters'
28
- end
data/test/files/en.yml DELETED
@@ -1,5 +0,0 @@
1
- en:
2
- activemodel:
3
- errors:
4
- messages:
5
- invalid_transition: "cannot %{event}"
data/test/test_helper.rb DELETED
@@ -1,56 +0,0 @@
1
- begin
2
- require 'pry-byebug'
3
- rescue LoadError
4
- end
5
-
6
- require 'state_machines-activemodel'
7
- require 'minitest/autorun'
8
- require 'minitest/reporters'
9
- require 'active_support/all'
10
- Minitest::Reporters.use! [Minitest::Reporters::ProgressReporter.new]
11
- I18n.enforce_available_locales = true
12
-
13
- class BaseTestCase < MiniTest::Test
14
- protected
15
- # Creates a new ActiveModel model (and the associated table)
16
- def new_model(&block)
17
- # Simple ActiveModel superclass
18
- parent = Class.new do
19
- def self.model_attribute(name)
20
- define_method(name) { instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : nil }
21
- define_method("#{name}=") do |value|
22
- send("#{name}_will_change!") if self.class <= ActiveModel::Dirty && value != send(name)
23
- instance_variable_set("@#{name}", value)
24
- end
25
- end
26
-
27
- def self.create
28
- object = new
29
- object.save
30
- object
31
- end
32
-
33
- def initialize(attrs = {})
34
- attrs.each { |attr, value| send("#{attr}=", value) }
35
- end
36
-
37
- def attributes
38
- @attributes ||= {}
39
- end
40
-
41
- def save
42
- true
43
- end
44
- end
45
-
46
- model = Class.new(parent) do
47
- def self.name
48
- 'Foo'
49
- end
50
-
51
- model_attribute :state
52
- end
53
- model.class_eval(&block) if block_given?
54
- model
55
- end
56
- end