akitaonrails-dry_scaffold 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG.textile +43 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +445 -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 +31 -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 +401 -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 +56 -0
  35. data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +67 -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 +58 -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 +192 -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,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 %>HelperTest
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,192 @@
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
+
16
+ CONFIG_ARGS = config['dry_scaffold']['args'] rescue nil
17
+ CONFIG_OPTIONS = config['dry_scaffold']['options'] rescue nil
18
+ end
19
+
20
+ # Banner: Generator arguments and options.
21
+ BANNER_ARGS = [
22
+ "[field:type field:type ...]"
23
+ ].freeze
24
+ BANNER_OPTIONS = [
25
+ "[--skip-tests]",
26
+ "[--shoulda]",
27
+ "[--rspec]",
28
+ "[--fixtures]",
29
+ "[--fgirl]",
30
+ "[--machinist]",
31
+ "[--odaddy]"
32
+ ].freeze
33
+
34
+ DEFAULT_ARGS = {
35
+ :actions => (CONFIG_ARGS['actions'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil),
36
+ :formats => (CONFIG_ARGS['formats'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil)
37
+ }.freeze
38
+
39
+ DEFAULT_OPTIONS = {
40
+ :resourceful => CONFIG_OPTIONS['resourceful'] || HAS_INHERITED_RESOURCES,
41
+ :formtastic => CONFIG_OPTIONS['formtastic'] || HAS_FORMTASTIC,
42
+ :pagination => CONFIG_OPTIONS['pagination'] || HAS_WILL_PAGINATE,
43
+ :skip_tests => !CONFIG_OPTIONS['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'] || true,
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 => 'functional',
74
+ :shoulda => 'functional',
75
+ :rspec => 'controllers'
76
+ }
77
+ UNIT_TESTS_PATH = {
78
+ :test => '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] || DEFAULT_TEST_FRAMEWORK
93
+ end
94
+
95
+ protected
96
+
97
+ def symbol_array_to_expression(array)
98
+ ":#{array.compact.join(', :')}" if array.present?
99
+ end
100
+
101
+ def banner_args
102
+ BANNER_ARGS.join(' ')
103
+ end
104
+
105
+ def banner_options
106
+ BANNER_OPTIONS.join(' ')
107
+ end
108
+
109
+ def banner
110
+ "\nUsage: \n\n#{$0} #{spec.name} MODEL_NAME"
111
+ end
112
+
113
+ def add_options!(opt)
114
+ opt.separator ' '
115
+ opt.separator 'Scaffold + Model Options:'
116
+
117
+ opt.on('--skip-tests', "Test: Skip generation of tests.") do |v|
118
+ options[:skip_tests] = v
119
+ end
120
+
121
+ opt.on("--tunit", "Test: Generate \"test_unit\" tests. Note: Rails default.") do |v|
122
+ options[:test_unit] = v
123
+ options[:test_framework] = :test_unit
124
+ end
125
+
126
+ opt.on("--shoulda", "Test: Generate \"shoulda\" tests.") do |v|
127
+ options[:shoulda] = v
128
+ options[:test_framework] = :shoulda
129
+ end
130
+
131
+ opt.on("--rspec", "Test: Generate \"rspec\" tests.") do |v|
132
+ options[:rspec] = v
133
+ options[:test_framework] = :rspec
134
+ end
135
+
136
+ opt.on("--fixtures", "Test: Generate fixtures. Note: Rails default.") do |v|
137
+ options[:fixtures] = v
138
+ options[:factory_framework] = :fixtures
139
+ end
140
+
141
+ opt.on("--fgirl", "Test: Generate \"factory_girl\" factories.") do |v|
142
+ options[:factory_girl] = v
143
+ options[:factory_framework] = :factory_girl
144
+ end
145
+
146
+ opt.on("--machinist", "Test: Generate \"machinist\" blueprints (factories).") do |v|
147
+ options[:machinist] = v
148
+ options[:factory_framework] = :machinist
149
+ end
150
+
151
+ opt.on("--odaddy", "Test: Generate \"object_daddy\" generator/factory methods.") do |v|
152
+ options[:object_daddy] = v
153
+ options[:factory_framework] = :object_daddy
154
+ end
155
+ end
156
+
157
+ end
158
+
159
+ module Rails
160
+ module Generator
161
+ class GeneratedAttribute
162
+ def default_for_fixture
163
+ @default ||= case type
164
+ when :integer then 1
165
+ when :float then 1.5
166
+ when :decimal then '9.99'
167
+ when :datetime, :timestamp, :time then Time.now.to_s(:db)
168
+ when :date then Date.today.to_s(:db)
169
+ when :string then 'Hello'
170
+ when :text then 'Lorem ipsum dolor sit amet...'
171
+ when :boolean then false
172
+ else
173
+ ''
174
+ end
175
+ end
176
+ def default_for_factory
177
+ @default ||= case type
178
+ when :integer then 1
179
+ when :float then 1.5
180
+ when :decimal then '9.99'
181
+ when :datetime, :timestamp, :time then 'Time.now'
182
+ when :date then 'Date.today'
183
+ when :string then '"Hello"'
184
+ when :text then '"Lorem ipsum dolor sit amet..."'
185
+ when :boolean then false
186
+ else
187
+ ''
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end