focus-generator 0.0.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.
Files changed (197) hide show
  1. data/Gemfile +2 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +109 -0
  4. data/Rakefile +10 -0
  5. data/features/fcus_authentication.feature +80 -0
  6. data/features/fcus_config.feature +17 -0
  7. data/features/fcus_layout.feature +20 -0
  8. data/features/fcus_scaffold.feature +80 -0
  9. data/features/step_definitions/common_steps.rb +62 -0
  10. data/features/step_definitions/rails_setup_steps.rb +6 -0
  11. data/features/support/env.rb +6 -0
  12. data/features/support/matchers.rb +7 -0
  13. data/lib/generators/fcus.rb +28 -0
  14. data/lib/generators/fcus/authentication/USAGE +50 -0
  15. data/lib/generators/fcus/authentication/authentication_generator.rb +154 -0
  16. data/lib/generators/fcus/authentication/templates/authlogic_session.rb +2 -0
  17. data/lib/generators/fcus/authentication/templates/controller_authentication.rb +60 -0
  18. data/lib/generators/fcus/authentication/templates/fixtures.yml +24 -0
  19. data/lib/generators/fcus/authentication/templates/migration.rb +20 -0
  20. data/lib/generators/fcus/authentication/templates/sessions_controller.rb +41 -0
  21. data/lib/generators/fcus/authentication/templates/sessions_helper.rb +2 -0
  22. data/lib/generators/fcus/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  23. data/lib/generators/fcus/authentication/templates/tests/rspec/user.rb +83 -0
  24. data/lib/generators/fcus/authentication/templates/tests/rspec/users_controller.rb +56 -0
  25. data/lib/generators/fcus/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  26. data/lib/generators/fcus/authentication/templates/tests/shoulda/user.rb +85 -0
  27. data/lib/generators/fcus/authentication/templates/tests/shoulda/users_controller.rb +61 -0
  28. data/lib/generators/fcus/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  29. data/lib/generators/fcus/authentication/templates/tests/testunit/user.rb +88 -0
  30. data/lib/generators/fcus/authentication/templates/tests/testunit/users_controller.rb +53 -0
  31. data/lib/generators/fcus/authentication/templates/user.rb +38 -0
  32. data/lib/generators/fcus/authentication/templates/users_controller.rb +32 -0
  33. data/lib/generators/fcus/authentication/templates/users_helper.rb +2 -0
  34. data/lib/generators/fcus/authentication/templates/views/erb/_form.html.erb +20 -0
  35. data/lib/generators/fcus/authentication/templates/views/erb/edit.html.erb +3 -0
  36. data/lib/generators/fcus/authentication/templates/views/erb/login.html.erb +30 -0
  37. data/lib/generators/fcus/authentication/templates/views/erb/signup.html.erb +5 -0
  38. data/lib/generators/fcus/authentication/templates/views/haml/_form.html.haml +16 -0
  39. data/lib/generators/fcus/authentication/templates/views/haml/edit.html.haml +3 -0
  40. data/lib/generators/fcus/authentication/templates/views/haml/login.html.haml +26 -0
  41. data/lib/generators/fcus/authentication/templates/views/haml/signup.html.haml +5 -0
  42. data/lib/generators/fcus/config/USAGE +23 -0
  43. data/lib/generators/fcus/config/config_generator.rb +24 -0
  44. data/lib/generators/fcus/config/templates/config.yml +8 -0
  45. data/lib/generators/fcus/config/templates/load_config.rb +2 -0
  46. data/lib/generators/fcus/layout/USAGE +25 -0
  47. data/lib/generators/fcus/layout/layout_generator.rb +29 -0
  48. data/lib/generators/fcus/layout/templates/error_messages_helper.rb +23 -0
  49. data/lib/generators/fcus/layout/templates/layout.html.erb +19 -0
  50. data/lib/generators/fcus/layout/templates/layout.html.haml +21 -0
  51. data/lib/generators/fcus/layout/templates/layout_helper.rb +22 -0
  52. data/lib/generators/fcus/layout/templates/stylesheet.css +83 -0
  53. data/lib/generators/fcus/layout/templates/stylesheet.sass +73 -0
  54. data/lib/generators/fcus/scaffold/USAGE +51 -0
  55. data/lib/generators/fcus/scaffold/scaffold_generator.rb +318 -0
  56. data/lib/generators/fcus/scaffold/templates/actions/create.rb +8 -0
  57. data/lib/generators/fcus/scaffold/templates/actions/destroy.rb +5 -0
  58. data/lib/generators/fcus/scaffold/templates/actions/edit.rb +3 -0
  59. data/lib/generators/fcus/scaffold/templates/actions/index.rb +3 -0
  60. data/lib/generators/fcus/scaffold/templates/actions/new.rb +3 -0
  61. data/lib/generators/fcus/scaffold/templates/actions/show.rb +3 -0
  62. data/lib/generators/fcus/scaffold/templates/actions/update.rb +8 -0
  63. data/lib/generators/fcus/scaffold/templates/controller.rb +3 -0
  64. data/lib/generators/fcus/scaffold/templates/fixtures.yml +9 -0
  65. data/lib/generators/fcus/scaffold/templates/helper.rb +2 -0
  66. data/lib/generators/fcus/scaffold/templates/migration.rb +16 -0
  67. data/lib/generators/fcus/scaffold/templates/model.rb +4 -0
  68. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  69. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  70. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  71. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  72. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  73. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  74. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  75. data/lib/generators/fcus/scaffold/templates/tests/rspec/controller.rb +8 -0
  76. data/lib/generators/fcus/scaffold/templates/tests/rspec/model.rb +7 -0
  77. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  78. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  79. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  80. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  81. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  82. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  83. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  84. data/lib/generators/fcus/scaffold/templates/tests/shoulda/controller.rb +5 -0
  85. data/lib/generators/fcus/scaffold/templates/tests/shoulda/model.rb +7 -0
  86. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  87. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  88. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  89. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  90. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  91. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  92. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  93. data/lib/generators/fcus/scaffold/templates/tests/testunit/controller.rb +5 -0
  94. data/lib/generators/fcus/scaffold/templates/tests/testunit/model.rb +7 -0
  95. data/lib/generators/fcus/scaffold/templates/views/erb/_form.html.erb +10 -0
  96. data/lib/generators/fcus/scaffold/templates/views/erb/edit.html.erb +14 -0
  97. data/lib/generators/fcus/scaffold/templates/views/erb/index.html.erb +29 -0
  98. data/lib/generators/fcus/scaffold/templates/views/erb/new.html.erb +7 -0
  99. data/lib/generators/fcus/scaffold/templates/views/erb/show.html.erb +20 -0
  100. data/lib/generators/fcus/scaffold/templates/views/haml/_form.html.haml +9 -0
  101. data/lib/generators/fcus/scaffold/templates/views/haml/edit.html.haml +14 -0
  102. data/lib/generators/fcus/scaffold/templates/views/haml/index.html.haml +25 -0
  103. data/lib/generators/fcus/scaffold/templates/views/haml/new.html.haml +7 -0
  104. data/lib/generators/fcus/scaffold/templates/views/haml/show.html.haml +20 -0
  105. data/rails_generators/fcus_authentication/USAGE +50 -0
  106. data/rails_generators/fcus_authentication/fcus_authentication_generator.rb +128 -0
  107. data/rails_generators/fcus_authentication/lib/insert_commands.rb +74 -0
  108. data/rails_generators/fcus_authentication/templates/authentication.rb +61 -0
  109. data/rails_generators/fcus_authentication/templates/authlogic_session.rb +2 -0
  110. data/rails_generators/fcus_authentication/templates/fixtures.yml +24 -0
  111. data/rails_generators/fcus_authentication/templates/migration.rb +20 -0
  112. data/rails_generators/fcus_authentication/templates/sessions_controller.rb +45 -0
  113. data/rails_generators/fcus_authentication/templates/sessions_helper.rb +2 -0
  114. data/rails_generators/fcus_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  115. data/rails_generators/fcus_authentication/templates/tests/rspec/user.rb +83 -0
  116. data/rails_generators/fcus_authentication/templates/tests/rspec/users_controller.rb +26 -0
  117. data/rails_generators/fcus_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  118. data/rails_generators/fcus_authentication/templates/tests/shoulda/user.rb +85 -0
  119. data/rails_generators/fcus_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  120. data/rails_generators/fcus_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  121. data/rails_generators/fcus_authentication/templates/tests/testunit/user.rb +88 -0
  122. data/rails_generators/fcus_authentication/templates/tests/testunit/users_controller.rb +23 -0
  123. data/rails_generators/fcus_authentication/templates/user.rb +42 -0
  124. data/rails_generators/fcus_authentication/templates/users_controller.rb +18 -0
  125. data/rails_generators/fcus_authentication/templates/users_helper.rb +2 -0
  126. data/rails_generators/fcus_authentication/templates/views/erb/login.html.erb +30 -0
  127. data/rails_generators/fcus_authentication/templates/views/erb/signup.html.erb +24 -0
  128. data/rails_generators/fcus_authentication/templates/views/haml/login.html.haml +30 -0
  129. data/rails_generators/fcus_authentication/templates/views/haml/signup.html.haml +24 -0
  130. data/rails_generators/fcus_config/USAGE +23 -0
  131. data/rails_generators/fcus_config/fcus_config_generator.rb +32 -0
  132. data/rails_generators/fcus_config/templates/config.yml +8 -0
  133. data/rails_generators/fcus_config/templates/load_config.rb +2 -0
  134. data/rails_generators/fcus_layout/USAGE +25 -0
  135. data/rails_generators/fcus_layout/fcus_layout_generator.rb +44 -0
  136. data/rails_generators/fcus_layout/templates/helper.rb +22 -0
  137. data/rails_generators/fcus_layout/templates/layout.html.erb +22 -0
  138. data/rails_generators/fcus_layout/templates/layout.html.haml +19 -0
  139. data/rails_generators/fcus_layout/templates/stylesheet.css +81 -0
  140. data/rails_generators/fcus_layout/templates/stylesheet.sass +67 -0
  141. data/rails_generators/fcus_scaffold/USAGE +51 -0
  142. data/rails_generators/fcus_scaffold/fcus_scaffold_generator.rb +232 -0
  143. data/rails_generators/fcus_scaffold/templates/actions/create.rb +9 -0
  144. data/rails_generators/fcus_scaffold/templates/actions/destroy.rb +6 -0
  145. data/rails_generators/fcus_scaffold/templates/actions/edit.rb +3 -0
  146. data/rails_generators/fcus_scaffold/templates/actions/index.rb +3 -0
  147. data/rails_generators/fcus_scaffold/templates/actions/new.rb +3 -0
  148. data/rails_generators/fcus_scaffold/templates/actions/show.rb +3 -0
  149. data/rails_generators/fcus_scaffold/templates/actions/update.rb +9 -0
  150. data/rails_generators/fcus_scaffold/templates/controller.rb +3 -0
  151. data/rails_generators/fcus_scaffold/templates/fixtures.yml +9 -0
  152. data/rails_generators/fcus_scaffold/templates/helper.rb +2 -0
  153. data/rails_generators/fcus_scaffold/templates/migration.rb +16 -0
  154. data/rails_generators/fcus_scaffold/templates/model.rb +3 -0
  155. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  156. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  157. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  158. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  159. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  160. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  161. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  162. data/rails_generators/fcus_scaffold/templates/tests/rspec/controller.rb +8 -0
  163. data/rails_generators/fcus_scaffold/templates/tests/rspec/model.rb +7 -0
  164. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  165. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  166. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  167. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  168. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  169. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  170. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  171. data/rails_generators/fcus_scaffold/templates/tests/shoulda/controller.rb +5 -0
  172. data/rails_generators/fcus_scaffold/templates/tests/shoulda/model.rb +7 -0
  173. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  174. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  175. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  176. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  177. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  178. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  179. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  180. data/rails_generators/fcus_scaffold/templates/tests/testunit/controller.rb +5 -0
  181. data/rails_generators/fcus_scaffold/templates/tests/testunit/model.rb +7 -0
  182. data/rails_generators/fcus_scaffold/templates/views/erb/_form.html.erb +10 -0
  183. data/rails_generators/fcus_scaffold/templates/views/erb/edit.html.erb +14 -0
  184. data/rails_generators/fcus_scaffold/templates/views/erb/index.html.erb +29 -0
  185. data/rails_generators/fcus_scaffold/templates/views/erb/new.html.erb +7 -0
  186. data/rails_generators/fcus_scaffold/templates/views/erb/show.html.erb +20 -0
  187. data/rails_generators/fcus_scaffold/templates/views/haml/_form.html.haml +10 -0
  188. data/rails_generators/fcus_scaffold/templates/views/haml/edit.html.haml +14 -0
  189. data/rails_generators/fcus_scaffold/templates/views/haml/index.html.haml +25 -0
  190. data/rails_generators/fcus_scaffold/templates/views/haml/new.html.haml +7 -0
  191. data/rails_generators/fcus_scaffold/templates/views/haml/show.html.haml +20 -0
  192. data/test/test_fcus_authentication_generator.rb +274 -0
  193. data/test/test_fcus_config_generator.rb +37 -0
  194. data/test/test_fcus_layout_generator.rb +42 -0
  195. data/test/test_fcus_scaffold_generator.rb +534 -0
  196. data/test/test_helper.rb +119 -0
  197. metadata +314 -0
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+
3
+ class TestFcusConfigGenerator < Test::Unit::TestCase
4
+ include FcusGenerators::TestHelper
5
+
6
+ # Some generator-related assertions:
7
+ # assert_generated_file(name, &block) # block passed the file contents
8
+ # assert_directory_exists(name)
9
+ # assert_generated_class(name, &block)
10
+ # assert_generated_module(name, &block)
11
+ # assert_generated_test_for(name, &block)
12
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
13
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
14
+ #
15
+ # Other helper methods are:
16
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
17
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
18
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
19
+
20
+ context "generator without name" do
21
+ rails_generator :fcus_config
22
+ should_generate_file 'config/app_config.yml'
23
+ should_generate_file 'config/initializers/load_app_config.rb'
24
+ end
25
+
26
+ context "generator with name" do
27
+ rails_generator :fcus_config, "FooBar"
28
+ should_generate_file 'config/foo_bar_config.yml'
29
+
30
+ should "use the name as a constant in the initializer" do
31
+ assert_generated_file 'config/initializers/load_foo_bar_config.rb' do |body|
32
+ assert_match "config/foo_bar_config.yml", body
33
+ assert_match "FOO_BAR_CONFIG = ", body
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+
3
+ class TestFcusLayoutGenerator < Test::Unit::TestCase
4
+ include FcusGenerators::TestHelper
5
+
6
+ # Some generator-related assertions:
7
+ # assert_generated_file(name, &block) # block passed the file contents
8
+ # assert_directory_exists(name)
9
+ # assert_generated_class(name, &block)
10
+ # assert_generated_module(name, &block)
11
+ # assert_generated_test_for(name, &block)
12
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
13
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
14
+ #
15
+ # Other helper methods are:
16
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
17
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
18
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
19
+
20
+ context "generator without name" do
21
+ rails_generator :fcus_layout
22
+ should_generate_file 'app/views/layouts/application.html.erb'
23
+ end
24
+
25
+ context "generator with name" do
26
+ rails_generator :fcus_layout, "foobar"
27
+ should_generate_file 'app/views/layouts/foobar.html.erb'
28
+ should_generate_file 'public/stylesheets/foobar.css'
29
+ should_generate_file 'app/helpers/layout_helper.rb'
30
+ end
31
+
32
+ context "generator with CamelCase name" do
33
+ rails_generator :fcus_layout, "FooBar"
34
+ should_generate_file 'app/views/layouts/foo_bar.html.erb'
35
+ end
36
+
37
+ context "generator with haml option" do
38
+ rails_generator :fcus_layout, "foobar", :haml => true
39
+ should_generate_file 'app/views/layouts/foobar.html.haml'
40
+ should_generate_file 'public/stylesheets/sass/foobar.sass'
41
+ end
42
+ end
@@ -0,0 +1,534 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+
3
+ class TestFcusScaffoldGenerator < Test::Unit::TestCase
4
+ include FcusGenerators::TestHelper
5
+
6
+ # Some generator-related assertions:
7
+ # assert_generated_file(name, &block) # block passed the file contents
8
+ # assert_directory_exists(name)
9
+ # assert_generated_class(name, &block)
10
+ # assert_generated_module(name, &block)
11
+ # assert_generated_test_for(name, &block)
12
+ # The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
13
+ # assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
14
+ #
15
+ # Other helper methods are:
16
+ # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
17
+ # bare_setup - place this in setup method to create the APP_ROOT folder for each test
18
+ # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
19
+
20
+ context "routed" do
21
+ setup do
22
+ Dir.mkdir("#{RAILS_ROOT}/config") unless File.exists?("#{RAILS_ROOT}/config")
23
+ File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f|
24
+ f.puts "ActionController::Routing::Routes.draw do |map|\n\nend"
25
+ end
26
+ end
27
+
28
+ teardown do
29
+ FileUtils.rm_rf "#{RAILS_ROOT}/config"
30
+ end
31
+
32
+ context "generator without name" do
33
+ should "raise usage error" do
34
+ assert_raise Rails::Generator::UsageError do
35
+ run_rails_generator :fcus_scaffold
36
+ end
37
+ end
38
+ end
39
+
40
+ context "generator with no options and no existing model" do
41
+ rails_generator :fcus_scaffold, "LineItem"
42
+
43
+ should_generate_file "app/helpers/line_items_helper.rb"
44
+
45
+ should "generate controller with class as camelcase name pluralized and all actions" do
46
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
47
+ assert_match "class LineItemsController < ApplicationController", body
48
+ %w[index show new create edit update destroy].each do |action|
49
+ assert_match "def #{action}", body
50
+ end
51
+ end
52
+ end
53
+
54
+ %w[index show new edit].each do |action|
55
+ should_generate_file "app/views/line_items/#{action}.html.erb"
56
+ end
57
+
58
+ should "have name attribute" do
59
+ assert_generated_file "app/views/line_items/_form.html.erb" do |body|
60
+ assert_match "<%= f.text_field :name %>", body
61
+ end
62
+ end
63
+
64
+ should "add map.resources line to routes" do
65
+ assert_generated_file "config/routes.rb" do |body|
66
+ assert_match "map.resources :line_items", body
67
+ end
68
+ end
69
+
70
+ should_not_generate_file "app/models/line_item.rb"
71
+ end
72
+
73
+ context "generator with some attributes" do
74
+ rails_generator :fcus_scaffold, "line_item", "name:string", "description:text"
75
+
76
+ should "generate migration with attribute columns" do
77
+ file = Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").first
78
+ assert file, "migration file doesn't exist"
79
+ assert_match(/[0-9]+_create_line_items.rb$/, file)
80
+ assert_generated_file "db/migrate/#{File.basename(file)}" do |body|
81
+ assert_match "class CreateLineItems", body
82
+ assert_match "t.string :name", body
83
+ assert_match "t.text :description", body
84
+ assert_match "t.timestamps", body
85
+ end
86
+ end
87
+
88
+ should "generate model with class as camelcase name and add attr_accessible for attributes" do
89
+ assert_generated_file "app/models/line_item.rb" do |body|
90
+ assert_match "class LineItem < ActiveRecord::Base", body
91
+ assert_match "attr_accessible :name, :description", body
92
+ end
93
+ end
94
+ end
95
+
96
+ context "generator with index action" do
97
+ rails_generator :fcus_scaffold, "line_item", "index"
98
+
99
+ should_generate_file "app/views/line_items/index.html.erb"
100
+
101
+ should "generate controller with index action" do
102
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
103
+ assert_match "def index", body
104
+ assert_match "@line_items = LineItem.all", body
105
+ assert_no_match(/ def index/, body)
106
+ end
107
+ end
108
+ end
109
+
110
+ context "generator with show action" do
111
+ rails_generator :fcus_scaffold, "line_item", "show"
112
+
113
+ should_generate_file "app/views/line_items/show.html.erb"
114
+
115
+ should "generate controller with show action" do
116
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
117
+ assert_match "def show", body
118
+ assert_match "@line_item = LineItem.find(params[:id])", body
119
+ end
120
+ end
121
+ end
122
+
123
+ context "generator with new and create actions" do
124
+ rails_generator :fcus_scaffold, "LineItem", "new", "create"
125
+
126
+ should_not_generate_file "app/views/line_items/create.html.erb"
127
+ should_not_generate_file "app/views/line_items/_form.html.erb"
128
+
129
+ should "render form in 'new' template" do
130
+ assert_generated_file "app/views/line_items/new.html.erb" do |body|
131
+ assert_match "<% form_for @line_item do |f| %>", body
132
+ end
133
+ end
134
+
135
+ should "generate controller with actions" do
136
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
137
+ assert_match "def new", body
138
+ assert_match "@line_item = LineItem.new\n", body
139
+ assert_match "def create", body
140
+ assert_match "@line_item = LineItem.new(params[:line_item])", body
141
+ assert_match "if @line_item.save", body
142
+ assert_match "flash[:notice] = \"Successfully created line item.\"", body
143
+ assert_match "redirect_to root_url", body
144
+ assert_match "render :action => 'new'", body
145
+ end
146
+ end
147
+ end
148
+
149
+ context "generator with edit and update actions" do
150
+ rails_generator :fcus_scaffold, "line_item", "edit", "update"
151
+
152
+ should_not_generate_file "app/views/line_items/update.html.erb"
153
+ should_not_generate_file "app/views/line_items/_form.html.erb"
154
+
155
+ should "render form in 'edit' template" do
156
+ assert_generated_file "app/views/line_items/edit.html.erb" do |body|
157
+ assert_match "<% form_for @line_item do |f| %>", body
158
+ end
159
+ end
160
+
161
+ should "generate controller with actions" do
162
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
163
+ assert_match "def edit", body
164
+ assert_match "@line_item = LineItem.find(params[:id])", body
165
+ assert_match "def update", body
166
+ assert_match "if @line_item.update_attributes(params[:line_item])", body
167
+ assert_match "flash[:notice] = \"Successfully updated line item.\"", body
168
+ assert_match "redirect_to root_url", body
169
+ assert_match "render :action => 'edit'", body
170
+ end
171
+ end
172
+ end
173
+
174
+ context "generator with edit and update actions" do
175
+ rails_generator :fcus_scaffold, "line_item", "destroy"
176
+
177
+ should_not_generate_file "app/views/line_items/destroy.html.erb"
178
+
179
+ should "generate controller with action" do
180
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
181
+ assert_match "def destroy", body
182
+ assert_match "@line_item = LineItem.find(params[:id])", body
183
+ assert_match "@line_item.destroy", body
184
+ assert_match "flash[:notice] = \"Successfully destroyed line item.\"", body
185
+ assert_match "redirect_to root_url", body
186
+ end
187
+ end
188
+ end
189
+
190
+ context "generator with new and edit actions" do
191
+ rails_generator :fcus_scaffold, "line_item", "new", "edit"
192
+
193
+ should_generate_file "app/views/line_items/_form.html.erb"
194
+
195
+ should "render the form partial in views" do
196
+ %w[new edit].each do |action|
197
+ assert_generated_file "app/views/line_items/#{action}.html.erb" do |body|
198
+ assert_match "<%= render :partial => 'form' %>", body
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ context "generator with attributes and actions" do
205
+ rails_generator :fcus_scaffold, "line_item", "name:string", "new", "price:float", "index", "available:boolean"
206
+
207
+ should "render a form field for each attribute in 'new' template" do
208
+ assert_generated_file "app/views/line_items/new.html.erb" do |body|
209
+ assert_match "<%= f.text_field :name %>", body
210
+ assert_match "<%= f.text_field :price %>", body
211
+ assert_match "<%= f.check_box :available %>", body
212
+ end
213
+ end
214
+ end
215
+
216
+ context "generator with show, create, and update actions" do
217
+ rails_generator :fcus_scaffold, "line_item", "show", "create", "update"
218
+
219
+ should "redirect to line item show page, not index" do
220
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
221
+ assert_match "redirect_to @line_item", body
222
+ assert_no_match(/redirect_to line_items_url/, body)
223
+ end
224
+ end
225
+ end
226
+
227
+ context "generator with attributes and skip model option" do
228
+ rails_generator :fcus_scaffold, "line_item", "foo:string", :skip_model => true
229
+
230
+ should "use passed attribute" do
231
+ assert_generated_file "app/views/line_items/_form.html.erb" do |body|
232
+ assert_match "<%= f.text_field :foo %>", body
233
+ end
234
+ end
235
+
236
+ should "not generate migration file" do
237
+ assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
238
+ end
239
+
240
+ should_not_generate_file "app/models/line_item.rb"
241
+ end
242
+
243
+ context "generator with no attributes" do
244
+ rails_generator :fcus_scaffold, "line_item"
245
+
246
+ should "not generate migration file" do
247
+ assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
248
+ end
249
+
250
+ should_not_generate_file "app/models/line_item.rb"
251
+ end
252
+
253
+ context "generator with only new and edit actions" do
254
+ rails_generator :fcus_scaffold, "line_item", "new", "edit"
255
+
256
+ should "included create and update actions in controller" do
257
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
258
+ assert_match "def create", body
259
+ assert_match "def update", body
260
+ assert_match "root_url", body
261
+ end
262
+ end
263
+ end
264
+
265
+ context "generator with exclemation mark and show, new, and edit actions" do
266
+ rails_generator :fcus_scaffold, "line_item", "!", "show", "new", "edit"
267
+
268
+ should "only include index and destroy actions" do
269
+ assert_generated_file "app/controllers/line_items_controller.rb" do |body|
270
+ %w[index destroy].each { |a| assert_match "def #{a}", body }
271
+ %w[show new create edit update].each do |a|
272
+ assert_no_match(/def #{a}/, body)
273
+ end
274
+ end
275
+ end
276
+ end
277
+
278
+ context "generator with --skip-controller" do
279
+ rails_generator :fcus_scaffold, "line_item", :skip_controller => true
280
+ should_not_generate_file "app/controllers/line_items_controller.rb"
281
+ should_not_generate_file "app/helpers/line_items_helper.rb"
282
+ should_not_generate_file "app/views/line_items/index.html.erb"
283
+ end
284
+
285
+ context "generator with --skip-migration" do
286
+ rails_generator :fcus_scaffold, "line_item", "name:string", :skip_migration => true
287
+
288
+ should "not generate migration file" do
289
+ assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
290
+ end
291
+ end
292
+
293
+ context "generator with --skip-timestamps" do
294
+ rails_generator :fcus_scaffold, "line_item", "name:string", :skip_timestamps => true
295
+
296
+ should "generate migration with no timestamps" do
297
+ file = Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").first
298
+ assert file, "migration file doesn't exist"
299
+ assert_generated_file "db/migrate/#{File.basename(file)}" do |body|
300
+ assert_no_match(/t.timestamps/, body)
301
+ end
302
+ end
303
+ end
304
+
305
+ context "existing model" do
306
+ setup do
307
+ Dir.mkdir("#{RAILS_ROOT}/app") unless File.exists?("#{RAILS_ROOT}/app")
308
+ Dir.mkdir("#{RAILS_ROOT}/app/models") unless File.exists?("#{RAILS_ROOT}/app/models")
309
+ File.open("#{RAILS_ROOT}/app/models/recipe.rb", 'w') do |f|
310
+ f.puts "raise 'should not be loaded'"
311
+ end
312
+ end
313
+
314
+ teardown do
315
+ FileUtils.rm_rf "#{RAILS_ROOT}/app"
316
+ end
317
+
318
+ context "generator with skip model option" do
319
+ rails_generator :fcus_scaffold, "recipe", :skip_model => true
320
+
321
+ should "use model columns for attributes" do
322
+ assert_generated_file "app/views/recipes/_form.html.erb" do |body|
323
+ assert_match "<%= f.text_field :foo %>", body
324
+ assert_match "<%= f.text_field :bar %>", body
325
+ assert_match "<%= f.text_field :book_id %>", body
326
+ assert_no_match(/:id/, body)
327
+ assert_no_match(/:created_at/, body)
328
+ assert_no_match(/:updated_at/, body)
329
+ end
330
+ end
331
+
332
+ should "not generate migration file" do
333
+ assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
334
+ end
335
+ end
336
+
337
+ context "generator with attribute specified" do
338
+ rails_generator :fcus_scaffold, "recipe", "zippo:string"
339
+
340
+ should "use specified attribute" do
341
+ assert_generated_file "app/views/recipes/_form.html.erb" do |body|
342
+ assert_match "<%= f.text_field :zippo %>", body
343
+ end
344
+ end
345
+ end
346
+ end
347
+
348
+ context "with spec dir" do
349
+ setup do
350
+ Dir.mkdir("#{RAILS_ROOT}/spec") unless File.exists?("#{RAILS_ROOT}/spec")
351
+ end
352
+
353
+ teardown do
354
+ FileUtils.rm_rf "#{RAILS_ROOT}/spec"
355
+ end
356
+
357
+ context "generator with some attributes" do
358
+ rails_generator :fcus_scaffold, "line_item", "name:string", "description:text"
359
+
360
+ should_generate_file "spec/models/line_item_spec.rb"
361
+
362
+ should "have controller specs for each action" do
363
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
364
+ assert_match "get :index", body
365
+ assert_match "get :show", body
366
+ assert_match "get :new", body
367
+ assert_match "get :edit", body
368
+ assert_match "post :create", body
369
+ assert_match "put :update", body
370
+ assert_match "delete :destroy", body
371
+ end
372
+ end
373
+
374
+ should "have fixture with attributes" do
375
+ assert_generated_file "spec/fixtures/line_items.yml" do |body|
376
+ assert_match "name: MyString", body
377
+ assert_match "description: MyText", body
378
+ end
379
+ end
380
+ end
381
+
382
+ context "generator with new and index actions" do
383
+ rails_generator :fcus_scaffold, "line_item", "new", "index"
384
+
385
+ should "have controller spec with only mentioned actions" do
386
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
387
+ assert_match "get :index", body
388
+ assert_match "get :new", body
389
+ assert_match "post :create", body
390
+ assert_no_match(/get :show/, body)
391
+ assert_no_match(/get :edit/, body)
392
+ assert_no_match(/put :update/, body)
393
+ assert_no_match(/delete :destroy/, body)
394
+ end
395
+ end
396
+
397
+ should "redirect to index action on successful create" do
398
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
399
+ assert_match "redirect_to(line_items_url)", body
400
+ end
401
+ end
402
+ end
403
+
404
+ context "generator with edit and index actions" do
405
+ rails_generator :fcus_scaffold, "line_item", "edit", "index"
406
+
407
+ should "redirect to index action on successful update" do
408
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
409
+ assert_match "redirect_to(line_items_url)", body
410
+ end
411
+ end
412
+ end
413
+
414
+ context "generator with testunit specified" do
415
+ rails_generator :fcus_scaffold, "line_item", "name:string", :test_framework => :testunit
416
+
417
+ should_generate_file "test/unit/line_item_test.rb"
418
+ end
419
+ end
420
+
421
+ context "with test dir" do
422
+ setup do
423
+ Dir.mkdir("#{RAILS_ROOT}/test") unless File.exists?("#{RAILS_ROOT}/test")
424
+ end
425
+
426
+ teardown do
427
+ FileUtils.rm_rf "#{RAILS_ROOT}/test"
428
+ end
429
+
430
+ context "generator with some attributes" do
431
+ rails_generator :fcus_scaffold, "line_item", "name:string", "description:text"
432
+
433
+ should_generate_file "test/unit/line_item_test.rb"
434
+
435
+ should "have controller tests for each action" do
436
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
437
+ assert_match "get :index", body
438
+ assert_match "get :show", body
439
+ assert_match "get :new", body
440
+ assert_match "get :edit", body
441
+ assert_match "post :create", body
442
+ assert_match "put :update", body
443
+ assert_match "delete :destroy", body
444
+ end
445
+ end
446
+
447
+ should "have fixture with attributes" do
448
+ assert_generated_file "test/fixtures/line_items.yml" do |body|
449
+ assert_match "name: MyString", body
450
+ assert_match "description: MyText", body
451
+ end
452
+ end
453
+ end
454
+
455
+ context "generator with new and index actions" do
456
+ rails_generator :fcus_scaffold, "line_item", "new", "index"
457
+
458
+ should "have controller test with only mentioned actions" do
459
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
460
+ assert_match "get :index", body
461
+ assert_match "get :new", body
462
+ assert_match "post :create", body
463
+ assert_no_match(/get :show/, body)
464
+ assert_no_match(/get :edit/, body)
465
+ assert_no_match(/put :update/, body)
466
+ assert_no_match(/delete :destroy/, body)
467
+ end
468
+ end
469
+
470
+ should "redirect to index action on successful create" do
471
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
472
+ assert_match "assert_redirected_to line_items_url", body
473
+ end
474
+ end
475
+ end
476
+
477
+ context "generator with edit and index actions" do
478
+ rails_generator :fcus_scaffold, "line_item", "edit", "index"
479
+
480
+ should "redirect to index action on successful update" do
481
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
482
+ assert_match "assert_redirected_to line_items_url", body
483
+ end
484
+ end
485
+ end
486
+
487
+ context "generator with rspec specified" do
488
+ rails_generator :fcus_scaffold, "line_item", "name:string", :test_framework => :rspec
489
+
490
+ should_generate_file "spec/models/line_item_spec.rb"
491
+ end
492
+
493
+ context "generator with shoulda specified" do
494
+ rails_generator :fcus_scaffold, "line_item", "name:string", :test_framework => :shoulda
495
+
496
+ should "have controller and model tests using shoulda syntax" do
497
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
498
+ assert_match " should ", body
499
+ end
500
+
501
+ assert_generated_file "test/unit/line_item_test.rb" do |body|
502
+ assert_match " should ", body
503
+ end
504
+ end
505
+ end
506
+ end
507
+
508
+ context "generator with haml option" do
509
+ rails_generator :fcus_scaffold, "LineItem", :haml => true
510
+
511
+ %w[index show new edit _form].each do |action|
512
+ should_generate_file "app/views/line_items/#{action}.html.haml"
513
+ end
514
+
515
+ should "render the form partial in views" do
516
+ %w[new edit].each do |action|
517
+ assert_generated_file "app/views/line_items/#{action}.html.haml" do |body|
518
+ assert_match /^= render :partial => 'form'$/, body
519
+ end
520
+ end
521
+ end
522
+ end
523
+ end
524
+ end
525
+
526
+ # just an example model we can use
527
+ class Recipe < ActiveRecord::Base
528
+ add_column :id, :integer
529
+ add_column :foo, :string
530
+ add_column :bar, :string
531
+ add_column :book_id, :integer
532
+ add_column :created_at, :datetime
533
+ add_column :updated_at, :datetime
534
+ end