nifty-generators 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +11 -0
  2. data/README.rdoc +2 -2
  3. data/features/nifty_authentication.feature +2 -2
  4. data/features/nifty_scaffold.feature +15 -0
  5. data/features/step_definitions/common_steps.rb +1 -1
  6. data/features/step_definitions/rails_setup_steps.rb +1 -1
  7. data/lib/generators/nifty.rb +2 -2
  8. data/lib/generators/nifty/authentication/USAGE +15 -15
  9. data/lib/generators/nifty/authentication/authentication_generator.rb +10 -9
  10. data/lib/generators/nifty/authentication/templates/authentication.rb +9 -9
  11. data/lib/generators/nifty/authentication/templates/migration.rb +1 -1
  12. data/lib/generators/nifty/authentication/templates/sessions_controller.rb +4 -4
  13. data/lib/generators/nifty/authentication/templates/tests/rspec/sessions_controller.rb +6 -6
  14. data/lib/generators/nifty/authentication/templates/tests/rspec/user.rb +15 -15
  15. data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +5 -5
  16. data/lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
  17. data/lib/generators/nifty/authentication/templates/tests/shoulda/user.rb +15 -15
  18. data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +2 -2
  19. data/lib/generators/nifty/authentication/templates/tests/testunit/sessions_controller.rb +3 -3
  20. data/lib/generators/nifty/authentication/templates/tests/testunit/user.rb +15 -15
  21. data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +2 -2
  22. data/lib/generators/nifty/authentication/templates/user.rb +7 -7
  23. data/lib/generators/nifty/authentication/templates/users_controller.rb +1 -1
  24. data/lib/generators/nifty/config/USAGE +2 -2
  25. data/lib/generators/nifty/config/config_generator.rb +3 -3
  26. data/lib/generators/nifty/layout/USAGE +2 -2
  27. data/lib/generators/nifty/layout/layout_generator.rb +4 -4
  28. data/lib/generators/nifty/layout/templates/error_messages_helper.rb +2 -2
  29. data/lib/generators/nifty/layout/templates/layout.html.erb +1 -1
  30. data/lib/generators/nifty/layout/templates/layout.html.haml +4 -4
  31. data/lib/generators/nifty/layout/templates/layout_helper.rb +3 -3
  32. data/lib/generators/nifty/layout/templates/stylesheet.sass +41 -41
  33. data/lib/generators/nifty/scaffold/USAGE +9 -9
  34. data/lib/generators/nifty/scaffold/scaffold_generator.rb +8 -6
  35. data/lib/generators/nifty/scaffold/templates/migration.rb +1 -1
  36. data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +1 -1
  37. data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +1 -1
  38. data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +3 -3
  39. data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  40. data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  41. data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +1 -1
  42. data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +1 -1
  43. data/rails_generators/nifty_authentication/USAGE +15 -15
  44. data/rails_generators/nifty_authentication/lib/insert_commands.rb +8 -8
  45. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +20 -20
  46. data/rails_generators/nifty_authentication/templates/authentication.rb +9 -9
  47. data/rails_generators/nifty_authentication/templates/migration.rb +1 -1
  48. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +4 -4
  49. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +5 -5
  50. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +15 -15
  51. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +4 -4
  52. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
  53. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +15 -15
  54. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +2 -2
  55. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +3 -3
  56. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +15 -15
  57. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +2 -2
  58. data/rails_generators/nifty_authentication/templates/user.rb +7 -7
  59. data/rails_generators/nifty_authentication/templates/users_controller.rb +1 -1
  60. data/rails_generators/nifty_config/USAGE +2 -2
  61. data/rails_generators/nifty_config/nifty_config_generator.rb +3 -3
  62. data/rails_generators/nifty_layout/USAGE +2 -2
  63. data/rails_generators/nifty_layout/nifty_layout_generator.rb +3 -3
  64. data/rails_generators/nifty_layout/templates/helper.rb +3 -3
  65. data/rails_generators/nifty_layout/templates/layout.html.erb +2 -2
  66. data/rails_generators/nifty_layout/templates/layout.html.haml +4 -4
  67. data/rails_generators/nifty_scaffold/USAGE +9 -9
  68. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +38 -38
  69. data/rails_generators/nifty_scaffold/templates/migration.rb +1 -1
  70. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +1 -1
  71. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +1 -1
  72. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +2 -2
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  75. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +1 -1
  76. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +1 -1
  77. data/test/test_helper.rb +7 -7
  78. data/test/test_nifty_authentication_generator.rb +30 -30
  79. data/test/test_nifty_config_generator.rb +4 -4
  80. data/test/test_nifty_layout_generator.rb +5 -5
  81. data/test/test_nifty_scaffold_generator.rb +93 -93
  82. metadata +6 -4
