dry_scaffold 0.3.6

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 (73) hide show
  1. data/CHANGELOG.textile +55 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +473 -0
  4. data/Rakefile +54 -0
  5. data/TODO.textile +36 -0
  6. data/bin/dmodel +3 -0
  7. data/bin/dry_model +3 -0
  8. data/bin/dry_scaffold +3 -0
  9. data/bin/dscaffold +3 -0
  10. data/config/scaffold.yml +33 -0
  11. data/generators/dmodel/dmodel_generator.rb +15 -0
  12. data/generators/dry_model/USAGE +9 -0
  13. data/generators/dry_model/dry_model_generator.rb +134 -0
  14. data/generators/dry_model/prototypes/active_record_migration.rb +17 -0
  15. data/generators/dry_model/prototypes/active_record_model.rb +9 -0
  16. data/generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml +3 -0
  17. data/generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb +4 -0
  18. data/generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb +8 -0
  19. data/generators/dry_model/prototypes/tests/rspec/unit_test.rb +9 -0
  20. data/generators/dry_model/prototypes/tests/shoulda/unit_test.rb +20 -0
  21. data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +15 -0
  22. data/generators/dry_model/templates/models/active_record_migration.rb +23 -0
  23. data/generators/dry_model/templates/models/active_record_model.rb +15 -0
  24. data/generators/dry_model/templates/models/fixture_data/active_record_fixtures.yml +6 -0
  25. data/generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb +5 -0
  26. data/generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb +9 -0
  27. data/generators/dry_model/templates/models/tests/rspec/unit_test.rb +11 -0
  28. data/generators/dry_model/templates/models/tests/shoulda/unit_test.rb +23 -0
  29. data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +17 -0
  30. data/generators/dry_scaffold/USAGE +11 -0
  31. data/generators/dry_scaffold/dry_scaffold_generator.rb +410 -0
  32. data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +135 -0
  33. data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +25 -0
  34. data/generators/dry_scaffold/prototypes/controllers/tests/rspec/functional_test.rb +57 -0
  35. data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +99 -0
  36. data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +70 -0
  37. data/generators/dry_scaffold/prototypes/helpers/helper.rb +3 -0
  38. data/generators/dry_scaffold/prototypes/helpers/tests/rspec/unit_test.rb +9 -0
  39. data/generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb +9 -0
  40. data/generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb +9 -0
  41. data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +20 -0
  42. data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +21 -0
  43. data/generators/dry_scaffold/prototypes/views/haml/_form.html.haml +3 -0
  44. data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +9 -0
  45. data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +10 -0
  46. data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +17 -0
  47. data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +18 -0
  48. data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +10 -0
  49. data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +13 -0
  50. data/generators/dry_scaffold/templates/controllers/action_controller.rb +250 -0
  51. data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +26 -0
  52. data/generators/dry_scaffold/templates/controllers/tests/rspec/functional_test.rb +85 -0
  53. data/generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb +90 -0
  54. data/generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb +87 -0
  55. data/generators/dry_scaffold/templates/helpers/helper.rb +3 -0
  56. data/generators/dry_scaffold/templates/helpers/tests/rspec/unit_test.rb +9 -0
  57. data/generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb +9 -0
  58. data/generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb +9 -0
  59. data/generators/dry_scaffold/templates/views/builder/index.atom.builder +20 -0
  60. data/generators/dry_scaffold/templates/views/builder/index.rss.builder +21 -0
  61. data/generators/dry_scaffold/templates/views/haml/_form.html.haml +13 -0
  62. data/generators/dry_scaffold/templates/views/haml/_item.html.haml +10 -0
  63. data/generators/dry_scaffold/templates/views/haml/edit.html.haml +18 -0
  64. data/generators/dry_scaffold/templates/views/haml/index.html.haml +20 -0
  65. data/generators/dry_scaffold/templates/views/haml/layout.html.haml +19 -0
  66. data/generators/dry_scaffold/templates/views/haml/new.html.haml +18 -0
  67. data/generators/dry_scaffold/templates/views/haml/show.html.haml +13 -0
  68. data/generators/dscaffold/dscaffold_generator.rb +15 -0
  69. data/lib/dry_generator.rb +197 -0
  70. data/lib/dry_scaffold/tasks.rb +5 -0
  71. data/lib/setup_helper.rb +36 -0
  72. data/tasks/dry_scaffold.rake +95 -0
  73. metadata +140 -0
