grimen-dry_scaffold 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile CHANGED
@@ -1,3 +1,7 @@
1
+ h1. 0.3.1 (2009-09-09)
2
+
3
+ * Added Rspec tests generation
4
+
1
5
  h1. 0.3.0 (2009-07-23)
2
6
 
3
7
  * Major refactoring of the code.
data/README.textile CHANGED
@@ -37,6 +37,7 @@ h4. Models
37
37
  h4. Testing
38
38
 
39
39
  * "*shoulda*":http://github.com/thoughtbot/shoulda - Testing framework
40
+ * "*rspec*":http://wiki.github.com/dchelimsky/rspec - Testing framework
40
41
 
41
42
  h2. Features
42
43
 
@@ -157,11 +158,7 @@ InheritedResources with pagination:
157
158
  paginate_options ||= {}
158
159
  paginate_options[:page] ||= (params[:page] || 1)
159
160
  paginate_options[:per_page] ||= (params[:per_page] || 20)
160
- @collection = @resources ||= end_of_association_chain.paginate(paginate_options)
161
- end
162
-
163
- def resource
164
- @resource = @resource ||= end_of_association_chain.find(params[:id])
161
+ @resources ||= end_of_association_chain.paginate(paginate_options)
165
162
  end</pre>
166
163
 
167
164
  h3. View Partials
@@ -226,15 +223,24 @@ config.gem 'will_paginate'
226
223
  config.gem 'justinfrench-formtastic', :lib => 'formtastic', :source => 'http://gems.github.com'
227
224
  config.gem 'josevalim-inherited_resources', :lib => 'inherited_resources', :source => 'http://gems.github.com'</pre>
228
225
 
226
+ Also configure @config/environments/test.rb@ with the Rspec library if you want to
227
+
228
+ <pre>config.gem 'rspec'
229
+ config.gem 'rspec-rails'</pre>
230
+
231
+ And don't forget to initialize it as well:
232
+
233
+ <pre>./script/generate rspec</pre>
234
+
229
235
  h2. Usage
230
236
 
231
- <pre>./script/generate dry_scaffold ModelName [attribute:type attribute:type] [_actions:new,create,...] [_formats:html,json,...] [_indexes:attribute,...] [--skip-pagination] [--skip-resourceful] [--skip-formtastic] [--skip-views] [--skip-helpers] [--skip-migration] [--skip-timestamps] [--skip-tests] [--layout] [--tunit] [--shoulda] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>
237
+ <pre>./script/generate dry_scaffold ModelName [attribute:type attribute:type] [_actions:new,create,...] [_formats:html,json,...] [_indexes:attribute,...] [--skip-pagination] [--skip-resourceful] [--skip-formtastic] [--skip-views] [--skip-helpers] [--skip-migration] [--skip-timestamps] [--skip-tests] [--layout] [--tunit] [--shoulda] [--rspec] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>
232
238
 
233
239
  ...or use the alias @dscaffold@ instead of @dry_scaffold@.
234
240
 
235
241
  For generating just a *model*, then use:
236
242
 
237
- <pre>./script/generate dry_model ModelName [attribute:type attribute:type] [_indexes:attribute,...] [--skip-migration] [--skip-timestamps] [--skip-tests] [--tunit] [--shoulda] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>
243
+ <pre>./script/generate dry_model ModelName [attribute:type attribute:type] [_indexes:attribute,...] [--skip-migration] [--skip-timestamps] [--skip-tests] [--tunit] [--shoulda] [--rspec] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>
238
244
 
239
245
  ...or use the alias @dmodel@ instead of @dry_model@.
240
246
 
@@ -399,6 +405,7 @@ h4. All
399
405
  * @--skip-tests@ - Don't generate tests (functional/unit/...).
400
406
  * @--tunit@ - Generate/Use test_unit tests. Note: Rails default.
401
407
  * @--shoulda@ - Generate/Use *shoulda* tests.
408
+ * @--rspec@ - Generate/Use *rspec* tests.
402
409
  * @--fixtures@ - Generate/Use fixtures. Note: Rails default.
403
410
  * @--fgirl@ - Generate/Use *factory_girl* factories.
404
411
  * @--machinist@ - Generate/Use *machinist* blueprints (factories).
data/config/scaffold.yml CHANGED
@@ -5,7 +5,7 @@ dry_scaffold:
5
5
  formats: html,js,xml,json
6
6
  options:
7
7
  formtastic: true
