grimen-dry_scaffold 0.2.6 → 0.3.0

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 (56) hide show
  1. data/CHANGELOG.textile +6 -0
  2. data/README.textile +26 -17
  3. data/TODO.textile +43 -6
  4. data/config/scaffold.yml +14 -6
  5. data/generators/dry_model/USAGE +2 -5
  6. data/generators/dry_model/dry_model_generator.rb +68 -145
  7. data/generators/dry_model/prototypes/active_record_migration.rb +1 -1
  8. data/generators/dry_model/prototypes/active_record_model.rb +2 -2
  9. data/generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml +3 -0
  10. data/generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb +4 -0
  11. data/generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb +8 -0
  12. data/generators/dry_model/prototypes/tests/shoulda/unit_test.rb +20 -0
  13. data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +8 -2
  14. data/generators/dry_model/templates/models/active_record_migration.rb +2 -2
  15. data/generators/dry_model/templates/models/{test_data → fixture_data}/active_record_fixtures.yml +1 -1
  16. data/generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb +5 -0
  17. data/generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb +9 -0
  18. data/generators/dry_model/templates/models/tests/shoulda/unit_test.rb +23 -0
  19. data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +10 -2
  20. data/generators/dry_scaffold/USAGE +4 -5
  21. data/generators/dry_scaffold/dry_scaffold_generator.rb +145 -151
  22. data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +53 -52
  23. data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +5 -4
  24. data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +107 -0
  25. data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +76 -0
  26. data/generators/dry_scaffold/prototypes/helpers/helper.rb +1 -1
  27. data/generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb +9 -0
  28. data/generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb +6 -2
  29. data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +9 -9
  30. data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +7 -7
  31. data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +6 -6
  32. data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +3 -3
  33. data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +5 -5
  34. data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +1 -2
  35. data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +3 -3
  36. data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +6 -6
  37. data/generators/dry_scaffold/templates/controllers/action_controller.rb +7 -6
  38. data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +2 -2
  39. data/generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb +90 -0
  40. data/generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb +46 -37
  41. data/generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb +9 -0
  42. data/generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb +4 -0
  43. data/generators/dry_scaffold/templates/views/haml/_item.html.haml +3 -3
  44. data/generators/dry_scaffold/templates/views/haml/edit.html.haml +1 -1
  45. data/generators/dry_scaffold/templates/views/haml/index.html.haml +1 -1
  46. data/generators/dry_scaffold/templates/views/haml/new.html.haml +1 -1
  47. data/generators/dry_scaffold/templates/views/haml/show.html.haml +2 -2
  48. data/lib/dry_generator.rb +176 -0
  49. data/tasks/dry_scaffold.rake +5 -1
  50. metadata +16 -9
  51. data/generators/dry_model/prototypes/test_data/active_record_fixtures.yml +0 -3
  52. data/generators/dry_model/prototypes/test_data/factory_girl_factories.rb +0 -4
  53. data/generators/dry_model/prototypes/test_data/machinist_factories.rb +0 -8
  54. data/generators/dry_model/templates/models/test_data/factory_girl_factories.rb +0 -5
  55. data/generators/dry_model/templates/models/test_data/machinist_factories.rb +0 -9
  56. data/generators/dry_scaffold/prototypes/controllers/tests/unit_test/functional_test.rb +0 -64
data/CHANGELOG.textile CHANGED
@@ -1,3 +1,9 @@
1
+ h1. 0.3.0 (2009-07-23)
2
+
3
+ * Major refactoring of the code.
4
+ * Test/Fixture-stuff re-written from the ground, now tested thoroughly and considered stable - was not before. Plenty sloppy bugs squashed.
5
+ * Added Shoulda tests generation.
6
+
1
7
  h1. 0.2.5 (2009-06-12)
2
8
 
3
9
  * Fixed typo: Gem configuration instructions in README.
data/README.textile CHANGED
@@ -24,15 +24,19 @@ h3. Optional:
24
24
 