@@ -9,7 +9,7 @@ class Create<%= plural_class_name %> < ActiveRecord::Migration
9
9
  <%- end -%>
10
10
  end
11
11
  end
12
-
12
+
13
13
  def self.down
14
14
  drop_table :<%= plural_name %>
15
15
  end
@@ -3,7 +3,7 @@
3
3
  post :create
4
4
  response.should render_template(:new)
5
5
  end
6
-
6
+
7
7
  it "create action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  post :create
@@ -3,7 +3,7 @@
3
3
  put :update, :id => <%= class_name %>.first
4
4
  response.should render_template(:edit)
5
5
  end
6
-
6
+
7
7
  it "update action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  put :update, :id => <%= class_name %>.first
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+
3
3
  describe <%= plural_class_name %>Controller do
4
4
  fixtures :all
5
5
  integrate_views
6
-
6
+
7
7
  <%= controller_methods 'tests/rspec/actions' %>
8
8
  end
@@ -4,7 +4,7 @@
4
4
  post :create
5
5
  assert_template 'new'
6
6
  end
7
-
7
+
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
10
  post :create
@@ -4,7 +4,7 @@
4
4
  put :update, :id => <%= class_name %>.first
5
5
  assert_template 'edit'
6
6
  end
7
-
7
+
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
10
  put :update, :id => <%= class_name %>.first
@@ -3,7 +3,7 @@
3
3
  post :create
4
4
  assert_template 'new'
5
5
  end
6
-
6
+
7
7
  def test_create_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  post :create
@@ -3,7 +3,7 @@
3
3
  put :update, :id => <%= class_name %>.first
4
4
  assert_template 'edit'
5
5
  end
6
-
6
+
7
7
  def test_update_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  put :update, :id => <%= class_name %>.first
@@ -28,7 +28,7 @@ require 'mocha'
28
28
  module NiftyGenerators
29
29
  module TestHelper
30
30
  include RubiGen::GeneratorTestHelper
31
-
31
+
32
32
  def setup
33
33
  bare_setup
34
34
  end
@@ -36,34 +36,34 @@ module NiftyGenerators
36
36
  def teardown
37
37
  bare_teardown
38
38
  end
39
-
39
+
40
40
  protected
41
-
41
+
42
42
  def run_rails_generator(generator, *args)
43
43
  options = args.pop if args.last.kind_of? Hash
44
44
  options ||= {}
45
45
  run_generator(generator.to_s, args, generator_sources, options.reverse_merge(:quiet => true))
46
46
  end
47
-
47
+
48
48
  def generator_sources
49
49
  [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__), "..", "rails_generators"))]
50
50
  end
51
51
  end
52
-
52
+
53
53
  module ShouldaAdditions
54
54
  def rails_generator(*args)
55
55
  setup do
56
56
  run_rails_generator(*args)
57
57
  end
58
58
  end
59
-
59
+
60
60
  def should_generate_file(file, &block)
61
61
  should "generate file #{file}" do
62
62
  yield("foo") if block_given?
63
63
  assert_generated_file(file)
64
64
  end
65
65
  end
66
-
66
+
67
67
  def should_not_generate_file(file)
68
68
  should "not generate file #{file}" do
69
69
  assert !File.exists?("#{APP_ROOT}/#{file}"),"The file '#{file}' should not exist"
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
2
 
3
3
  class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
4
4
  include NiftyGenerators::TestHelper
5
-
5
+
6
6
  # Some generator-related assertions:
7
7
  # assert_generated_file(name, &block) # block passed the file contents
8
8
  # assert_directory_exists(name)
@@ -29,7 +29,7 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
29
29
  f.puts "class Application < ActionController::Base\n\nend"
30
30
  end
31
31
  end
32
-
32
+
33
33
  teardown do
34
34
  FileUtils.rm_rf "#{RAILS_ROOT}/config"
35
35
  FileUtils.rm_rf "#{RAILS_ROOT}/app"
@@ -49,11 +49,11 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
49
49
  should_generate_file 'test/unit/user_test.rb'
50
50
  should_generate_file 'test/functional/users_controller_test.rb'
51
51
  should_generate_file 'test/functional/sessions_controller_test.rb'
52
-
52
+
53
53
  should "generate migration file" do
54
54
  assert !Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
55
55
  end
56
-
56
+
57
57
  should "generate routes" do
58
58
  assert_generated_file "config/routes.rb" do |body|
59
59
  assert_match "map.resources :sessions", body
@@ -63,7 +63,7 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
63
63
  assert_match "map.signup 'signup', :controller => 'users', :action => 'new'", body
64
64
  end
