state_machines-activemodel 0.0.2 → 0.0.3

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +14 -10
  4. data/Appraisals +4 -15
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +9 -6
  8. data/Rakefile +5 -6
  9. data/gemfiles/active_model_4.1.gemfile +5 -1
  10. data/gemfiles/active_model_4.2.gemfile +11 -0
  11. data/lib/state_machines/integrations/active_model.rb +105 -108
  12. data/lib/state_machines/integrations/active_model/locale.rb +8 -8
  13. data/lib/state_machines/integrations/{version.rb → active_model/version.rb} +1 -1
  14. data/state_machines-activemodel.gemspec +10 -9
  15. data/{spec/support → test/files}/en.yml +1 -1
  16. data/test/integration_test.rb +23 -0
  17. data/test/machine_by_default_test.rb +24 -0
  18. data/test/machine_errors_test.rb +19 -0
  19. data/test/machine_multiple_test.rb +18 -0
  20. data/test/machine_with_callbacks_test.rb +130 -0
  21. data/test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb +26 -0
  22. data/test/machine_with_dirty_attribute_and_state_events_test.rb +23 -0
  23. data/test/machine_with_dirty_attributes_and_custom_attribute_test.rb +34 -0
  24. data/test/machine_with_dirty_attributes_during_loopback_test.rb +49 -0
  25. data/test/machine_with_dirty_attributes_test.rb +33 -0
  26. data/test/machine_with_dynamic_initial_state_test.rb +14 -0
  27. data/test/machine_with_events_test.rb +13 -0
  28. data/test/machine_with_failed_after_callbacks_test.rb +31 -0
  29. data/test/machine_with_failed_before_callbacks_test.rb +32 -0
  30. data/test/machine_with_initialized_state_test.rb +35 -0
  31. data/test/machine_with_internationalization_test.rb +190 -0
  32. data/test/machine_with_model_state_attribute_test.rb +31 -0
  33. data/test/machine_with_non_model_state_attribute_undefined_test.rb +26 -0
  34. data/test/machine_with_state_driven_validations_test.rb +31 -0
  35. data/test/machine_with_states_test.rb +13 -0
  36. data/test/machine_with_static_initial_state_test.rb +13 -0
  37. data/test/machine_with_validations_and_custom_attribute_test.rb +22 -0
  38. data/test/machine_with_validations_test.rb +46 -0
  39. data/test/test_helper.rb +58 -0
  40. metadata +83 -36
  41. data/gemfiles/active_model_3.2.gemfile +0 -7
  42. data/gemfiles/active_model_3.2.gemfile.lock +0 -50
  43. data/gemfiles/active_model_4.0.gemfile +0 -7
  44. data/gemfiles/active_model_4.0.gemfile.lock +0 -56
  45. data/gemfiles/active_model_4.1.gemfile.lock +0 -57
  46. data/gemfiles/active_model_edge.gemfile +0 -7
  47. data/gemfiles/active_model_edge.gemfile.lock +0 -62
  48. data/spec/active_model_spec.rb +0 -801
  49. data/spec/integration_spec.rb +0 -26
  50. data/spec/spec_helper.rb +0 -8
  51. data/spec/support/helpers.rb +0 -48
  52. data/spec/support/migration_helpers.rb +0 -43