25
25
  h4. Controllers/Views
26
26
 
27
- * "*will_paginate*":http://github.com/mislav/will_paginate - Pagination
28
- * "*formtastic*":http://github.com/justinfrench/formtastic - DRY and semantic forms
29
27
  * "*inherited_resources*":http://github.com/josevalim/inherited_resources - DRY/Resourceful controllers
28
+ * "*formtastic*":http://github.com/justinfrench/formtastic - DRY and semantic forms
29
+ * "*will_paginate*":http://github.com/mislav/will_paginate - Pagination
30
30
 
31
31
  h4. Models
32
32
 
33
33
  * "*factory_girl*":http://github.com/thoughtbot/factory_girl - Fixture-replacement
34
34
  * "*machinist*":http://github.com/notahat/machinist - Fixture-replacement
35
35
  * "*object_daddy*":http://github.com/flogic/object_daddy - Fixture-replacement
36
+
37
+ h4. Testing
38
+
39
+ * "*Shoulda*":http://github.com/thoughtbot/shoulda - Testing framework
36
40
 
37
41
  h2. Features
38
42
 
@@ -47,7 +51,7 @@ The most characteristic features:
47
51
  * Collection pagination using will_paginate by default. Note: Can be turned off.
48
52
  * Optionally specify what actions/views to generate (stubs for specified REST-actions will be generated).
49
53
  * Optionally specify what respond_to-formats to generate (stubs for the most common respond_to-formats will be generated).
50
- * Generates default helpers/models/migrations, and REST-routes.
54
+ * Generates default helpers/models/migrations, and REST-routes (if not already defined).
51
55
 
52
56
  h3. Formtastic Forms
53
57
 
@@ -172,7 +176,7 @@ h3. More To Come... (TODO)
172
176
  These are things I have in mind:
173
177
 
174
178
  * Handle belongs_to, i.e. specify MODEL --belongs-to PARENT_MODEL, which generates proper routes, proper before-filters if inherited_resources-controller, adding belongs_to-association in model, and correct form_for arguments.
175
- * Choose test suits: testunit/shoulda/rspec
179
+ * RSpec-support?
176
180
 
177
181
  h2. Setup
178
182
 
@@ -211,7 +215,7 @@ h4. Manual
211
215
  Get the gems...you want:
212
216
 
213
217
  <pre>sudo gem install haml
214
- sudo gem install will_paginate
218
+ sudo gem install mislav-will_paginate
215
219
  sudo gem install justinfrench-formtastic
216
220
  sudo gem install josevalim-inherited_resources</pre>
217
221
 
@@ -219,18 +223,18 @@ sudo gem install josevalim-inherited_resources</pre>
219
223
 
220
224
  <pre>config.gem 'haml'
221
225
  config.gem 'will_paginate'
222
- config.gem 'justinfrench-formtastic', :lib => 'formtastic, :source => 'http://gems.github.com'
226
+ config.gem 'justinfrench-formtastic', :lib => 'formtastic', :source => 'http://gems.github.com'
223
227
  config.gem 'josevalim-inherited_resources', :lib => 'inherited_resources', :source => 'http://gems.github.com'</pre>
224
228
 
225
229
  h2. Usage
226
230
 
227
- <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-tests] [--include-layout] [--fixtures] [--fgirl] [--machinist] [--odaddy] [--skip-migration] [--skip-timestamps]</pre>
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>
228
232
 
229
233
  ...or use the alias @dscaffold@ instead of @dry_scaffold@.
230
234
 
231
235
  For generating just a *model*, then use:
232
236
 
233
- <pre>./script/generate dry_model ModelName [attribute:type attribute:type] [_indexes:attribute,...] [--fixtures] [--fgirl] [--machinist] [--odaddy] [--skip-migration] [--skip-timestamps] [--skip-tests]</pre>
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>
234
238
 
235
239
  ...or use the alias @dmodel@ instead of @dry_model@.
236
240
 