65
65
  end
66
-
66
+
67
67
  should "include Authentication" do
68
68
  application_controller_name = Rails.version >= '2.3.0' ? 'application_controller' : 'application'
69
69
  assert_generated_file "app/controllers/#{application_controller_name}.rb" do |body|
@@ -85,7 +85,7 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
85
85
  should_generate_file 'test/unit/account_test.rb'
86
86
  should_generate_file 'test/functional/accounts_controller_test.rb'
87
87
  should_generate_file 'test/functional/current_sessions_controller_test.rb'
88
-
88
+
89
89
  should "generate routes" do
90
90
  assert_generated_file "config/routes.rb" do |body|
91
91
  assert_match "map.resources :current_sessions", body
@@ -96,10 +96,10 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
96
96
  end
97
97
  end
98
98
  end
99
-
99
+
100
100
  context "generator with shoulda option" do
101
101
  rails_generator :nifty_authentication, :test_framework => :shoulda
102
-
102
+
103
103
  should "have controller and model tests using shoulda syntax" do
104
104
  assert_generated_file "test/functional/users_controller_test.rb" do |body|
105
105
  assert_match " should ", body
@@ -107,27 +107,27 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
107
107
  assert_generated_file "test/functional/sessions_controller_test.rb" do |body|
108
108
  assert_match " should ", body
109
109
  end
110
-
110
+
111
111
  assert_generated_file "test/unit/user_test.rb" do |body|
112
112
  assert_match " should ", body
113
113
  end
114
114
  end
115
115
  end
116
-
116
+
117
117
  context "generator with rspec option" do
118
118
  rails_generator :nifty_authentication, :test_framework => :rspec
119
119
  should_generate_file 'spec/fixtures/users.yml'
120
120
  end
121
-
121
+
122
122
  context "with spec dir" do
123
123
  setup do
124
124
  Dir.mkdir("#{RAILS_ROOT}/spec") unless File.exists?("#{RAILS_ROOT}/spec")
125
125
  end
126
-
126
+
127
127
  teardown do
128
128
  FileUtils.rm_rf "#{RAILS_ROOT}/spec"
129
129
  end
130
-
130
+
131
131
  context "generator without arguments" do
132
132
  rails_generator :nifty_authentication
133
133
  should_generate_file 'spec/fixtures/users.yml'
@@ -135,7 +135,7 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
135
135
  should_generate_file 'spec/controllers/users_controller_spec.rb'
136
136
  should_generate_file 'spec/controllers/sessions_controller_spec.rb'
137
137
  end
138
-
138
+
139
139
  context "generator with user and session names" do
140
140
  rails_generator :nifty_authentication, "Account", "CurrentSessions"
141
141
  should_generate_file 'spec/fixtures/accounts.yml'
@@ -143,16 +143,16 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
143
143
  should_generate_file 'spec/controllers/accounts_controller_spec.rb'
144
144
  should_generate_file 'spec/controllers/current_sessions_controller_spec.rb'
145
145
  end
146
-
146
+
147
147
  context "generator with testunit option" do
148
148
  rails_generator :nifty_authentication, :test_framework => :testunit
149
149
  should_generate_file 'test/fixtures/users.yml'
150
150
  end
151
151
  end
152
-
152
+
153
153
  context "generator with haml option" do
154
154
  rails_generator :nifty_authentication, :haml => true
155
-
155
+
156
156
  should_generate_file "app/views/users/new.html.haml"
157
157
  should_generate_file "app/views/sessions/new.html.haml"
158
158
  end
@@ -171,7 +171,7 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
171
171
  should_generate_file 'test/functional/accounts_controller_test.rb'
172
172
  should_generate_file 'test/functional/account_sessions_controller_test.rb'
173
173
  should_generate_file 'lib/authentication.rb'
174
-
174
+
175
175
  should "only include acts_as_authentic in account model" do
176
176
  assert_generated_file "app/models/account.rb" do |body|
177
177
  assert_match "acts_as_authentic", body
@@ -179,43 +179,43 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
179
179
  assert_no_match(/def/, body)
180
180
  end
181
181
  end
182
-
182
+
183
183
  should "should generate authentication module with current_account_session method" do
184
184
  assert_generated_file "lib/authentication.rb" do |body|
185
185
  assert_match "def current_account_session", body
186
186
  end
187
187
  end
188
-
188
+
189
189
  should "should generate AccountSession model" do
190
190
  assert_generated_file "app/models/account_session.rb" do |body|
191
191
  assert_match "class AccountSession < Authlogic::Session::Base", body
192
192
  end
193
193
  end
194
-
194
+
195
195
  should "should generate restful style actions in sessions controller" do
