ryanb-nifty-generators 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/CHANGELOG +4 -0
  2. data/Manifest +19 -0
  3. data/README +33 -0
  4. data/TODO +0 -1
  5. data/nifty-generators.gemspec +5 -5
  6. data/rails_generators/nifty_scaffold/USAGE +2 -2
  7. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +43 -7
  8. data/rails_generators/nifty_scaffold/templates/action_specs/create.rb +11 -0
  9. data/rails_generators/nifty_scaffold/templates/action_specs/destroy.rb +6 -0
  10. data/rails_generators/nifty_scaffold/templates/action_specs/edit.rb +4 -0
  11. data/rails_generators/nifty_scaffold/templates/action_specs/index.rb +4 -0
  12. data/rails_generators/nifty_scaffold/templates/action_specs/new.rb +4 -0
  13. data/rails_generators/nifty_scaffold/templates/action_specs/show.rb +4 -0
  14. data/rails_generators/nifty_scaffold/templates/action_specs/update.rb +11 -0
  15. data/rails_generators/nifty_scaffold/templates/action_tests/create.rb +11 -0
  16. data/rails_generators/nifty_scaffold/templates/action_tests/destroy.rb +6 -0
  17. data/rails_generators/nifty_scaffold/templates/action_tests/edit.rb +4 -0
  18. data/rails_generators/nifty_scaffold/templates/action_tests/index.rb +4 -0
  19. data/rails_generators/nifty_scaffold/templates/action_tests/new.rb +4 -0
  20. data/rails_generators/nifty_scaffold/templates/action_tests/show.rb +4 -0
  21. data/rails_generators/nifty_scaffold/templates/action_tests/update.rb +11 -0
  22. data/rails_generators/nifty_scaffold/templates/controller.rb +1 -1
  23. data/rails_generators/nifty_scaffold/templates/controller_spec.rb +8 -0
  24. data/rails_generators/nifty_scaffold/templates/controller_test.rb +5 -0
  25. data/rails_generators/nifty_scaffold/templates/fixtures.yml +9 -0
  26. data/rails_generators/nifty_scaffold/templates/model_spec.rb +11 -0
  27. data/rails_generators/nifty_scaffold/templates/model_test.rb +8 -0
  28. data/test/test_nifty_scaffold_generator.rb +134 -0
  29. metadata +21 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.1* (May 9th, 2008)
2
+
3
+ * adding tests and specs to scaffold generator
4
+
1
5
  *0.1.0* (May 8th, 2008)
2
6
 
3
7
  * initial release
data/Manifest CHANGED
@@ -8,6 +8,20 @@ rails_generators/nifty_layout/templates/layout.html.erb
8
8
  rails_generators/nifty_layout/templates/stylesheet.css
9
9
  rails_generators/nifty_layout/USAGE
10
10
  rails_generators/nifty_scaffold/nifty_scaffold_generator.rb
11
+ rails_generators/nifty_scaffold/templates/action_specs/create.rb
12
+ rails_generators/nifty_scaffold/templates/action_specs/destroy.rb
13
+ rails_generators/nifty_scaffold/templates/action_specs/edit.rb
14
+ rails_generators/nifty_scaffold/templates/action_specs/index.rb
15
+ rails_generators/nifty_scaffold/templates/action_specs/new.rb
16
+ rails_generators/nifty_scaffold/templates/action_specs/show.rb
17
+ rails_generators/nifty_scaffold/templates/action_specs/update.rb
18
+ rails_generators/nifty_scaffold/templates/action_tests/create.rb
19
+ rails_generators/nifty_scaffold/templates/action_tests/destroy.rb
20
+ rails_generators/nifty_scaffold/templates/action_tests/edit.rb
21
+ rails_generators/nifty_scaffold/templates/action_tests/index.rb
22
+ rails_generators/nifty_scaffold/templates/action_tests/new.rb
23
+ rails_generators/nifty_scaffold/templates/action_tests/show.rb
24
+ rails_generators/nifty_scaffold/templates/action_tests/update.rb
11
25
  rails_generators/nifty_scaffold/templates/actions/create.rb