@@ -380,7 +384,6 @@ These are the options for the scaffold-generator.
380
384
  * @--skip-formtastic@ - Don't generate formtastic forms in views, i.e. don't use *formtastic*.
381
385
  * @--skip-views@ - Don't generate views.
382
386
  * @--skip-helpers@ - Don't generate helpers.
383
- * @--skip-tests@ - Don't generate tests (functional/unit/...).
384
387
  * @--skip-builders@ - Don't generate builders.
385
388
  * @--layout@ - Generate layout.
386
389
 
@@ -388,16 +391,22 @@ h4. Model
388
391
 
389
392
  These are the options for the model/scaffold-generators.
390
393
 
391
- * @--fixtures@ - Generate fixtures.
392
- * @--fgirl@ - Generate *factory_girl* factories.
393
- * @--machinist@ - Generate *machinist* blueprints (factories).
394
- * @--odaddy@ - Generate *object_daddy* generator/factory methods.
395
394
  * @--skip-timestamps@ - Don't add timestamps to the migration file.
396
395
  * @--skip-migration@ - Skip generation of migration file.
396
+
397
+ h4. All
398
+
399
+ * @--skip-tests@ - Don't generate tests (functional/unit/...).
400
+ * @--tunit@ - Generate/Use test_unit tests. Note: Rails default.
401
+ * @--shoulda@ - Generate/Use *shoulda* tests.
402
+ * @--fixtures@ - Generate/Use fixtures. Note: Rails default.
403
+ * @--fgirl@ - Generate/Use *factory_girl* factories.
404
+ * @--machinist@ - Generate/Use *machinist* blueprints (factories).
405
+ * @--odaddy@ - Generate/Use *object_daddy* generator/factory methods.
397
406
 
398
407
  As DryScaffold is built upon Rails generator, the default generator options is available as well. For more details; see Rails documentation.
399
408
 
400
- h3. Setting Defaults
409
+ h3. Setting Defaults
401
410
 
402
411
  You can set defaults for the generator args/options in @config/scaffold.yml@. To generate this file, simply do:
403
412
 
@@ -410,11 +419,11 @@ No need for more samples here, just create a new Rails project, install DryScaff
410
419
  For your inspiration, you could try the following:
411
420
 
412
421
  <pre>./script/generate dry_scaffold Zebra name:string about:text --skip-resourceful
413
- ./script/generate dry_scaffold Kangaroo name:string about:text --skip-formtastic
422
+ ./script/generate dscaffold Kangaroo name:string about:text --skip-formtastic
414
423
  ./script/generate dscaffold Duck name:string about:text _actions:new,create,index,quack
415
424
  ./script/generate dscaffold Parrot name:string about:text _formats:html,xml,yml
416
- ./script/generate dscaffold GoldFish name:string about:text _indexes:name --fgirl
417
- ./script/generate dry_model Frog name:string about:text _indexes:name,name+about --fixtures</pre>
425
+ ./script/generate dmodel GoldFish name:string about:text _indexes:name --fgirl
426
+ ./script/generate dmodel Frog name:string about:text _indexes:name,name+about --fixtures</pre>
418
427
 
419
428
  ...or just go crazy!
420
429
 
data/TODO.textile CHANGED
@@ -2,12 +2,49 @@ h1. TODO
2
2
 
3
3
  h2. Next
4
4
 
5
- * Feature: Handle belongs_to, i.e. specify MODEL --belongs-to PARENT_MODEL, which generates proper routes, proper before-filters if inherited_resources-controller, adding belongs_to-association in model, and correct form_for arguments.
6
- * Choose test suits: testunit/shoulda/rspec
5
+ * Bug/Issue: InheritedResources functional testing issue.
6
+ * Feature: RSpec-templates?
7
+ * Optimization: Write even better functional tests for REST-actions. Goal: Killer-tests, i.e. "best practice"-tests. Suggestion: Routing, formats, ...
7
8
 
8
- h2. Maybe later
9
+ h2. Maybe
9
10
 