8
- resourceful: false
8
+ resourceful: true
9
9
  pagination: true
10
10
  layout: false
11
11
  views: true
@@ -13,6 +13,7 @@ dry_scaffold:
13
13
  tests: true
14
14
  tunit: true
15
15
  shoulda: false
16
+ rspec: false
16
17
  fixtures: true
17
18
  fgirl: false
18
19
  machinist: false
@@ -60,7 +60,7 @@ class DryModelGenerator < DryGenerator
60
60
 
61
61
  # Model Tests.
62
62
  unless options[:skip_tests]
63
- model_tests_path = File.join(TEST_PATHS[test_framework], 'unit')
63
+ model_tests_path = File.join(TEST_PATHS[test_framework], UNIT_TESTS_PATH[test_framework])
64
64
  m.directory File.join(model_tests_path, class_path)
65
65
  m.template File.join('models', 'tests', "#{test_framework}", 'unit_test.rb'),
66
66
  File.join(model_tests_path, class_path, "#{file_name}_test.rb")
@@ -70,7 +70,7 @@ class DryModelGenerator < DryGenerator
70
70
  fixtures_path = File.join(TEST_PATHS[test_framework], 'fixtures')
71
71
  m.directory File.join(fixtures_path, class_path)
72
72
  m.template File.join('models', 'fixture_data', 'active_record_fixtures.yml'),
73
- File.join(fixtures_path, class_path, "#{plural_name}.yml")
73
+ File.join(fixtures_path, class_path, "#{table_name}.yml")
74
74
  end
75
75
  if options[:factory_girl]
76
76
  factory_girl_path = File.join(TEST_PATHS[test_framework], 'factories')
@@ -131,4 +131,4 @@ class DryModelGenerator < DryGenerator
131
131
  [super, banner_args, banner_options].join(' ')
132
132
  end
133
133
 
134
- end
134
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe DuckTest do
4
+ fixtures :ducks
5
+
6
+ it "should be valid" do
7
+ DuckTest.new.should be_valid
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ <% if options[:fixtures] -%>
5
+ fixtures :<%= table_name %>
6
+
7
+ <% end -%>
8
+ it "should be valid" do
9
+ Comment.new.should be_valid
10
+ end
11
+ end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class <%= class_name %>Test < ActiveRecord::TestCase
4
4
 
5
5
  <% if options[:fixtures] -%>
6
- fixtures :<%= plural_name %>
6
+ fixtures :<%= table_name %>
7
7
 
8
8
  <% end -%>
9
9
  setup do
@@ -14,4 +14,4 @@ class <%= class_name %>Test < ActiveRecord::TestCase
14
14
  assert true
15
15
  end
16
16
 
17
- end
17
+ end
@@ -142,7 +142,7 @@ class DryScaffoldGenerator < DryGenerator
142
142
 
143
143
  # Controller Tests.
144
144
  unless options[:skip_tests]
145
- controller_tests_path = File.join(TEST_PATHS[test_framework], 'functional')
145
+ controller_tests_path = File.join(TEST_PATHS[test_framework], FUNCTIONAL_TESTS_PATH[test_framework])
146
146
  m.directory File.join(controller_tests_path, controller_class_path)
147
147
  m.template File.join('controllers', 'tests', "#{test_framework}", 'functional_test.rb'),
148
148
  File.join(controller_tests_path, controller_class_path, "#{controller_file_name}_controller_test.rb")
@@ -219,7 +219,7 @@ class DryScaffoldGenerator < DryGenerator
219
219
  when :object_daddy then
220
220
  "#{class_name}.generate"
221
221
  else #:fixtures
222
- "#{plural_name}(:basic)"
222
+ "#{table_name}(:basic)"
223
223
  end
224
224
  end
225
225
 
@@ -398,4 +398,4 @@ class DryScaffoldGenerator < DryGenerator
398
398
  [super, banner_args, banner_options].join(' ')
399
399
  end
400
400
 