@@ -0,0 +1,90 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ <% if actions.include?(:create) -%>
6
+ context 'create' do
7
+ setup do
8
+ <%= resource_instance %> = <%= build_object %>
9
+ post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
10
+ <%= resource_instance %> = <%= class_name %>.find(:all).last
11
+ end
12
+ should_redirect_to '<%= show_path %>'
13
+ end
14
+
15
+ <% end -%>
16
+ <% if actions.include?(:update) -%>
17
+ context 'update' do
18
+ setup do
19
+ <%= resource_instance %> = <%= build_object %>
20
+ put :update, :id => <%= resource_instance %>.to_param, :<%= singular_name %> => <%= resource_instance %>.attributes
21
+ end
22
+ should_redirect_to '<%= show_path %>'
23
+ end
24
+
25
+ <% end -%>
26
+ <% if actions.include?(:destroy) -%>
27
+ context 'destroy' do
28
+ setup do
29
+ <%= resource_instance %> = <%= build_object %>
30
+ delete :destroy, :id => <%= resource_instance %>.to_param
31
+ end
32
+ should_redirect_to '<%= index_path %>'
33
+ end
34
+
35
+ <% end -%>
36
+ <% if actions.include?(:new) -%>
37
+ context 'new' do
38
+ setup do
39
+ get :new
40
+ end
41
+ should_respond_with :success
42
+ should_render_template :new
43
+ should_assign_to :<%= singular_name %>
44
+ end
45
+
46
+ <% end -%>
47
+ <% if actions.include?(:edit) -%>
48
+ context 'edit' do
49
+ setup do
50
+ <%= resource_instance %> = <%= build_object %>
51
+ get :edit, :id => <%= resource_instance %>.to_param
52
+ end
53
+ should_respond_with :success
54
+ should_render_template :edit
55
+ should_assign_to :<%= singular_name %>
56
+ end
57
+
58
+ <% end -%>
59
+ <% if actions.include?(:show) -%>
60
+ context 'show' do
61
+ setup do
62
+ <%= resource_instance %> = <%= build_object %>
63
+ get :show, :id => <%= resource_instance %>.to_param
64
+ end
65
+ should_respond_with :success
66
+ should_render_template :show
67
+ should_assign_to :<%= singular_name %>
68
+ end
69
+
70
+ <% end -%>
71
+ <% if actions.include?(:index) -%>
72
+ context 'index' do
73
+ setup do
74
+ get :index
75
+ end
76
+ should_respond_with :success
77
+ should_assign_to :<%= plural_name %>
78
+ end
79
+
80
+ <% end -%>
81
+ <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
82
+ context '<%= action.to_s %>' do
83
+ setup do
84
+ get :<%= action.to_s %>
85
+ end
86
+ should_respond_with :success
87
+ end
88
+
89
+ <% end -%>
90
+ end
@@ -0,0 +1,87 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ <% if actions.include?(:create) -%>
6
+ test 'create' do
7
+ <%= class_name %>.any_instance.expects(:save).returns(true)
8
+ <%= resource_instance %> = <%= build_object %>
9
+ post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
10
+ assert_response :redirect
11
+ end
12
+
13
+ test 'create with failure' do
14
+ <%= class_name %>.any_instance.expects(:save).returns(false)
15
+ <%= resource_instance %> = <%= build_object %>
16
+ post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
17
+ assert_template 'new'
18
+ end
19
+
20
+ <% end -%>
21
+ <% if actions.include?(:update) -%>
22
+ test 'update' do
23
+ <%= class_name %>.any_instance.expects(:save).returns(true)
24
+ <%= resource_instance %> = <%= build_object %>
25
+ put :update, :id => <%= build_object %>.to_param, :<%= singular_name %> => <%= resource_instance %>.attributes
26
+ assert_response :redirect
27
+ end
28
+
29
+ test 'update with failure' do
30
+ <%= class_name %>.any_instance.expects(:save).returns(false)
31
+ <%= resource_instance %> = <%= build_object %>
32
+ put :update, :id => <%= build_object %>.to_param, :<%= singular_name %> => <%= resource_instance %>.attributes
33
+ assert_template 'edit'
34
+ end
35
+
36
+ <% end -%>
37
+ <% if actions.include?(:destroy) -%>
38
+ test 'destroy' do
39
+ <%= class_name %>.any_instance.expects(:destroy).returns(true)
40
+ <%= resource_instance %> = <%= build_object %>
41
+ delete :destroy, :id => <%= resource_instance %>.to_param
42
+ assert_not_nil flash[:notice]
43
+ assert_response :redirect
44
+ end
45
+
46
+ # Not possible: destroy with failure
47
+
48
+ <% end -%>
49
+ <% if actions.include?(:new) -%>
50
+ test 'new' do
51
+ get :new
52
+ assert_response :success
53
+ end
54
+
55
+ <% end -%>
56
+ <% if actions.include?(:edit) -%>
57
+ test 'edit' do
58
+ <%= resource_instance %> = <%= build_object %>
59
+ get :edit, :id => <%= resource_instance %>.to_param
60
+ assert_response :success
61
+ end
62
+
63
+ <% end -%>
64
+ <% if actions.include?(:show) -%>
65
+ test 'show' do
66
+ <%= resource_instance %> = <%= build_object %>
67
+ get :show, :id => <%= resource_instance %>.to_param
68
+ assert_response :success
69
+ end
70
+
71
+ <% end -%>
72
+ <% if actions.include?(:index) -%>
73
+ test 'index' do
74
+ get :index
75
+ assert_response :success
76
+ assert_not_nil assigns(:<%= table_name %>)
77
+ end
78
+
79
+ <% end -%>
80
+ <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
81
+ test '<%= action.to_s %>' do
82
+ get :<%= action.to_s %>
83
+ assert_response :success
84
+ end
85
+
86
+ <% end -%>
87
+ end
@@ -0,0 +1,3 @@
1
+ module <%= controller_class_name %>Helper
2
+
3
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= controller_class_name %>Helper do
4
+
5
+ it 'should do something' do
6
+ assert true
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>HelperTest < ActionView::TestCase
4
+
5
+ should 'test something' do
6
+ assert true
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>HelperTest < ActionView::TestCase
4
+
5
+ test 'something' do
6
+ assert true
7
+ end
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ atom_feed(:language => I18n.locale) do |feed|
2
+ feed.title '<%= class_name.pluralize %>'
3
+ feed.subtitle 'Index of all <%= plural_name %>.'
4
+ # Optional: feed.link <%= feed_link(:atom) %>
5
+ feed.updated <%= feed_date(:atom) %>
6
+
7
+ <%= collection_instance %>.each do |<%= singular_name %>|
8
+ feed.entry(<%= singular_name %>) do |entry|
9
+ entry.title 'title'
10
+ entry.summary 'summary'
11
+ # Optional: entry.content 'content', :type => 'html'
12
+ # Optional: entry.updated <%= feed_entry_date(:atom) %>
13
+ # Optional: entry.link <%= feed_entry_link(:atom) %>
14
+
15
+ <%= singular_name %>.author do |author|
16
+ author.name 'author_name'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ xml.instruct! :xml, :version => '1.0'
2
+ xml.rss(:version => '2.0') do
3
+ xml.channel do
4
+ xml.title '<%= class_name.pluralize %>'
5
+ xml.description 'Index of all <%= plural_name %>.'
6
+ xml.link <%= feed_link(:rss) %>
7
+ xml.lastBuildDate <%= feed_date(:rss) %>
8
+ xml.language I18n.locale
9
+
10
+ <%= collection_instance %>.each do |<%= singular_name %>|
11
+ xml.item do
12
+ xml.title 'title'
13
+ xml.description 'summary'
14
+ xml.pubDate <%= feed_entry_date(:rss) %>
15
+ xml.link <%= feed_entry_link(:rss) %>
16
+
17
+ xml.author 'author_name'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ <% if options[:formtastic] -%>
2
+ - form.inputs do
3
+ <% attributes.each do |attribute| -%>
4
+ = form.input :<%= attribute.name %>, :label => '<%= attribute.name.humanize %>'
5
+ <% end -%>
6
+ <% else -%>
7
+ %fieldset
8
+ %dl
9
+ <% attributes.each do |attribute| -%>
10
+ %dt.label= form.label :<%= attribute.name %>, '<%= attribute.name.humanize %>'
11
+ %dd.<%= attribute.name %>= form.<%= attribute.field_type %> :<%= attribute.name %>
12
+ <% end -%>
13
+ <% end -%>
@@ -0,0 +1,10 @@
1
+ - content_tag_for(:tr, <%= singular_name -%>, :class => cycle(:odd, :even)) do
2
+ <% attributes.each do |attribute| -%>
3
+ %td.<%= attribute.name %>= h <%= singular_name %>.try(:<%= attribute.name %>)
4
+ <% end -%>
5
+ %td.actions
6
+ = link_to 'Show', <%= show_path(singular_name) %>
7
+ |
8
+ = link_to 'Edit', <%= edit_path(singular_name) %>
9
+ |
10
+ = link_to 'Destroy', <%= destroy_path(singular_name) %>, :confirm => 'Are you sure?', :method => :delete
@@ -0,0 +1,18 @@
1
+ %h1.heading
2
+ = "Editing <%= singular_name %> %s" % <%= resource_instance %>.id
3
+
4
+ <% if options[:formtastic] -%>
5
+ - semantic_form_for(<%= resource_instance %>) do |form|
6
+ = render 'form', :form => form
7
+ - form.buttons do
8
+ = form.commit_button 'Update'
9
+ <% else -%>
10
+ - form_for(<%= resource_instance %>) do |form|
11
+ = form.error_messages
12
+ = render 'form', :form => form
13
+ %p.buttons
14
+ = form.submit 'Update'
15
+ <% end -%>
16
+
17
+ %p.actions
18
+ = link_to 'Cancel', <%= index_path %>
@@ -0,0 +1,20 @@
1
+ %h1.heading
2
+ = "<%= plural_name.humanize %>"
3
+
4
+ %p.actions
5
+ = link_to 'New <%= singular_name.humanize %>', <%= new_path %>
6
+
7
+ %table
8
+ %thead.header
9
+ %tr
10
+ <% attributes.each do |attribute| -%>
11
+ %th.<%= attribute.name %>= '<%= attribute.name.humanize %>'
12
+ <% end -%>
13
+ %th.actions= 'Actions'
14
+ %tbody.items.<%= plural_name %>
15
+ - <%= collection_instance %>.each do |<%= singular_name %>|
16
+ = render 'item', :<%= singular_name %> => <%= singular_name %>
17
+
18
+ <% if options[:pagination] -%>
19
+ = will_paginate(<%= collection_instance %>)
20
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ !!! 1.1
2
+
3
+ %html{html_attrs(I18n.locale)}
4
+ %head
5
+ %title= "#{controller.controller_name.humanize}: #{controller.action_name}"
6
+
7
+ = stylesheet_link_tag 'screen', :media => 'screen, projection'
8
+ = stylesheet_link_tag 'print', :media => 'print'
9
+ /[if IE]
10
+ = stylesheet_link_tag 'ie', :media => 'screen, projection'
11
+ = stylesheet_link_tag 'scaffold' if File.exist?(stylesheet_path('scaffold').gsub(/\?.+/, ''))
12
+
13
+ = javascript_include_tag :defaults
14
+
15
+ %body{:id => "#{controller.controller_name}_#{controller.action_name}", :class => "#{controller.controller_name}_controller #{controller.action_name}_action"}
16
+
17
+ %p.flash{:style => 'color: green'}= flash[:notice]
18
+
19
+ = yield
@@ -0,0 +1,18 @@
1
+ %h1.heading
2
+ = 'New <%= singular_name.humanize %>'
3
+
4
+ <% if options[:formtastic] -%>
5
+ - semantic_form_for(<%= resource_instance %>) do |form|
6
+ = render 'form', :form => form
7
+ - form.buttons do
8
+ = form.commit_button 'Create'
9
+ <% else -%>
10
+ - form_for(<%= resource_instance %>) do |form|
11
+ = form.error_messages
12
+ = render 'form', :form => form
13
+ %p.buttons
14
+ = form.submit 'Create'
15
+ <% end -%>
16
+
17
+ %p.actions
18
+ = link_to 'Cancel', <%= index_path %>
@@ -0,0 +1,13 @@
1
+ %h1.heading
2
+ = "<%= singular_name.humanize %> %s" % <%= resource_instance %>.id
3
+
4
+ - content_tag_for(:dl, <%= resource_instance %>) do
5
+ <% attributes.each do |attribute| -%>
6
+ %dt.label= '<%= attribute.name.humanize %>'
7
+ %dd.<%= attribute.name -%>= h <%= resource_instance %>.try(:<%= attribute.name %>)
8
+ <% end -%>
9
+
10
+ %p.actions
11
+ = link_to 'Edit', <%= edit_path %>
12
+ |
13
+ = link_to 'Index', <%= index_path %>
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'dry_scaffold', 'dry_scaffold_generator')
2
+
3
+ class DscaffoldGenerator < DryScaffoldGenerator
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ # Make Rails look for templates within generator "dry_scaffold" path
8
+ @source_root = options[:source] || File.join(spec.path, '..', 'dry_scaffold', 'templates')
9
+ end
10
+
11
+ def usage_message
12
+ File.read(File.join(spec.path, '..', 'dry_scaffold', 'USAGE')) rescue ''
13
+ end
14
+
15
+ end
@@ -0,0 +1,197 @@
1
+ class DryGenerator < Rails::Generator::NamedBase
2
+
3
+ HAS_WILL_PAGINATE = defined?(WillPaginate)
4
+ HAS_FORMTASTIC = defined?(Formtastic)
5
+ HAS_INHERITED_RESOURCES = defined?(InheritedResources)
6
+ HAS_SHOULDA = defined?(Shoulda)
7
+ HAS_RSPEC = defined?(Rspec)
8
+
9
+ # Load defaults from config file - default or custom.
10
+ begin
11
+ default_config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'scaffold.yml'))
12
+ custom_config_file = File.expand_path(File.join(Rails.root, 'config', 'scaffold.yml'))
13
+ config_file = File.join(File.exist?(custom_config_file) ? custom_config_file : default_config_file)
14
+ config = YAML::load(File.open(config_file))
15
+ CONFIG_ARGS = config['dry_scaffold']['args'] rescue nil
16
+ CONFIG_OPTIONS = config['dry_scaffold']['options'] rescue nil
17
+ end
18
+
19
+ # Banner: Generator arguments and options.
20
+ BANNER_ARGS = [
21
+ "[field:type field:type ...]"
22
+ ].freeze
23
+ BANNER_OPTIONS = [
24
+ "[--skip-tests]",
25
+ "[--shoulda]",
26
+ "[--rspec]",
27
+ "[--fixtures]",
28
+ "[--fgirl]",
29
+ "[--machinist]",
30
+ "[--odaddy]"
31
+ ].freeze
32
+
33
+ DEFAULT_ARGS = {
34
+ :actions => (CONFIG_ARGS['actions'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil),
35
+ :formats => (CONFIG_ARGS['formats'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil)
36
+ }.freeze
37
+
38
+ DEFAULT_OPTIONS = {
39
+ :resourceful => CONFIG_OPTIONS['resourceful'] || HAS_INHERITED_RESOURCES,
40
+ :formtastic => CONFIG_OPTIONS['formtastic'] || HAS_FORMTASTIC,
41
+ :pagination => CONFIG_OPTIONS['pagination'] || HAS_WILL_PAGINATE,
42
+ :skip_tests => !CONFIG_OPTIONS['tests'] || false,
43
+ :skip_controller_tests => !CONFIG_OPTIONS['controller_tests'] || false,
44
+ :skip_helpers => !CONFIG_OPTIONS['helpers'] || false,
45
+ :skip_views => !CONFIG_OPTIONS['views'] || false,
46
+ :layout => CONFIG_OPTIONS['layout'] || false,
47
+ :fixtures => CONFIG_OPTIONS['fixtures'] || false,
48
+ :factory_girl => CONFIG_OPTIONS['factory_girl'] || CONFIG_OPTIONS['fgirl'] || false,
49
+ :machinist => CONFIG_OPTIONS['machinist'] || false,
50
+ :object_daddy => CONFIG_OPTIONS['object_daddy'] || CONFIG_OPTIONS['odaddy'] || false,
51
+ :test_unit => CONFIG_OPTIONS['test_unit'] || CONFIG_OPTIONS['tunit'] || false,
52
+ :shoulda => CONFIG_OPTIONS['shoulda'] || false,
53
+ :rspec => CONFIG_OPTIONS['rspec'] || false
54
+ }.freeze
55
+
56
+ TEST_PATHS = {
57
+ :test_unit => 'test',
58
+ :shoulda => 'test',
59
+ :rspec => 'spec'
60
+ }.freeze
61
+
62
+ TEST_POST_FIX = {
63
+ :test_unit => 'test',
64
+ :shoulda => 'test',
65
+ :rspec => 'spec'
66
+ }.freeze
67
+
68
+ DEFAULT_TEST_FRAMEWORK = :test_unit
69
+ DEFAULT_FACTORY_FRAMEWORK = :fixtures
70
+
71
+ TESTS_PATH = File.join('test').freeze
72
+ FUNCTIONAL_TESTS_PATH = {
73
+ :test_unit => 'functional',
74
+ :shoulda => 'functional',
75
+ :rspec => 'controllers'
76
+ }
77
+ UNIT_TESTS_PATH = {
78
+ :test_unit => 'unit',
79
+ :shoulda => 'unit',
80
+ :rspec => 'models',
81
+ }
82
+
83
+ NON_ATTR_ARG_KEY_PREFIX = '_'.freeze
84
+
85
+ attr_accessor :view_template_format,
86
+ :test_framework,
87
+ :factory_framework
88
+
89
+ def initialize(runtime_args, runtime_options = {})
90
+ super(runtime_args, runtime_options)
91
+ set_test_framework
92
+ end
93
+
94
+ protected
95
+
96
+ def set_test_framework
97
+ @test_framework = (options[:test_framework] && options[:test_framework].to_sym) ||
98
+ [:rspec, :test_unit, :shoulda].detect{ |t| options[t] } ||
99
+ DEFAULT_TEST_FRAMEWORK
100
+ end
101
+
102
+ def symbol_array_to_expression(array)
103
+ ":#{array.compact.join(', :')}" if array.present?
104
+ end
105
+
106
+ def banner_args
107
+ BANNER_ARGS.join(' ')
108
+ end
109
+
110
+ def banner_options
111
+ BANNER_OPTIONS.join(' ')
112
+ end
113
+
114
+ def banner
115
+ "\nUsage: \n\n#{$0} #{spec.name} MODEL_NAME"
116
+ end
117
+
118
+ def add_options!(opt)
119
+ opt.separator ' '
120
+ opt.separator 'Scaffold + Model Options:'
121
+
122
+ opt.on('--skip-tests', "Test: Skip generation of tests.") do |v|
123
+ options[:skip_tests] = v
124
+ end
125
+
126
+ opt.on("--tunit", "Test: Generate \"test_unit\" tests. Note: Rails default.") do |v|
127
+ options[:test_unit] = v
128
+ options[:test_framework] = :test_unit
129
+ end
130
+
131
+ opt.on("--shoulda", "Test: Generate \"shoulda\" tests.") do |v|
132
+ options[:shoulda] = v
133
+ options[:test_framework] = :shoulda
134
+ end
135
+
136
+ opt.on("--rspec", "Test: Generate \"rspec\" tests.") do |v|
137
+ options[:rspec] = v
138
+ options[:test_framework] = :rspec
139
+ end
140
+
141
+ opt.on("--fixtures", "Test: Generate fixtures. Note: Rails default.") do |v|
142
+ options[:fixtures] = v
143
+ options[:factory_framework] = :fixtures
144
+ end
145
+
146
+ opt.on("--fgirl", "Test: Generate \"factory_girl\" factories.") do |v|
147
+ options[:factory_girl] = v
148
+ options[:factory_framework] = :factory_girl
149
+ end
150
+
151
+ opt.on("--machinist", "Test: Generate \"machinist\" blueprints (factories).") do |v|
152
+ options[:machinist] = v
153
+ options[:factory_framework] = :machinist
154
+ end
155
+
156
+ opt.on("--odaddy", "Test: Generate \"object_daddy\" generator/factory methods.") do |v|
157
+ options[:object_daddy] = v
158
+ options[:factory_framework] = :object_daddy
159
+ end
160
+ end
161
+
162
+ end
163
+
164
+ module Rails
165
+ module Generator
166
+ class GeneratedAttribute
167
+ def default_for_fixture
168
+ @default ||= case type
169
+ when :integer then 1
170
+ when :float then 1.5
171
+ when :decimal then '9.99'
172
+ when :datetime, :timestamp, :time then Time.now.to_s(:db)
173
+ when :date then Date.today.to_s(:db)
174
+ when :string then 'Hello'
175
+ when :text then 'Lorem ipsum dolor sit amet...'
176
+ when :boolean then false
177
+ else
178
+ ''
179
+ end
180
+ end
181
+ def default_for_factory
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'
187
+ when :date then 'Date.today'
188
+ when :string then '"Hello"'
189
+ when :text then '"Lorem ipsum dolor sit amet..."'
190
+ when :boolean then false
191
+ else
192
+ ''
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end