10
- * Clean-up: Comment the code a bit more =)
11
- * Refactor: Break up in different generators: dry_controller, dry_views, etc., and use as dependencies in dry_scaffold?
12
11
  * Feature: Check for overridden templates in: RAILS_ROOT/lib/dry_scaffold/templates/
13
- * Feature: Builder for podcast-feed, similar to RSS/Atom-builders. http://wiki.github.com/radiant/radiant/host-a-podcast
12
+ * Feature: Handle belongs_to, i.e. specify MODEL --belongs-to PARENT_MODEL, which generates proper routes, proper before-filters if inherited_resources-controller, adding belongs_to-association in model, and correct form_for arguments.
13
+ * Feature: Builder for podcast-feed, similar to RSS/Atom-builders. http://wiki.github.com/radiant/radiant/host-a-podcast
14
+ * Tests: Generator tests. =P (Not very straightforward...)
15
+
16
+ h2. Issues
17
+
18
+ * Contact José regarding the InheritedResources-issue:
19
+
20
+ 1) ActionController::RoutingError: parrot_url failed to generate from {:controller=>"parrots", :id=>#<Parrot id: nil, name: "Hello", created_at: "2009-07-21 18:53:25", updated_at: "2009-07-21 18:53:25">, :action=>"show"}, expected: {:controller=>"parrots", :action=>"show"}, diff: {:id=>#<Parrot id: nil, name: "Hello", created_at: "2009-07-21 18:53:25", updated_at: "2009-07-21 18:53:25">}
21
+ (eval):16:in `parrot_url'
22
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/url_helpers.rb:194:in `resource_url'
23
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base_helpers.rb:311:in `send'
24
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base_helpers.rb:311:in `parse_redirect_url'
25
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base.rb:79:in `create'
26
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/respond_to.rb:301:in `call'
27
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/respond_to.rb:301:in `respond_any'
28
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/respond_to.rb:233:in `respond_to'
29
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base_helpers.rb:283:in `respond_to_with_dual_blocks'
30
+ /opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base.rb:78:in `create'
31
+ haml (2.0.9) rails/./lib/sass/plugin/rails.rb:19:in `process'
32
+ /test/functional/donkeys_controller_test.rb:8:in `test_create'
33
+
34
+ test 'create' do
35
+ Donkey.any_instance.expects(:save).returns(true)
36
+ @donkey = donkeys(:basic)
37
+ post :create, :donkey => @donkey.attributes # <<<<<<<<<<<<< donkeys_controller_test.rb:8
38
+ assert_response :redirect
39
+ end
40
+
41
+ 2) test_destroy_with_failure(DonkeysControllerTest) [/test/functional/donkeys_controller_test.rb:45]:
42
+ <nil> expected to not be nil.
43
+
44
+ test 'destroy with failure' do
45
+ Donkey.any_instance.expects(:destroy).returns(false)
46
+ @donkey = donkeys(:basic)
47
+ delete :destroy, :id => @donkey.to_param
48
+ assert_not_nil flash[:error] # <<<<<<<<<<<<< donkeys_controller_test.rb:45
49
+ assert_response :redirect
50
+ end
data/config/scaffold.yml CHANGED
@@ -5,18 +5,26 @@ dry_scaffold:
5
5
  formats: html,js,xml,json
6
6
  options:
7
7
  formtastic: true
8
- resourceful: true
8
+ resourceful: false
9
9
  pagination: true
10
+ layout: false
10
11
  views: true
11
12
  helpers: true
12
13
  tests: true
13
- layout: false
14
- dry_model:
15
- options:
16
- fixtures: false
14
+ tunit: true
15
+ shoulda: false
16
+ fixtures: true
17
17
  fgirl: false
18
18
  machinist: false
19
19
  object_daddy: false
20
+ dry_model:
21
+ options:
20
22
  migration: true
21
23
  timestamps: true
