state_machines-activemodel 0.7.1 → 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: ae165c9fd876896da288bb4664d82fe5ccfcbffd2f3bff6978bac49c24b85d19
4
- data.tar.gz: 94a59b091f0391a67730f8375e64e7fa7c32d1bb8a76601df05c0e46669a46d6
3
+ metadata.gz: c8bb31a6d52d73caf948365731b8670f86a57814d839c4606cd12c88b178f48f
4
+ data.tar.gz: c3f2f12fc7077f4fb230b08908314684fbbe7c59153cd12cc35dbacd767dd386
5
5
  SHA512:
6
- metadata.gz: 4344a12a72ad87e797c2c47887455514323d5e769ae5aa118eb732b0e73d0cb89d86fdb6517b5a067fc9dd6195ad8b2a3f033862c656b0ffaf52459ee5d393d7
7
- data.tar.gz: 7b03795219c1d78945a07fd59ab2c96624d497d21bd8e6af02307300b425bdadf77bd582e5768449406952dd9af63c55c01df288efaf2f39db2c77510e274235
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,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/state-machines/state_machines-activemodel.svg?branch=master)](https://travis-ci.org/state-machines/state_machines-activemodel)
1
+ ![Build Status](https://github.com/state-machines/state_machines-activemodel/actions/workflows/ruby.yml/badge.svg)
2
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
@@ -23,7 +23,7 @@ Or install it yourself as:
23
23
 
24
24
  ## Dependencies
25
25
 
26
- Active Model 4.1+
26
+ Active Model 5.1+
27
27
 
28
28
  ## Usage
29
29
 
@@ -1,7 +1,7 @@
1
1
  module StateMachines
2
2
  module Integrations
3
3
  module ActiveModel
4
- VERSION = '0.7.1'
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.7.1
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-09-03 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,28 +17,28 @@ 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
33
  - !ruby/object:Gem::Version
34
- version: '4.1'
34
+ version: '6.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '4.1'
41
+ version: '6.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -117,26 +117,12 @@ executables: []
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
- - ".gitignore"
121
- - ".travis.yml"
122
- - Appraisals
123
- - Gemfile
124
120
  - LICENSE.txt
125
121
  - README.md
126
- - Rakefile
127
- - gemfiles/active_model_4.1.gemfile
128
- - gemfiles/active_model_4.2.gemfile
129
- - gemfiles/active_model_5.0.gemfile
130
- - gemfiles/active_model_5.1.gemfile
131
- - gemfiles/active_model_5.2.gemfile
132
- - gemfiles/active_model_6.0.gemfile
133
- - gemfiles/active_model_edge.gemfile
134
122
  - lib/state_machines-activemodel.rb
135
123
  - lib/state_machines/integrations/active_model.rb
136
124
  - lib/state_machines/integrations/active_model/locale.rb
137
125
  - lib/state_machines/integrations/active_model/version.rb
138
- - state_machines-activemodel.gemspec
139
- - test/files/en.yml
140
126
  - test/integration_test.rb
141
127
  - test/machine_by_default_test.rb
142
128
  - test/machine_errors_test.rb
@@ -151,6 +137,7 @@ files:
151
137
  - test/machine_with_events_test.rb
152
138
  - test/machine_with_failed_after_callbacks_test.rb
153
139
  - test/machine_with_failed_before_callbacks_test.rb
140
+ - test/machine_with_initialized_aliased_attribute_test.rb
154
141
  - test/machine_with_initialized_state_test.rb
155
142
  - test/machine_with_internationalization_test.rb
156
143
  - test/machine_with_model_state_attribute_test.rb
@@ -160,7 +147,6 @@ files:
160
147
  - test/machine_with_static_initial_state_test.rb
161
148
  - test/machine_with_validations_and_custom_attribute_test.rb
162
149
  - test/machine_with_validations_test.rb
163
- - test/test_helper.rb
164
150
  homepage: https://github.com/state-machines/state_machines-activemodel
165
151
  licenses:
166
152
  - MIT
@@ -173,19 +159,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
159
  requirements:
174
160
  - - ">="
175
161
  - !ruby/object:Gem::Version
176
- version: 2.0.0
162
+ version: 3.0.0
177
163
  required_rubygems_version: !ruby/object:Gem::Requirement
178
164
  requirements:
179
165
  - - ">="
180
166
  - !ruby/object:Gem::Version
181
167
  version: '0'
182
168
  requirements: []
183
- rubygems_version: 3.0.1
169
+ rubygems_version: 3.4.10
184
170
  signing_key:
185
171
  specification_version: 4
186
172
  summary: ActiveModel integration for State Machines
187
173
  test_files:
188
- - test/files/en.yml
189
174
  - test/integration_test.rb
190
175
  - test/machine_by_default_test.rb
191
176
  - test/machine_errors_test.rb
@@ -200,6 +185,7 @@ test_files:
200
185
  - test/machine_with_events_test.rb
201
186
  - test/machine_with_failed_after_callbacks_test.rb
202
187
  - test/machine_with_failed_before_callbacks_test.rb
188
+ - test/machine_with_initialized_aliased_attribute_test.rb
203
189
  - test/machine_with_initialized_state_test.rb
204
190
  - test/machine_with_internationalization_test.rb
205
191
  - test/machine_with_model_state_attribute_test.rb
@@ -209,4 +195,3 @@ test_files:
209
195
  - test/machine_with_static_initial_state_test.rb
210
196
  - test/machine_with_validations_and_custom_attribute_test.rb
211
197
  - test/machine_with_validations_test.rb
212
- - 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,69 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
-
4
- rvm:
5
- - 2.1
6
- - 2.2.9
7
- - 2.3.8
8
- - 2.4.6
9
- - 2.5.5
10
- - 2.6.3
11
- - jruby
12
- - rbx-2
13
-
14
- gemfile:
15
- - gemfiles/active_model_4.2.gemfile
16
-
17
- matrix:
18
- include:
19
- - gemfile: gemfiles/active_model_4.1.gemfile
20
- rvm: 2.1
21
- - gemfile: gemfiles/active_model_4.1.gemfile
22
- rvm: 2.2.9
23
- - gemfile: gemfiles/active_model_4.1.gemfile
24
- rvm: 2.3.8
25
- - gemfile: gemfiles/active_model_5.0.gemfile
26
- rvm: 2.2.9
27
- - gemfile: gemfiles/active_model_5.0.gemfile
28
- rvm: 2.3.8
29
- - gemfile: gemfiles/active_model_5.0.gemfile
30
- rvm: 2.4.6
31
- - gemfile: gemfiles/active_model_5.0.gemfile
32
- rvm: 2.5.5
33
- - gemfile: gemfiles/active_model_5.0.gemfile
34
- rvm: 2.6.3
35
- - gemfile: gemfiles/active_model_5.1.gemfile
36
- rvm: 2.2.9
37
- - gemfile: gemfiles/active_model_5.1.gemfile
38
- rvm: 2.3.8
39
- - gemfile: gemfiles/active_model_5.1.gemfile
40
- rvm: 2.4.6
41
- - gemfile: gemfiles/active_model_5.1.gemfile
42
- rvm: 2.5.5
43
- - gemfile: gemfiles/active_model_5.1.gemfile
44
- rvm: 2.6.3
45
- - gemfile: gemfiles/active_model_5.2.gemfile
46
- rvm: 2.2.9
47
- - gemfile: gemfiles/active_model_5.2.gemfile
48
- rvm: 2.3.8
49
- - gemfile: gemfiles/active_model_5.2.gemfile
50
- rvm: 2.4.6
51
- - gemfile: gemfiles/active_model_5.2.gemfile
52
- rvm: 2.5.5
53
- - gemfile: gemfiles/active_model_5.2.gemfile
54
- rvm: 2.6.3
55
- - gemfile: gemfiles/active_model_6.0.gemfile
56
- rvm: 2.5.5
57
- - gemfile: gemfiles/active_model_6.0.gemfile
58
- rvm: 2.6.3
59
- - gemfile: gemfiles/active_model_edge.gemfile
60
- rvm: 2.6.3
61
- - gemfile: gemfiles/active_model_edge.gemfile
62
- rvm: 2.5.5
63
- allow_failures:
64
- - rvm: jruby
65
- - rvm: rbx-2
66
- - gemfile: gemfiles/active_model_edge.gemfile
67
- rvm: 2.5.5
68
- - gemfile: gemfiles/active_model_edge.gemfile
69
- rvm: 2.6.3
data/Appraisals DELETED
@@ -1,28 +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_6.0' do
23
- gem 'activemodel', github: 'rails/rails', branch: '6-0-stable'
24
- end
25
-
26
- appraise 'active_model_edge' do
27
- gem 'activemodel', github: 'rails/rails', branch: 'master'
28
- 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'
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