12
26
  rails_generators/nifty_scaffold/templates/actions/destroy.rb
13
27
  rails_generators/nifty_scaffold/templates/actions/edit.rb
@@ -16,9 +30,14 @@ rails_generators/nifty_scaffold/templates/actions/new.rb
16
30
  rails_generators/nifty_scaffold/templates/actions/show.rb
17
31
  rails_generators/nifty_scaffold/templates/actions/update.rb
18
32
  rails_generators/nifty_scaffold/templates/controller.rb
33
+ rails_generators/nifty_scaffold/templates/controller_spec.rb
34
+ rails_generators/nifty_scaffold/templates/controller_test.rb
35
+ rails_generators/nifty_scaffold/templates/fixtures.yml
19
36
  rails_generators/nifty_scaffold/templates/helper.rb
20
37
  rails_generators/nifty_scaffold/templates/migration.rb
21
38
  rails_generators/nifty_scaffold/templates/model.rb
39
+ rails_generators/nifty_scaffold/templates/model_spec.rb
40
+ rails_generators/nifty_scaffold/templates/model_test.rb
22
41
  rails_generators/nifty_scaffold/templates/views/_form.html.erb
23
42
  rails_generators/nifty_scaffold/templates/views/edit.html.erb
24
43
  rails_generators/nifty_scaffold/templates/views/index.html.erb
data/README CHANGED
@@ -2,9 +2,11 @@
2
2
 
3
3
  A collection of useful Rails generator scripts by Ryan Bates.
4
4
 
5
+
5
6
  == Install
6
7
 
7
8
  gem install ryanb-nifty-generators --source=http://gems.github.com
9
+
8
10
 
9
11
  == Usage
10
12
 
@@ -16,6 +18,7 @@ To run the generator, go to your rails project directory and call it
16
18
  using the script/generate or script/destroy command.
17
19
 
18
20
  script/generate nifty_scaffold Recipe name:string index new
21
+
19
22
 
20
23
  == Included Generators
21
24
 
@@ -26,6 +29,36 @@ Run the command with the --help option to learn more.
26
29
 
27
30
  script/generate nifty_layout --help
28
31
 
32
+ == Troubleshooting
33
+
34
+ *I get "undefined method 'title'" error for nifty_scaffold.*
35
+
36
+ Try running nifty_layout too, that will generate this helper method. Or
37
+ you can just change the templates to whatever approach you prefer for
38
+ setting the title.
39
+
40
+
41
+ *Forms don't work for nifty_scaffold.*
42
+
43
+ Try restarting your development server. Sometimes it doesn't detect the
44
+ change in the routing.
45
+
46
+
47
+ *The tests/specs don't work for nifty_scaffold.*
48
+
49
+ Make sure you have mocha installed and require it in your spec/test helper.
50
+
51
+ gem install mocha
52
+
53
+ # in spec_helper.rb
54
+ config.mock_with :mocha
55
+
56
+ # in test_helper.rb
57
+ require 'mocha'
58
+
59
+ Also, make sure you're using edge rails (or 2.1 when released) as some methods require that.
60
+
61
+
29
62
  == Development
30
63
 
31
64
  This project can be found on github at the following URL.
data/TODO CHANGED
@@ -1,4 +1,3 @@
1
1
 
2
2
  Nifty Scaffold Generator
3
- - generate tests/specs
4
3
  - add some validation for attributes/action names
@@ -1,20 +1,20 @@
1
1
 
2
- # Gem::Specification for Nifty-generators-0.1.0
2
+ # Gem::Specification for Nifty-generators-0.1.1
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{nifty-generators}
7
- s.version = "0.1.0"
7
+ s.version = "0.1.1"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Ryan Bates"]
13
- s.date = %q{2008-05-08}
13
+ s.date = %q{2008-05-09}
14
14
  s.description = %q{A collection of useful generator scripts for Rails.}
15
15
  s.email = %q{ryan (at) railscasts (dot) com}
16
16
  s.extra_rdoc_files = ["CHANGELOG", "lib/nifty_generators.rb", "LICENSE", "README", "tasks/deployment.rake", "TODO"]