22
- tests: true
24
+ tests: true
25
+ tunit: true
26
+ shoulda: false
27
+ fixtures: true
28
+ fgirl: false
29
+ machinist: false
30
+ object_daddy: false
@@ -5,8 +5,5 @@ DESCRIPTION
5
5
  A replacement for the Rails model generator - a part of the dry_generator toolset.
6
6
 
7
7
  EXAMPLE
8
- ./script/generate dry_model ModelName [attribute:type attribute:type] [_index:name,owner_id+owner_type,active,...] [--fixtures] [--fgirl] [--machinist] [--odaddy] [--skip-timestamps] [--skip-migration] [--skip-tests]
9
-
10
- ...or the shortcut version:
11
-
12
- ./script/generate dmodel ...
8
+ ./script/generate dmodel GoldFish name:string about:text _indexes:name --fgirl
9
+ ./script/generate dmodel Frog name:string about:text _indexes:name,name+about --fixtures
@@ -1,55 +1,25 @@
1
- require 'rubygems'
2
- %w(factory_girl machinist object_daddy).each do |lib|
3
- begin
4
- require lib
5
- rescue MissingSourceFile
6
- eval("#{lib.upcase} = #{false}")
7
- else
8
- eval("#{lib.upcase} = #{true}")
9
- end
10
- end
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'dry_generator'))
11
2
 
12
- class DryModelGenerator < Rails::Generator::NamedBase
13
-
14
- # Load defaults from config file - default or custom.
15
- begin
16
- default_config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'scaffold.yml'))
17
- custom_config_file = File.expand_path(File.join(Rails.root, 'config', 'scaffold.yml'))
18
- config_file = File.join(File.exist?(custom_config_file) ? custom_config_file : default_config_file)
19
- config = YAML::load(File.open(config_file))
20
- CONFIG_OPTIONS = config['dry_model']['options'] rescue nil
21
- end
3
+ class DryModelGenerator < DryGenerator
22
4
 
23
- DEFAULT_OPTIONS = {
24
- :fixtures => CONFIG_OPTIONS['fixtures'] || false,
25
- :factory_girl => CONFIG_OPTIONS['factory_girl'] || false,
26
- :machinist => CONFIG_OPTIONS['machinist'] || false,
27
- :object_daddy => CONFIG_OPTIONS['object_daddy'] || false,
28
- :skip_timestamps => !CONFIG_OPTIONS['timestamps'] || false,
29
- :skip_migration => !CONFIG_OPTIONS['migration'] || false,
30
- :skip_tests => !CONFIG_OPTIONS['tests'] || false
31
- }
5
+ # Banner: Generator arguments and options.
6
+ BANNER_ARGS = [
7
+ "[_indexes:field,field+field,field,...]"
8
+ ].freeze
9
+ BANNER_OPTIONS = [
10
+ "[--skip-timestamps]",
11
+ "[--skip-migration]"
12
+ ].freeze
32
13
 
33
- DEFAULT_TEST_FRAMEWORK = :test_unit
14
+ # Paths.
15
+ MODELS_PATH = File.join('app', 'models').freeze
16
+ MIGRATIONS_PATH = File.join('db', 'migrate').freeze
34
17
 
35
- MODELS_PATH = File.join('app', 'models').freeze
36
- MIGRATIONS_PATH = File.join('db', 'migrate').freeze
37
- TESTS_PATH = File.join('test').freeze
38
- UNIT_TESTS_PATH = File.join(TESTS_PATH, 'unit').freeze
39
- FIXTURES_PATH = File.join(TESTS_PATH, 'fixtures').freeze
40
- FACTORY_GIRL_FACTORIES_PATH = File.join(TESTS_PATH, 'factories').freeze
41
- MACHINIST_FACTORIES_PATH = File.join(TESTS_PATH, 'blueprints').freeze
42
-
43
- NON_ATTR_ARG_KEY_PREFIX = '_'.freeze
44
-
45
18
  attr_reader :indexes,
46
- :references,
47
- :test_framework
19
+ :references
48
20
 
49
21
  def initialize(runtime_args, runtime_options = {})
