aasm 4.12.3 → 5.1.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/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.travis.yml +48 -18
- data/Appraisals +50 -26
- data/CHANGELOG.md +75 -3
- data/Dockerfile +44 -0
- data/Gemfile +2 -3
- data/README.md +216 -110
- data/aasm.gemspec +2 -0
- data/docker-compose.yml +40 -0
- data/gemfiles/norails.gemfile +10 -0
- data/gemfiles/rails_4.2.gemfile +9 -8
- data/gemfiles/rails_4.2_mongoid_5.gemfile +6 -5
- data/gemfiles/rails_4.2_nobrainer.gemfile +9 -0
- data/gemfiles/rails_5.0.gemfile +6 -6
- data/gemfiles/rails_5.0_nobrainer.gemfile +9 -0
- data/gemfiles/rails_5.1.gemfile +14 -0
- data/gemfiles/rails_5.2.gemfile +14 -0
- data/lib/aasm.rb +5 -2
- data/lib/aasm/aasm.rb +30 -27
- data/lib/aasm/base.rb +25 -7
- data/lib/aasm/core/event.rb +14 -24
- data/lib/aasm/core/invoker.rb +129 -0
- data/lib/aasm/core/invokers/base_invoker.rb +75 -0
- data/lib/aasm/core/invokers/class_invoker.rb +52 -0
- data/lib/aasm/core/invokers/literal_invoker.rb +47 -0
- data/lib/aasm/core/invokers/proc_invoker.rb +59 -0
- data/lib/aasm/core/state.rb +10 -9
- data/lib/aasm/core/transition.rb +7 -68
- data/lib/aasm/errors.rb +4 -3
- data/lib/aasm/instance_base.rb +16 -4
- data/lib/aasm/persistence.rb +3 -0
- data/lib/aasm/persistence/active_record_persistence.rb +25 -5
- data/lib/aasm/persistence/base.rb +1 -1
- data/lib/aasm/persistence/core_data_query_persistence.rb +2 -1
- data/lib/aasm/persistence/dynamoid_persistence.rb +1 -1
- data/lib/aasm/persistence/mongoid_persistence.rb +1 -1
- data/lib/aasm/persistence/no_brainer_persistence.rb +105 -0
- data/lib/aasm/persistence/orm.rb +23 -19
- data/lib/aasm/persistence/plain_persistence.rb +2 -1
- data/lib/aasm/persistence/redis_persistence.rb +1 -1
- data/lib/aasm/persistence/sequel_persistence.rb +0 -1
- data/lib/aasm/rspec/allow_event.rb +5 -1
- data/lib/aasm/rspec/allow_transition_to.rb +5 -1
- data/lib/aasm/rspec/transition_from.rb +5 -1
- data/lib/aasm/version.rb +1 -1
- data/lib/generators/aasm/orm_helpers.rb +6 -0
- data/lib/generators/active_record/aasm_generator.rb +3 -1
- data/lib/generators/nobrainer/aasm_generator.rb +28 -0
- data/lib/motion-aasm.rb +1 -0
- data/spec/database.rb +16 -1
- data/spec/en.yml +0 -3
- data/spec/generators/active_record_generator_spec.rb +6 -0
- data/spec/generators/no_brainer_generator_spec.rb +29 -0
- data/spec/{en_deprecated_style.yml → localizer_test_model_deprecated_style.yml} +0 -4
- data/spec/localizer_test_model_new_style.yml +5 -0
- data/spec/models/active_record/active_record_callback.rb +93 -0
- data/spec/models/active_record/instance_level_skip_validation_example.rb +19 -0
- data/spec/models/active_record/localizer_test_model.rb +3 -3
- data/spec/models/active_record/person.rb +23 -0
- data/spec/models/active_record/simple_new_dsl.rb +15 -0
- data/spec/models/active_record/work.rb +3 -0
- data/spec/models/callbacks/with_state_arg.rb +5 -1
- data/spec/models/callbacks/with_state_arg_multiple.rb +4 -1
- data/spec/models/default_state.rb +1 -1
- data/spec/models/nobrainer/complex_no_brainer_example.rb +36 -0
- data/spec/models/nobrainer/invalid_persistor_no_brainer.rb +39 -0
- data/spec/models/nobrainer/no_scope_no_brainer.rb +21 -0
- data/spec/models/nobrainer/nobrainer_relationships.rb +25 -0
- data/spec/models/nobrainer/silent_persistor_no_brainer.rb +39 -0
- data/spec/models/nobrainer/simple_new_dsl_nobrainer.rb +25 -0
- data/spec/models/nobrainer/simple_no_brainer.rb +23 -0
- data/spec/models/nobrainer/validator_no_brainer.rb +98 -0
- data/spec/models/simple_example.rb +8 -0
- data/spec/models/simple_example_with_guard_args.rb +17 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/spec_helpers/active_record.rb +2 -1
- data/spec/spec_helpers/dynamoid.rb +7 -5
- data/spec/spec_helpers/mongoid.rb +20 -1
- data/spec/spec_helpers/nobrainer.rb +15 -0
- data/spec/spec_helpers/redis.rb +5 -2
- data/spec/spec_helpers/sequel.rb +1 -1
- data/spec/unit/abstract_class_spec.rb +27 -0
- data/spec/unit/api_spec.rb +4 -0
- data/spec/unit/callback_multiple_spec.rb +7 -3
- data/spec/unit/callbacks_spec.rb +32 -2
- data/spec/unit/complex_example_spec.rb +0 -1
- data/spec/unit/event_spec.rb +13 -0
- data/spec/unit/exception_spec.rb +1 -1
- data/spec/unit/inspection_multiple_spec.rb +9 -5
- data/spec/unit/inspection_spec.rb +7 -3
- data/spec/unit/invoker_spec.rb +189 -0
- data/spec/unit/invokers/base_invoker_spec.rb +72 -0
- data/spec/unit/invokers/class_invoker_spec.rb +95 -0
- data/spec/unit/invokers/literal_invoker_spec.rb +86 -0
- data/spec/unit/invokers/proc_invoker_spec.rb +86 -0
- data/spec/unit/localizer_spec.rb +9 -10
- data/spec/unit/persistence/active_record_persistence_multiple_spec.rb +4 -4
- data/spec/unit/persistence/active_record_persistence_spec.rb +109 -4
- data/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +0 -4
- data/spec/unit/persistence/mongoid_persistence_spec.rb +0 -4
- data/spec/unit/persistence/no_brainer_persistence_multiple_spec.rb +198 -0
- data/spec/unit/persistence/no_brainer_persistence_spec.rb +158 -0
- data/spec/unit/rspec_matcher_spec.rb +9 -0
- data/spec/unit/simple_example_spec.rb +15 -0
- data/spec/unit/state_spec.rb +23 -7
- data/spec/unit/transition_spec.rb +1 -1
- data/test/minitest_helper.rb +2 -2
- data/test/unit/minitest_matcher_test.rb +1 -1
- metadata +106 -12
- data/callbacks.txt +0 -51
- data/gemfiles/rails_3.2.gemfile +0 -13
- data/gemfiles/rails_4.0.gemfile +0 -15
@@ -34,7 +34,7 @@ module AASM
|
|
34
34
|
# This allows for nil aasm states - be sure to add validation to your model
|
35
35
|
def aasm_read_state(name=:default)
|
36
36
|
state = send(self.class.aasm(name).attribute_name)
|
37
|
-
if state.
|
37
|
+
if !state || state.empty?
|
38
38
|
aasm_new_record? ? aasm(name).determine_state_name(self.class.aasm(name).initial_state) : nil
|
39
39
|
else
|
40
40
|
state.to_sym
|
@@ -77,7 +77,8 @@ module AASM
|
|
77
77
|
#
|
78
78
|
def aasm_ensure_initial_state
|
79
79
|
AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |state_machine_name|
|
80
|
-
send(
|
80
|
+
next if !send(self.class.aasm(state_machine_name).attribute_name) || send(self.class.aasm(state_machine_name).attribute_name).empty?
|
81
|
+
send("#{self.class.aasm(state_machine_name).attribute_name}=", aasm(state_machine_name).enter_initial_state.to_s)
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end # InstanceMethods
|
@@ -83,7 +83,7 @@ module AASM
|
|
83
83
|
#
|
84
84
|
def aasm_ensure_initial_state
|
85
85
|
AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |state_machine_name|
|
86
|
-
aasm(state_machine_name).enter_initial_state if send(self.class.aasm(state_machine_name).attribute_name).
|
86
|
+
aasm(state_machine_name).enter_initial_state if !send(self.class.aasm(state_machine_name).attribute_name) || send(self.class.aasm(state_machine_name).attribute_name).empty?
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end # InstanceMethods
|
@@ -106,7 +106,7 @@ module AASM
|
|
106
106
|
# mongoid has_many relationship does not load child object attributes when
|
107
107
|
# only ids are loaded, for example parent.child_ids will not load child object attributes.
|
108
108
|
# This feature is introduced in mongoid > 4.
|
109
|
-
if attribute_names.include?(attribute_name) && attributes[attribute_name].
|
109
|
+
if attribute_names.include?(attribute_name) && !attributes[attribute_name] || attributes[attribute_name].empty?
|
110
110
|
# attribute_missing? is defined in mongoid > 4
|
111
111
|
return if Mongoid::VERSION.to_f >= 4 && attribute_missing?(attribute_name)
|
112
112
|
send("#{self.class.aasm(state_machine_name).attribute_name}=", aasm(state_machine_name).enter_initial_state.to_s)
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'aasm/persistence/orm'
|
2
|
+
module AASM
|
3
|
+
module Persistence
|
4
|
+
module NoBrainerPersistence
|
5
|
+
# This method:
|
6
|
+
#
|
7
|
+
# * extends the model with ClassMethods
|
8
|
+
# * includes InstanceMethods
|
9
|
+
#
|
10
|
+
# Adds
|
11
|
+
#
|
12
|
+
# before_validation :aasm_ensure_initial_state
|
13
|
+
#
|
14
|
+
# As a result, it doesn't matter when you define your methods - the following 2 are equivalent
|
15
|
+
#
|
16
|
+
# class Foo
|
17
|
+
# include NoBrainer::Document
|
18
|
+
# def aasm_write_state(state)
|
19
|
+
# "bar"
|
20
|
+
# end
|
21
|
+
# include AASM
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# class Foo
|
25
|
+
# include NoBrainer::Document
|
26
|
+
# include AASM
|
27
|
+
# def aasm_write_state(state)
|
28
|
+
# "bar"
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
def self.included(base)
|
33
|
+
base.send(:include, AASM::Persistence::Base)
|
34
|
+
base.send(:include, AASM::Persistence::ORM)
|
35
|
+
base.send(:include, AASM::Persistence::NoBrainerPersistence::InstanceMethods)
|
36
|
+
base.extend AASM::Persistence::NoBrainerPersistence::ClassMethods
|
37
|
+
|
38
|
+
base.after_initialize :aasm_ensure_initial_state
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
def aasm_create_scope(state_machine_name, scope_name)
|
43
|
+
scope_options = lambda {
|
44
|
+
where(aasm(state_machine_name).attribute_name.to_sym => scope_name.to_s)
|
45
|
+
}
|
46
|
+
send(:scope, scope_name, scope_options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module InstanceMethods
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def aasm_save
|
55
|
+
self.save
|
56
|
+
end
|
57
|
+
|
58
|
+
def aasm_raise_invalid_record
|
59
|
+
raise NoBrainer::Error::DocumentInvalid.new(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def aasm_supports_transactions?
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def aasm_update_column(attribute_name, value)
|
67
|
+
write_attribute(attribute_name, value)
|
68
|
+
save(validate: false)
|
69
|
+
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
def aasm_read_attribute(name)
|
74
|
+
read_attribute(name)
|
75
|
+
end
|
76
|
+
|
77
|
+
def aasm_write_attribute(name, value)
|
78
|
+
write_attribute(name, value)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Ensures that if the aasm_state column is nil and the record is new
|
82
|
+
# that the initial state gets populated before validation on create
|
83
|
+
#
|
84
|
+
# foo = Foo.new
|
85
|
+
# foo.aasm_state # => nil
|
86
|
+
# foo.valid?
|
87
|
+
# foo.aasm_state # => "open" (where :open is the initial state)
|
88
|
+
#
|
89
|
+
#
|
90
|
+
# foo = Foo.find(:first)
|
91
|
+
# foo.aasm_state # => 1
|
92
|
+
# foo.aasm_state = nil
|
93
|
+
# foo.valid?
|
94
|
+
# foo.aasm_state # => nil
|
95
|
+
#
|
96
|
+
def aasm_ensure_initial_state
|
97
|
+
AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |name|
|
98
|
+
aasm_column = self.class.aasm(name).attribute_name
|
99
|
+
aasm(name).enter_initial_state if !read_attribute(aasm_column) || read_attribute(aasm_column).empty?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end # InstanceMethods
|
103
|
+
end
|
104
|
+
end # Persistence
|
105
|
+
end # AASM
|
data/lib/aasm/persistence/orm.rb
CHANGED
@@ -81,6 +81,10 @@ module AASM
|
|
81
81
|
true
|
82
82
|
end
|
83
83
|
|
84
|
+
def aasm_execute_after_commit
|
85
|
+
yield
|
86
|
+
end
|
87
|
+
|
84
88
|
def aasm_write_state_attribute(state, name=:default)
|
85
89
|
aasm_write_attribute(self.class.aasm(name).attribute_name, aasm_raw_attribute_value(state, name))
|
86
90
|
end
|
@@ -116,32 +120,32 @@ module AASM
|
|
116
120
|
|
117
121
|
# Returns true if event was fired successfully and transaction completed.
|
118
122
|
def aasm_fire_event(state_machine_name, name, options, *args, &block)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
else
|
123
|
+
return super unless aasm_supports_transactions? && options[:persist]
|
124
|
+
|
125
|
+
event = self.class.aasm(state_machine_name).state_machine.events[name]
|
126
|
+
event.fire_callbacks(:before_transaction, self, *args)
|
127
|
+
event.fire_global_callbacks(:before_all_transactions, self, *args)
|
128
|
+
|
129
|
+
begin
|
130
|
+
success = if options[:persist] && use_transactions?(state_machine_name)
|
131
|
+
aasm_transaction(requires_new?(state_machine_name), requires_lock?(state_machine_name)) do
|
130
132
|
super
|
131
133
|
end
|
134
|
+
else
|
135
|
+
super
|
136
|
+
end
|
132
137
|
|
133
|
-
|
138
|
+
if success && !(event.options.keys & [:after_commit, :after_all_commits]).empty?
|
139
|
+
aasm_execute_after_commit do
|
134
140
|
event.fire_callbacks(:after_commit, self, *args)
|
135
141
|
event.fire_global_callbacks(:after_all_commits, self, *args)
|
136
142
|
end
|
137
|
-
|
138
|
-
success
|
139
|
-
ensure
|
140
|
-
event.fire_callbacks(:after_transaction, self, *args)
|
141
|
-
event.fire_global_callbacks(:after_all_transactions, self, *args)
|
142
143
|
end
|
143
|
-
|
144
|
-
|
144
|
+
|
145
|
+
success
|
146
|
+
ensure
|
147
|
+
event.fire_callbacks(:after_transaction, self, *args)
|
148
|
+
event.fire_global_callbacks(:after_all_transactions, self, *args)
|
145
149
|
end
|
146
150
|
end
|
147
151
|
|
@@ -5,7 +5,8 @@ module AASM
|
|
5
5
|
# may be overwritten by persistence mixins
|
6
6
|
def aasm_read_state(name=:default)
|
7
7
|
# all the following lines behave like @current_state ||= aasm(name).enter_initial_state
|
8
|
-
current = aasm(name).
|
8
|
+
current = aasm(name).instance_variable_defined?("@current_state_#{name}") &&
|
9
|
+
aasm(name).instance_variable_get("@current_state_#{name}")
|
9
10
|
return current if current
|
10
11
|
aasm(name).instance_variable_set("@current_state_#{name}", aasm(name).enter_initial_state)
|
11
12
|
end
|
@@ -69,7 +69,7 @@ module AASM
|
|
69
69
|
def aasm_ensure_initial_state
|
70
70
|
AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |name|
|
71
71
|
aasm_column = self.class.aasm(name).attribute_name
|
72
|
-
aasm(name).enter_initial_state if send(aasm_column).value.
|
72
|
+
aasm(name).enter_initial_state if !send(aasm_column).value || send(aasm_column).value.empty?
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -1,13 +1,17 @@
|
|
1
1
|
RSpec::Matchers.define :allow_event do |event|
|
2
2
|
match do |obj|
|
3
3
|
@state_machine_name ||= :default
|
4
|
-
obj.aasm(@state_machine_name).may_fire_event?(event)
|
4
|
+
obj.aasm(@state_machine_name).may_fire_event?(event, *@args)
|
5
5
|
end
|
6
6
|
|
7
7
|
chain :on do |state_machine_name|
|
8
8
|
@state_machine_name = state_machine_name
|
9
9
|
end
|
10
10
|
|
11
|
+
chain :with do |*args|
|
12
|
+
@args = args
|
13
|
+
end
|
14
|
+
|
11
15
|
description do
|
12
16
|
"allow event #{expected} (on :#{@state_machine_name})"
|
13
17
|
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
RSpec::Matchers.define :allow_transition_to do |state|
|
2
2
|
match do |obj|
|
3
3
|
@state_machine_name ||= :default
|
4
|
-
obj.aasm(@state_machine_name).states(:permitted => true).include?(state)
|
4
|
+
obj.aasm(@state_machine_name).states({:permitted => true}, *@args).include?(state)
|
5
5
|
end
|
6
6
|
|
7
7
|
chain :on do |state_machine_name|
|
8
8
|
@state_machine_name = state_machine_name
|
9
9
|
end
|
10
10
|
|
11
|
+
chain :with do |*args|
|
12
|
+
@args = args
|
13
|
+
end
|
14
|
+
|
11
15
|
description do
|
12
16
|
"allow transition to #{expected} (on :#{@state_machine_name})"
|
13
17
|
end
|
@@ -2,7 +2,11 @@ RSpec::Matchers.define :transition_from do |from_state|
|
|
2
2
|
match do |obj|
|
3
3
|
@state_machine_name ||= :default
|
4
4
|
obj.aasm(@state_machine_name).current_state = from_state.to_sym
|
5
|
-
|
5
|
+
begin
|
6
|
+
obj.send(@event, *@args) && obj.aasm(@state_machine_name).current_state == @to_state.to_sym
|
7
|
+
rescue AASM::InvalidTransition
|
8
|
+
false
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
chain :on do |state_machine_name|
|
data/lib/aasm/version.rb
CHANGED
@@ -22,6 +22,12 @@ RUBY
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def column_exists?
|
26
|
+
table_name.singularize.humanize.constantize.column_names.include?(column_name.to_s)
|
27
|
+
rescue NameError
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
25
31
|
def model_exists?
|
26
32
|
File.exists?(File.join(destination_root, model_path))
|
27
33
|
end
|
@@ -11,7 +11,9 @@ module ActiveRecord
|
|
11
11
|
source_root File.expand_path("../templates", __FILE__)
|
12
12
|
|
13
13
|
def copy_aasm_migration
|
14
|
-
if
|
14
|
+
if column_exists?
|
15
|
+
puts "Both model and column exists"
|
16
|
+
elsif model_exists?
|
15
17
|
migration_template "migration_existing.rb", "db/migrate/add_#{column_name}_to_#{table_name}.rb"
|
16
18
|
else
|
17
19
|
migration_template "migration.rb", "db/migrate/aasm_create_#{table_name}.rb"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'generators/aasm/orm_helpers'
|
3
|
+
|
4
|
+
module NoBrainer
|
5
|
+
module Generators
|
6
|
+
class AASMGenerator < Rails::Generators::NamedBase
|
7
|
+
include AASM::Generators::OrmHelpers
|
8
|
+
namespace 'nobrainer:aasm'
|
9
|
+
argument :column_name, type: :string, default: 'aasm_state'
|
10
|
+
|
11
|
+
def generate_model
|
12
|
+
invoke 'nobrainer:model', [name] unless model_exists?
|
13
|
+
end
|
14
|
+
|
15
|
+
def inject_aasm_content
|
16
|
+
inject_into_file model_path, model_contents, after: "include NoBrainer::Document::Timestamps\n" if model_exists?
|
17
|
+
end
|
18
|
+
|
19
|
+
def inject_field_types
|
20
|
+
inject_into_file model_path, migration_data, after: "include NoBrainer::Document::Timestamps\n" if model_exists?
|
21
|
+
end
|
22
|
+
|
23
|
+
def migration_data
|
24
|
+
" field :#{column_name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/motion-aasm.rb
CHANGED
@@ -16,6 +16,7 @@ exclude_files = [
|
|
16
16
|
'aasm/persistence/active_record_persistence.rb',
|
17
17
|
'aasm/persistence/dynamoid_persistence.rb',
|
18
18
|
'aasm/persistence/mongoid_persistence.rb',
|
19
|
+
'aasm/persistence/no_brainer_persistence.rb',
|
19
20
|
'aasm/persistence/sequel_persistence.rb',
|
20
21
|
'aasm/persistence/redis_persistence.rb'
|
21
22
|
]
|
data/spec/database.rb
CHANGED
@@ -11,13 +11,23 @@ ActiveRecord::Migration.suppress_messages do
|
|
11
11
|
ActiveRecord::Migration.create_table "multiple_simple_new_dsls", :force => true do |t|
|
12
12
|
t.string "status"
|
13
13
|
end
|
14
|
+
ActiveRecord::Migration.create_table "implemented_abstract_class_dsls", :force => true do |t|
|
15
|
+
t.string "status"
|
16
|
+
end
|
17
|
+
ActiveRecord::Migration.create_table "users", :force => true do |t|
|
18
|
+
t.string "status"
|
19
|
+
end
|
14
20
|
|
15
21
|
ActiveRecord::Migration.create_table "complex_active_record_examples", :force => true do |t|
|
16
22
|
t.string "left"
|
17
23
|
t.string "right"
|
18
24
|
end
|
19
25
|
|
20
|
-
|
26
|
+
ActiveRecord::Migration.create_table "works", :force => true do |t|
|
27
|
+
t.string "status"
|
28
|
+
end
|
29
|
+
|
30
|
+
%w(validators multiple_validators workers invalid_persistors multiple_invalid_persistors silent_persistors multiple_silent_persistors active_record_callbacks).each do |table_name|
|
21
31
|
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
22
32
|
t.string "name"
|
23
33
|
t.string "status"
|
@@ -41,4 +51,9 @@ ActiveRecord::Migration.suppress_messages do
|
|
41
51
|
t.string "search"
|
42
52
|
t.string "sync"
|
43
53
|
end
|
54
|
+
|
55
|
+
ActiveRecord::Migration.create_table "instance_level_skip_validation_examples", :force => true do |t|
|
56
|
+
t.string "state"
|
57
|
+
t.string "some_string"
|
58
|
+
end
|
44
59
|
end
|
data/spec/en.yml
CHANGED
@@ -43,5 +43,11 @@ if defined?(ActiveRecord)
|
|
43
43
|
assert_migration "db/migrate/add_state_to_jobs.rb"
|
44
44
|
end
|
45
45
|
|
46
|
+
it "dont add column if column is already exists" do
|
47
|
+
require 'models/active_record/work.rb'
|
48
|
+
load_schema
|
49
|
+
run_generator %w(work status)
|
50
|
+
assert_no_migration "db/migrate/add_status_to_jobs.rb"
|
51
|
+
end
|
46
52
|
end
|
47
53
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined?(NoBrainer::Document)
|
4
|
+
require 'generator_spec'
|
5
|
+
require 'generators/nobrainer/aasm_generator'
|
6
|
+
|
7
|
+
describe NoBrainer::Generators::AASMGenerator, type: :generator do
|
8
|
+
destination File.expand_path('../../../tmp', __FILE__)
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
prepare_destination
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates model with aasm block for default column_name' do
|
15
|
+
run_generator %w[user]
|
16
|
+
assert_file 'app/models/user.rb', /include AASM\n\n aasm do\n end\n/
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'creates model with aasm block for custom column_name' do
|
20
|
+
run_generator %w[user state]
|
21
|
+
assert_file 'app/models/user.rb', /aasm :column => 'state' do\n end\n/
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'creates model with aasm block for namespaced model' do
|
25
|
+
run_generator %w[Admin::User state]
|
26
|
+
assert_file 'app/models/admin/user.rb', /aasm :column => 'state' do\n end\n/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|