17
- s.files = ["CHANGELOG", "lib/nifty_generators.rb", "LICENSE", "Manifest", "rails_generators/nifty_layout/nifty_layout_generator.rb", "rails_generators/nifty_layout/templates/helper.rb", "rails_generators/nifty_layout/templates/layout.html.erb", "rails_generators/nifty_layout/templates/stylesheet.css", "rails_generators/nifty_layout/USAGE", "rails_generators/nifty_scaffold/nifty_scaffold_generator.rb", "rails_generators/nifty_scaffold/templates/actions/create.rb", "rails_generators/nifty_scaffold/templates/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/actions/edit.rb", "rails_generators/nifty_scaffold/templates/actions/index.rb", "rails_generators/nifty_scaffold/templates/actions/new.rb", "rails_generators/nifty_scaffold/templates/actions/show.rb", "rails_generators/nifty_scaffold/templates/actions/update.rb", "rails_generators/nifty_scaffold/templates/controller.rb", "rails_generators/nifty_scaffold/templates/helper.rb", "rails_generators/nifty_scaffold/templates/migration.rb", "rails_generators/nifty_scaffold/templates/model.rb", "rails_generators/nifty_scaffold/templates/views/_form.html.erb", "rails_generators/nifty_scaffold/templates/views/edit.html.erb", "rails_generators/nifty_scaffold/templates/views/index.html.erb", "rails_generators/nifty_scaffold/templates/views/new.html.erb", "rails_generators/nifty_scaffold/templates/views/show.html.erb", "rails_generators/nifty_scaffold/USAGE", "README", "tasks/deployment.rake", "test/test_helper.rb", "test/test_nifty_layout_generator.rb", "test/test_nifty_scaffold_generator.rb", "TODO", "nifty-generators.gemspec"]
17
+ s.files = ["CHANGELOG", "lib/nifty_generators.rb", "LICENSE", "Manifest", "rails_generators/nifty_layout/nifty_layout_generator.rb", "rails_generators/nifty_layout/templates/helper.rb", "rails_generators/nifty_layout/templates/layout.html.erb", "rails_generators/nifty_layout/templates/stylesheet.css", "rails_generators/nifty_layout/USAGE", "rails_generators/nifty_scaffold/nifty_scaffold_generator.rb", "rails_generators/nifty_scaffold/templates/action_specs/create.rb", "rails_generators/nifty_scaffold/templates/action_specs/destroy.rb", "rails_generators/nifty_scaffold/templates/action_specs/edit.rb", "rails_generators/nifty_scaffold/templates/action_specs/index.rb", "rails_generators/nifty_scaffold/templates/action_specs/new.rb", "rails_generators/nifty_scaffold/templates/action_specs/show.rb", "rails_generators/nifty_scaffold/templates/action_specs/update.rb", "rails_generators/nifty_scaffold/templates/action_tests/create.rb", "rails_generators/nifty_scaffold/templates/action_tests/destroy.rb", "rails_generators/nifty_scaffold/templates/action_tests/edit.rb", "rails_generators/nifty_scaffold/templates/action_tests/index.rb", "rails_generators/nifty_scaffold/templates/action_tests/new.rb", "rails_generators/nifty_scaffold/templates/action_tests/show.rb", "rails_generators/nifty_scaffold/templates/action_tests/update.rb", "rails_generators/nifty_scaffold/templates/actions/create.rb", "rails_generators/nifty_scaffold/templates/actions/destroy.rb", "rails_generators/nifty_scaffold/templates/actions/edit.rb", "rails_generators/nifty_scaffold/templates/actions/index.rb", "rails_generators/nifty_scaffold/templates/actions/new.rb", "rails_generators/nifty_scaffold/templates/actions/show.rb", "rails_generators/nifty_scaffold/templates/actions/update.rb", "rails_generators/nifty_scaffold/templates/controller.rb", "rails_generators/nifty_scaffold/templates/controller_spec.rb", "rails_generators/nifty_scaffold/templates/controller_test.rb", "rails_generators/nifty_scaffold/templates/fixtures.yml", "rails_generators/nifty_scaffold/templates/helper.rb", "rails_generators/nifty_scaffold/templates/migration.rb", "rails_generators/nifty_scaffold/templates/model.rb", "rails_generators/nifty_scaffold/templates/model_spec.rb", "rails_generators/nifty_scaffold/templates/model_test.rb", "rails_generators/nifty_scaffold/templates/views/_form.html.erb", "rails_generators/nifty_scaffold/templates/views/edit.html.erb", "rails_generators/nifty_scaffold/templates/views/index.html.erb", "rails_generators/nifty_scaffold/templates/views/new.html.erb", "rails_generators/nifty_scaffold/templates/views/show.html.erb", "rails_generators/nifty_scaffold/USAGE", "README", "tasks/deployment.rake", "test/test_helper.rb", "test/test_nifty_layout_generator.rb", "test/test_nifty_scaffold_generator.rb", "TODO", "nifty-generators.gemspec"]
18
18
  s.has_rdoc = true