50
- super
51
-
52
- @test_framework = DEFAULT_TEST_FRAMEWORK
22
+ super(runtime_args, runtime_options)
53
23
 
54
24
  @attributes ||= []
55
25
  args_for_model = []
@@ -83,41 +53,43 @@ class DryModelGenerator < Rails::Generator::NamedBase
83
53
  # Check for class naming collisions.
84
54
  m.class_collisions class_name, "#{class_name}Test"
85
55
 
86
- # Directories.
56
+ # Model.
87
57
  m.directory File.join(MODELS_PATH, class_path)
88
- m.directory File.join(UNIT_TESTS_PATH, class_path) unless options[:skip_tests]
89
- m.directory File.join(FIXTURES_PATH, class_path) if options[:fixtures]
90
- m.directory File.join(FACTORY_GIRL_FACTORIES_PATH, class_path) if options[:factory_girl]
91
- m.directory File.join(MACHINIST_FACTORIES_PATH, class_path) if options[:machinist]
92
-
93
- # Model
94
58
  m.template File.join('models', 'active_record_model.rb'),
95
59
  File.join(MODELS_PATH, class_path, "#{file_name}.rb")
96
60
 
97
61
  # Model Tests.
98
62
  unless options[:skip_tests]
63
+ model_tests_path = File.join(TEST_PATHS[test_framework], 'unit')
64
+ m.directory File.join(model_tests_path, class_path)
99
65
  m.template File.join('models', 'tests', "#{test_framework}", 'unit_test.rb'),
100
- File.join(UNIT_TESTS_PATH, class_path, "#{file_name}_test.rb")
101
- end
102
-
103
- # Fixtures/Factories.
104
- if options[:fixtures]
105
- m.template File.join('models', 'test_data', 'active_record_fixtures.yml'),
106
- File.join(FIXTURES_PATH, "#{file_name}.yml")
107
- end
108
- if options[:factory_girl]
109
- m.template File.join('models', 'test_data', 'factory_girl_factories.rb'),
110
- File.join(FACTORY_GIRL_FACTORIES_PATH, "#{file_name}.rb")
111
- end
112
- if options[:machinist]
113
- m.template File.join('models', 'test_data', 'machinist_factories.rb'),
114
- File.join(MACHINIST_FACTORIES_PATH, "#{file_name}.rb")
66
+ File.join(model_tests_path, class_path, "#{file_name}_test.rb")
67
+
68
+ # Fixtures/Factories.
69
+ if options[:fixtures]
70
+ fixtures_path = File.join(TEST_PATHS[test_framework], 'fixtures')
71
+ m.directory File.join(fixtures_path, class_path)
72
+ m.template File.join('models', 'fixture_data', 'active_record_fixtures.yml'),
73
+ File.join(fixtures_path, class_path, "#{plural_name}.yml")
74
+ end
75
+ if options[:factory_girl]
76
+ factory_girl_path = File.join(TEST_PATHS[test_framework], 'factories')
77
+ m.directory File.join(factory_girl_path, class_path)
78
+ m.template File.join('models', 'fixture_data', 'factory_girl_factories.rb'),
79
+ File.join(factory_girl_path, class_path, "#{plural_name}.rb")
80
+ end
81
+ if options[:machinist]
82
+ machinist_path = File.join(TEST_PATHS[test_framework], 'blueprints')
83
+ m.directory File.join(machinist_path, class_path)
84
+ m.template File.join('models', 'fixture_data', 'machinist_blueprints.rb'),
85
+ File.join(machinist_path, class_path, "#{plural_name}.rb")
86
+ end
87
+ # NOTE: :object_daddy handled in model
115
88
  end
116
- # NOTE: :object_daddy handled in model
117
89
 
118
90
  # Migration.
119
91
  unless options[:skip_migration]