196
196
  assert_generated_file "app/controllers/account_sessions_controller.rb" do |body|
197
197
  assert_match "AccountSession.new", body
198
198
  end
199
199
  end
200
-
200
+
201
201
  should "should generate form for account session" do
202
202
  assert_generated_file "app/views/account_sessions/new.html.erb" do |body|
203
203
  assert_match "form_for @account_session", body
204
204
  end
205
205
  end
206
-
206
+
207
207
  should "should not include tests in account since authlogic is already tested" do
208
208
  assert_generated_file "test/unit/account_test.rb" do |body|
209
209
  assert_no_match(/def test/, body)
210
210
  end
211
211
  end
212
-
212
+
213
213
  should "should handle session controller tests differently" do
214
214
  assert_generated_file "test/functional/account_sessions_controller_test.rb" do |body|
215
215
  assert_match "AccountSession.find", body
216
216
  end
217
217
  end
218
-
218
+
219
219
  should "generate migration with authlogic columns" do
220
220
  file = Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").first
221
221
  assert file, "migration file doesn't exist"
@@ -239,31 +239,31 @@ class TestNiftyAuthenticationGenerator < Test::Unit::TestCase
239
239
  should_generate_file 'app/helpers/user_sessions_helper.rb'
240
240
  should_generate_file 'app/views/user_sessions/new.html.erb'
241
241
  should_generate_file 'test/functional/user_sessions_controller_test.rb'
242
-
242
+
243
243
  should "should generate authentication module with current_user_session method" do
244
244
  assert_generated_file "lib/authentication.rb" do |body|
245
245
  assert_match "def current_user_session", body
246
246
  end
247
247
  end
248
-
248
+
249
249
  should "should generate UserSession model" do
250
250
  assert_generated_file "app/models/user_session.rb" do |body|
251
251
  assert_match "class UserSession < Authlogic::Session::Base", body
252
252
  end
253
253
  end
254
-
254
+
255
255
  should "should generate restful style actions in sessions controller" do
256
256
  assert_generated_file "app/controllers/user_sessions_controller.rb" do |body|
257
257
  assert_match "UserSession.new", body
258
258
  end
259
259
  end
260
-
260
+
261
261
  should "should generate form for user session" do
262
262
  assert_generated_file "app/views/user_sessions/new.html.erb" do |body|
263
263
  assert_match "form_for @user_session", body
264
264
  end
265
265
  end
266
-
266
+
267
267
  should "should handle session controller tests differently" do
268
268
  assert_generated_file "test/functional/user_sessions_controller_test.rb" do |body|
269
269
  assert_match "UserSession.find", body
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
2
 
3
3
  class TestNiftyConfigGenerator < Test::Unit::TestCase
4
4
  include NiftyGenerators::TestHelper
5
-
5
+
6
6
  # Some generator-related assertions:
7
7
  # assert_generated_file(name, &block) # block passed the file contents
8
8
  # assert_directory_exists(name)
@@ -16,17 +16,17 @@ class TestNiftyConfigGenerator < Test::Unit::TestCase
16
16
  # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
17
17
  # bare_setup - place this in setup method to create the APP_ROOT folder for each test
18
18
  # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
19
-
19
+
20
20
  context "generator without name" do
21
21
  rails_generator :nifty_config
22
22
  should_generate_file 'config/app_config.yml'
23
23
  should_generate_file 'config/initializers/load_app_config.rb'
24
24
  end
25
-
25
+
26
26
  context "generator with name" do
27
27
  rails_generator :nifty_config, "FooBar"
28
28
  should_generate_file 'config/foo_bar_config.yml'
29
-
29
+
30
30
  should "use the name as a constant in the initializer" do
31
31
  assert_generated_file 'config/initializers/load_foo_bar_config.rb' do |body|
32
32
  assert_match "config/foo_bar_config.yml", body
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
2
 
3
3
  class TestNiftyLayoutGenerator < Test::Unit::TestCase
4
4
  include NiftyGenerators::TestHelper
5
-
5
+
6
6
  # Some generator-related assertions:
7
7
  # assert_generated_file(name, &block) # block passed the file contents
8
8
  # assert_directory_exists(name)
@@ -16,24 +16,24 @@ class TestNiftyLayoutGenerator < Test::Unit::TestCase
16
16
  # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
17
17
  # bare_setup - place this in setup method to create the APP_ROOT folder for each test
18
18
  # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
19
-
19
+
20
20
  context "generator without name" do
21
21
  rails_generator :nifty_layout
22
22
  should_generate_file 'app/views/layouts/application.html.erb'
23
23
  end
24
-
24
+
25
25
  context "generator with name" do
26
26
  rails_generator :nifty_layout, "foobar"
