control 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +87 -0
- data/Rakefile +18 -0
- data/control.gemspec +19 -0
- data/db/migrate/create_transitions.rb +18 -0
- data/db/schema.rb +14 -0
- data/lib/control/errors.rb +19 -0
- data/lib/control/state.rb +135 -0
- data/lib/control/transition.rb +53 -0
- data/lib/control/workflow.rb +52 -0
- data/lib/generators/control_install/USAGE +8 -0
- data/lib/generators/control_install/control_install_generator.rb +22 -0
- data/test/lib/control/state_test.rb +80 -0
- data/test/lib/control/transition_test.rb +84 -0
- data/test/lib/control/workflow_test.rb +107 -0
- data/test/rails_app/Gemfile +22 -0
- data/test/rails_app/Gemfile.lock +130 -0
- data/test/rails_app/README.rdoc +261 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/assets/images/rails.png +0 -0
- data/test/rails_app/app/assets/javascripts/application.js +15 -0
- data/test/rails_app/app/assets/javascripts/assemblies.js.coffee +3 -0
- data/test/rails_app/app/assets/javascripts/boxes.js.coffee +3 -0
- data/test/rails_app/app/assets/javascripts/products.js.coffee +3 -0
- data/test/rails_app/app/assets/javascripts/rejects.js.coffee +3 -0
- data/test/rails_app/app/assets/javascripts/validates.js.coffee +3 -0
- data/test/rails_app/app/assets/stylesheets/application.css +13 -0
- data/test/rails_app/app/assets/stylesheets/assemblies.css.scss +3 -0
- data/test/rails_app/app/assets/stylesheets/boxes.css.scss +3 -0
- data/test/rails_app/app/assets/stylesheets/products.css.scss +8 -0
- data/test/rails_app/app/assets/stylesheets/rejects.css.scss +3 -0
- data/test/rails_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/test/rails_app/app/assets/stylesheets/validates.css.scss +3 -0
- data/test/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/rails_app/app/controllers/assemblies_controller.rb +88 -0
- data/test/rails_app/app/controllers/boxes_controller.rb +88 -0
- data/test/rails_app/app/controllers/products_controller.rb +83 -0
- data/test/rails_app/app/controllers/rejects_controller.rb +88 -0
- data/test/rails_app/app/controllers/validates_controller.rb +88 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/helpers/assemblies_helper.rb +2 -0
- data/test/rails_app/app/helpers/boxes_helper.rb +2 -0
- data/test/rails_app/app/helpers/products_helper.rb +14 -0
- data/test/rails_app/app/helpers/rejects_helper.rb +2 -0
- data/test/rails_app/app/helpers/validates_helper.rb +2 -0
- data/test/rails_app/app/models/assembly.rb +6 -0
- data/test/rails_app/app/models/box.rb +5 -0
- data/test/rails_app/app/models/product.rb +8 -0
- data/test/rails_app/app/models/reject.rb +6 -0
- data/test/rails_app/app/models/validate.rb +6 -0
- data/test/rails_app/app/views/assemblies/_form.html.erb +24 -0
- data/test/rails_app/app/views/assemblies/edit.html.erb +6 -0
- data/test/rails_app/app/views/assemblies/index.html.erb +25 -0
- data/test/rails_app/app/views/assemblies/new.html.erb +5 -0
- data/test/rails_app/app/views/assemblies/show.html.erb +14 -0
- data/test/rails_app/app/views/boxes/_form.html.erb +24 -0
- data/test/rails_app/app/views/boxes/edit.html.erb +6 -0
- data/test/rails_app/app/views/boxes/index.html.erb +25 -0
- data/test/rails_app/app/views/boxes/new.html.erb +5 -0
- data/test/rails_app/app/views/boxes/show.html.erb +14 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/app/views/products/_form.html.erb +21 -0
- data/test/rails_app/app/views/products/edit.html.erb +6 -0
- data/test/rails_app/app/views/products/index.html.erb +23 -0
- data/test/rails_app/app/views/products/new.html.erb +5 -0
- data/test/rails_app/app/views/products/show.html.erb +34 -0
- data/test/rails_app/app/views/rejects/_form.html.erb +20 -0
- data/test/rails_app/app/views/rejects/edit.html.erb +6 -0
- data/test/rails_app/app/views/rejects/index.html.erb +23 -0
- data/test/rails_app/app/views/rejects/new.html.erb +5 -0
- data/test/rails_app/app/views/rejects/show.html.erb +9 -0
- data/test/rails_app/app/views/validates/_form.html.erb +40 -0
- data/test/rails_app/app/views/validates/edit.html.erb +6 -0
- data/test/rails_app/app/views/validates/index.html.erb +33 -0
- data/test/rails_app/app/views/validates/new.html.erb +5 -0
- data/test/rails_app/app/views/validates/show.html.erb +35 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +59 -0
- data/test/rails_app/config/boot.rb +6 -0
- data/test/rails_app/config/database.yml +25 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +37 -0
- data/test/rails_app/config/environments/production.rb +67 -0
- data/test/rails_app/config/environments/test.rb +37 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +15 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/rails_app/config/locales/en.yml +5 -0
- data/test/rails_app/config/routes.rb +68 -0
- data/test/rails_app/db/development.sqlite3 +0 -0
- data/test/rails_app/db/migrate/20120126165218_create_products.rb +8 -0
- data/test/rails_app/db/migrate/20120126165821_add_codename_to_products.rb +6 -0
- data/test/rails_app/db/migrate/20120126173019_create_validates.rb +14 -0
- data/test/rails_app/db/migrate/20120126173232_create_assemblies.rb +10 -0
- data/test/rails_app/db/migrate/20120126173516_create_boxes.rb +10 -0
- data/test/rails_app/db/migrate/20120126173539_create_rejects.rb +9 -0
- data/test/rails_app/db/migrate/20120126174101_create_transitions.rb +18 -0
- data/test/rails_app/db/schema.rb +64 -0
- data/test/rails_app/db/seeds.rb +7 -0
- data/test/rails_app/db/test.sqlite3 +0 -0
- data/test/rails_app/doc/README_FOR_APP +2 -0
- data/test/rails_app/log/development.log +8963 -0
- data/test/rails_app/log/test.log +321 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +25 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/public/index.html.old +241 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/rails_app/script/rails +6 -0
- data/test/rails_app/test/fixtures/assemblies.yml +9 -0
- data/test/rails_app/test/fixtures/boxes.yml +9 -0
- data/test/rails_app/test/fixtures/products.yml +11 -0
- data/test/rails_app/test/fixtures/rejects.yml +7 -0
- data/test/rails_app/test/fixtures/validates.yml +17 -0
- data/test/rails_app/test/functional/assemblies_controller_test.rb +49 -0
- data/test/rails_app/test/functional/boxes_controller_test.rb +49 -0
- data/test/rails_app/test/functional/products_controller_test.rb +49 -0
- data/test/rails_app/test/functional/rejects_controller_test.rb +49 -0
- data/test/rails_app/test/functional/validates_controller_test.rb +49 -0
- data/test/rails_app/test/performance/browsing_test.rb +12 -0
- data/test/rails_app/test/test_helper.rb +13 -0
- data/test/rails_app/test/unit/assembly_test.rb +7 -0
- data/test/rails_app/test/unit/box_test.rb +7 -0
- data/test/rails_app/test/unit/helpers/assemblies_helper_test.rb +4 -0
- data/test/rails_app/test/unit/helpers/boxes_helper_test.rb +4 -0
- data/test/rails_app/test/unit/helpers/products_helper_test.rb +4 -0
- data/test/rails_app/test/unit/helpers/rejects_helper_test.rb +4 -0
- data/test/rails_app/test/unit/helpers/validates_helper_test.rb +4 -0
- data/test/rails_app/test/unit/product_test.rb +7 -0
- data/test/rails_app/test/unit/reject_test.rb +7 -0
- data/test/rails_app/test/unit/validate_test.rb +7 -0
- data/test/rails_app/tmp/cache/assets/CD7/6F0/sprockets%2Fbd3936370d0f952ada5774e2230046ed +0 -0
- data/test/rails_app/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/rails_app/tmp/cache/assets/CDF/890/sprockets%2F1380c8a9a90c9434c33ea3a2b759546f +0 -0
- data/test/rails_app/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016 +0 -0
- data/test/rails_app/tmp/cache/assets/CF1/E50/sprockets%2F627ffd39f3642a2a236775d77839fac3 +0 -0
- data/test/rails_app/tmp/cache/assets/CFC/170/sprockets%2F80efc018414af123b11d0c6485e87b1b +0 -0
- data/test/rails_app/tmp/cache/assets/D0B/B40/sprockets%2F2eace11b521905c77d38470c975fa28a +0 -0
- data/test/rails_app/tmp/cache/assets/D13/8E0/sprockets%2F4476d1e237763ebe413a93e0ae559e6b +0 -0
- data/test/rails_app/tmp/cache/assets/D13/E20/sprockets%2F382583b312ba3d6f09b596f6bb63a98b +0 -0
- data/test/rails_app/tmp/cache/assets/D15/750/sprockets%2F4cc25a6e69224dc83fed65a4242479c5 +0 -0
- data/test/rails_app/tmp/cache/assets/D1B/3B0/sprockets%2F0098fc768cb8d9c834fcb13163c85b54 +0 -0
- data/test/rails_app/tmp/cache/assets/D20/C40/sprockets%2F46d84fd895a96b157269bd6b7bae2623 +0 -0
- data/test/rails_app/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/rails_app/tmp/cache/assets/D3F/4A0/sprockets%2Fba62c891c908a4219fb4d2005f886aee +0 -0
- data/test/rails_app/tmp/cache/assets/D45/C10/sprockets%2F29eede3408740d29d159a8367d1abe4e +0 -0
- data/test/rails_app/tmp/cache/assets/D4B/EC0/sprockets%2Fb261fa987a3e88f07b352eba69495e3b +0 -0
- data/test/rails_app/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/rails_app/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/rails_app/tmp/cache/assets/D65/620/sprockets%2Fc821c64ad244b34cd1c92ce6e4844f2a +0 -0
- data/test/rails_app/tmp/cache/assets/D78/F10/sprockets%2Fc81a77308c5e0c2b8efc69bece538149 +0 -0
- data/test/rails_app/tmp/cache/assets/D7B/040/sprockets%2F2ea981ebd7b7a34bd9d75f626f81c526 +0 -0
- data/test/rails_app/tmp/cache/assets/D9C/4A0/sprockets%2Fc15750bf0161f2878cf9da9bb1a84ecb +0 -0
- data/test/rails_app/tmp/cache/assets/DA2/120/sprockets%2Fdfd12e4fb8ce07a2d3c4856974a2f4e3 +0 -0
- data/test/rails_app/tmp/cache/assets/DA9/180/sprockets%2F1eca18f8334b5ce5f73e18d778bc7e3b +0 -0
- data/test/rails_app/tmp/cache/assets/DB4/120/sprockets%2Fc4ad185fad2acc8f1133bb2a80f400d7 +0 -0
- data/test/rails_app/tmp/cache/assets/DD2/B40/sprockets%2Ff8f229b2c6e61975aca38da7a1cb7b8c +0 -0
- data/test/rails_app/tmp/cache/assets/DD5/CF0/sprockets%2Fac6d0c5baedfe70588f57e99b0c4c722 +0 -0
- data/test/rails_app/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/rails_app/tmp/cache/assets/DDD/AE0/sprockets%2F524b597ade6bc1d79c9a4ffd6e3682bd +0 -0
- data/test/rails_app/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/rails_app/tmp/cache/assets/E06/E60/sprockets%2F1afcf29a4e0c835cb47d9bf28cf8a86b +0 -0
- data/test/rails_app/tmp/cache/assets/E19/2A0/sprockets%2F10fcfbe6ebae11a40c8eac41939a1b9a +0 -0
- data/test/rails_app/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6 +0 -0
- data/test/rails_app/tmp/cache/assets/E35/980/sprockets%2Fa5beac77f747ffbc71d32edecf38904a +0 -0
- data/test/rails_app/tmp/cache/sass/0caf4829b2adaabee514492a80140305d59a00b9/assemblies.css.scssc +0 -0
- data/test/rails_app/tmp/cache/sass/0caf4829b2adaabee514492a80140305d59a00b9/boxes.css.scssc +0 -0
- data/test/rails_app/tmp/cache/sass/0caf4829b2adaabee514492a80140305d59a00b9/products.css.scssc +0 -0
- data/test/rails_app/tmp/cache/sass/0caf4829b2adaabee514492a80140305d59a00b9/rejects.css.scssc +0 -0
- data/test/rails_app/tmp/cache/sass/0caf4829b2adaabee514492a80140305d59a00b9/scaffolds.css.scssc +0 -0
- data/test/rails_app/tmp/cache/sass/0caf4829b2adaabee514492a80140305d59a00b9/validates.css.scssc +0 -0
- data/test/test_helper.rb +67 -0
- data/test/test_schema.rb +32 -0
- metadata +210 -1
@@ -0,0 +1,80 @@
|
|
1
|
+
require(File.expand_path(File.join('.','test/test_helper')))
|
2
|
+
|
3
|
+
class StateTest < Test::Unit::TestCase
|
4
|
+
def test_state_can_define_next_states
|
5
|
+
assert Box.respond_to? 'next_states'
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_correct_next_states
|
9
|
+
assert Validate.next_states.include?(Box)
|
10
|
+
assert Validate.next_states.include?(Reject)
|
11
|
+
assert !Validate.next_states.include?(Validate)
|
12
|
+
assert !Validate.next_states.include?(Assembly)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_next_state_is_valid_state
|
16
|
+
InvalidState.next_states :state_that_does_not_exist
|
17
|
+
assert_raise NameError do
|
18
|
+
InvalidState.next_states
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_infer_workflow_to_which_i_belong
|
23
|
+
p = Product.new
|
24
|
+
|
25
|
+
box = Box.new
|
26
|
+
box.product = p
|
27
|
+
|
28
|
+
assert box.workflow
|
29
|
+
assert box.workflow == box.product
|
30
|
+
assert Product == box.workflow.class
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_state_change_complies_with_defined_next_states
|
34
|
+
p = Product.new
|
35
|
+
|
36
|
+
validate = Validate.new
|
37
|
+
validate.product = p
|
38
|
+
validate.save
|
39
|
+
|
40
|
+
assembly = Assembly.new
|
41
|
+
assembly.product = p
|
42
|
+
|
43
|
+
assert_raise Control::InvalidTransition do
|
44
|
+
assembly.save
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_previous_state
|
49
|
+
p = Product.new
|
50
|
+
p.save
|
51
|
+
|
52
|
+
assembly = Assembly.new
|
53
|
+
assembly.product = p
|
54
|
+
assembly.save
|
55
|
+
|
56
|
+
validate = Validate.new
|
57
|
+
validate.product = p
|
58
|
+
validate.save
|
59
|
+
|
60
|
+
assert assembly.previous.nil?
|
61
|
+
assert validate.previous == assembly
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_next_state
|
65
|
+
p = Product.new
|
66
|
+
p.save
|
67
|
+
|
68
|
+
assembly = Assembly.new
|
69
|
+
assembly.product = p
|
70
|
+
assembly.save
|
71
|
+
|
72
|
+
validate = Validate.new
|
73
|
+
validate.product = p
|
74
|
+
validate.save
|
75
|
+
|
76
|
+
assert assembly.next == validate
|
77
|
+
assert validate.next.nil?
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require(File.expand_path(File.join('.','test/test_helper')))
|
2
|
+
|
3
|
+
class TransitionTest < Test::Unit::TestCase
|
4
|
+
def test_after_state_save_transition_must_be_saved
|
5
|
+
p = Product.new
|
6
|
+
p.save
|
7
|
+
|
8
|
+
assert p.transitions.count == 0
|
9
|
+
|
10
|
+
a = Assembly.new
|
11
|
+
a.product = p
|
12
|
+
a.save
|
13
|
+
|
14
|
+
assert p.transitions.count == 1
|
15
|
+
assert p.transitions.first.to_class == Assembly.to_s
|
16
|
+
assert p.transitions.first.created_at < Time.current
|
17
|
+
|
18
|
+
v = Validate.new
|
19
|
+
v.product = p
|
20
|
+
v.save
|
21
|
+
|
22
|
+
assert p.transitions.count == 2
|
23
|
+
assert p.transitions.last.from_class == Assembly.to_s
|
24
|
+
assert p.transitions.last.to_class == Validate.to_s
|
25
|
+
assert p.transitions.first.created_at < p.transitions.last.created_at
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO: Check for correct exception raised, not just valid object
|
29
|
+
def test_correct_class_names
|
30
|
+
t = Control::Transition.new
|
31
|
+
t.workflow_class = Product.to_s
|
32
|
+
t.workflow_id = 1
|
33
|
+
t.from_class = Validate.to_s
|
34
|
+
t.from_id = 1
|
35
|
+
t.to_class = Assembly.to_s
|
36
|
+
t.to_id = 1
|
37
|
+
|
38
|
+
assert t.valid?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_empty_transition
|
42
|
+
t = Control::Transition.new
|
43
|
+
assert !t.valid?
|
44
|
+
end
|
45
|
+
|
46
|
+
# TODO: Check for correct exception raised, not just valid object
|
47
|
+
def test_incorrect_workflow
|
48
|
+
t = Control::Transition.new
|
49
|
+
t.workflow_class = "Prudoct"
|
50
|
+
t.workflow_id = 1
|
51
|
+
t.from_class = Validate.to_s
|
52
|
+
t.from_id = 1
|
53
|
+
t.to_class = Assembly.to_s
|
54
|
+
t.to_id = 1
|
55
|
+
|
56
|
+
assert !t.valid?
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO: Check for correct exception raised, not just valid object
|
60
|
+
def test_incorrect_from
|
61
|
+
t = Control::Transition.new
|
62
|
+
t.workflow_class = Product.to_s
|
63
|
+
t.workflow_id = 1
|
64
|
+
t.from_class = 'Valideta'
|
65
|
+
t.from_id = 1
|
66
|
+
t.to_class = Assembly.to_s
|
67
|
+
t.to_id = 1
|
68
|
+
|
69
|
+
assert !t.valid?
|
70
|
+
end
|
71
|
+
|
72
|
+
# TODO: Check for correct exception raised, not just valid object
|
73
|
+
def test_incorrect_to
|
74
|
+
t = Control::Transition.new
|
75
|
+
t.workflow_class = Product.to_s
|
76
|
+
t.workflow_id = 1
|
77
|
+
t.from_class = Validate.to_s
|
78
|
+
t.from_id = 1
|
79
|
+
t.to_class = 'Assembli'
|
80
|
+
t.to_id = 1
|
81
|
+
|
82
|
+
assert !t.valid?
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require(File.expand_path(File.join('.','test/test_helper')))
|
2
|
+
|
3
|
+
class WorkflowTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_state_belongs_to_workflow
|
6
|
+
p = Product.new
|
7
|
+
p.save
|
8
|
+
|
9
|
+
a = Assembly.new
|
10
|
+
a.product = p
|
11
|
+
|
12
|
+
assert_nothing_raised Control::NoAssociationToWorkflow do
|
13
|
+
a.save
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_state_does_not_belong_to_workflow
|
18
|
+
workflowless_state = WorkflowlessState.new
|
19
|
+
assert_raise Control::NoAssociationToWorkflow do
|
20
|
+
workflowless_state.save
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_state_must_have_workflow_associated
|
25
|
+
|
26
|
+
p = Product.new
|
27
|
+
p.save
|
28
|
+
|
29
|
+
a = Assembly.new
|
30
|
+
|
31
|
+
assert_raise Control::NoAssociationToWorkflow do
|
32
|
+
a.save
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_workflow_is_enabled_by_default
|
38
|
+
assert Product.new.enabled
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_state_list
|
42
|
+
assert Product.new.class.states.count == 4
|
43
|
+
assert Product.new.class.states.include?(Box)
|
44
|
+
assert Product.new.class.states.include?(Assembly)
|
45
|
+
assert Product.new.class.states.include?(Reject)
|
46
|
+
assert Product.new.class.states.include?(Validate)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initially_current_state_is_not_defined
|
50
|
+
assert Product.new.current_state == nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_after_transition_current_state_must_change
|
54
|
+
p = Product.new
|
55
|
+
p.save
|
56
|
+
|
57
|
+
a = Assembly.new
|
58
|
+
a.product = p
|
59
|
+
a.save
|
60
|
+
|
61
|
+
assert p.current_state == a
|
62
|
+
|
63
|
+
v = Validate.new
|
64
|
+
v.product = p
|
65
|
+
v.save
|
66
|
+
|
67
|
+
assert p.current_state == v
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_transition_to_same_state
|
71
|
+
p = Product.new
|
72
|
+
p.save
|
73
|
+
|
74
|
+
b1 = Box.new
|
75
|
+
b1.product = p
|
76
|
+
b1.save
|
77
|
+
|
78
|
+
b2 = Box.new
|
79
|
+
b2.product = p
|
80
|
+
b2.save
|
81
|
+
|
82
|
+
assert p.transitions.count == 2
|
83
|
+
assert p.current_state == b2
|
84
|
+
assert p.current_state.class == p.current_state.previous.class
|
85
|
+
assert p.transitions.last.from_class == p.transitions.last.to_class
|
86
|
+
assert p.transitions.last.from != p.transitions.last.to
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_final_state_means_workflow_blocked
|
90
|
+
p = Product.new
|
91
|
+
p.save
|
92
|
+
|
93
|
+
r = Reject.new
|
94
|
+
r.product = p
|
95
|
+
|
96
|
+
assert_nothing_raised Control::FinalState do
|
97
|
+
r.save
|
98
|
+
end
|
99
|
+
|
100
|
+
a = Assembly.new
|
101
|
+
a.product = p
|
102
|
+
|
103
|
+
assert_raise Control::FinalState do
|
104
|
+
a.save
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails'
|
4
|
+
gem 'sqlite3'
|
5
|
+
|
6
|
+
group :assets do
|
7
|
+
gem 'sass-rails', '~> 3.2.3'
|
8
|
+
gem 'coffee-rails', '~> 3.2.1'
|
9
|
+
|
10
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
11
|
+
gem 'therubyracer'
|
12
|
+
|
13
|
+
gem 'uglifier', '>= 1.0.3'
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'jquery-rails'
|
17
|
+
|
18
|
+
# To use debugger
|
19
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
20
|
+
|
21
|
+
gem 'thin'
|
22
|
+
gem 'control', :path => '../../'
|
@@ -0,0 +1,130 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../../
|
3
|
+
specs:
|
4
|
+
control (0.7.1)
|
5
|
+
activerecord (>= 3.0.0)
|
6
|
+
activesupport (>= 3.0.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (3.2.1)
|
12
|
+
actionpack (= 3.2.1)
|
13
|
+
mail (~> 2.4.0)
|
14
|
+
actionpack (3.2.1)
|
15
|
+
activemodel (= 3.2.1)
|
16
|
+
activesupport (= 3.2.1)
|
17
|
+
builder (~> 3.0.0)
|
18
|
+
erubis (~> 2.7.0)
|
19
|
+
journey (~> 1.0.1)
|
20
|
+
rack (~> 1.4.0)
|
21
|
+
rack-cache (~> 1.1)
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
sprockets (~> 2.1.2)
|
24
|
+
activemodel (3.2.1)
|
25
|
+
activesupport (= 3.2.1)
|
26
|
+
builder (~> 3.0.0)
|
27
|
+
activerecord (3.2.1)
|
28
|
+
activemodel (= 3.2.1)
|
29
|
+
activesupport (= 3.2.1)
|
30
|
+
arel (~> 3.0.0)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.2.1)
|
33
|
+
activemodel (= 3.2.1)
|
34
|
+
activesupport (= 3.2.1)
|
35
|
+
activesupport (3.2.1)
|
36
|
+
i18n (~> 0.6)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
arel (3.0.0)
|
39
|
+
builder (3.0.0)
|
40
|
+
coffee-rails (3.2.2)
|
41
|
+
coffee-script (>= 2.2.0)
|
42
|
+
railties (~> 3.2.0)
|
43
|
+
coffee-script (2.2.0)
|
44
|
+
coffee-script-source
|
45
|
+
execjs
|
46
|
+
coffee-script-source (1.2.0)
|
47
|
+
daemons (1.1.8)
|
48
|
+
erubis (2.7.0)
|
49
|
+
eventmachine (0.12.10)
|
50
|
+
execjs (1.3.0)
|
51
|
+
multi_json (~> 1.0)
|
52
|
+
hike (1.2.1)
|
53
|
+
i18n (0.6.0)
|
54
|
+
journey (1.0.1)
|
55
|
+
jquery-rails (2.0.0)
|
56
|
+
railties (>= 3.2.0.beta, < 5.0)
|
57
|
+
thor (~> 0.14)
|
58
|
+
json (1.6.5)
|
59
|
+
libv8 (3.3.10.4)
|
60
|
+
mail (2.4.1)
|
61
|
+
i18n (>= 0.4.0)
|
62
|
+
mime-types (~> 1.16)
|
63
|
+
treetop (~> 1.4.8)
|
64
|
+
mime-types (1.17.2)
|
65
|
+
multi_json (1.0.4)
|
66
|
+
polyglot (0.3.3)
|
67
|
+
rack (1.4.1)
|
68
|
+
rack-cache (1.1)
|
69
|
+
rack (>= 0.4)
|
70
|
+
rack-ssl (1.3.2)
|
71
|
+
rack
|
72
|
+
rack-test (0.6.1)
|
73
|
+
rack (>= 1.0)
|
74
|
+
rails (3.2.1)
|
75
|
+
actionmailer (= 3.2.1)
|
76
|
+
actionpack (= 3.2.1)
|
77
|
+
activerecord (= 3.2.1)
|
78
|
+
activeresource (= 3.2.1)
|
79
|
+
activesupport (= 3.2.1)
|
80
|
+
bundler (~> 1.0)
|
81
|
+
railties (= 3.2.1)
|
82
|
+
railties (3.2.1)
|
83
|
+
actionpack (= 3.2.1)
|
84
|
+
activesupport (= 3.2.1)
|
85
|
+
rack-ssl (~> 1.3.2)
|
86
|
+
rake (>= 0.8.7)
|
87
|
+
rdoc (~> 3.4)
|
88
|
+
thor (~> 0.14.6)
|
89
|
+
rake (0.9.2.2)
|
90
|
+
rdoc (3.12)
|
91
|
+
json (~> 1.4)
|
92
|
+
sass (3.1.14)
|
93
|
+
sass-rails (3.2.4)
|
94
|
+
railties (~> 3.2.0)
|
95
|
+
sass (>= 3.1.10)
|
96
|
+
tilt (~> 1.3)
|
97
|
+
sprockets (2.1.2)
|
98
|
+
hike (~> 1.2)
|
99
|
+
rack (~> 1.0)
|
100
|
+
tilt (~> 1.1, != 1.3.0)
|
101
|
+
sqlite3 (1.3.5)
|
102
|
+
therubyracer (0.9.9)
|
103
|
+
libv8 (~> 3.3.10)
|
104
|
+
thin (1.3.1)
|
105
|
+
daemons (>= 1.0.9)
|
106
|
+
eventmachine (>= 0.12.6)
|
107
|
+
rack (>= 1.0.0)
|
108
|
+
thor (0.14.6)
|
109
|
+
tilt (1.3.3)
|
110
|
+
treetop (1.4.10)
|
111
|
+
polyglot
|
112
|
+
polyglot (>= 0.3.1)
|
113
|
+
tzinfo (0.3.31)
|
114
|
+
uglifier (1.2.3)
|
115
|
+
execjs (>= 0.3.0)
|
116
|
+
multi_json (>= 1.0.2)
|
117
|
+
|
118
|
+
PLATFORMS
|
119
|
+
ruby
|
120
|
+
|
121
|
+
DEPENDENCIES
|
122
|
+
coffee-rails (~> 3.2.1)
|
123
|
+
control!
|
124
|
+
jquery-rails
|
125
|
+
rails
|
126
|
+
sass-rails (~> 3.2.3)
|
127
|
+
sqlite3
|
128
|
+
therubyracer
|
129
|
+
thin
|
130
|
+
uglifier (>= 1.0.3)
|
@@ -0,0 +1,261 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| |-- images
|
161
|
+
| |-- javascripts
|
162
|
+
| `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| `-- tasks
|
177
|
+
|-- log
|
178
|
+
|-- public
|
179
|
+
|-- script
|
180
|
+
|-- test
|
181
|
+
| |-- fixtures
|
182
|
+
| |-- functional
|
183
|
+
| |-- integration
|
184
|
+
| |-- performance
|
185
|
+
| `-- unit
|
186
|
+
|-- tmp
|
187
|
+
| |-- cache
|
188
|
+
| |-- pids
|
189
|
+
| |-- sessions
|
190
|
+
| `-- sockets
|
191
|
+
`-- vendor
|
192
|
+
|-- assets
|
193
|
+
`-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|