401
- end
401
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe DucksController do
4
+ fixtures :all
5
+ integrate_views
6
+
7
+ it "index action should render index template" do
8
+ get :index
9
+ response.should render_template(:index)
10
+ end
11
+
12
+ it "show action should render show template" do
13
+ get :show, :id => Duck.first
14
+ response.should render_template(:show)
15
+ end
16
+
17
+ it "new action should render new template" do
18
+ get :new
19
+ response.should render_template(:new)
20
+ end
21
+
22
+ it "create action should render new template when model is invalid" do
23
+ Duck.any_instance.stubs(:valid?).returns(false)
24
+ post :create
25
+ response.should render_template(:new)
26
+ end
27
+
28
+ it "create action should redirect when model is valid" do
29
+ Duck.any_instance.stubs(:valid?).returns(true)
30
+ post :create
31
+ response.should redirect_to(duck_url(assigns[:duck]))
32
+ end
33
+
34
+ it "edit action should render edit template" do
35
+ get :edit, :id => Duck.first
36
+ response.should render_template(:edit)
37
+ end
38
+
39
+ it "update action should render edit template when model is invalid" do
40
+ Duck.any_instance.stubs(:valid?).returns(false)
41
+ put :update, :id => Duck.first
42
+ response.should render_template(:edit)
43
+ end
44
+
45
+ it "update action should redirect when model is valid" do
46
+ Duck.any_instance.stubs(:valid?).returns(true)
47
+ put :update, :id => Duck.first
48
+ response.should redirect_to(duck_url(assigns[:duck]))
49
+ end
50
+
51
+ it "destroy action should destroy model and redirect to index action" do
52
+ duck = Duck.first
53
+ delete :destroy, :id => duck
54
+ response.should redirect_to(ducks_url)
55
+ Duck.exists?(duck.id).should be_false
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe DucksHelperTest
4
+
5
+ it 'should do something' do
6
+ assert true
7
+ end
8
+
9
+ end
@@ -7,38 +7,20 @@ class <%= controller_class_name %>Controller < InheritedResources::Base
7
7
  respond_to <%= symbol_array_to_expression(formats) %>
8
8
 
9
9
  <% end -%>
10
- <% if actions -%>
11
- before_filter :load_resource, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_MEMBER_AUTOLOAD_ACTIONS) %>]
12
- <% end -%>
13
- <% if actions -%>
14
- before_filter :load_and_paginate_resources, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_COLLECTION_AUTOLOAD_ACTIONS) %>]
15
-
16
- <% end -%>
17
-
18
10
  <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
19
11
  # GET /<%= plural_name %>/<%= action.to_s %>
20
12
  def <%= action.to_s %>
21
-
22
13
  end
23
14
 
24
15
  <% end -%>
16
+ <% if options[:pagination] -%>
25
17
  protected
26
18
 
27
19
  def collection
28
- <% if options[:pagination] -%>
29
20
  paginate_options ||= {}
30
21
  paginate_options[:page] ||= (params[:page] || 1)
31
22
  paginate_options[:per_page] ||= (params[:per_page] || 20)
32
- @collection = @<%= model_plural_name %> ||= end_of_association_chain.paginate(paginate_options)
33
- <% else -%>
34
- @collection = @<%= model_plural_name %> ||= end_of_association_chain.all
35
- <% end -%>
23
+ @<%= model_plural_name %> ||= end_of_association_chain.paginate(paginate_options)
36
24
  end
37
- alias :load_and_paginate_resources :collection
38
-
39
- def resource
40
- @resource = @<%= model_singular_name %> ||= end_of_association_chain.find(params[:id])
41
- end
42
- alias :load_resource :resource
43
-
25
+ <% end %>
44
26
  end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= controller_class_name %>Controller do
