state_machines-activemodel 0.8.0 → 0.9.0

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
  SHA256:
3
- metadata.gz: 4451c4d642636e3d81d9bb608b8dd78cfbd01bf7340989959e12791ec2fd76e0
4
- data.tar.gz: a7c86d2041b2e8deefdc809831802b413f1e0a8f7fec7aa867fcd54685262f9d
3
+ metadata.gz: c8bb31a6d52d73caf948365731b8670f86a57814d839c4606cd12c88b178f48f
4
+ data.tar.gz: c3f2f12fc7077f4fb230b08908314684fbbe7c59153cd12cc35dbacd767dd386
5
5
  SHA512:
6
- metadata.gz: 2fff7546bfd98859e0a8c5e5eb6e97909a4b5d42a3ade4440c8c21bb7728d4257093532a7b63e140c8418682d0da410f657d8a78db48c1bd13cd5f90ef59ff90
7
- data.tar.gz: 12bdad22386d96dc415f2eea856c5ca1329cb1fd7f213613102b9cfc0cfcb7da550d1548f633771491cd92b8a8491b390952ec44fb62db7e4cfa1f7e395366cc
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-2021 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.com/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
@@ -1,7 +1,7 @@
1
1
  module StateMachines
2
2
  module Integrations
3
3
  module ActiveModel
4
- VERSION = '0.8.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
@@ -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,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines-activemodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  - Aaron Pfeifer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-31 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: '5.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: '5.1'
41
+ version: '6.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -117,24 +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_5.1.gemfile
128
- - gemfiles/active_model_5.2.gemfile
129
- - gemfiles/active_model_6.0.gemfile
130
- - gemfiles/active_model_6.1.gemfile
131
- - gemfiles/active_model_edge.gemfile
132
122
  - lib/state_machines-activemodel.rb
133
123
  - lib/state_machines/integrations/active_model.rb
134
124
  - lib/state_machines/integrations/active_model/locale.rb
135
125
  - lib/state_machines/integrations/active_model/version.rb
136
- - state_machines-activemodel.gemspec
137
- - test/files/en.yml
138
126
  - test/integration_test.rb
139
127
  - test/machine_by_default_test.rb
140
128
  - test/machine_errors_test.rb
@@ -149,6 +137,7 @@ files:
149
137
  - test/machine_with_events_test.rb
150
138
  - test/machine_with_failed_after_callbacks_test.rb
151
139
  - test/machine_with_failed_before_callbacks_test.rb
140
+ - test/machine_with_initialized_aliased_attribute_test.rb
152
141
  - test/machine_with_initialized_state_test.rb
153
142
  - test/machine_with_internationalization_test.rb
154
143
  - test/machine_with_model_state_attribute_test.rb
@@ -158,12 +147,11 @@ files:
158
147
  - test/machine_with_static_initial_state_test.rb
159
148
  - test/machine_with_validations_and_custom_attribute_test.rb
160
149
  - test/machine_with_validations_test.rb
161
- - test/test_helper.rb
162
150
  homepage: https://github.com/state-machines/state_machines-activemodel
163
151
  licenses:
164
152
  - MIT
165
153
  metadata: {}
166
- post_install_message:
154
+ post_install_message:
167
155
  rdoc_options: []
168
156
  require_paths:
169
157
  - lib
@@ -171,19 +159,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
159
  requirements:
172
160
  - - ">="
173
161
  - !ruby/object:Gem::Version
174
- version: 2.2.2
162
+ version: 3.0.0
175
163
  required_rubygems_version: !ruby/object:Gem::Requirement
176
164
  requirements:
177
165
  - - ">="
178
166
  - !ruby/object:Gem::Version
179
167
  version: '0'
180
168
  requirements: []
181
- rubygems_version: 3.0.3
182
- signing_key:
169
+ rubygems_version: 3.4.10
170
+ signing_key:
183
171
  specification_version: 4
184
172
  summary: ActiveModel integration for State Machines
185
173
  test_files:
186
- - test/files/en.yml
187
174
  - test/integration_test.rb
188
175
  - test/machine_by_default_test.rb
189
176
  - test/machine_errors_test.rb
@@ -198,6 +185,7 @@ test_files:
198
185
  - test/machine_with_events_test.rb
199
186
  - test/machine_with_failed_after_callbacks_test.rb
200
187
  - test/machine_with_failed_before_callbacks_test.rb
188
+ - test/machine_with_initialized_aliased_attribute_test.rb
201
189
  - test/machine_with_initialized_state_test.rb
202
190
  - test/machine_with_internationalization_test.rb
203
191
  - test/machine_with_model_state_attribute_test.rb
@@ -207,4 +195,3 @@ test_files:
207
195
  - test/machine_with_static_initial_state_test.rb
208
196
  - test/machine_with_validations_and_custom_attribute_test.rb
209
197
  - test/machine_with_validations_test.rb
210
- - 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,21 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
-
4
- rvm:
5
- - 2.5.8
6
- - 2.6.6
7
- - 2.7.2
8
- - jruby
9
- - rbx-2
10
-
11
- gemfile:
12
- - gemfiles/active_model_5.1.gemfile
13
- - gemfiles/active_model_5.2.gemfile
14
- - gemfiles/active_model_6.0.gemfile
15
- - gemfiles/active_model_6.1.gemfile
16
- - gemfiles/active_model_edge.gemfile
17
-
18
- matrix:
19
- allow_failures:
20
- - rvm: jruby
21
- - rvm: rbx-2
data/Appraisals DELETED
@@ -1,20 +0,0 @@
1
- # ActiveModel integrations
2
- appraise 'active_model_5.1' do
3
- gem 'activemodel', github: 'rails/rails', branch: '5-1-stable'
4
- end
5
-
6
- appraise 'active_model_5.2' do
7
- gem 'activemodel', github: 'rails/rails', branch: '5-2-stable'
8
- end
9
-
10
- appraise 'active_model_6.0' do
11
- gem 'activemodel', github: 'rails/rails', branch: '6-0-stable'
12
- end
13
-
14
- appraise 'active_model_6.1' do
15
- gem 'activemodel', github: 'rails/rails', branch: '6-1-stable'
16
- end
17
-
18
- appraise 'active_model_edge' do
19
- gem 'activemodel', github: 'rails/rails', branch: 'master'
20
- 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: "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,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", github: "rails/rails", branch: "6-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: "6-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: "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.2.2'
20
- spec.add_dependency 'state_machines', '>= 0.5.0'
21
- spec.add_dependency 'activemodel', '>= 5.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