railties 3.0.0.beta4 → 3.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +24 -6
  2. data/README.rdoc +25 -0
  3. data/guides/assets/javascripts/code_highlighter.js +0 -0
  4. data/guides/assets/javascripts/guides.js +0 -0
  5. data/guides/assets/stylesheets/print.css +0 -0
  6. data/guides/assets/stylesheets/reset.css +0 -0
  7. data/guides/assets/stylesheets/style.css +0 -0
  8. data/guides/source/3_0_release_notes.textile +5 -3
  9. data/guides/source/action_controller_overview.textile +19 -0
  10. data/guides/source/active_record_basics.textile +27 -21
  11. data/guides/source/active_record_querying.textile +39 -37
  12. data/guides/source/{activerecord_validations_callbacks.textile → active_record_validations_callbacks.textile} +30 -29
  13. data/guides/source/active_support_core_extensions.textile +232 -107
  14. data/guides/source/api_documentation_guidelines.textile +187 -0
  15. data/guides/source/association_basics.textile +45 -1
  16. data/guides/source/configuring.textile +7 -7
  17. data/guides/source/contributing_to_rails.textile +42 -15
  18. data/guides/source/form_helpers.textile +1 -1
  19. data/guides/source/generators.textile +37 -37
  20. data/guides/source/getting_started.textile +11 -11
  21. data/guides/source/i18n.textile +1 -1
  22. data/guides/source/index.html.erb +14 -6
  23. data/guides/source/initialization.textile +130 -124
  24. data/guides/source/layout.html.erb +5 -2
  25. data/guides/source/layouts_and_rendering.textile +2 -2
  26. data/guides/source/migrations.textile +4 -3
  27. data/guides/source/plugins.textile +15 -15
  28. data/guides/source/rails_application_templates.textile +2 -2
  29. data/guides/source/routing.textile +83 -62
  30. data/guides/source/security.textile +2 -2
  31. data/guides/w3c_validator.rb +30 -6
  32. data/lib/rails.rb +3 -3
  33. data/lib/rails/application.rb +43 -19
  34. data/lib/rails/application/bootstrap.rb +2 -0
  35. data/lib/rails/application/configuration.rb +3 -3
  36. data/lib/rails/application/finisher.rb +6 -6
  37. data/lib/rails/cli.rb +1 -19
  38. data/lib/rails/commands.rb +5 -5
  39. data/lib/rails/commands/application.rb +1 -1
  40. data/lib/rails/commands/console.rb +1 -4
  41. data/lib/rails/commands/generate.rb +0 -0
  42. data/lib/rails/commands/plugin.rb +57 -52
  43. data/lib/rails/commands/runner.rb +2 -1
  44. data/lib/rails/commands/server.rb +6 -2
  45. data/lib/rails/configuration.rb +2 -3
  46. data/lib/rails/console/app.rb +0 -2
  47. data/lib/rails/engine.rb +14 -15
  48. data/lib/rails/engine/configuration.rb +5 -5
  49. data/lib/rails/generators.rb +2 -3
  50. data/lib/rails/generators/actions.rb +4 -4
  51. data/lib/rails/generators/base.rb +1 -1
  52. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +1 -6
  53. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +4 -4
  54. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +3 -3
  55. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +7 -7
  56. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +2 -2
  57. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +3 -3
  58. data/lib/rails/generators/generated_attribute.rb +2 -1
  59. data/lib/rails/generators/named_base.rb +24 -0
  60. data/lib/rails/generators/rails/app/app_generator.rb +10 -9
  61. data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
  62. data/lib/rails/generators/rails/app/templates/README +6 -31
  63. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  64. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +0 -1
  65. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  66. data/lib/rails/generators/rails/app/templates/config/application.rb +11 -11
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +36 -24
  68. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +1 -1
  69. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -0
  71. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +3 -0
  72. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +3 -0
  73. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +2 -2
  76. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  77. data/lib/rails/generators/rails/app/templates/public/index.html +0 -17
  78. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +2027 -900
  79. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +114 -57
  80. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  81. data/lib/rails/generators/rails/model/USAGE +1 -1
  82. data/lib/rails/generators/rails/resource/resource_generator.rb +4 -14
  83. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +0 -2
  84. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +28 -30
  85. data/lib/rails/generators/resource_helpers.rb +1 -1
  86. data/lib/rails/generators/test_case.rb +25 -11
  87. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  88. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +0 -1
  89. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +13 -15
  90. data/lib/rails/info.rb +1 -2
  91. data/lib/rails/info_routes.rb +1 -1
  92. data/lib/rails/initializable.rb +3 -16
  93. data/lib/rails/paths.rb +31 -36
  94. data/lib/rails/plugin.rb +10 -6
  95. data/lib/rails/rack/logger.rb +11 -13
  96. data/lib/rails/railtie.rb +14 -42
  97. data/lib/rails/ruby_version_check.rb +19 -5
  98. data/lib/rails/script_rails_loader.rb +29 -0
  99. data/lib/rails/tasks/annotations.rake +2 -2
  100. data/lib/rails/tasks/documentation.rake +47 -16
  101. data/lib/rails/tasks/framework.rake +9 -9
  102. data/lib/rails/tasks/middleware.rake +1 -1
  103. data/lib/rails/tasks/misc.rake +5 -5
  104. data/lib/rails/tasks/routes.rake +1 -1
  105. data/lib/rails/tasks/tmp.rake +5 -5
  106. data/lib/rails/test_unit/testing.rake +38 -14
  107. data/lib/rails/version.rb +1 -1
  108. metadata +29 -17
  109. data/README +0 -281
  110. data/lib/rails/application/routes_reloader.rb +0 -46
  111. data/lib/rails/log_subscriber.rb +0 -115
  112. data/lib/rails/log_subscriber/test_helper.rb +0 -97
  113. data/lib/rails/webrick_server.rb +0 -156