4
+ <% if options[:fixtures] -%>
5
+ fixtures :all
6
+ <% end -%>
7
+ integrate_views
8
+
9
+ <% if actions.include?(:index) -%>
10
+ it "index action should render index template" do
11
+ get :index
12
+ response.should render_template(:index)
13
+ end
14
+
15
+ <% end %>
16
+ <% if actions.include?(:show) -%>
17
+ it "show action should render show template" do
18
+ get :show, :id => Duck.first
19
+ response.should render_template(:show)
20
+ end
21
+
22
+ <% end %>
23
+ <% if actions.include?(:new) -%>
24
+ it "new action should render new template" do
25
+ get :new
26
+ response.should render_template(:new)
27
+ end
28
+
29
+ <% end %>
30
+ <% if actions.include?(:create) -%>
31
+ it "create action should render new template when model is invalid" do
32
+ Duck.any_instance.stubs(:valid?).returns(false)
33
+ post :create
34
+ response.should render_template(:new)
35
+ end
36
+
37
+ it "create action should redirect when model is valid" do
38
+ Duck.any_instance.stubs(:valid?).returns(true)
39
+ post :create
40
+ response.should redirect_to(duck_url(assigns[:duck]))
41
+ end
42
+
43
+ <% end %>
44
+ <% if actions.include?(:edit) -%>
45
+ it "edit action should render edit template" do
46
+ get :edit, :id => Duck.first
47
+ response.should render_template(:edit)
48
+ end
49
+
50
+ <% end %>
51
+ <% if actions.include?(:update) -%>
52
+ it "update action should render edit template when model is invalid" do
53
+ Duck.any_instance.stubs(:valid?).returns(false)
54
+ put :update, :id => Duck.first
55
+ response.should render_template(:edit)
56
+ end
57
+
58
+ it "update action should redirect when model is valid" do
59
+ Duck.any_instance.stubs(:valid?).returns(true)
60
+ put :update, :id => Duck.first
61
+ response.should redirect_to(duck_url(assigns[:duck]))
62
+ end
63
+
64
+ <% end %>
65
+ <% if actions.include?(:destroy) -%>
66
+ it "destroy action should destroy model and redirect to index action" do
67
+ duck = Duck.first
68
+ delete :destroy, :id => duck
69
+ response.should redirect_to(ducks_url)
70
+ Duck.exists?(duck.id).should be_false
71
+ end
72
+
73
+ <% end %>
74
+ <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
75
+ it '<%= action.to_s %> action should render <%= action.to_s %> template' do
76
+ get :<%= action.to_s %>
77
+ response.should render_template(:<%= action.to_s %>)
78
+ end
79
+
80
+ <% end -%>
81
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= controller_class_name %>HelperTest
4
+
5
+ it 'should do something' do
6
+ assert true
7
+ end
8
+
9
+ end
data/lib/dry_generator.rb CHANGED
@@ -4,6 +4,7 @@ class DryGenerator < Rails::Generator::NamedBase
4
4
  HAS_FORMTASTIC = defined?(Formtastic)
5
5
  HAS_INHERITED_RESOURCES = defined?(InheritedResources)
6
6
  HAS_SHOULDA = defined?(Shoulda)
7
+ HAS_RSPEC = defined?(Rspec)
7
8
 
8
9
  # Load defaults from config file - default or custom.
9
10
  begin
@@ -23,6 +24,7 @@ class DryGenerator < Rails::Generator::NamedBase
23
24
  BANNER_OPTIONS = [
24
25
  "[--skip-tests]",
25
26
  "[--shoulda]",
27
+ "[--rspec]",
26
28
  "[--fixtures]",
27
29
  "[--fgirl]",
28
30
  "[--machinist]",
@@ -47,20 +49,30 @@ class DryGenerator < Rails::Generator::NamedBase
47
49
  :machinist => CONFIG_OPTIONS['machinist'] || false,
48
50
  :object_daddy => CONFIG_OPTIONS['object_daddy'] || CONFIG_OPTIONS['odaddy'] || false,
49
51
  :test_unit => CONFIG_OPTIONS['test_unit'] || CONFIG_OPTIONS['tunit'] || true,
50
- :shoulda => CONFIG_OPTIONS['shoulda'] || false
52
+ :shoulda => CONFIG_OPTIONS['shoulda'] || false,
53
+ :rspec => CONFIG_OPTIONS['rspec'] || false
51
54
  }.freeze
52
55
 
53
56
  TEST_PATHS = {
54
57
  :test_unit => 'test',
55
- :shoulda => 'test'
58
+ :shoulda => 'test',
59
+ :rspec => 'spec'
56
60
  }.freeze
57
61
 
58
62
  DEFAULT_TEST_FRAMEWORK = :test_unit
59
63
  DEFAULT_FACTORY_FRAMEWORK = :fixtures
60
64
 
61
65
  TESTS_PATH = File.join('test').freeze
62
- FUNCTIONAL_TESTS_PATH = File.join(TESTS_PATH, 'functional').freeze
63
- UNIT_TESTS_PATH = File.join(TESTS_PATH, 'unit').freeze
66
+ FUNCTIONAL_TESTS_PATH = {
67
+ :test => 'functional',
68
+ :shoulda => 'functional',
69
+ :rspec => 'controllers'
70
+ }
71
+ UNIT_TESTS_PATH = {
72
+ :test => 'unit',
73
+ :shoulda => 'unit',
74
+ :rspec => 'models',
75
+ }
64
76
 
65
77
  NON_ATTR_ARG_KEY_PREFIX = '_'.freeze
66
78
 