@@ -0,0 +1,46 @@
1
+ require_relative 'test_helper'
2
+
3
+ class MachineWithValidationsTest < BaseTestCase
4
+ def setup
5
+ @model = new_model { include ActiveModel::Validations }
6
+ @machine = StateMachines::Machine.new(@model, action: :save)
7
+ @machine.state :parked
8
+
9
+ @record = @model.new
10
+ end
11
+
12
+ def test_should_invalidate_using_errors
13
+ I18n.backend = I18n::Backend::Simple.new if Object.const_defined?(:I18n)
14
+ @record.state = 'parked'
15
+
16
+ @machine.invalidate(@record, :state, :invalid_transition, [[:event, 'park']])
17
+ assert_equal ['State cannot transition via "park"'], @record.errors.full_messages
18
+ end
19
+
20
+ def test_should_auto_prefix_custom_attributes_on_invalidation
21
+ @machine.invalidate(@record, :event, :invalid)
22
+
23
+ assert_equal ['State event is invalid'], @record.errors.full_messages
24
+ end
25
+
26
+ def test_should_clear_errors_on_reset
27
+ @record.state = 'parked'
28
+ @record.errors.add(:state, 'is invalid')
29
+
30
+ @machine.reset(@record)
31
+ assert_equal [], @record.errors.full_messages
32
+ end
33
+
34
+ def test_should_be_valid_if_state_is_known
35
+ @record.state = 'parked'
36
+
37
+ assert @record.valid?
38
+ end
39
+
40
+ def test_should_not_be_valid_if_state_is_unknown
41
+ @record.state = 'invalid'
42
+
43
+ assert !@record.valid?
44
+ assert_equal ['State is invalid'], @record.errors.full_messages
45
+ end
46
+ end
@@ -0,0 +1,58 @@
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
+ @changed_attributes = {}
36
+ end
37
+
38
+ def attributes
39
+ @attributes ||= {}
40
+ end
41
+
42
+ def save
43
+ @changed_attributes = {}
44
+ true
45
+ end
46
+ end
47
+
48
+ model = Class.new(parent) do
49
+ def self.name
50
+ 'Foo'
51
+ end
52
+
53
+ model_attribute :state
54
+ end
55
+ model.class_eval(&block) if block_given?
56
+ model
57
+ end
58
+ end
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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -9,36 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-14 00:00:00.000000000 Z
12
+ date: 2015-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: state_machines
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 0.1.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'
27
+ version: 0.1.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: '3.2'
34
+ version: '4.1'
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: '3.2'
41
+ version: '4.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -82,22 +82,37 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '1'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rspec
85
+ name: minitest
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '='
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 3.0.0.beta2
90
+ version: '5.4'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '='
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: 3.0.0.beta2
97
+ version: '5.4'
98
+ - !ruby/object:Gem::Dependency
99
+ name: minitest-reporters
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
98
112
  description: Adds support for creating state machines for attributes on ActiveModel
99
113
  email:
100
114
  - terminale@gmail.com
115
+ - aaron@pluginaweek.org
101
116
  executables: []
102
117
  extensions: []
103
118
  extra_rdoc_files: []
@@ -110,26 +125,39 @@ files:
110
125
  - LICENSE.txt
111
126
  - README.md
112
127
  - Rakefile
113
- - gemfiles/active_model_3.2.gemfile
114
- - gemfiles/active_model_3.2.gemfile.lock
115
- - gemfiles/active_model_4.0.gemfile
116
- - gemfiles/active_model_4.0.gemfile.lock
117
128
  - gemfiles/active_model_4.1.gemfile
118
- - gemfiles/active_model_4.1.gemfile.lock
119
- - gemfiles/active_model_edge.gemfile
120
- - gemfiles/active_model_edge.gemfile.lock
129
+ - gemfiles/active_model_4.2.gemfile
121
130
  - lib/state_machines-activemodel.rb
122
131
  - lib/state_machines/integrations/active_model.rb
123
132
  - lib/state_machines/integrations/active_model/locale.rb
124
- - lib/state_machines/integrations/version.rb
125
- - spec/active_model_spec.rb
126
- - spec/integration_spec.rb
127
- - spec/spec_helper.rb
128
- - spec/support/en.yml
129
- - spec/support/helpers.rb
130
- - spec/support/migration_helpers.rb
133
+ - lib/state_machines/integrations/active_model/version.rb
131
134
  - state_machines-activemodel.gemspec
