stator 0.3.4 → 0.5.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 +4 -4
- data/.github/workflows/build.yml +22 -0
- data/.ruby-version +1 -1
- data/Appraisals +19 -0
- data/Gemfile +3 -3
- data/gemfiles/activerecord_5.1.gemfile +11 -0
- data/gemfiles/activerecord_5.1.gemfile.lock +64 -0
- data/gemfiles/activerecord_5.2.gemfile +11 -0
- data/gemfiles/activerecord_5.2.gemfile.lock +64 -0
- data/gemfiles/activerecord_6.0.gemfile +11 -0
- data/gemfiles/activerecord_6.0.gemfile.lock +64 -0
- data/gemfiles/activerecord_6.1.gemfile +11 -0
- data/gemfiles/activerecord_6.1.gemfile.lock +63 -0
- data/gemfiles/activerecord_7.0.gemfile +11 -0
- data/gemfiles/activerecord_7.0.gemfile.lock +61 -0
- data/lib/stator/integration.rb +5 -5
- data/lib/stator/machine.rb +1 -1
- data/lib/stator/version.rb +2 -2
- data/spec/model_spec.rb +42 -7
- data/spec/support/models.rb +13 -0
- data/stator.gemspec +1 -0
- metadata +15 -8
- data/.travis.yml +0 -41
- data/gemfiles/ar40.gemfile +0 -10
- data/gemfiles/ar41.gemfile +0 -10
- data/gemfiles/ar42.gemfile +0 -10
- data/gemfiles/ar52.gemfile +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ed80bf93083d69f85339e493f1e2512344590bb769481bf35ae56a2d84697805
|
|
4
|
+
data.tar.gz: fb06422dde19bcd74c2cf9c3dfb2f9dfa506ca922c3a923919d96490eadacc0f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 129800a5b02be2a8b2ac2fdc4d038cf7b51f147ad5090731e6de2a272312d01abe58569d462ddf2b51ebc397c3af5fe903ff1aa84588e234a8088a2694b9296d
|
|
7
|
+
data.tar.gz: 9d36dfc17db1d95e72843c18f4ee7f6392ebfbf3c5bcc3950e2bdd091808a9df2e646e1d5ee6d3532bcbf40772958eef8af2c4cd6e7ae0c1baab8982ee246818
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: build
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
ruby-version: [2.7.5]
|
|
14
|
+
experimental: [false]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v2
|
|
17
|
+
- uses: ruby/setup-ruby@v1
|
|
18
|
+
with:
|
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
20
|
+
bundler-cache: true # runs `bundle install` and caches installed gems automatically
|
|
21
|
+
- run: bundle exec appraisal install
|
|
22
|
+
- run: bundle exec appraisal rspec
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.5
|
|
1
|
+
2.7.5
|
data/Appraisals
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
appraise "activerecord-5.1" do
|
|
2
|
+
gem "activerecord", "~> 5.1.0"
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
appraise "activerecord-5.2" do
|
|
6
|
+
gem "activerecord", "~> 5.2.0"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
appraise "activerecord-6.0" do
|
|
10
|
+
gem "activerecord", "~> 6.0.0"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
appraise "activerecord-6.1" do
|
|
14
|
+
gem "activerecord", "~> 6.1.0"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
appraise "activerecord-7.0" do
|
|
18
|
+
gem "activerecord", "~> 7.0.0"
|
|
19
|
+
end
|
data/Gemfile
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
gem 'activerecord', '5.2.3'
|
|
3
|
+
gem 'activerecord', '~> 5.2.8'
|
|
5
4
|
|
|
6
5
|
gemspec
|
|
7
6
|
|
|
8
|
-
gem '
|
|
7
|
+
gem 'appraisal'
|
|
8
|
+
gem 'activerecord-nulldb-adapter'
|
|
9
9
|
gem 'rake'
|
|
10
10
|
gem 'rspec'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
stator (0.5.0)
|
|
5
|
+
activerecord
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (5.1.7)
|
|
11
|
+
activesupport (= 5.1.7)
|
|
12
|
+
activerecord (5.1.7)
|
|
13
|
+
activemodel (= 5.1.7)
|
|
14
|
+
activesupport (= 5.1.7)
|
|
15
|
+
arel (~> 8.0)
|
|
16
|
+
activerecord-nulldb-adapter (0.4.0)
|
|
17
|
+
activerecord (>= 2.0.0)
|
|
18
|
+
activesupport (5.1.7)
|
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
20
|
+
i18n (>= 0.7, < 2)
|
|
21
|
+
minitest (~> 5.1)
|
|
22
|
+
tzinfo (~> 1.1)
|
|
23
|
+
appraisal (2.4.1)
|
|
24
|
+
bundler
|
|
25
|
+
rake
|
|
26
|
+
thor (>= 0.14.0)
|
|
27
|
+
arel (8.0.0)
|
|
28
|
+
concurrent-ruby (1.1.10)
|
|
29
|
+
diff-lcs (1.5.0)
|
|
30
|
+
i18n (1.12.0)
|
|
31
|
+
concurrent-ruby (~> 1.0)
|
|
32
|
+
minitest (5.16.2)
|
|
33
|
+
rake (13.0.6)
|
|
34
|
+
rspec (3.11.0)
|
|
35
|
+
rspec-core (~> 3.11.0)
|
|
36
|
+
rspec-expectations (~> 3.11.0)
|
|
37
|
+
rspec-mocks (~> 3.11.0)
|
|
38
|
+
rspec-core (3.11.0)
|
|
39
|
+
rspec-support (~> 3.11.0)
|
|
40
|
+
rspec-expectations (3.11.0)
|
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
42
|
+
rspec-support (~> 3.11.0)
|
|
43
|
+
rspec-mocks (3.11.1)
|
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
45
|
+
rspec-support (~> 3.11.0)
|
|
46
|
+
rspec-support (3.11.0)
|
|
47
|
+
thor (1.2.1)
|
|
48
|
+
thread_safe (0.3.6)
|
|
49
|
+
tzinfo (1.2.10)
|
|
50
|
+
thread_safe (~> 0.1)
|
|
51
|
+
|
|
52
|
+
PLATFORMS
|
|
53
|
+
ruby
|
|
54
|
+
|
|
55
|
+
DEPENDENCIES
|
|
56
|
+
activerecord (~> 5.1.0)
|
|
57
|
+
activerecord-nulldb-adapter
|
|
58
|
+
appraisal
|
|
59
|
+
rake
|
|
60
|
+
rspec
|
|
61
|
+
stator!
|
|
62
|
+
|
|
63
|
+
BUNDLED WITH
|
|
64
|
+
2.3.25
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
stator (0.5.0)
|
|
5
|
+
activerecord
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (5.2.8.1)
|
|
11
|
+
activesupport (= 5.2.8.1)
|
|
12
|
+
activerecord (5.2.8.1)
|
|
13
|
+
activemodel (= 5.2.8.1)
|
|
14
|
+
activesupport (= 5.2.8.1)
|
|
15
|
+
arel (>= 9.0)
|
|
16
|
+
activerecord-nulldb-adapter (0.8.0)
|
|
17
|
+
activerecord (>= 5.2.0, < 7.1)
|
|
18
|
+
activesupport (5.2.8.1)
|
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
20
|
+
i18n (>= 0.7, < 2)
|
|
21
|
+
minitest (~> 5.1)
|
|
22
|
+
tzinfo (~> 1.1)
|
|
23
|
+
appraisal (2.4.1)
|
|
24
|
+
bundler
|
|
25
|
+
rake
|
|
26
|
+
thor (>= 0.14.0)
|
|
27
|
+
arel (9.0.0)
|
|
28
|
+
concurrent-ruby (1.1.10)
|
|
29
|
+
diff-lcs (1.5.0)
|
|
30
|
+
i18n (1.12.0)
|
|
31
|
+
concurrent-ruby (~> 1.0)
|
|
32
|
+
minitest (5.16.2)
|
|
33
|
+
rake (13.0.6)
|
|
34
|
+
rspec (3.11.0)
|
|
35
|
+
rspec-core (~> 3.11.0)
|
|
36
|
+
rspec-expectations (~> 3.11.0)
|
|
37
|
+
rspec-mocks (~> 3.11.0)
|
|
38
|
+
rspec-core (3.11.0)
|
|
39
|
+
rspec-support (~> 3.11.0)
|
|
40
|
+
rspec-expectations (3.11.0)
|
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
42
|
+
rspec-support (~> 3.11.0)
|
|
43
|
+
rspec-mocks (3.11.1)
|
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
45
|
+
rspec-support (~> 3.11.0)
|
|
46
|
+
rspec-support (3.11.0)
|
|
47
|
+
thor (1.2.1)
|
|
48
|
+
thread_safe (0.3.6)
|
|
49
|
+
tzinfo (1.2.10)
|
|
50
|
+
thread_safe (~> 0.1)
|
|
51
|
+
|
|
52
|
+
PLATFORMS
|
|
53
|
+
ruby
|
|
54
|
+
|
|
55
|
+
DEPENDENCIES
|
|
56
|
+
activerecord (~> 5.2.0)
|
|
57
|
+
activerecord-nulldb-adapter
|
|
58
|
+
appraisal
|
|
59
|
+
rake
|
|
60
|
+
rspec
|
|
61
|
+
stator!
|
|
62
|
+
|
|
63
|
+
BUNDLED WITH
|
|
64
|
+
2.3.25
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
stator (0.5.0)
|
|
5
|
+
activerecord
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (6.0.5.1)
|
|
11
|
+
activesupport (= 6.0.5.1)
|
|
12
|
+
activerecord (6.0.5.1)
|
|
13
|
+
activemodel (= 6.0.5.1)
|
|
14
|
+
activesupport (= 6.0.5.1)
|
|
15
|
+
activerecord-nulldb-adapter (0.8.0)
|
|
16
|
+
activerecord (>= 5.2.0, < 7.1)
|
|
17
|
+
activesupport (6.0.5.1)
|
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
|
+
i18n (>= 0.7, < 2)
|
|
20
|
+
minitest (~> 5.1)
|
|
21
|
+
tzinfo (~> 1.1)
|
|
22
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
23
|
+
appraisal (2.4.1)
|
|
24
|
+
bundler
|
|
25
|
+
rake
|
|
26
|
+
thor (>= 0.14.0)
|
|
27
|
+
concurrent-ruby (1.1.10)
|
|
28
|
+
diff-lcs (1.5.0)
|
|
29
|
+
i18n (1.12.0)
|
|
30
|
+
concurrent-ruby (~> 1.0)
|
|
31
|
+
minitest (5.16.2)
|
|
32
|
+
rake (13.0.6)
|
|
33
|
+
rspec (3.11.0)
|
|
34
|
+
rspec-core (~> 3.11.0)
|
|
35
|
+
rspec-expectations (~> 3.11.0)
|
|
36
|
+
rspec-mocks (~> 3.11.0)
|
|
37
|
+
rspec-core (3.11.0)
|
|
38
|
+
rspec-support (~> 3.11.0)
|
|
39
|
+
rspec-expectations (3.11.0)
|
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
+
rspec-support (~> 3.11.0)
|
|
42
|
+
rspec-mocks (3.11.1)
|
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
|
+
rspec-support (~> 3.11.0)
|
|
45
|
+
rspec-support (3.11.0)
|
|
46
|
+
thor (1.2.1)
|
|
47
|
+
thread_safe (0.3.6)
|
|
48
|
+
tzinfo (1.2.10)
|
|
49
|
+
thread_safe (~> 0.1)
|
|
50
|
+
zeitwerk (2.6.0)
|
|
51
|
+
|
|
52
|
+
PLATFORMS
|
|
53
|
+
ruby
|
|
54
|
+
|
|
55
|
+
DEPENDENCIES
|
|
56
|
+
activerecord (~> 6.0.0)
|
|
57
|
+
activerecord-nulldb-adapter
|
|
58
|
+
appraisal
|
|
59
|
+
rake
|
|
60
|
+
rspec
|
|
61
|
+
stator!
|
|
62
|
+
|
|
63
|
+
BUNDLED WITH
|
|
64
|
+
2.3.25
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
stator (0.5.0)
|
|
5
|
+
activerecord
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (6.1.6.1)
|
|
11
|
+
activesupport (= 6.1.6.1)
|
|
12
|
+
activerecord (6.1.6.1)
|
|
13
|
+
activemodel (= 6.1.6.1)
|
|
14
|
+
activesupport (= 6.1.6.1)
|
|
15
|
+
activerecord-nulldb-adapter (0.8.0)
|
|
16
|
+
activerecord (>= 5.2.0, < 7.1)
|
|
17
|
+
activesupport (6.1.6.1)
|
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
|
+
i18n (>= 1.6, < 2)
|
|
20
|
+
minitest (>= 5.1)
|
|
21
|
+
tzinfo (~> 2.0)
|
|
22
|
+
zeitwerk (~> 2.3)
|
|
23
|
+
appraisal (2.4.1)
|
|
24
|
+
bundler
|
|
25
|
+
rake
|
|
26
|
+
thor (>= 0.14.0)
|
|
27
|
+
concurrent-ruby (1.1.10)
|
|
28
|
+
diff-lcs (1.5.0)
|
|
29
|
+
i18n (1.12.0)
|
|
30
|
+
concurrent-ruby (~> 1.0)
|
|
31
|
+
minitest (5.16.2)
|
|
32
|
+
rake (13.0.6)
|
|
33
|
+
rspec (3.11.0)
|
|
34
|
+
rspec-core (~> 3.11.0)
|
|
35
|
+
rspec-expectations (~> 3.11.0)
|
|
36
|
+
rspec-mocks (~> 3.11.0)
|
|
37
|
+
rspec-core (3.11.0)
|
|
38
|
+
rspec-support (~> 3.11.0)
|
|
39
|
+
rspec-expectations (3.11.0)
|
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
+
rspec-support (~> 3.11.0)
|
|
42
|
+
rspec-mocks (3.11.1)
|
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
|
+
rspec-support (~> 3.11.0)
|
|
45
|
+
rspec-support (3.11.0)
|
|
46
|
+
thor (1.2.1)
|
|
47
|
+
tzinfo (2.0.5)
|
|
48
|
+
concurrent-ruby (~> 1.0)
|
|
49
|
+
zeitwerk (2.6.0)
|
|
50
|
+
|
|
51
|
+
PLATFORMS
|
|
52
|
+
ruby
|
|
53
|
+
|
|
54
|
+
DEPENDENCIES
|
|
55
|
+
activerecord (~> 6.1.0)
|
|
56
|
+
activerecord-nulldb-adapter
|
|
57
|
+
appraisal
|
|
58
|
+
rake
|
|
59
|
+
rspec
|
|
60
|
+
stator!
|
|
61
|
+
|
|
62
|
+
BUNDLED WITH
|
|
63
|
+
2.3.25
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
stator (0.5.0)
|
|
5
|
+
activerecord
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (7.0.3.1)
|
|
11
|
+
activesupport (= 7.0.3.1)
|
|
12
|
+
activerecord (7.0.3.1)
|
|
13
|
+
activemodel (= 7.0.3.1)
|
|
14
|
+
activesupport (= 7.0.3.1)
|
|
15
|
+
activerecord-nulldb-adapter (0.8.0)
|
|
16
|
+
activerecord (>= 5.2.0, < 7.1)
|
|
17
|
+
activesupport (7.0.3.1)
|
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
|
+
i18n (>= 1.6, < 2)
|
|
20
|
+
minitest (>= 5.1)
|
|
21
|
+
tzinfo (~> 2.0)
|
|
22
|
+
appraisal (2.4.1)
|
|
23
|
+
bundler
|
|
24
|
+
rake
|
|
25
|
+
thor (>= 0.14.0)
|
|
26
|
+
concurrent-ruby (1.1.10)
|
|
27
|
+
diff-lcs (1.5.0)
|
|
28
|
+
i18n (1.12.0)
|
|
29
|
+
concurrent-ruby (~> 1.0)
|
|
30
|
+
minitest (5.16.2)
|
|
31
|
+
rake (13.0.6)
|
|
32
|
+
rspec (3.11.0)
|
|
33
|
+
rspec-core (~> 3.11.0)
|
|
34
|
+
rspec-expectations (~> 3.11.0)
|
|
35
|
+
rspec-mocks (~> 3.11.0)
|
|
36
|
+
rspec-core (3.11.0)
|
|
37
|
+
rspec-support (~> 3.11.0)
|
|
38
|
+
rspec-expectations (3.11.0)
|
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
+
rspec-support (~> 3.11.0)
|
|
41
|
+
rspec-mocks (3.11.1)
|
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
+
rspec-support (~> 3.11.0)
|
|
44
|
+
rspec-support (3.11.0)
|
|
45
|
+
thor (1.2.1)
|
|
46
|
+
tzinfo (2.0.5)
|
|
47
|
+
concurrent-ruby (~> 1.0)
|
|
48
|
+
|
|
49
|
+
PLATFORMS
|
|
50
|
+
ruby
|
|
51
|
+
|
|
52
|
+
DEPENDENCIES
|
|
53
|
+
activerecord (~> 7.0.0)
|
|
54
|
+
activerecord-nulldb-adapter
|
|
55
|
+
appraisal
|
|
56
|
+
rake
|
|
57
|
+
rspec
|
|
58
|
+
stator!
|
|
59
|
+
|
|
60
|
+
BUNDLED WITH
|
|
61
|
+
2.3.25
|
data/lib/stator/integration.rb
CHANGED
|
@@ -25,9 +25,9 @@ module Stator
|
|
|
25
25
|
|
|
26
26
|
def state_was(use_previous = false)
|
|
27
27
|
if use_previous
|
|
28
|
-
@record.
|
|
28
|
+
@record.attribute_before_last_save(@machine.field)
|
|
29
29
|
else
|
|
30
|
-
@record.
|
|
30
|
+
@record.attribute_in_database(@machine.field)
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -41,9 +41,9 @@ module Stator
|
|
|
41
41
|
|
|
42
42
|
def state_changed?(use_previous = false)
|
|
43
43
|
if use_previous
|
|
44
|
-
|
|
44
|
+
@record.saved_change_to_attribute?(@machine.field)
|
|
45
45
|
else
|
|
46
|
-
@record.
|
|
46
|
+
@record.will_save_change_to_attribute?(@machine.field)
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -158,7 +158,7 @@ module Stator
|
|
|
158
158
|
return unless @record.respond_to?(field_name)
|
|
159
159
|
return unless @record.respond_to?("#{field_name}=")
|
|
160
160
|
return unless @record.send(field_name.to_s).nil? || state_changed?
|
|
161
|
-
return if @record.
|
|
161
|
+
return if @record.will_save_change_to_attribute?(field_name)
|
|
162
162
|
|
|
163
163
|
@record.send("#{field_name}=", (Time.zone || Time).now)
|
|
164
164
|
end
|
data/lib/stator/machine.rb
CHANGED
|
@@ -118,7 +118,7 @@ module Stator
|
|
|
118
118
|
integration.state == #{state.to_s.inspect}
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
def #{method_name}
|
|
121
|
+
def #{method_name}_state_by?(time)
|
|
122
122
|
integration = self._stator(#{@namespace.inspect}).integration(self)
|
|
123
123
|
integration.state_by?(#{state.to_s.inspect}, time)
|
|
124
124
|
end
|
data/lib/stator/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
|
@@ -11,7 +11,7 @@ describe Stator::Model do
|
|
|
11
11
|
it "should see the initial setting of the state as a change with the initial state as the previous value" do
|
|
12
12
|
u = User.new
|
|
13
13
|
u.state = "activated"
|
|
14
|
-
u.
|
|
14
|
+
u.state_in_database.should eql("pending")
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should not obstruct normal validations" do
|
|
@@ -35,6 +35,26 @@ describe Stator::Model do
|
|
|
35
35
|
u.should be_valid
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
it "should work normally with active_record dirty methods" do
|
|
39
|
+
u = User.new(email: "doug@example.com")
|
|
40
|
+
|
|
41
|
+
u.will_save_change_to_state?.should_not be true
|
|
42
|
+
u.state_in_database.should eq("pending")
|
|
43
|
+
u.state_before_last_save.should be nil
|
|
44
|
+
|
|
45
|
+
u.state = "hyperactivated"
|
|
46
|
+
|
|
47
|
+
u.will_save_change_to_state?.should be true
|
|
48
|
+
u.state_in_database.should eq("pending")
|
|
49
|
+
u.state_before_last_save.should be nil
|
|
50
|
+
|
|
51
|
+
u.save!
|
|
52
|
+
|
|
53
|
+
u.will_save_change_to_state?.should_not be true
|
|
54
|
+
u.state_in_database.should eq("hyperactivated")
|
|
55
|
+
u.state_before_last_save.should eq("pending")
|
|
56
|
+
end
|
|
57
|
+
|
|
38
58
|
it "should ensure a valid state transition when given an illegal state based on the current state" do
|
|
39
59
|
u = User.new
|
|
40
60
|
|
|
@@ -77,6 +97,21 @@ describe Stator::Model do
|
|
|
77
97
|
u.should be_persisted
|
|
78
98
|
end
|
|
79
99
|
|
|
100
|
+
it "should conditionally invoke after_save callbacks when use_previous is true" do
|
|
101
|
+
u = User.new
|
|
102
|
+
u.email = "doug@example.com"
|
|
103
|
+
|
|
104
|
+
u.semiactivate!
|
|
105
|
+
|
|
106
|
+
u.state.should eql("semiactivated")
|
|
107
|
+
u.activation_notification_published.should_not be true
|
|
108
|
+
|
|
109
|
+
u.activate!
|
|
110
|
+
|
|
111
|
+
u.state.should eql("activated")
|
|
112
|
+
u.activation_notification_published.should be true
|
|
113
|
+
end
|
|
114
|
+
|
|
80
115
|
it "should blow up if the record is invalid and a bang method is used" do
|
|
81
116
|
u = User.new(email: "doug@other.com", name: "doug")
|
|
82
117
|
lambda {
|
|
@@ -311,40 +346,40 @@ describe Stator::Model do
|
|
|
311
346
|
t = Time.now
|
|
312
347
|
u = User.create!( email: "doug@example.com", activated_state_at: t)
|
|
313
348
|
u.state_by?(:activated, Time.at(t.to_i + 1)).should be true
|
|
314
|
-
u.
|
|
349
|
+
u.activated_state_by?(Time.at(t.to_i + 1)).should be true
|
|
315
350
|
end
|
|
316
351
|
|
|
317
352
|
it "should be true when the transition is at the same time" do
|
|
318
353
|
t = Time.now
|
|
319
354
|
u = User.create!( email: "doug@example.com", activated_state_at: t)
|
|
320
355
|
u.state_by?(:activated, t).should be true
|
|
321
|
-
u.
|
|
356
|
+
u.activated_state_by?(t).should be true
|
|
322
357
|
end
|
|
323
358
|
|
|
324
359
|
it "should be false when the transition is later" do
|
|
325
360
|
t = Time.now
|
|
326
361
|
u = User.create!( email: "doug@example.com", activated_state_at: t)
|
|
327
362
|
u.state_by?(:activated, Time.at(t.to_i - 1)).should be false
|
|
328
|
-
u.
|
|
363
|
+
u.activated_state_by?(Time.at(t.to_i - 1)).should be false
|
|
329
364
|
end
|
|
330
365
|
|
|
331
366
|
it "should be false when the transition is nil" do
|
|
332
367
|
t = Time.now
|
|
333
368
|
u = User.create!( email: "doug@example.com", activated_state_at: nil)
|
|
334
369
|
u.state_by?(:activated, t).should be false
|
|
335
|
-
u.
|
|
370
|
+
u.activated_state_by?(t).should be false
|
|
336
371
|
end
|
|
337
372
|
|
|
338
373
|
it "should be true when the transition is not nil and the time is nil" do
|
|
339
374
|
u = User.create!( email: "doug@example.com", activated_state_at: Time.now)
|
|
340
375
|
u.state_by?(:activated, nil).should be true
|
|
341
|
-
u.
|
|
376
|
+
u.activated_state_by?(nil).should be true
|
|
342
377
|
end
|
|
343
378
|
|
|
344
379
|
it "should be false when both are nil" do
|
|
345
380
|
u = User.create!(email: "doug@example.com", activated_state_at: nil)
|
|
346
381
|
u.state_by?(:activated, nil).should be false
|
|
347
|
-
u.
|
|
382
|
+
u.activated_state_by?(nil).should be false
|
|
348
383
|
end
|
|
349
384
|
end
|
|
350
385
|
end
|
data/spec/support/models.rb
CHANGED
|
@@ -3,11 +3,17 @@ class User < ActiveRecord::Base
|
|
|
3
3
|
|
|
4
4
|
before_save :set_tagged_at
|
|
5
5
|
|
|
6
|
+
attr_reader :activation_notification_published
|
|
7
|
+
|
|
6
8
|
stator track: true, initial: :pending do
|
|
7
9
|
|
|
8
10
|
transition :activate do
|
|
9
11
|
from :pending, :semiactivated
|
|
10
12
|
to :activated
|
|
13
|
+
|
|
14
|
+
conditional(use_previous: true) do |condition|
|
|
15
|
+
after_save :publish_activation_notification, :if => condition
|
|
16
|
+
end
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
transition :deactivate do
|
|
@@ -88,6 +94,13 @@ class User < ActiveRecord::Base
|
|
|
88
94
|
def set_tagged_at
|
|
89
95
|
self.tagged_at = self.semiactivated_state_at
|
|
90
96
|
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def publish_activation_notification
|
|
101
|
+
@activation_notification_published = true
|
|
102
|
+
end
|
|
103
|
+
|
|
91
104
|
end
|
|
92
105
|
|
|
93
106
|
class Animal < ActiveRecord::Base
|
data/stator.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Nelson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -32,19 +32,26 @@ executables: []
|
|
|
32
32
|
extensions: []
|
|
33
33
|
extra_rdoc_files: []
|
|
34
34
|
files:
|
|
35
|
+
- ".github/workflows/build.yml"
|
|
35
36
|
- ".gitignore"
|
|
36
37
|
- ".rspec"
|
|
37
38
|
- ".ruby-gemset"
|
|
38
39
|
- ".ruby-version"
|
|
39
|
-
-
|
|
40
|
+
- Appraisals
|
|
40
41
|
- Gemfile
|
|
41
42
|
- LICENSE.txt
|
|
42
43
|
- README.md
|
|
43
44
|
- Rakefile
|
|
44
|
-
- gemfiles/
|
|
45
|
-
- gemfiles/
|
|
46
|
-
- gemfiles/
|
|
47
|
-
- gemfiles/
|
|
45
|
+
- gemfiles/activerecord_5.1.gemfile
|
|
46
|
+
- gemfiles/activerecord_5.1.gemfile.lock
|
|
47
|
+
- gemfiles/activerecord_5.2.gemfile
|
|
48
|
+
- gemfiles/activerecord_5.2.gemfile.lock
|
|
49
|
+
- gemfiles/activerecord_6.0.gemfile
|
|
50
|
+
- gemfiles/activerecord_6.0.gemfile.lock
|
|
51
|
+
- gemfiles/activerecord_6.1.gemfile
|
|
52
|
+
- gemfiles/activerecord_6.1.gemfile.lock
|
|
53
|
+
- gemfiles/activerecord_7.0.gemfile
|
|
54
|
+
- gemfiles/activerecord_7.0.gemfile.lock
|
|
48
55
|
- lib/stator.rb
|
|
49
56
|
- lib/stator/alias.rb
|
|
50
57
|
- lib/stator/integration.rb
|
|
@@ -75,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
75
82
|
- !ruby/object:Gem::Version
|
|
76
83
|
version: '0'
|
|
77
84
|
requirements: []
|
|
78
|
-
rubygems_version: 3.
|
|
85
|
+
rubygems_version: 3.3.23
|
|
79
86
|
signing_key:
|
|
80
87
|
specification_version: 4
|
|
81
88
|
summary: The simplest of ActiveRecord state machines
|
data/.travis.yml
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
|
|
3
|
-
rvm:
|
|
4
|
-
- 2.0.0
|
|
5
|
-
- 2.1.6
|
|
6
|
-
- 2.2.3
|
|
7
|
-
- 2.4.5
|
|
8
|
-
- 2.5.3
|
|
9
|
-
|
|
10
|
-
gemfile:
|
|
11
|
-
- gemfiles/ar40.gemfile
|
|
12
|
-
- gemfiles/ar41.gemfile
|
|
13
|
-
- gemfiles/ar42.gemfile
|
|
14
|
-
- gemfiles/ar52.gemfile
|
|
15
|
-
|
|
16
|
-
matrix:
|
|
17
|
-
allow_failures:
|
|
18
|
-
- gemfile: gemfiles/ar42.gemfile
|
|
19
|
-
- gemfile: gemfiles/ar52.gemfile
|
|
20
|
-
|
|
21
|
-
exclude:
|
|
22
|
-
- rvm: 2.0.0
|
|
23
|
-
gemfile: gemfiles/ar52.gemfile
|
|
24
|
-
|
|
25
|
-
- rvm: 2.1.6
|
|
26
|
-
gemfile: gemfiles/ar52.gemfile
|
|
27
|
-
|
|
28
|
-
- rvm: 2.2.3
|
|
29
|
-
gemfile: gemfiles/ar52.gemfile
|
|
30
|
-
|
|
31
|
-
- rvm: 2.4.5
|
|
32
|
-
gemfile: gemfiles/ar40.gemfile
|
|
33
|
-
|
|
34
|
-
- rvm: 2.4.5
|
|
35
|
-
gemfile: gemfiles/ar41.gemfile
|
|
36
|
-
|
|
37
|
-
- rvm: 2.5.3
|
|
38
|
-
gemfile: gemfiles/ar40.gemfile
|
|
39
|
-
|
|
40
|
-
- rvm: 2.5.3
|
|
41
|
-
gemfile: gemfiles/ar41.gemfile
|
data/gemfiles/ar40.gemfile
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
|
4
|
-
gem 'activerecord', '~> 4.0.0'
|
|
5
|
-
|
|
6
|
-
gemspec :path => '../'
|
|
7
|
-
|
|
8
|
-
gem 'rake'
|
|
9
|
-
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
|
10
|
-
gem 'rspec'
|
data/gemfiles/ar41.gemfile
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
|
4
|
-
gem 'activerecord', '~> 4.1.0'
|
|
5
|
-
|
|
6
|
-
gemspec :path => '../'
|
|
7
|
-
|
|
8
|
-
gem 'rake'
|
|
9
|
-
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
|
10
|
-
gem 'rspec'
|
data/gemfiles/ar42.gemfile
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
|
4
|
-
gem 'activerecord', '~> 4.0.0'
|
|
5
|
-
|
|
6
|
-
gemspec :path => '../'
|
|
7
|
-
|
|
8
|
-
gem 'rake'
|
|
9
|
-
gem 'activerecord-nulldb-adapter', :require => false, :github => 'nulldb/nulldb', :ref => 'ffc7dae4697c6b9fb15bed9edca3acb1f00eb5f0'
|
|
10
|
-
gem 'rspec'
|
data/gemfiles/ar52.gemfile
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in stator.gemspec
|
|
4
|
-
gem 'activerecord', '~> 5.2.0'
|
|
5
|
-
|
|
6
|
-
gemspec :path => '../'
|
|
7
|
-
|
|
8
|
-
gem 'rake'
|
|
9
|
-
gem 'activerecord-nulldb-adapter', '~> 0.4.0', :require => false, :git => 'git@github.com:nulldb/nulldb.git'
|
|
10
|
-
gem 'rspec'
|