19
19
  s.homepage = %q{http://github.com/ryanb/nifty-generators}
20
20
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nifty-generators", "--main", "README"]
@@ -34,7 +34,7 @@ end
34
34
  # begin
35
35
  # require 'echoe'
36
36
  #
37
- # Echoe.new('nifty-generators', '0.1.0') do |p|
37
+ # Echoe.new('nifty-generators', '0.1.1') do |p|
38
38
  # p.summary = "A collection of useful generator scripts for Rails."
39
39
  # p.description = "A collection of useful generator scripts for Rails."
40
40
  # p.url = "http://github.com/ryanb/nifty-generators"
@@ -1,8 +1,8 @@
1
1
  Description:
2
2
  Scaffolds an entire resource, from model and migration to controller and
3
3
  views. The resource is ready to use as a starting point for your restful,
4
- resource-oriented application. Tests are not generated yet, but expect
5
- them in future releases.
4
+ resource-oriented application. Tests or specs are also generated depending
5
+ on if you have a "spec" directory or not.
6
6
 
7
7
  Usage:
8
8
  Pass the name of the model, either CamelCased or under_scored, as the first
@@ -49,6 +49,18 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
49
49
  unless options[:skip_migration]
50
50
  m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
51
51
  end
52
+
53
+ if spec_dir?
54
+ m.directory "spec/models"
55
+ m.template "model_spec.rb", "spec/models/#{singular_name}_spec.rb"
56
+ m.directory "spec/fixtures"
57
+ m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
58
+ else
59
+ m.directory "test/unit"
60
+ m.template "model_test.rb", "test/unit/#{singular_name}_test.rb"
61
+ m.directory "test/fixtures"
62
+ m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
63
+ end
52
64
  end
53
65
 
54
66
  unless options[:skip_controller]
@@ -70,6 +82,14 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
70
82
  end
71
83
 
72
84
  m.route_resources plural_name
85
+
86
+ if spec_dir?
87
+ m.directory "spec/controllers"
88
+ m.template "controller_spec.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
89
+ else
90
+ m.directory "test/functional"
91
+ m.template "controller_test.rb", "test/functional/#{plural_name}_controller_test.rb"
92
+ end
73
93
  end
74
94
  end
75
95
  end
@@ -106,14 +126,10 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
106
126
  plural_name.camelize
107
127
  end
108
128
 
109
- def controller_methods
129
+ def controller_methods(dir_name)
110
130
  controller_actions.map do |action|
111
- controller_method(action)
112
- end.join("\n")
113
- end
114
-
115
- def controller_method(name)
116
- read_template("actions/#{name}.rb")
131
+ read_template("#{dir_name}/#{action}.rb")
132
+ end.join(" \n").strip
117
133
  end
118
134
 
119
135
  def render_form
@@ -132,12 +148,32 @@ class NiftyScaffoldGenerator < Rails::Generator::Base
132
148
  end
133
149
  end
134
150
 
151
+ def item_path_for_spec
152
+ if action? :show
153
+ "#{singular_name}_path(assigns[:#{singular_name}])"
154
+ else
155
+ "#{plural_name}_path"
156
+ end
157
+ end
158
+
159
+ def item_path_for_test
160
+ if action? :show
161
+ "#{singular_name}_path(assigns(:#{singular_name}))"
162
+ else
163
+ "#{plural_name}_path"
164
+ end
165
+ end
166
+
135
167
  def model_columns_for_attributes
136
168
  class_name.constantize.columns.reject do |column|
137
169
  column.name.to_s =~ /^(id|created_at|updated_at)$/
138
170
  end
139
171
  end
140
172
 
173
+ def spec_dir?
174
+ File.exist? destination_path("spec")
175
+ end
176
+
141
177
  protected
142
178
 
143
179
  def add_options!(opt)
@@ -0,0 +1,11 @@
1
+ it "create action should render new template when model is invalid" do
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ post :create
4
+ response.should render_template(:new)
5
+ end
6
+
7
+ it "create action should redirect to index action when model is valid" do
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ post :create
10
+ response.should redirect_to(<%= item_path_for_spec %>)
11
+ end
@@ -0,0 +1,6 @@
1
+ it "destroy action should destroy model and redirect to index action" do
2
+ <%= singular_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= singular_name %>
4
+ response.should redirect_to(<%= plural_name %>_path)
5
+ <%= class_name %>.exists?(<%= singular_name %>.id).should be_false
6
+ end
@@ -0,0 +1,4 @@
1
+ it "edit action should render edit template" do
2
+ get :edit, :id => <%= class_name %>.first
3
+ response.should render_template(:edit)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "index action should render index template" do
2
+ get :index
3
+ response.should render_template(:index)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "new action should render new template" do
2
+ get :new
3
+ response.should render_template(:new)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "show action should render show template" do
2
+ get :show, :id => <%= class_name %>.first
3
+ response.should render_template(:show)
4
+ end
@@ -0,0 +1,11 @@
1
+ it "update action should render edit template when model is invalid" do
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ put :update, :id => <%= class_name %>.first
4
+ response.should render_template(:edit)
5
+ end
6
+
7
+ it "update action should redirect to show action when model is valid" do
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ put :update, :id => <%= class_name %>.first
10
+ response.should redirect_to(<%= item_path_for_spec %>)
11
+ end
@@ -0,0 +1,11 @@
1
+ def test_create_invalid
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ post :create
4
+ assert_template 'new'
5
+ end
6
+
7
+ def test_create_valid
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ post :create
10
+ assert_redirected_to <%= item_path_for_test %>
11
+ end
@@ -0,0 +1,6 @@
1
+ def test_destroy
2
+ <%= singular_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= singular_name %>
4
+ assert_redirected_to <%= plural_name %>_path
5
+ assert !<%= class_name %>.exists?(<%= singular_name %>.id)
6
+ end
@@ -0,0 +1,4 @@
1
+ def test_edit
2
+ get :edit, :id => <%= class_name %>.first
3
+ assert_template 'edit'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_index
2
+ get :index
3
+ assert_template 'index'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_new
2
+ get :new
3
+ assert_template 'new'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_show
2
+ get :show, :id => <%= class_name %>.first
3
+ assert_template 'show'
4
+ end
@@ -0,0 +1,11 @@
1
+ def test_update_invalid
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ put :update, :id => <%= class_name %>.first
4
+ assert_template 'edit'
5
+ end
6
+
7
+ def test_update_valid
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ put :update, :id => <%= class_name %>.first
10
+ assert_redirected_to <%= item_path_for_test %>
11
+ end
@@ -1,3 +1,3 @@
1
1
  class <%= plural_class_name %>Controller < ApplicationController
2
- <%= controller_methods.strip %>
2
+ <%= controller_methods :actions %>
3
3
  end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= plural_class_name %>Controller do
4
+ fixtures :all
5
+ integrate_views
6
+
7
+ <%= controller_methods :action_specs %>
8
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class <%= plural_class_name %>ControllerTest < ActionController::TestCase
4
+ <%= controller_methods :action_tests %>
5
+ end
@@ -0,0 +1,9 @@
1
+ one:
2
+ <%- for attribute in attributes -%>
3
+ <%= attribute.name %>: <%= attribute.default %>
4
+ <%- end -%>
5
+
6
+ two:
7
+ <%- for attribute in attributes -%>
8
+ <%= attribute.name %>: <%= attribute.default %>
9
+ <%- end -%>
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ before(:each) do
5
+ @<%= singular_name %> = <%= class_name %>.new
6
+ end
7
+
8
+ it "should be valid" do
9
+ @<%= singular_name %>.should be_valid
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ def test_truth
6
+ assert true
7
+ end
8
+ end
@@ -342,6 +342,140 @@ class TestNiftyScaffoldGenerator < Test::Unit::TestCase
342
342
  end
343
343
  end
344
344
  end
345
+
346
+ context "with spec dir" do
347
+ setup do
348
+ Dir.mkdir("#{RAILS_ROOT}/spec") unless File.exists?("#{RAILS_ROOT}/spec")
349
+ end
350
+
351
+ teardown do
352
+ FileUtils.rm_rf "#{RAILS_ROOT}/spec"
353
+ end
354
+
355
+ context "generator with some attributes" do
356
+ rails_generator :nifty_scaffold, "line_item", "name:string", "description:text"
357
+
358
+ should_generate_file "spec/models/line_item_spec.rb"
359
+
360
+ should "have controller specs for each action" do
361
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
362
+ assert_match "get :index", body
363
+ assert_match "get :show", body
364
+ assert_match "get :new", body
365
+ assert_match "get :edit", body
366
+ assert_match "post :create", body
367
+ assert_match "put :update", body
368
+ assert_match "delete :destroy", body
369
+ end
370
+ end
371
+
372
+ should "have fixture with attributes" do
373
+ assert_generated_file "spec/fixtures/line_items.yml" do |body|
374
+ assert_match "name: MyString", body
375
+ assert_match "description: MyText", body
376
+ end
377
+ end
378
+ end
379
+
380
+ context "generator with new and index actions" do
381
+ rails_generator :nifty_scaffold, "line_item", "new", "index"
382
+
383
+ should "have controller spec with only mentioned actions" do
384
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
385
+ assert_match "get :index", body
386
+ assert_match "get :new", body
387
+ assert_match "post :create", body
388
+ assert_no_match(/get :show/, body)
389
+ assert_no_match(/get :edit/, body)
390
+ assert_no_match(/put :update/, body)
391
+ assert_no_match(/delete :destroy/, body)
392
+ end
393
+ end
394
+
395
+ should "should redirect to index action on successful create" do
396
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
397
+ assert_match "redirect_to(line_items_path)", body
398
+ end
399
+ end
400
+ end
401
+
402
+ context "generator with edit and index actions" do
403
+ rails_generator :nifty_scaffold, "line_item", "edit", "index"
404
+
405
+ should "should redirect to index action on successful update" do
406
+ assert_generated_file "spec/controllers/line_items_controller_spec.rb" do |body|
407
+ assert_match "redirect_to(line_items_path)", body
408
+ end
409
+ end
410
+ end
411
+ end
412
+
413
+ context "with test dir" do
414
+ setup do
415
+ Dir.mkdir("#{RAILS_ROOT}/test") unless File.exists?("#{RAILS_ROOT}/test")
416
+ end
417
+
418
+ teardown do
419
+ FileUtils.rm_rf "#{RAILS_ROOT}/test"
420
+ end
421
+
422
+ context "generator with some attributes" do
423
+ rails_generator :nifty_scaffold, "line_item", "name:string", "description:text"
424
+
425
+ should_generate_file "test/unit/line_item_test.rb"
426
+
427
+ should "have controller tests for each action" do
428
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
429
+ assert_match "get :index", body
430
+ assert_match "get :show", body
431
+ assert_match "get :new", body
432
+ assert_match "get :edit", body
433
+ assert_match "post :create", body
434
+ assert_match "put :update", body
435
+ assert_match "delete :destroy", body
436
+ end
437
+ end
438
+
439
+ should "have fixture with attributes" do
440
+ assert_generated_file "test/fixtures/line_items.yml" do |body|
441
+ assert_match "name: MyString", body
442
+ assert_match "description: MyText", body
443
+ end
444
+ end
445
+ end
446
+
447
+ context "generator with new and index actions" do
448
+ rails_generator :nifty_scaffold, "line_item", "new", "index"
449
+
450
+ should "have controller test with only mentioned actions" do
451
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
452
+ assert_match "get :index", body
453
+ assert_match "get :new", body
454
+ assert_match "post :create", body
455
+ assert_no_match(/get :show/, body)
456
+ assert_no_match(/get :edit/, body)
457
+ assert_no_match(/put :update/, body)
458
+ assert_no_match(/delete :destroy/, body)
459
+ end
460
+ end
461
+
462
+ should "should redirect to index action on successful create" do
463
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
464
+ assert_match "assert_redirected_to line_items_path", body
465
+ end
466
+ end
467
+ end
468
+
469
+ context "generator with edit and index actions" do
470
+ rails_generator :nifty_scaffold, "line_item", "edit", "index"
471
+
472
+ should "should redirect to index action on successful update" do
473
+ assert_generated_file "test/functional/line_items_controller_test.rb" do |body|
474
+ assert_match "assert_redirected_to line_items_path", body
475
+ end
476
+ end
477
+ end
478
+ end
345
479
  end
346
480
  end
347
481
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ryanb-nifty-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-08 00:00:00 -07:00
12
+ date: 2008-05-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,6 +37,20 @@ files:
37
37
  - rails_generators/nifty_layout/templates/stylesheet.css
38
38
  - rails_generators/nifty_layout/USAGE
39
39
  - rails_generators/nifty_scaffold/nifty_scaffold_generator.rb
40
+ - rails_generators/nifty_scaffold/templates/action_specs/create.rb
41
+ - rails_generators/nifty_scaffold/templates/action_specs/destroy.rb
42
+ - rails_generators/nifty_scaffold/templates/action_specs/edit.rb
43
+ - rails_generators/nifty_scaffold/templates/action_specs/index.rb
44
+ - rails_generators/nifty_scaffold/templates/action_specs/new.rb
45
+ - rails_generators/nifty_scaffold/templates/action_specs/show.rb
46
+ - rails_generators/nifty_scaffold/templates/action_specs/update.rb
47
+ - rails_generators/nifty_scaffold/templates/action_tests/create.rb
48
+ - rails_generators/nifty_scaffold/templates/action_tests/destroy.rb
49
+ - rails_generators/nifty_scaffold/templates/action_tests/edit.rb
50
+ - rails_generators/nifty_scaffold/templates/action_tests/index.rb
51
+ - rails_generators/nifty_scaffold/templates/action_tests/new.rb
52
+ - rails_generators/nifty_scaffold/templates/action_tests/show.rb
53
+ - rails_generators/nifty_scaffold/templates/action_tests/update.rb
40
54
  - rails_generators/nifty_scaffold/templates/actions/create.rb
41
55
  - rails_generators/nifty_scaffold/templates/actions/destroy.rb
42
56
  - rails_generators/nifty_scaffold/templates/actions/edit.rb
@@ -45,9 +59,14 @@ files:
45
59
  - rails_generators/nifty_scaffold/templates/actions/show.rb
46
60
  - rails_generators/nifty_scaffold/templates/actions/update.rb
47
61
  - rails_generators/nifty_scaffold/templates/controller.rb
62
+ - rails_generators/nifty_scaffold/templates/controller_spec.rb
63
+ - rails_generators/nifty_scaffold/templates/controller_test.rb
64
+ - rails_generators/nifty_scaffold/templates/fixtures.yml
48
65
  - rails_generators/nifty_scaffold/templates/helper.rb
49
66
  - rails_generators/nifty_scaffold/templates/migration.rb
50
67
  - rails_generators/nifty_scaffold/templates/model.rb
68
+ - rails_generators/nifty_scaffold/templates/model_spec.rb
69
+ - rails_generators/nifty_scaffold/templates/model_test.rb
51
70
  - rails_generators/nifty_scaffold/templates/views/_form.html.erb
52
71
  - rails_generators/nifty_scaffold/templates/views/edit.html.erb
53
72
  - rails_generators/nifty_scaffold/templates/views/index.html.erb