state_machines-activerecord 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +20 -0
- data/Appraisals +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +23 -0
- data/README.md +65 -0
- data/Rakefile +9 -0
- data/gemfiles/active_record_4.1.gemfile +13 -0
- data/gemfiles/active_record_4.2.gemfile +13 -0
- data/lib/state_machines-activerecord.rb +1 -0
- data/lib/state_machines/integrations/active_record.rb +588 -0
- data/lib/state_machines/integrations/active_record/locale.rb +12 -0
- data/lib/state_machines/integrations/active_record/version.rb +7 -0
- data/log/.gitkeep +0 -0
- data/state_machines-activerecord.gemspec +27 -0
- data/test/files/en.yml +5 -0
- data/test/files/models/post.rb +11 -0
- data/test/integration_test.rb +23 -0
- data/test/machine_by_default_test.rb +16 -0
- data/test/machine_errors_test.rb +19 -0
- data/test/machine_multiple_test.rb +17 -0
- data/test/machine_nested_action_test.rb +38 -0
- data/test/machine_unmigrated_test.rb +14 -0
- data/test/machine_with_aliased_attribute_test.rb +23 -0
- data/test/machine_with_callbacks_test.rb +172 -0
- data/test/machine_with_column_state_attribute_test.rb +44 -0
- data/test/machine_with_complex_pluralization_scopes_test.rb +16 -0
- data/test/machine_with_conflicting_predicate_test.rb +18 -0
- data/test/machine_with_conflicting_state_name_test.rb +29 -0
- data/test/machine_with_custom_attribute_test.rb +21 -0
- data/test/machine_with_default_scope_test.rb +18 -0
- data/test/machine_with_different_column_default_test.rb +27 -0
- data/test/machine_with_different_integer_column_default_test.rb +29 -0
- data/test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb +24 -0
- data/test/machine_with_dirty_attribute_and_state_events_test.rb +20 -0
- data/test/machine_with_dirty_attributes_and_custom_attribute_test.rb +32 -0
- data/test/machine_with_dirty_attributes_during_loopback_test.rb +22 -0
- data/test/machine_with_dirty_attributes_test.rb +35 -0
- data/test/machine_with_dynamic_initial_state_test.rb +99 -0
- data/test/machine_with_event_attributes_on_autosave_test.rb +48 -0
- data/test/machine_with_event_attributes_on_custom_action_test.rb +41 -0
- data/test/machine_with_event_attributes_on_save_bang_test.rb +82 -0
- data/test/machine_with_event_attributes_on_save_test.rb +184 -0
- data/test/machine_with_event_attributes_on_validation_test.rb +126 -0
- data/test/machine_with_events_test.rb +13 -0
- data/test/machine_with_failed_action_test.rb +40 -0
- data/test/machine_with_failed_after_callbacks_test.rb +35 -0
- data/test/machine_with_failed_before_callbacks_test.rb +36 -0
- data/test/machine_with_initialized_state_test.rb +35 -0
- data/test/machine_with_internationalization_test.rb +180 -0
- data/test/machine_with_loopback_test.rb +22 -0
- data/test/machine_with_non_column_state_attribute_defined_test.rb +35 -0
- data/test/machine_with_non_column_state_attribute_undefined_test.rb +33 -0
- data/test/machine_with_same_column_default_test.rb +26 -0
- data/test/machine_with_scopes_and_joins_test.rb +37 -0
- data/test/machine_with_scopes_and_owner_subclass_test.rb +27 -0
- data/test/machine_with_scopes_test.rb +70 -0
- data/test/machine_with_state_driven_validations_test.rb +30 -0
- data/test/machine_with_states_test.rb +13 -0
- data/test/machine_with_static_initial_state_test.rb +166 -0
- data/test/machine_with_transactions_test.rb +26 -0
- data/test/machine_with_validations_and_custom_attribute_test.rb +21 -0
- data/test/machine_with_validations_test.rb +47 -0
- data/test/machine_without_database_test.rb +20 -0
- data/test/machine_without_transactions_test.rb +26 -0
- data/test/model_test.rb +12 -0
- data/test/test_helper.rb +42 -0
- metadata +264 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MachineWithoutDatabaseTest < BaseTestCase
|
4
|
+
def setup
|
5
|
+
@model = new_model(false) do
|
6
|
+
# Simulate the database not being available entirely
|
7
|
+
def self.connection
|
8
|
+
raise ActiveRecord::ConnectionNotEstablished
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.connected?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_allow_machine_creation
|
18
|
+
assert_nothing_raised { StateMachines::Machine.new(@model) }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class MachineWithoutTransactionsTest < BaseTestCase
|
4
|
+
def setup
|
5
|
+
@model = new_model
|
6
|
+
@machine = StateMachines::Machine.new(@model, :use_transactions => false)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_not_rollback_transaction_if_false
|
10
|
+
@machine.within_transaction(@model.new) do
|
11
|
+
@model.create
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal 1, @model.count
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_not_rollback_transaction_if_true
|
19
|
+
@machine.within_transaction(@model.new) do
|
20
|
+
@model.create
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_equal 1, @model.count
|
25
|
+
end
|
26
|
+
end
|
data/test/model_test.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require_relative 'files/models/post'
|
3
|
+
|
4
|
+
class ModelTest < ActiveSupport::TestCase
|
5
|
+
def test_should_have_draft_state_in_defaut_machine
|
6
|
+
assert_equal 'draft', Post.new.state
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_should_have_the_correct_integration
|
10
|
+
assert_equal StateMachines::Integrations::ActiveRecord, StateMachines::Integrations.match(Post)
|
11
|
+
end
|
12
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
begin
|
2
|
+
require 'pry-byebug'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
require 'minitest/reporters'
|
6
|
+
Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
|
7
|
+
require 'state_machines-activerecord'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
require 'securerandom'
|
10
|
+
|
11
|
+
# Establish database connection
|
12
|
+
ActiveRecord::Base.establish_connection('adapter' => 'sqlite3', 'database' => ':memory:')
|
13
|
+
ActiveRecord::Base.logger = Logger.new("#{File.dirname(__FILE__)}/../log/active_record.log")
|
14
|
+
|
15
|
+
if ActiveSupport.gem_version >= Gem::Version.new('4.2.0')
|
16
|
+
ActiveSupport.test_order = :random
|
17
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
18
|
+
end
|
19
|
+
|
20
|
+
class BaseTestCase < ActiveSupport::TestCase
|
21
|
+
protected
|
22
|
+
# Creates a new ActiveRecord model (and the associated table)
|
23
|
+
def new_model(create_table = :foo, &block)
|
24
|
+
name = create_table || :foo
|
25
|
+
table_name = "#{name}_#{SecureRandom.hex(6)}"
|
26
|
+
|
27
|
+
model = Class.new(ActiveRecord::Base) do
|
28
|
+
self.table_name = table_name.to_s
|
29
|
+
connection.create_table(table_name, :force => true) { |t| t.string(:state) } if create_table
|
30
|
+
|
31
|
+
(
|
32
|
+
class << self;
|
33
|
+
self;
|
34
|
+
end).class_eval do
|
35
|
+
define_method(:name) { "#{name.to_s.capitalize}" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
model.class_eval(&block) if block_given?
|
39
|
+
model.reset_column_information if create_table
|
40
|
+
model
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: state_machines-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abdelkader Boudih
|
8
|
+
- Aaron Pfeifer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: state_machines-activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.0.3
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.3
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activerecord
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '4.1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '4.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: sqlite3
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: appraisal
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: minitest
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 5.4.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 5.4.0
|
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'
|
112
|
+
description: Adds support for creating state machines for attributes on ActiveRecord
|
113
|
+
email:
|
114
|
+
- terminale@gmail.com
|
115
|
+
- aaron@pluginaweek.org
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Appraisals
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- gemfiles/active_record_4.1.gemfile
|
128
|
+
- gemfiles/active_record_4.2.gemfile
|
129
|
+
- lib/state_machines-activerecord.rb
|
130
|
+
- lib/state_machines/integrations/active_record.rb
|
131
|
+
- lib/state_machines/integrations/active_record/locale.rb
|
132
|
+
- lib/state_machines/integrations/active_record/version.rb
|
133
|
+
- log/.gitkeep
|
134
|
+
- state_machines-activerecord.gemspec
|
135
|
+
- test/files/en.yml
|
136
|
+
- test/files/models/post.rb
|
137
|
+
- test/integration_test.rb
|
138
|
+
- test/machine_by_default_test.rb
|
139
|
+
- test/machine_errors_test.rb
|
140
|
+
- test/machine_multiple_test.rb
|
141
|
+
- test/machine_nested_action_test.rb
|
142
|
+
- test/machine_unmigrated_test.rb
|
143
|
+
- test/machine_with_aliased_attribute_test.rb
|
144
|
+
- test/machine_with_callbacks_test.rb
|
145
|
+
- test/machine_with_column_state_attribute_test.rb
|
146
|
+
- test/machine_with_complex_pluralization_scopes_test.rb
|
147
|
+
- test/machine_with_conflicting_predicate_test.rb
|
148
|
+
- test/machine_with_conflicting_state_name_test.rb
|
149
|
+
- test/machine_with_custom_attribute_test.rb
|
150
|
+
- test/machine_with_default_scope_test.rb
|
151
|
+
- test/machine_with_different_column_default_test.rb
|
152
|
+
- test/machine_with_different_integer_column_default_test.rb
|
153
|
+
- test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
|
154
|
+
- test/machine_with_dirty_attribute_and_state_events_test.rb
|
155
|
+
- test/machine_with_dirty_attributes_and_custom_attribute_test.rb
|
156
|
+
- test/machine_with_dirty_attributes_during_loopback_test.rb
|
157
|
+
- test/machine_with_dirty_attributes_test.rb
|
158
|
+
- test/machine_with_dynamic_initial_state_test.rb
|
159
|
+
- test/machine_with_event_attributes_on_autosave_test.rb
|
160
|
+
- test/machine_with_event_attributes_on_custom_action_test.rb
|
161
|
+
- test/machine_with_event_attributes_on_save_bang_test.rb
|
162
|
+
- test/machine_with_event_attributes_on_save_test.rb
|
163
|
+
- test/machine_with_event_attributes_on_validation_test.rb
|
164
|
+
- test/machine_with_events_test.rb
|
165
|
+
- test/machine_with_failed_action_test.rb
|
166
|
+
- test/machine_with_failed_after_callbacks_test.rb
|
167
|
+
- test/machine_with_failed_before_callbacks_test.rb
|
168
|
+
- test/machine_with_initialized_state_test.rb
|
169
|
+
- test/machine_with_internationalization_test.rb
|
170
|
+
- test/machine_with_loopback_test.rb
|
171
|
+
- test/machine_with_non_column_state_attribute_defined_test.rb
|
172
|
+
- test/machine_with_non_column_state_attribute_undefined_test.rb
|
173
|
+
- test/machine_with_same_column_default_test.rb
|
174
|
+
- test/machine_with_scopes_and_joins_test.rb
|
175
|
+
- test/machine_with_scopes_and_owner_subclass_test.rb
|
176
|
+
- test/machine_with_scopes_test.rb
|
177
|
+
- test/machine_with_state_driven_validations_test.rb
|
178
|
+
- test/machine_with_states_test.rb
|
179
|
+
- test/machine_with_static_initial_state_test.rb
|
180
|
+
- test/machine_with_transactions_test.rb
|
181
|
+
- test/machine_with_validations_and_custom_attribute_test.rb
|
182
|
+
- test/machine_with_validations_test.rb
|
183
|
+
- test/machine_without_database_test.rb
|
184
|
+
- test/machine_without_transactions_test.rb
|
185
|
+
- test/model_test.rb
|
186
|
+
- test/test_helper.rb
|
187
|
+
homepage: https://github.com/seuros/state_machines-activemodel
|
188
|
+
licenses:
|
189
|
+
- MIT
|
190
|
+
metadata: {}
|
191
|
+
post_install_message:
|
192
|
+
rdoc_options: []
|
193
|
+
require_paths:
|
194
|
+
- lib
|
195
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0'
|
200
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
requirements: []
|
206
|
+
rubyforge_project:
|
207
|
+
rubygems_version: 2.2.2
|
208
|
+
signing_key:
|
209
|
+
specification_version: 4
|
210
|
+
summary: State machines Active Record Integration
|
211
|
+
test_files:
|
212
|
+
- test/files/en.yml
|
213
|
+
- test/files/models/post.rb
|
214
|
+
- test/integration_test.rb
|
215
|
+
- test/machine_by_default_test.rb
|
216
|
+
- test/machine_errors_test.rb
|
217
|
+
- test/machine_multiple_test.rb
|
218
|
+
- test/machine_nested_action_test.rb
|
219
|
+
- test/machine_unmigrated_test.rb
|
220
|
+
- test/machine_with_aliased_attribute_test.rb
|
221
|
+
- test/machine_with_callbacks_test.rb
|
222
|
+
- test/machine_with_column_state_attribute_test.rb
|
223
|
+
- test/machine_with_complex_pluralization_scopes_test.rb
|
224
|
+
- test/machine_with_conflicting_predicate_test.rb
|
225
|
+
- test/machine_with_conflicting_state_name_test.rb
|
226
|
+
- test/machine_with_custom_attribute_test.rb
|
227
|
+
- test/machine_with_default_scope_test.rb
|
228
|
+
- test/machine_with_different_column_default_test.rb
|
229
|
+
- test/machine_with_different_integer_column_default_test.rb
|
230
|
+
- test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb
|
231
|
+
- test/machine_with_dirty_attribute_and_state_events_test.rb
|
232
|
+
- test/machine_with_dirty_attributes_and_custom_attribute_test.rb
|
233
|
+
- test/machine_with_dirty_attributes_during_loopback_test.rb
|
234
|
+
- test/machine_with_dirty_attributes_test.rb
|
235
|
+
- test/machine_with_dynamic_initial_state_test.rb
|
236
|
+
- test/machine_with_event_attributes_on_autosave_test.rb
|
237
|
+
- test/machine_with_event_attributes_on_custom_action_test.rb
|
238
|
+
- test/machine_with_event_attributes_on_save_bang_test.rb
|
239
|
+
- test/machine_with_event_attributes_on_save_test.rb
|
240
|
+
- test/machine_with_event_attributes_on_validation_test.rb
|
241
|
+
- test/machine_with_events_test.rb
|
242
|
+
- test/machine_with_failed_action_test.rb
|
243
|
+
- test/machine_with_failed_after_callbacks_test.rb
|
244
|
+
- test/machine_with_failed_before_callbacks_test.rb
|
245
|
+
- test/machine_with_initialized_state_test.rb
|
246
|
+
- test/machine_with_internationalization_test.rb
|
247
|
+
- test/machine_with_loopback_test.rb
|
248
|
+
- test/machine_with_non_column_state_attribute_defined_test.rb
|
249
|
+
- test/machine_with_non_column_state_attribute_undefined_test.rb
|
250
|
+
- test/machine_with_same_column_default_test.rb
|
251
|
+
- test/machine_with_scopes_and_joins_test.rb
|
252
|
+
- test/machine_with_scopes_and_owner_subclass_test.rb
|
253
|
+
- test/machine_with_scopes_test.rb
|
254
|
+
- test/machine_with_state_driven_validations_test.rb
|
255
|
+
- test/machine_with_states_test.rb
|
256
|
+
- test/machine_with_static_initial_state_test.rb
|
257
|
+
- test/machine_with_transactions_test.rb
|
258
|
+
- test/machine_with_validations_and_custom_attribute_test.rb
|
259
|
+
- test/machine_with_validations_test.rb
|
260
|
+
- test/machine_without_database_test.rb
|
261
|
+
- test/machine_without_transactions_test.rb
|
262
|
+
- test/model_test.rb
|
263
|
+
- test/test_helper.rb
|
264
|
+
has_rdoc:
|