27
27
  should_generate_file 'app/views/layouts/foobar.html.erb'
28
28
  should_generate_file 'public/stylesheets/foobar.css'
29
29
  should_generate_file 'app/helpers/layout_helper.rb'
30
30
  end
31
-
31
+
32
32
  context "generator with CamelCase name" do
33
33
  rails_generator :nifty_layout, "FooBar"
34
34
  should_generate_file 'app/views/layouts/foo_bar.html.erb'
35
35
  end
36
-
36
+
37
37
  context "generator with haml option" do
38
38
  rails_generator :nifty_layout, "foobar", :haml => true
39
39
  should_generate_file 'app/views/layouts/foobar.html.haml'
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
2
 
3
3
  class TestNiftyScaffoldGenerator < Test::Unit::TestCase
4
4
  include NiftyGenerators::TestHelper
5
-
5
+
6
6
  # Some generator-related assertions:
7
7
  # assert_generated_file(name, &block) # block passed the file contents
8
8
  # assert_directory_exists(name)
@@ -16,7 +16,7 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
16
16
  # app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
17
17
  # bare_setup - place this in setup method to create the APP_ROOT folder for each test
18
18
  # bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
19
-
19
+
20
20
  context "routed" do
21
21
  setup do
22
22
  Dir.mkdir("#{RAILS_ROOT}/config") unless File.exists?("#{RAILS_ROOT}/config")
@@ -24,11 +24,11 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
24
24
  f.puts "ActionController::Routing::Routes.draw do |map|\n\nend"
25
25
  end
26
26
  end
27
-
27
+
28
28
  teardown do
29
29
  FileUtils.rm_rf "#{RAILS_ROOT}/config"
30
30
  end
31
-
31
+
32
32
  context "generator without name" do
33
33
  should "raise usage error" do
34
34
  assert_raise Rails::Generator::UsageError do
@@ -36,12 +36,12 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
36
36
  end
37
37
  end
38
38
  end
39
-
39
+
40
40
  context "generator with no options and no existing model" do
41
41
  rails_generator :nifty_scaffold, "LineItem"
42
-
42
+
43
43
  should_generate_file "app/helpers/line_items_helper.rb"
44
-
44
+
45
45
  should "generate controller with class as camelcase name pluralized and all actions" do
46
46
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
47
47
  assert_match "class LineItemsController < ApplicationController", body
@@ -50,29 +50,29 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
50
50
  end
51
51
  end
52
52
  end
53
-
53
+
54
54
  %w[index show new edit].each do |action|
55
55
  should_generate_file "app/views/line_items/#{action}.html.erb"
56
56
  end
57
-
57
+
58
58
  should "have name attribute" do
59
59
  assert_generated_file "app/views/line_items/_form.html.erb" do |body|
60
60
  assert_match "<%= f.text_field :name %>", body
61
61
  end
62
62
  end
63
-
63
+
64
64
  should "add map.resources line to routes" do
65
65
  assert_generated_file "config/routes.rb" do |body|
66
66
  assert_match "map.resources :line_items", body
67
67
  end
68
68
  end
69
-
69
+
70
70
  should_not_generate_file "app/models/line_item.rb"
71
71
  end
72
-
72
+
73
73
  context "generator with some attributes" do
74
74
  rails_generator :nifty_scaffold, "line_item", "name:string", "description:text"
75
-
75
+
76
76
  should "generate migration with attribute columns" do
77
77
  file = Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").first
78
78
  assert file, "migration file doesn't exist"
@@ -84,7 +84,7 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
84
84
  assert_match "t.timestamps", body
85
85
  end
86
86
  end
87
-
87
+
88
88
  should "generate model with class as camelcase name and add attr_accessible for attributes" do
89
89
  assert_generated_file "app/models/line_item.rb" do |body|
90
90
  assert_match "class LineItem < ActiveRecord::Base", body
@@ -92,12 +92,12 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
92
92
  end
93
93
  end
94
94
  end
95
-
95
+
96
96
  context "generator with index action" do
97
97
  rails_generator :nifty_scaffold, "line_item", "index"
98
-
98
+
99
99
  should_generate_file "app/views/line_items/index.html.erb"
100
-
100
+
101
101
  should "generate controller with index action" do
102
102
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
103
103
  assert_match "def index", body
@@ -106,12 +106,12 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
106
106
  end
107
107
  end
108
108
  end
109
-
109
+
110
110
  context "generator with show action" do
111
111
  rails_generator :nifty_scaffold, "line_item", "show"
112
-
112
+
113
113
  should_generate_file "app/views/line_items/show.html.erb"
114
-
114
+
115
115
  should "generate controller with show action" do
116
116
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
117
117
  assert_match "def show", body
@@ -119,19 +119,19 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
119
119
  end
120
120
  end
121
121
  end
122
-
122
+
123
123
  context "generator with new and create actions" do
124
124
  rails_generator :nifty_scaffold, "LineItem", "new", "create"
125
-
125
+
126
126
  should_not_generate_file "app/views/line_items/create.html.erb"
127
127
  should_not_generate_file "app/views/line_items/_form.html.erb"
128
-
128
+
129
129
  should "render form in 'new' template" do
130
130
  assert_generated_file "app/views/line_items/new.html.erb" do |body|
131
131
  assert_match "<% form_for @line_item do |f| %>", body
132
132
  end
133
133
  end
134
-
134
+
135
135
  should "generate controller with actions" do
136
136
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
137
137
  assert_match "def new", body
@@ -145,19 +145,19 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
145
145
  end
146
146
  end
147
147
  end
148
-
148
+
149
149
  context "generator with edit and update actions" do
150
150
  rails_generator :nifty_scaffold, "line_item", "edit", "update"
151
-
151
+
152
152
  should_not_generate_file "app/views/line_items/update.html.erb"
153
153
  should_not_generate_file "app/views/line_items/_form.html.erb"
154
-
154
+
155
155
  should "render form in 'edit' template" do
156
156
  assert_generated_file "app/views/line_items/edit.html.erb" do |body|
157
157
  assert_match "<% form_for @line_item do |f| %>", body
158
158
  end
159
159
  end
160
-
160
+
161
161
  should "generate controller with actions" do
162
162
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
163
163
  assert_match "def edit", body
@@ -170,12 +170,12 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
170
170
  end
171
171
  end
172
172
  end
173
-
173
+
174
174
  context "generator with edit and update actions" do
175
175
  rails_generator :nifty_scaffold, "line_item", "destroy"
176
-
176
+
177
177
  should_not_generate_file "app/views/line_items/destroy.html.erb"
178
-
178
+
179
179
  should "generate controller with action" do
180
180
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
181
181
  assert_match "def destroy", body
@@ -186,12 +186,12 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
186
186
  end
187
187
  end
188
188
  end
189
-
189
+
190
190
  context "generator with new and edit actions" do
191
191
  rails_generator :nifty_scaffold, "line_item", "new", "edit"
192
-
192
+
193
193
  should_generate_file "app/views/line_items/_form.html.erb"
194
-
194
+
195
195
  should "render the form partial in views" do
196
196
  %w[new edit].each do |action|
197
197
  assert_generated_file "app/views/line_items/#{action}.html.erb" do |body|
@@ -200,10 +200,10 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
200
200
  end
201
201
  end
202
202
  end
203
-
203
+
204
204
  context "generator with attributes and actions" do
205
205
  rails_generator :nifty_scaffold, "line_item", "name:string", "new", "price:float", "index", "available:boolean"
206
-
206
+
207
207
  should "render a form field for each attribute in 'new' template" do
208
208
  assert_generated_file "app/views/line_items/new.html.erb" do |body|
209
209
  assert_match "<%= f.text_field :name %>", body
@@ -212,10 +212,10 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
212
212
  end
213
213
  end
214
214
  end
215
-
215
+
216
216
  context "generator with show, create, and update actions" do
217
217
  rails_generator :nifty_scaffold, "line_item", "show", "create", "update"
218
-
218
+
219
219
  should "redirect to line item show page, not index" do
220
220
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
221
221
  assert_match "redirect_to @line_item", body
@@ -223,36 +223,36 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
223
223
  end
224
224
  end
225
225
  end
226
-
226
+
227
227
  context "generator with attributes and skip model option" do
228
228
  rails_generator :nifty_scaffold, "line_item", "foo:string", :skip_model => true
229
-
229
+
230
230
  should "use passed attribute" do
231
231
  assert_generated_file "app/views/line_items/_form.html.erb" do |body|
232
232
  assert_match "<%= f.text_field :foo %>", body
233
233
  end
234
234
  end
235
-
235
+
236
236
  should "not generate migration file" do
237
237
  assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
238
238
  end
239
-
239
+
240
240
  should_not_generate_file "app/models/line_item.rb"
241
241
  end
242
-
242
+
243
243
  context "generator with no attributes" do
244
244
  rails_generator :nifty_scaffold, "line_item"
245
-
245
+
246
246
  should "not generate migration file" do
247
247
  assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
248
248
  end
249
-
249
+
250
250
  should_not_generate_file "app/models/line_item.rb"
251
251
  end
252
-
252
+
253
253
  context "generator with only new and edit actions" do
254
254
  rails_generator :nifty_scaffold, "line_item", "new", "edit"
255
-
255
+
256
256
  should "included create and update actions in controller" do
257
257
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
258
258
  assert_match "def create", body
@@ -261,10 +261,10 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
261
261
  end
262
262
  end
263
263
  end
264
-
264
+
265
265
  context "generator with exclemation mark and show, new, and edit actions" do
266
266
  rails_generator :nifty_scaffold, "line_item", "!", "show", "new", "edit"
267
-
267
+
268
268
  should "only include index and destroy actions" do
269
269
  assert_generated_file "app/controllers/line_items_controller.rb" do |body|
270
270
  %w[index destroy].each { |a| assert_match "def #{a}", body }
@@ -274,25 +274,25 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
274
274
  end
275
275
  end
276
276
  end
277
-
277
+
278
278
  context "generator with --skip-controller" do
279
279
  rails_generator :nifty_scaffold, "line_item", :skip_controller => true
280
280
  should_not_generate_file "app/controllers/line_items_controller.rb"
281
281
  should_not_generate_file "app/helpers/line_items_helper.rb"
282
282
  should_not_generate_file "app/views/line_items/index.html.erb"
283
283
  end
284
-
284
+
285
285
  context "generator with --skip-migration" do
286
286
  rails_generator :nifty_scaffold, "line_item", "name:string", :skip_migration => true
287
-
287
+
288
288
  should "not generate migration file" do
289
289
  assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
290
290
  end
291
291
  end
292
-
292
+
293
293
  context "generator with --skip-timestamps" do
294
294
  rails_generator :nifty_scaffold, "line_item", "name:string", :skip_timestamps => true
295
-
295
+
296
296
  should "generate migration with no timestamps" do
297
297
  file = Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").first
298
298
  assert file, "migration file doesn't exist"
@@ -301,7 +301,7 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
301
301
  end
302
302
  end
303
303
  end
304
-
304
+
305
305
  context "existing model" do
306
306
  setup do
307
307
  Dir.mkdir("#{RAILS_ROOT}/app") unless File.exists?("#{RAILS_ROOT}/app")
@@ -310,14 +310,14 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
310
310
  f.puts "raise 'should not be loaded'"
311
311
  end
312
312
  end
313
-
313
+
314
314
  teardown do
315
315
  FileUtils.rm_rf "#{RAILS_ROOT}/app"
316
316
  end
317
-
317
+
318
318
  context "generator with skip model option" do
319
319
  rails_generator :nifty_scaffold, "recipe", :skip_model => true
320
-
320
+
321
321
  should "use model columns for attributes" do
322
322
  assert_generated_file "app/views/recipes/_form.html.erb" do |body|
323
323
  assert_match "<%= f.text_field :foo %>", body
@@ -328,15 +328,15 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
328
328
  assert_no_match(/:updated_at/, body)
329
329
  end
330
330
  end
331
-
331
+
332
332
  should "not generate migration file" do
333
333
  assert Dir.glob("#{RAILS_ROOT}/db/migrate/*.rb").empty?
334
334
  end
335
335
  end
336
-
336
+
337
337
  context "generator with attribute specified" do
338
338
  rails_generator :nifty_scaffold, "recipe", "zippo:string"
339
-
339
+
340
340
  should "use specified attribute" do
341
341
  assert_generated_file "app/views/recipes/_form.html.erb" do |body|
342
342
  assert_match "<%= f.text_field :zippo %>", body
@@ -344,21 +344,21 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
344
344
  end
345
345
  end
346
346
  end
347
-
347
+
348
348
  context "with spec dir" do
349
349
  setup do
350
350
  Dir.mkdir("#{RAILS_ROOT}/spec") unless File.exists?("#{RAILS_ROOT}/spec")
351
351
  end
352
-
352
+
353
353
  teardown do
354
354
  FileUtils.rm_rf "#{RAILS_ROOT}/spec"
355
355
  end
356
-
356
+
357
357
  context "generator with some attributes" do
358
358
  rails_generator :nifty_scaffold, "line_item", "name:string", "description:text"
359
-
359
+
360
360
  should_generate_file "spec/models/line_item_spec.rb"
361
-
361
+
362
362
  should "have controller specs for each action" do
363
363
  assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
364
364
  assert_match "get :index", body
@@ -370,7 +370,7 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
370
370
  assert_match "delete :destroy", body
371
371
  end
372
372
  end
373
-
373
+
374
374
  should "have fixture with attributes" do
375
375
  assert_generated_file "spec/fixtures/line_items.yml" do |body|
376
376
  assert_match "name: MyString", body
@@ -378,10 +378,10 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
378
378
  end
379
379
  end
380
380
  end
381
-
381
+
382
382
  context "generator with new and index actions" do
383
383
  rails_generator :nifty_scaffold, "line_item", "new", "index"
384
-
384
+
385
385
  should "have controller spec with only mentioned actions" do
386
386
  assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
387
387
  assert_match "get :index", body
@@ -393,45 +393,45 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
393
393
  assert_no_match(/delete :destroy/, body)
394
394
  end
395
395
  end
396
-
396
+
397
397
  should "redirect to index action on successful create" do
398
398
  assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
399
399
  assert_match "redirect_to(line_items_url)", body
400
400
  end
401
401
  end
402
402
  end
403
-
403
+
404
404
  context "generator with edit and index actions" do
405
405
  rails_generator :nifty_scaffold, "line_item", "edit", "index"
406
-
406
+
407
407
  should "redirect to index action on successful update" do
408
408
  assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
409
409
  assert_match "redirect_to(line_items_url)", body
410
410
  end
411
411
  end
412
412
  end
413
-
413
+
414
414
  context "generator with testunit specified" do
415
415
  rails_generator :nifty_scaffold, "line_item", "name:string", :test_framework => :testunit
416
-
416
+
417
417
  should_generate_file "test/unit/line_item_test.rb"
418
418
  end
419
419
  end
420
-
420
+
421
421
  context "with test dir" do
422
422
  setup do
423
423
  Dir.mkdir("#{RAILS_ROOT}/test") unless File.exists?("#{RAILS_ROOT}/test")
424
424
  end
425
-
425
+
426
426
  teardown do
427
427
  FileUtils.rm_rf "#{RAILS_ROOT}/test"
428
428
  end
429
-
429
+
430
430
  context "generator with some attributes" do
431
431
  rails_generator :nifty_scaffold, "line_item", "name:string", "description:text"
432
-
432
+
433
433
  should_generate_file "test/unit/line_item_test.rb"
434
-
434
+
435
435
  should "have controller tests for each action" do
436
436
  assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
437
437
  assert_match "get :index", body
@@ -443,7 +443,7 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
443
443
  assert_match "delete :destroy", body
444
444
  end
445
445
  end
446
-
446
+
447
447
  should "have fixture with attributes" do
448
448
  assert_generated_file "test/fixtures/line_items.yml" do |body|
449
449
  assert_match "name: MyString", body
@@ -451,10 +451,10 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
451
451
  end
452
452
  end
453
453
  end
454
-
454
+
455
455
  context "generator with new and index actions" do
456
456
  rails_generator :nifty_scaffold, "line_item", "new", "index"
457
-
457
+
458
458
  should "have controller test with only mentioned actions" do
459
459
  assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
460
460
  assert_match "get :index", body
@@ -466,52 +466,52 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
466
466
  assert_no_match(/delete :destroy/, body)
467
467
  end
468
468
  end
469
-
469
+
470
470
  should "redirect to index action on successful create" do
471
471
  assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
472
472
  assert_match "assert_redirected_to line_items_url", body
473
473
  end
474
474
  end
475
475
  end
476
-
476
+
477
477
  context "generator with edit and index actions" do
478
478
  rails_generator :nifty_scaffold, "line_item", "edit", "index"
479
-
479
+
480
480
  should "redirect to index action on successful update" do
481
481
  assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
482
482
  assert_match "assert_redirected_to line_items_url", body
483
483
  end
484
484
  end
485
485
  end
486
-
486
+
487
487
  context "generator with rspec specified" do
488
488
  rails_generator :nifty_scaffold, "line_item", "name:string", :test_framework => :rspec
489
-
489
+
490
490
  should_generate_file "spec/models/line_item_spec.rb"
491
491
  end
492
-
492
+
493
493
  context "generator with shoulda specified" do
494
494
  rails_generator :nifty_scaffold, "line_item", "name:string", :test_framework => :shoulda
495
-
495
+
496
496
  should "have controller and model tests using shoulda syntax" do
497
497
  assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
498
498
  assert_match " should ", body
499
499
  end
500
-
500
+
501
501
  assert_generated_file "test/unit/line_item_test.rb" do |body|
502
502
  assert_match " should ", body
503
503
  end
504
504
  end
505
505
  end
506
506
  end
507
-
507
+
508
508
  context "generator with haml option" do
509
509
  rails_generator :nifty_scaffold, "LineItem", :haml => true
510
-
510
+
511
511
  %w[index show new edit _form].each do |action|
512
512
  should_generate_file "app/views/line_items/#{action}.html.haml"
513
513
  end
514
-
514
+
515
515
  should "render the form partial in views" do
516
516
  %w[new edit].each do |action|
517
517
  assert_generated_file "app/views/line_items/#{action}.html.haml" do |body|