pelle-dry_scaffold 0.3.5

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 +50 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +446 -0
  4. data/Rakefile +48 -0
  5. data/TODO.textile +40 -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 +409 -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 +194 -0
  70. data/lib/setup_helper.rb +36 -0
  71. data/rails/init.rb +3 -0
  72. data/tasks/dry_scaffold.rake +95 -0
  73. metadata +129 -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,194 @@
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
+
92
+ @test_framework = ( options[:test_framework] && options[:test_framework].to_sym ) ||
93
+ [:rspec,:test_unit,:shoulda].detect{|t|options[t]} ||
94
+ DEFAULT_TEST_FRAMEWORK
95
+ end
96
+
97
+ protected
98
+
99
+ def symbol_array_to_expression(array)
100
+ ":#{array.compact.join(', :')}" if array.present?
101
+ end
102
+
103
+ def banner_args
104
+ BANNER_ARGS.join(' ')
105
+ end
106
+
107
+ def banner_options
108
+ BANNER_OPTIONS.join(' ')
109
+ end
110
+
111
+ def banner
112
+ "\nUsage: \n\n#{$0} #{spec.name} MODEL_NAME"
113
+ end
114
+
115
+ def add_options!(opt)
116
+ opt.separator ' '
117
+ opt.separator 'Scaffold + Model Options:'
118
+
119
+ opt.on('--skip-tests', "Test: Skip generation of tests.") do |v|
120
+ options[:skip_tests] = v
121
+ end
122
+
123
+ opt.on("--tunit", "Test: Generate \"test_unit\" tests. Note: Rails default.") do |v|
124
+ options[:test_unit] = v
125
+ options[:test_framework] = :test_unit
126
+ end
127
+
128
+ opt.on("--shoulda", "Test: Generate \"shoulda\" tests.") do |v|
129
+ options[:shoulda] = v
130
+ options[:test_framework] = :shoulda
131
+ end
132
+
133
+ opt.on("--rspec", "Test: Generate \"rspec\" tests.") do |v|
134
+ options[:rspec] = v
135
+ options[:test_framework] = :rspec
136
+ end
137
+
138
+ opt.on("--fixtures", "Test: Generate fixtures. Note: Rails default.") do |v|
139
+ options[:fixtures] = v
140
+ options[:factory_framework] = :fixtures
141
+ end
142
+
143
+ opt.on("--fgirl", "Test: Generate \"factory_girl\" factories.") do |v|
144
+ options[:factory_girl] = v
145
+ options[:factory_framework] = :factory_girl
146
+ end
147
+
148
+ opt.on("--machinist", "Test: Generate \"machinist\" blueprints (factories).") do |v|
149
+ options[:machinist] = v
150
+ options[:factory_framework] = :machinist
151
+ end
152
+
153
+ opt.on("--odaddy", "Test: Generate \"object_daddy\" generator/factory methods.") do |v|
154
+ options[:object_daddy] = v
155
+ options[:factory_framework] = :object_daddy
156
+ end
157
+ end
158
+
159
+ end
160
+
161
+ module Rails
162
+ module Generator
163
+ class GeneratedAttribute
164
+ def default_for_fixture
165
+ @default ||= case type
166
+ when :integer then 1
167
+ when :float then 1.5
168
+ when :decimal then '9.99'
169
+ when :datetime, :timestamp, :time then Time.now.to_s(:db)
170
+ when :date then Date.today.to_s(:db)
171
+ when :string then 'Hello'
172
+ when :text then 'Lorem ipsum dolor sit amet...'
173
+ when :boolean then false
174
+ else
175
+ ''
176
+ end
177
+ end
178
+ def default_for_factory
179
+ @default ||= case type
180
+ when :integer then 1
181
+ when :float then 1.5
182
+ when :decimal then '9.99'
183
+ when :datetime, :timestamp, :time then 'Time.now'
184
+ when :date then 'Date.today'
185
+ when :string then '"Hello"'
186
+ when :text then '"Lorem ipsum dolor sit amet..."'
187
+ when :boolean then false
188
+ else
189
+ ''
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end