@@ -1,87 +1,148 @@
1
- document.observe("dom:loaded", function() {
1
+ (function() {
2
+ // Technique from Juriy Zaytsev
3
+ // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
4
+ function isEventSupported(eventName) {
5
+ var el = document.createElement('div');
6
+ eventName = 'on' + eventName;
7
+ var isSupported = (eventName in el);
8
+ if (!isSupported) {
9
+ el.setAttribute(eventName, 'return;');
10
+ isSupported = typeof el[eventName] == 'function';
11
+ }
12
+ el = null;
13
+ return isSupported;
14
+ }
15
+
16
+ function isForm(element) {
17
+ return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
18
+ }
19
+
20
+ function isInput(element) {
21
+ if (Object.isElement(element)) {
22
+ var name = element.nodeName.toUpperCase()
23
+ return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
24
+ }
25
+ else return false
26
+ }
27
+
28
+ var submitBubbles = isEventSupported('submit'),
29
+ changeBubbles = isEventSupported('change')
30
+
31
+ if (!submitBubbles || !changeBubbles) {
32
+ // augment the Event.Handler class to observe custom events when needed
33
+ Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
34
+ function(init, element, eventName, selector, callback) {
35
+ init(element, eventName, selector, callback)
36
+ // is the handler being attached to an element that doesn't support this event?
37
+ if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
38
+ (!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
39
+ // "submit" => "emulated:submit"
40
+ this.eventName = 'emulated:' + this.eventName
41
+ }
42
+ }
43
+ )
44
+ }
45
+
46
+ if (!submitBubbles) {
47
+ // discover forms on the page by observing focus events which always bubble
48
+ document.on('focusin', 'form', function(focusEvent, form) {
49
+ // special handler for the real "submit" event (one-time operation)
50
+ if (!form.retrieve('emulated:submit')) {
51
+ form.on('submit', function(submitEvent) {
52
+ var emulated = form.fire('emulated:submit', submitEvent, true)
53
+ // if custom event received preventDefault, cancel the real one too
54
+ if (emulated.returnValue === false) submitEvent.preventDefault()
55
+ })
56
+ form.store('emulated:submit', true)
57
+ }
58
+ })
59
+ }
60
+
61
+ if (!changeBubbles) {
62
+ // discover form inputs on the page
63
+ document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
64
+ // special handler for real "change" events
65
+ if (!input.retrieve('emulated:change')) {
66
+ input.on('change', function(changeEvent) {
67
+ input.fire('emulated:change', changeEvent, true)
68
+ })
69
+ input.store('emulated:change', true)
70
+ }
71
+ })
72
+ }
73
+
2
74
  function handleRemote(element) {
3
75
  var method, url, params;
4
76
 
77
+ var event = element.fire("ajax:before");
78
+ if (event.stopped) return false;
79
+
5
80
  if (element.tagName.toLowerCase() === 'form') {
6
81
  method = element.readAttribute('method') || 'post';
7
82
  url = element.readAttribute('action');
8
- params = element.serialize(true);
83
+ params = element.serialize();
9
84
  } else {
10
85
  method = element.readAttribute('data-method') || 'get';
11
86
  url = element.readAttribute('href');
12
87
  params = {};
13
88
  }
14
89
 
15
- var event = element.fire("ajax:before");
16
- if (event.stopped) return false;
17
-
18
90
  new Ajax.Request(url, {
19
91
  method: method,
20
92
  parameters: params,
21
- asynchronous: true,
22
93
  evalScripts: true,
23
94
 
24
- onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
25
- onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
26
- onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
27
- onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
28
- onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
29
- onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
95
+ onComplete: function(request) { element.fire("ajax:complete", request); },
96
+ onSuccess: function(request) { element.fire("ajax:success", request); },
97
+ onFailure: function(request) { element.fire("ajax:failure", request); }
30
98
  });
31
99
 
32
100
  element.fire("ajax:after");
33
101
  }
34
102
 
35
103
  function handleMethod(element) {
36
- var method, url, token_name, token;
37
-
38
- method = element.readAttribute('data-method');
39
- url = element.readAttribute('href');
40
- csrf_param = $$('meta[name=csrf-param]').first();
41
- csrf_token = $$('meta[name=csrf-token]').first();
104
+ var method = element.readAttribute('data-method'),
105
+ url = element.readAttribute('href'),
106
+ csrf_param = $$('meta[name=csrf-param]')[0],
107
+ csrf_token = $$('meta[name=csrf-token]')[0];
42
108
 
43
109
  var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
44
- element.parentNode.appendChild(form);
110
+ element.parentNode.insert(form);
45
111
 
46
- if (method != 'post') {
112
+ if (method !== 'post') {
47
113
  var field = new Element('input', { type: 'hidden', name: '_method', value: method });
48
- form.appendChild(field);
114
+ form.insert(field);
49
115
  }
50
116
 
51
117
  if (csrf_param) {
52
- var param = csrf_param.readAttribute('content');
53
- var token = csrf_token.readAttribute('content');
54
- var field = new Element('input', { type: 'hidden', name: param, value: token });
55
- form.appendChild(field);
118
+ var param = csrf_param.readAttribute('content'),
119
+ token = csrf_token.readAttribute('content'),
120
+ field = new Element('input', { type: 'hidden', name: param, value: token });
121
+ form.insert(field);
56
122
  }
57
123
 
58
124
  form.submit();
59
125
  }
60
126
 
61
- $(document.body).observe("click", function(event) {
62
- var message = event.findElement().readAttribute('data-confirm');
63
- if (message && !confirm(message)) {
64
- event.stop();
65
- return false;
66
- }
67
127
 
68
- var element = event.findElement("a[data-remote]");
69
- if (element) {
70
- handleRemote(element);
71
- event.stop();
72
- return true;
73
- }
128
+ document.on("click", "*[data-confirm]", function(event, element) {
129
+ var message = element.readAttribute('data-confirm');
130
+ if (!confirm(message)) event.stop();
131
+ });
74
132
 
75
- var element = event.findElement("a[data-method]");
76
- if (element) {
77
- handleMethod(element);
78
- event.stop();
79
- return true;
80
- }
133
+ document.on("click", "a[data-remote]", function(event, element) {
134
+ if (event.stopped) return;
135
+ handleRemote(element);
136
+ event.stop();
137
+ });
138
+
139
+ document.on("click", "a[data-method]", function(event, element) {
140
+ if (event.stopped) return;
141
+ handleMethod(element);
142
+ event.stop();
81
143
  });
82
144
 
83
- // TODO: I don't think submit bubbles in IE
84
- $(document.body).observe("submit", function(event) {
145
+ document.on("submit", function(event) {
85
146
  var element = event.findElement(),
86
147
  message = element.readAttribute('data-confirm');
87
148
  if (message && !confirm(message)) {
@@ -103,16 +164,12 @@ document.observe("dom:loaded", function() {
103
164
  }
104
165
  });
105
166
 
106
- $(document.body).observe("ajax:after", function(event) {
107
- var element = event.findElement();
108
-
109
- if (element.tagName.toLowerCase() === 'form') {
110
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
111
- inputs.each(function(input) {
112
- input.value = input.readAttribute('data-original-value');
113
- input.writeAttribute('data-original-value', null);
114
- input.disabled = false;
115
- });
116
- }
167
+ document.on("ajax:after", "form", function(event, element) {
168
+ var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
169
+ inputs.each(function(input) {
170
+ input.value = input.readAttribute('data-original-value');
171
+ input.removeAttribute('data-original-value');
172
+ input.disabled = false;
173
+ });
117
174
  });
118
- });
175
+ })();
@@ -3,7 +3,7 @@ require File.expand_path('../../config/environment', __FILE__)
3
3
  require 'rails/test_help'
4
4
 
5
5
  class ActiveSupport::TestCase
6
- <% unless options[:skip_activerecord] -%>
6
+ <% unless options[:skip_active_record] -%>
7
7
  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
8
8
  #
9
9
  # Note: You'll currently still have to declare fixtures explicitly in integration tests
@@ -40,6 +40,6 @@ Examples:
40
40
  Module: app/models/admin.rb
41
41
  Model: app/models/admin/account.rb
42
42
  Test: test/unit/admin/account_test.rb
43
- Fixtures: test/fixtures/admin_accounts.yml
43
+ Fixtures: test/fixtures/admin/accounts.yml
44
44
  Migration: db/migrate/XXX_add_admin_accounts.rb
45
45
 
@@ -14,23 +14,13 @@ module Rails
14
14
  class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [],
15
15
  :desc => "Actions for the resource controller"
16
16
 
17
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
18
-
19
17
  def add_resource_route
20
18
  return if options[:actions].present?
21
- route "resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}"
19
+ route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
20
+ route_config << "resources :#{file_name.pluralize}"
21
+ route_config << " end" * class_path.size
22
+ route route_config
22
23
  end
23
-
24
- protected
25
-
26
- def pluralize?(name)
27
- if options[:singleton]
28
- name
29
- else
30
- name.pluralize
31
- end
32
- end
33
-
34
24
  end
35
25
  end
36
26
  end
@@ -10,8 +10,6 @@ module Rails
10
10
  class_option :orm, :banner => "NAME", :type => :string, :required => true,
11
11
  :desc => "ORM to generate the controller for"
12
12
 
13
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
14
-
15
13
  def create_controller_files
16
14
  template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
17
15
  end
@@ -1,53 +1,51 @@
1
1
  class <%= controller_class_name %>Controller < ApplicationController
2
- <% unless options[:singleton] -%>
3
- # GET /<%= table_name %>
4
- # GET /<%= table_name %>.xml
2
+ # GET <%= route_url %>
3
+ # GET <%= route_url %>.xml
5
4
  def index
6
- @<%= table_name %> = <%= orm_class.all(class_name) %>
5
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
7
6
 
8
7
  respond_to do |format|
9
8
  format.html # index.html.erb
10
- format.xml { render :xml => @<%= table_name %> }
9
+ format.xml { render :xml => @<%= plural_table_name %> }
11
10
  end
12
11
  end
13
- <% end -%>
14
12
 
15
- # GET /<%= table_name %>/1
16
- # GET /<%= table_name %>/1.xml
13
+ # GET <%= route_url %>/1
14
+ # GET <%= route_url %>/1.xml
17
15
  def show
18
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
16
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
19
17
 
20
18
  respond_to do |format|
21
19
  format.html # show.html.erb
22
- format.xml { render :xml => @<%= file_name %> }
20
+ format.xml { render :xml => @<%= singular_table_name %> }
23
21
  end
24
22
  end
25
23
 
26
- # GET /<%= table_name %>/new
27
- # GET /<%= table_name %>/new.xml
24
+ # GET <%= route_url %>/new
25
+ # GET <%= route_url %>/new.xml
28
26
  def new
29
- @<%= file_name %> = <%= orm_class.build(class_name) %>
27
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
30
28
 
31
29
  respond_to do |format|
32
30
  format.html # new.html.erb
33
- format.xml { render :xml => @<%= file_name %> }
31
+ format.xml { render :xml => @<%= singular_table_name %> }
34
32
  end
35
33
  end
36
34
 
37
- # GET /<%= table_name %>/1/edit
35
+ # GET <%= route_url %>/1/edit
38
36
  def edit
39
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
37
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
40
38
  end
41
39
 
42
- # POST /<%= table_name %>
43
- # POST /<%= table_name %>.xml
40
+ # POST <%= route_url %>
41
+ # POST <%= route_url %>.xml
44
42
  def create
45
- @<%= file_name %> = <%= orm_class.build(class_name, "params[:#{file_name}]") %>
43
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
46
44
 
47
45
  respond_to do |format|
48
46
  if @<%= orm_instance.save %>
49
- format.html { redirect_to(@<%= file_name %>, :notice => '<%= human_name %> was successfully created.') }
50
- format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
47
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.') }
48
+ format.xml { render :xml => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
51
49
  else
52
50
  format.html { render :action => "new" }
53
51
  format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
@@ -55,14 +53,14 @@ class <%= controller_class_name %>Controller < ApplicationController
55
53
  end
56
54
  end
57
55
 
58
- # PUT /<%= table_name %>/1
59
- # PUT /<%= table_name %>/1.xml
56
+ # PUT <%= route_url %>/1
57
+ # PUT <%= route_url %>/1.xml
60
58
  def update
61
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
59
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
62
60
 
63
61
  respond_to do |format|
64
- if @<%= orm_instance.update_attributes("params[:#{file_name}]") %>
65
- format.html { redirect_to(@<%= file_name %>, :notice => '<%= human_name %> was successfully updated.') }
62
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
63
+ format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.') }
66
64
  format.xml { head :ok }
67
65
  else
68
66
  format.html { render :action => "edit" }
@@ -71,14 +69,14 @@ class <%= controller_class_name %>Controller < ApplicationController
71
69
  end
72
70
  end
73
71
 
74
- # DELETE /<%= table_name %>/1
75
- # DELETE /<%= table_name %>/1.xml
72
+ # DELETE <%= route_url %>/1
73
+ # DELETE <%= route_url %>/1.xml
76
74
  def destroy
77
- @<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
75
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
78
76
  @<%= orm_instance.destroy %>
79
77
 
80
78
  respond_to do |format|
81
- format.html { redirect_to(<%= table_name %>_url) }
79
+ format.html { redirect_to(<%= index_helper %>_url) }
82
80
  format.xml { head :ok }
83
81
  end
84
82
  end
@@ -72,7 +72,7 @@ module Rails
72
72
  end
73
73
 
74
74
  # Initialize ORM::Generators::ActiveModel to access instance methods.
75
- def orm_instance(name=file_name)
75
+ def orm_instance(name=singular_table_name)
76
76
  @orm_instance ||= @orm_class.new(name)
77
77
  end
78
78
  end
@@ -51,7 +51,7 @@ module Rails
51
51
  # Sets default arguments on generator invocation. This can be overwritten when
52
52
  # invoking it.
53
53
  #
54
- # arguments %w(app_name --skip-activerecord)
54
+ # arguments %w(app_name --skip-active-record)
55
55
  #
56
56
  def self.arguments(array)
57
57
  self.default_arguments = array
@@ -189,18 +189,23 @@ module Rails
189
189
  end
190
190
  alias :assert_method :assert_instance_method
191
191
 
192
- # Asserts the given field name gets translated to an attribute type
193
- # properly.
192
+ # Asserts the given attribute type gets translated to a field type
193
+ # properly:
194
194
  #
195
195
  # assert_field_type :date, :date_select
196
196
  #
197
- def assert_field_type(name, attribute_type)
198
- assert_equal(
199
- Rails::Generators::GeneratedAttribute.new('test', name.to_s).field_type,
200
- attribute_type
201
- )
197
+ def assert_field_type(attribute_type, field_type)
198
+ assert_equal(field_type, create_generated_attribute(attribute_type).field_type)
202
199
  end
203
-
200
+
201
+ # Asserts the given attribute type gets a proper default value:
202
+ #
203
+ # assert_field_type :string, "MyString"
204
+ #
205
+ def assert_field_default_value(attribute_type, value)
206
+ assert_equal(value, create_generated_attribute(attribute_type).default)
207
+ end
208
+
204
209
  # Runs the generator configured for this class. The first argument is an array like
205
210
  # command line arguments:
206
211
  #
@@ -209,8 +214,8 @@ module Rails
209
214
  # destination File.expand_path("../tmp", File.dirname(__FILE__))
210
215
  # teardown :cleanup_destination_root
211
216
  #
212
- # test "database.yml is not created when skipping activerecord" do
213
- # run_generator %w(myapp --skip-activerecord)
217
+ # test "database.yml is not created when skipping Active Record" do
218
+ # run_generator %w(myapp --skip-active-record)
214
219
  # assert_no_file "config/database.yml"
215
220
  # end
216
221
  # end
@@ -226,6 +231,15 @@ module Rails
226
231
  @generator ||= self.generator_class.new(args, options, config.reverse_merge(:destination_root => destination_root))
227
232
  end
228
233
 
234
+ # Create a Rails::Generators::GeneratedAttribute by supplying the
235
+ # attribute type and, optionally, the attribute name:
236
+ #
237
+ # create_generated_attribute(:string, 'name')
238
+ #
239
+ def create_generated_attribute(attribute_type, name = 'test')
240
+ Rails::Generators::GeneratedAttribute.new(name, attribute_type.to_s)
241
+ end
242
+
229
243
  protected
230
244
 
231
245
  def destination_root_is_set? #:nodoc: