state_machines-activerecord 0.5.0 → 0.5.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 +5 -5
- data/.travis.yml +27 -14
- data/Appraisals +7 -0
- data/README.md +32 -0
- data/gemfiles/active_record_5.2.gemfile +14 -0
- data/lib/state_machines/integrations/active_record.rb +12 -4
- data/lib/state_machines/integrations/active_record/version.rb +1 -1
- data/state_machines-activerecord.gemspec +1 -1
- data/test/machine_with_same_integer_column_default_test.rb +30 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3b0f15bfdc4b116addd104136821751286e8f8452f5513141cd633560e6e004
|
4
|
+
data.tar.gz: 76a1a6abed537af626d8a312cb7e2cb382d1b360a04111179c3808dacc940cf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439cfcd6eadd8abbaf6dd7de97ec584bf582465f1f2ff0dce0988c2b6c73af81a664f185a0b46c38cf7a8184d1365836d07ed3bc04acd117a78fb6b3ac372540
|
7
|
+
data.tar.gz: f37e758e101e747a8e135eea316316271ef5881eb3bff6606e17ceaa3ddf05ad09dc23d96dda2fd3aa22d5ea6fca9be224b19a07e2e0331677b3b9e9208007f9
|
data/.travis.yml
CHANGED
@@ -4,9 +4,10 @@ cache: bundler
|
|
4
4
|
|
5
5
|
rvm:
|
6
6
|
- 2.1
|
7
|
-
- 2.2.
|
8
|
-
- 2.3.
|
9
|
-
- 2.4.
|
7
|
+
- 2.2.9
|
8
|
+
- 2.3.6
|
9
|
+
- 2.4.3
|
10
|
+
- 2.5.0
|
10
11
|
- jruby
|
11
12
|
- rbx-2
|
12
13
|
|
@@ -17,26 +18,38 @@ gemfile:
|
|
17
18
|
matrix:
|
18
19
|
include:
|
19
20
|
- gemfile: gemfiles/active_record_5.0.gemfile
|
20
|
-
rvm: 2.2.
|
21
|
+
rvm: 2.2.9
|
21
22
|
- gemfile: gemfiles/active_record_5.0.gemfile
|
22
|
-
rvm: 2.3.
|
23
|
+
rvm: 2.3.6
|
23
24
|
- gemfile: gemfiles/active_record_5.0.gemfile
|
24
|
-
rvm: 2.4.
|
25
|
+
rvm: 2.4.3
|
26
|
+
- gemfile: gemfiles/active_record_5.0.gemfile
|
27
|
+
rvm: 2.5.0
|
25
28
|
- gemfile: gemfiles/active_record_5.1.gemfile
|
26
|
-
rvm: 2.2.
|
29
|
+
rvm: 2.2.9
|
27
30
|
- gemfile: gemfiles/active_record_5.1.gemfile
|
28
|
-
rvm: 2.3.
|
31
|
+
rvm: 2.3.6
|
29
32
|
- gemfile: gemfiles/active_record_5.1.gemfile
|
30
|
-
rvm: 2.4.
|
31
|
-
- gemfile: gemfiles/
|
32
|
-
rvm: 2.
|
33
|
+
rvm: 2.4.3
|
34
|
+
- gemfile: gemfiles/active_record_5.1.gemfile
|
35
|
+
rvm: 2.5.0
|
36
|
+
- gemfile: gemfiles/active_record_5.2.gemfile
|
37
|
+
rvm: 2.2.9
|
38
|
+
- gemfile: gemfiles/active_record_5.2.gemfile
|
39
|
+
rvm: 2.3.6
|
40
|
+
- gemfile: gemfiles/active_record_5.2.gemfile
|
41
|
+
rvm: 2.4.3
|
42
|
+
- gemfile: gemfiles/active_record_5.2.gemfile
|
43
|
+
rvm: 2.5.0
|
33
44
|
- gemfile: gemfiles/active_record_edge.gemfile
|
34
|
-
rvm: 2.3
|
45
|
+
rvm: 2.4.3
|
35
46
|
- gemfile: gemfiles/active_record_edge.gemfile
|
36
|
-
rvm: 2.
|
47
|
+
rvm: 2.5.0
|
37
48
|
exclude:
|
38
49
|
- gemfile: gemfiles/active_record_4.1.gemfile
|
39
|
-
rvm: 2.4.
|
50
|
+
rvm: 2.4.3
|
51
|
+
- gemfile: gemfiles/active_record_4.1.gemfile
|
52
|
+
rvm: 2.5.0
|
40
53
|
allow_failures:
|
41
54
|
- rvm: jruby
|
42
55
|
- rvm: rbx-2
|
data/Appraisals
CHANGED
@@ -24,6 +24,13 @@ appraise "active_record_5.1" do
|
|
24
24
|
gem "activemodel", github: 'rails/rails', branch: '5-1-stable'
|
25
25
|
end
|
26
26
|
|
27
|
+
appraise "active_record_5.2" do
|
28
|
+
gem "sqlite3", platforms: [:mri, :rbx]
|
29
|
+
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
|
30
|
+
gem "activerecord", github: 'rails/rails', branch: '5-2-stable'
|
31
|
+
gem "activemodel", github: 'rails/rails', branch: '5-2-stable'
|
32
|
+
end
|
33
|
+
|
27
34
|
appraise "active_record_edge" do
|
28
35
|
gem "sqlite3", platforms: [:mri, :rbx]
|
29
36
|
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
|
data/README.md
CHANGED
@@ -64,6 +64,38 @@ Vehicle.with_state(:parked) # also plural #with_states
|
|
64
64
|
Vehicle.without_states(:first_gear, :second_gear) # also singular #without_state
|
65
65
|
```
|
66
66
|
|
67
|
+
### State driven validations
|
68
|
+
|
69
|
+
As mentioned in `StateMachines::Machine#state`, you can define behaviors,
|
70
|
+
like validations, that only execute for certain states. One *important*
|
71
|
+
caveat here is that, due to a constraint in ActiveRecord's validation
|
72
|
+
framework, custom validators will not work as expected when defined to run
|
73
|
+
in multiple states. For example:
|
74
|
+
|
75
|
+
~~~
|
76
|
+
class Vehicle < ActiveRecord::Base
|
77
|
+
state_machine do
|
78
|
+
state :first_gear, :second_gear do
|
79
|
+
validate :speed_is_legal
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
~~~
|
84
|
+
|
85
|
+
In this case, the <tt>:speed_is_legal</tt> validation will only get run
|
86
|
+
for the <tt>:second_gear</tt> state. To avoid this, you can define your
|
87
|
+
custom validation like so:
|
88
|
+
|
89
|
+
~~~
|
90
|
+
class Vehicle < ActiveRecord::Base
|
91
|
+
state_machine do
|
92
|
+
state :first_gear, :second_gear do
|
93
|
+
validate {|vehicle| vehicle.speed_is_legal}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
~~~
|
98
|
+
|
67
99
|
## Contributing
|
68
100
|
|
69
101
|
1. Fork it ( https://github.com/state-machines/state_machines-activerecord/fork )
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "sqlite3", platforms: [:mri, :rbx]
|
6
|
+
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
|
7
|
+
gem "activerecord", github: "rails/rails", branch: "5-2-stable"
|
8
|
+
gem "activemodel", github: "rails/rails", branch: "5-2-stable"
|
9
|
+
|
10
|
+
platforms :mri_20, :mri_21 do
|
11
|
+
gem "pry-byebug"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -439,10 +439,18 @@ module StateMachines
|
|
439
439
|
end
|
440
440
|
|
441
441
|
# Gets the db default for the machine's attribute
|
442
|
-
|
443
|
-
|
444
|
-
if
|
445
|
-
|
442
|
+
if ::ActiveRecord.gem_version >= Gem::Version.new('4.2.0')
|
443
|
+
def owner_class_attribute_default
|
444
|
+
if owner_class.connected? && owner_class.table_exists?
|
445
|
+
owner_class.column_defaults[attribute.to_s]
|
446
|
+
end
|
447
|
+
end
|
448
|
+
else
|
449
|
+
def owner_class_attribute_default
|
450
|
+
if owner_class.connected? && owner_class.table_exists?
|
451
|
+
if column = owner_class.columns_hash[attribute.to_s]
|
452
|
+
column.default
|
453
|
+
end
|
446
454
|
end
|
447
455
|
end
|
448
456
|
end
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.add_dependency 'state_machines-activemodel', '>= 0.5.0'
|
21
|
-
spec.add_dependency 'activerecord' , '>= 4.1', '<
|
21
|
+
spec.add_dependency 'activerecord' , '>= 4.1', '< 6.0'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.3'
|
23
23
|
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
24
24
|
spec.add_development_dependency 'appraisal', '>= 1'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class MachineWithSameIntegerColumnDefaultTest < BaseTestCase
|
5
|
+
def setup
|
6
|
+
@original_stderr, $stderr = $stderr, StringIO.new
|
7
|
+
|
8
|
+
@model = new_model do
|
9
|
+
connection.add_column table_name, :status, :integer, :default => 1
|
10
|
+
end
|
11
|
+
@machine = StateMachines::Machine.new(@model, :status, :initial => :parked) do
|
12
|
+
state :parked, :value => 1
|
13
|
+
end
|
14
|
+
@record = @model.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_use_machine_default
|
18
|
+
assert_equal 1, @record.status
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_not_generate_a_warning
|
22
|
+
assert_no_match(/have defined a different default/, $stderr.string)
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
$stderr = @original_stderr
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_machines-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
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:
|
12
|
+
date: 2018-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: state_machines-activemodel
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: '4.1'
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
37
|
+
version: '6.0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '4.1'
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '6.0'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- gemfiles/active_record_4.2.gemfile
|
135
135
|
- gemfiles/active_record_5.0.gemfile
|
136
136
|
- gemfiles/active_record_5.1.gemfile
|
137
|
+
- gemfiles/active_record_5.2.gemfile
|
137
138
|
- gemfiles/active_record_edge.gemfile
|
138
139
|
- lib/state_machines-activerecord.rb
|
139
140
|
- lib/state_machines/integrations/active_record.rb
|
@@ -179,6 +180,7 @@ files:
|
|
179
180
|
- test/machine_with_loopback_test.rb
|
180
181
|
- test/machine_with_non_column_state_attribute_defined_test.rb
|
181
182
|
- test/machine_with_same_column_default_test.rb
|
183
|
+
- test/machine_with_same_integer_column_default_test.rb
|
182
184
|
- test/machine_with_scopes_and_joins_test.rb
|
183
185
|
- test/machine_with_scopes_and_owner_subclass_test.rb
|
184
186
|
- test/machine_with_scopes_test.rb
|
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
214
|
version: '0'
|
213
215
|
requirements: []
|
214
216
|
rubyforge_project:
|
215
|
-
rubygems_version: 2.
|
217
|
+
rubygems_version: 2.7.3
|
216
218
|
signing_key:
|
217
219
|
specification_version: 4
|
218
220
|
summary: State machines Active Record Integration
|
@@ -255,6 +257,7 @@ test_files:
|
|
255
257
|
- test/machine_with_loopback_test.rb
|
256
258
|
- test/machine_with_non_column_state_attribute_defined_test.rb
|
257
259
|
- test/machine_with_same_column_default_test.rb
|
260
|
+
- test/machine_with_same_integer_column_default_test.rb
|
258
261
|
- test/machine_with_scopes_and_joins_test.rb
|
259
262
|
- test/machine_with_scopes_and_owner_subclass_test.rb
|
260
263
|
- test/machine_with_scopes_test.rb
|