120
- m.migration_template File.join('models', 'active_record_migration.rb') , MIGRATIONS_PATH,
92
+ m.migration_template File.join('models', 'active_record_migration.rb'), MIGRATIONS_PATH,
121
93
  :assigns => {:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"},
122
94
  :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
123
95
  end
@@ -125,87 +97,38 @@ class DryModelGenerator < Rails::Generator::NamedBase
125
97
  end
126
98
 
127
99
  protected
100
+
101
+ def add_options!(opt)
102
+ super(opt)
128
103
 
129
- def add_options!(opt)
130
- opt.separator ''
131
- opt.separator 'Options:'
132
-
133
- opt.on("--fixtures", "Generate fixtures.") do |v|
134
- options[:fixtures] = v
135
- end
136
-
137
- opt.on("--fgirl", "Generate \"factory_girl\" factories.") do |v|
138
- options[:factory_girl] = v
139
- end
140
-
141
- opt.on("--machinist", "Generate \"machinist\" blueprints (factories).") do |v|
142
- options[:machinist] = v
143
- end
144
-
145
- opt.on("--odaddy", "Generate \"object_daddy\" generator/factory methods.") do |v|
146
- options[:object_daddy] = v
147
- end
148
-
149
- opt.on("--skip-timestamps", "Don't add timestamps to the migration file.") do |v|
150
- options[:skip_timestamps] = v
151
- end
152
-
153
- opt.on("--skip-migration", "Skip generation of migration file.") do |v|
154
- options[:skip_migration] = v
155
- end
156
-
157
- opt.on("--skip-tests", "Skip generation of tests.") do |v|
158
- options[:skip_tests] = v
159
- end
160
- end
104
+ opt.separator ' '
105
+ opt.separator 'Model Options:'
161
106
 
162
- def banner
163
- ["Usage: #{$0} #{spec.name} ModelName",
164
- "[field:type field:type]",
165
- "[_indexes:name,owner_id+owner_type,active,...]",
166
- "[--fixtures]",
167
- "[--fgirl]",
168
- "[--machinist]",
169
- "[--odaddy]",
170
- "[--skip_timestamps]",
171
- "[--skip-migration]",
172
- "[--skip-tests]"
173
- ].join(' ')
107
+ opt.on("--skip-timestamps", "Don't add timestamps to the migration file.") do |v|
108
+ options[:skip_timestamps] = v
174
109
  end
175
110
 
176
- end
177
-
178
- module Rails
179
- module Generator
180
- class GeneratedAttribute
181
- def default_for_fixture
182
- @default ||= case type
183
- when :integer then 1
184
- when :float then 1.5
185
- when :decimal then '9.99'
186
- when :datetime, :timestamp, :time then Time.now.to_s(:db)
187
- when :date then Date.today.to_s(:db)
188
- when :string then 'Hello'
189
- when :text then 'Lorem ipsum dolor sit amet...'
190
- when :boolean then false
191
- else
192
- ''
193
- end
111
+ opt.on("--skip-migration", "Skip generation of migration file.") do |v|
112
+ options[:skip_migration] = v
194
113
  end
195
- def default_for_factory
196
- @default ||= case type
197
- when :integer then 1
198
- when :float then 1.5
199
- when :decimal then '9.99'
200
- when :datetime, :timestamp, :time then 'Time.now'
201
- when :date then 'Date.today'
202
- when :string then '"Hello"'
203
- when :text then '"Lorem ipsum dolor sit amet..."'
204
- when :boolean then false
205
- else
206
- ''
207
- end
114
+
115
+ opt.on("--skip-tests", "Skip generation of tests.") do |v|
116
+ options[:skip_tests] = v
208
117
  end
118
+
119
+ opt.separator ' '
209
120
  end
210
- end
121
+
122
+ def banner_args
123
+ [BANNER_ARGS, super].flatten.join(' ')
124
+ end
125
+
126
+ def banner_options
127
+ [BANNER_OPTIONS, super].flatten.join(' ')
128
+ end
129
+
130
+ def banner
131
+ [super, banner_args, banner_options].join(' ')
132
+ end
133
+
211
134
  end