132
- homepage: https://github.com/seuros/state_machines-activemodel
135
+ - test/files/en.yml
136
+ - test/integration_test.rb
137
+ - test/machine_by_default_test.rb
138
+ - test/machine_errors_test.rb
139
+ - test/machine_multiple_test.rb
140
+ - test/machine_with_callbacks_test.rb
141
+ - test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
142
+ - test/machine_with_dirty_attribute_and_state_events_test.rb
143
+ - test/machine_with_dirty_attributes_and_custom_attribute_test.rb
144
+ - test/machine_with_dirty_attributes_during_loopback_test.rb
145
+ - test/machine_with_dirty_attributes_test.rb
146
+ - test/machine_with_dynamic_initial_state_test.rb
147
+ - test/machine_with_events_test.rb
148
+ - test/machine_with_failed_after_callbacks_test.rb
149
+ - test/machine_with_failed_before_callbacks_test.rb
150
+ - test/machine_with_initialized_state_test.rb
151
+ - test/machine_with_internationalization_test.rb
152
+ - test/machine_with_model_state_attribute_test.rb
153
+ - test/machine_with_non_model_state_attribute_undefined_test.rb
154
+ - test/machine_with_state_driven_validations_test.rb
155
+ - test/machine_with_states_test.rb
156
+ - test/machine_with_static_initial_state_test.rb
157
+ - test/machine_with_validations_and_custom_attribute_test.rb
158
+ - test/machine_with_validations_test.rb
159
+ - test/test_helper.rb
160
+ homepage: https://github.com/state-machines/state_machines-activemodel
133
161
  licenses:
134
162
  - MIT
135
163
  metadata: {}
@@ -154,10 +182,29 @@ signing_key:
154
182
  specification_version: 4
155
183
  summary: ActiveModel integration for State Machines
156
184
  test_files:
157
- - spec/active_model_spec.rb
158
- - spec/integration_spec.rb
159
- - spec/spec_helper.rb
160
- - spec/support/en.yml
161
- - spec/support/helpers.rb
162
- - spec/support/migration_helpers.rb
185
+ - test/files/en.yml
186
+ - test/integration_test.rb
187
+ - test/machine_by_default_test.rb
188
+ - test/machine_errors_test.rb
189
+ - test/machine_multiple_test.rb
190
+ - test/machine_with_callbacks_test.rb
191
+ - test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
192
+ - test/machine_with_dirty_attribute_and_state_events_test.rb
193
+ - test/machine_with_dirty_attributes_and_custom_attribute_test.rb
194
+ - test/machine_with_dirty_attributes_during_loopback_test.rb
195
+ - test/machine_with_dirty_attributes_test.rb
196
+ - test/machine_with_dynamic_initial_state_test.rb
197
+ - test/machine_with_events_test.rb
198
+ - test/machine_with_failed_after_callbacks_test.rb
199
+ - test/machine_with_failed_before_callbacks_test.rb
200
+ - test/machine_with_initialized_state_test.rb
201
+ - test/machine_with_internationalization_test.rb
202
+ - test/machine_with_model_state_attribute_test.rb
203
+ - test/machine_with_non_model_state_attribute_undefined_test.rb
204
+ - test/machine_with_state_driven_validations_test.rb
205
+ - test/machine_with_states_test.rb
206
+ - test/machine_with_static_initial_state_test.rb
207
+ - test/machine_with_validations_and_custom_attribute_test.rb
208
+ - test/machine_with_validations_test.rb
209
+ - test/test_helper.rb
163
210
  has_rdoc:
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 3.2.0"
6
-
7
- gemspec :path => "../"
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- state_machines-activemodel (0.0.2)
5
- activemodel (>= 3.2)
6
- state_machines
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (3.2.18)
12
- activesupport (= 3.2.18)
13
- builder (~> 3.0.0)
14
- activesupport (3.2.18)
15
- i18n (~> 0.6, >= 0.6.4)
16
- multi_json (~> 1.0)
17
- appraisal (1.0.0)
18
- bundler
19
- rake
20
- thor (>= 0.14.0)
21
- builder (3.0.4)
22
- diff-lcs (1.2.5)
23
- i18n (0.6.9)
24
- multi_json (1.10.0)
25
- rake (10.3.1)
26
- rspec (3.0.0.beta2)
27
- rspec-core (= 3.0.0.beta2)
28
- rspec-expectations (= 3.0.0.beta2)
29
- rspec-mocks (= 3.0.0.beta2)
30
- rspec-core (3.0.0.beta2)
31
- rspec-support (= 3.0.0.beta2)
32
- rspec-expectations (3.0.0.beta2)
33
- diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (= 3.0.0.beta2)
35
- rspec-mocks (3.0.0.beta2)
36
- rspec-support (= 3.0.0.beta2)
37
- rspec-support (3.0.0.beta2)
38
- state_machines (0.0.2)
39
- thor (0.19.1)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- activemodel (~> 3.2.0)
46
- appraisal (>= 1)
47
- bundler (>= 1.6)
48
- rake (>= 10)
49
- rspec (= 3.0.0.beta2)
50
- state_machines-activemodel!
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activemodel", "~> 4.0.0"
6
-
7
- gemspec :path => "../"
@@ -1,56 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- state_machines-activemodel (0.0.2)
5
- activemodel (>= 3.2)
6
- state_machines
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (4.0.5)
12
- activesupport (= 4.0.5)
13
- builder (~> 3.1.0)
14
- activesupport (4.0.5)
15
- i18n (~> 0.6, >= 0.6.9)
16
- minitest (~> 4.2)
17
- multi_json (~> 1.3)
18
- thread_safe (~> 0.1)
19
- tzinfo (~> 0.3.37)
20
- appraisal (1.0.0)
21
- bundler
22
- rake
23
- thor (>= 0.14.0)
24
- builder (3.1.4)
25
- diff-lcs (1.2.5)
26
- i18n (0.6.9)
27
- minitest (4.7.5)
28
- multi_json (1.10.0)
29
- rake (10.3.1)
30
- rspec (3.0.0.beta2)
31
- rspec-core (= 3.0.0.beta2)
32
- rspec-expectations (= 3.0.0.beta2)
33
- rspec-mocks (= 3.0.0.beta2)
34
- rspec-core (3.0.0.beta2)
35
- rspec-support (= 3.0.0.beta2)
36
- rspec-expectations (3.0.0.beta2)
37
- diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (= 3.0.0.beta2)
39
- rspec-mocks (3.0.0.beta2)
40
- rspec-support (= 3.0.0.beta2)
41
- rspec-support (3.0.0.beta2)
42
- state_machines (0.0.2)
43
- thor (0.19.1)
44
- thread_safe (0.3.3)
45
- tzinfo (0.3.39)
46
-
47
- PLATFORMS
48
- ruby
49
-
50
- DEPENDENCIES
51
- activemodel (~> 4.0.0)
52
- appraisal (>= 1)
53
- bundler (>= 1.6)
54
- rake (>= 10)
55
- rspec (= 3.0.0.beta2)
56
- state_machines-activemodel!
@@ -1,57 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- state_machines-activemodel (0.0.2)
5
- activemodel (>= 3.2)
6
- state_machines
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (4.1.1)
12
- activesupport (= 4.1.1)
13
- builder (~> 3.1)
14
- activesupport (4.1.1)
15
- i18n (~> 0.6, >= 0.6.9)
16
- json (~> 1.7, >= 1.7.7)
17
- minitest (~> 5.1)
18
- thread_safe (~> 0.1)
19
- tzinfo (~> 1.1)
20
- appraisal (1.0.0)
21
- bundler
22
- rake
23
- thor (>= 0.14.0)
24
- builder (3.2.2)
25
- diff-lcs (1.2.5)
26
- i18n (0.6.9)
27
- json (1.8.1)
28
- minitest (5.3.3)
29
- rake (10.3.1)
30
- rspec (3.0.0.beta2)
31
- rspec-core (= 3.0.0.beta2)
32
- rspec-expectations (= 3.0.0.beta2)
33
- rspec-mocks (= 3.0.0.beta2)
34
- rspec-core (3.0.0.beta2)
35
- rspec-support (= 3.0.0.beta2)
36
- rspec-expectations (3.0.0.beta2)
37
- diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (= 3.0.0.beta2)
39
- rspec-mocks (3.0.0.beta2)
40
- rspec-support (= 3.0.0.beta2)
41
- rspec-support (3.0.0.beta2)
42
- state_machines (0.0.2)
43
- thor (0.19.1)
44
- thread_safe (0.3.3)
45
- tzinfo (1.1.0)
46
- thread_safe (~> 0.1)
47
-
48
- PLATFORMS
49
- ruby
50
-
51
- DEPENDENCIES
52
- activemodel (~> 4.1.0)
53
- appraisal (>= 1)
54
- bundler (>= 1.6)
55
- rake (>= 10)
56
- rspec (= 3.0.0.beta2)
57
- state_machines-activemodel!