@@ -110,12 +122,10 @@ class DryGenerator < Rails::Generator::NamedBase
110
122
  options[:test_framework] = :shoulda
111
123
  end
112
124
 
113
- #opt.on('--rspec', "Test: Generate \"rspec\" tests.") do |v|
114
- # # TODO: Implement RSpec templates. Maybe.
115
- # puts '[dry_scaffold:] RSpec currently not supported.'
116
- # options[:rspec] = v
117
- # options[:test_framework] = :rspec
118
- #end
125
+ opt.on("--rspec", "Test: Generate \"rspec\" tests.") do |v|
126
+ options[:rspec] = v
127
+ options[:test_framework] = :rspec
128
+ end
119
129
 
120
130
  opt.on("--fixtures", "Test: Generate fixtures. Note: Rails default.") do |v|
121
131
  options[:fixtures] = v
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grimen-dry_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Grimfelt
@@ -13,7 +13,7 @@ date: 2009-08-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: A DRYer scaffold generator for Rails. Generates dry semantic and standards compliant views, and dry RESTful controllers.
16
+ description: A DRYer scaffold generator for Rails. Generates dry semantic and standards compliant views, and dry RESTful controllers. Has support for Rspec, Shoulda, Formtastic, Inherited Resources, Factory Girl, Machinist, Object Daddy, Will Paginate
17
17
  email: grimen@gmail.com
18
18
  executables:
19
19
  - dscaffold
@@ -45,6 +45,7 @@ files:
45
45
  - generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml
46
46
  - generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb
47
47
  - generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb
48
+ - generators/dry_model/prototypes/tests/rspec/unit_test.rb
48
49
  - generators/dry_model/prototypes/tests/shoulda/unit_test.rb
49
50
  - generators/dry_model/prototypes/tests/test_unit/unit_test.rb
50
51
  - generators/dry_model/templates/models/active_record_migration.rb
@@ -52,15 +53,18 @@ files:
52
53
  - generators/dry_model/templates/models/fixture_data/active_record_fixtures.yml
53
54
  - generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb
54
55
  - generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb
56
+ - generators/dry_model/templates/models/tests/rspec/unit_test.rb
55
57
  - generators/dry_model/templates/models/tests/shoulda/unit_test.rb
56
58
  - generators/dry_model/templates/models/tests/test_unit/unit_test.rb
57
59
  - generators/dry_scaffold/USAGE
58
60
  - generators/dry_scaffold/dry_scaffold_generator.rb
59
61
  - generators/dry_scaffold/prototypes/controllers/action_controller.rb
60
62
  - generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb
63
+ - generators/dry_scaffold/prototypes/controllers/tests/rspec/functional_test.rb
61
64
  - generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb
62
65
  - generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb
63
66
  - generators/dry_scaffold/prototypes/helpers/helper.rb
67
+ - generators/dry_scaffold/prototypes/helpers/tests/rspec/unit_test.rb
64
68
  - generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb
65
69
  - generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb
66
70
  - generators/dry_scaffold/prototypes/views/builder/index.atom.builder
@@ -74,9 +78,11 @@ files:
74
78
  - generators/dry_scaffold/prototypes/views/haml/show.html.haml
75
79
  - generators/dry_scaffold/templates/controllers/action_controller.rb
76
80
  - generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb
81
+ - generators/dry_scaffold/templates/controllers/tests/rspec/functional_test.rb
77
82
  - generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb
78
83
  - generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb
79
84
  - generators/dry_scaffold/templates/helpers/helper.rb
85
+ - generators/dry_scaffold/templates/helpers/tests/rspec/unit_test.rb
80
86
  - generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb
81
87
  - generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb
82
88
  - generators/dry_scaffold/templates/views/builder/index.atom.builder
@@ -95,7 +101,6 @@ files:
95
101
  - tasks/dry_scaffold.rake
96
102
  has_rdoc: false
97
103
  homepage: http://github.com/grimen/dry_scaffold/tree/master
98
- licenses:
99
104
  post_install_message:
100
105
  rdoc_options:
101
106
  - --charset=UTF-8
@@ -116,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
121
  requirements: []
117
122
 
118
123
  rubyforge_project:
119
- rubygems_version: 1.3.5
124
+ rubygems_version: 1.2.0
120
125
  signing_key:
121
126
  specification_version: 3
122
127
  summary: A DRYer scaffold generator for Rails. Generates dry semantic and standards compliant views, and dry RESTful controllers.