railties 3.2.0.rc1 → 3.2.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  3. data/guides/assets/stylesheets/kindle.css +11 -0
  4. data/guides/assets/stylesheets/main.css +8 -0
  5. data/guides/rails_guides/generator.rb +87 -20
  6. data/guides/rails_guides/helpers.rb +16 -0
  7. data/guides/source/3_2_release_notes.textile +452 -0
  8. data/guides/source/_license.html.erb +2 -0
  9. data/guides/source/_welcome.html.erb +19 -0
  10. data/guides/source/active_record_querying.textile +1 -1
  11. data/guides/source/active_support_core_extensions.textile +0 -10
  12. data/guides/source/asset_pipeline.textile +69 -67
  13. data/guides/source/caching_with_rails.textile +22 -0
  14. data/guides/source/documents.yaml +153 -0
  15. data/guides/source/getting_started.textile +2 -4
  16. data/guides/source/index.html.erb +14 -175
  17. data/guides/source/kindle/KINDLE.md +26 -0
  18. data/guides/source/kindle/copyright.html.erb +1 -0
  19. data/guides/source/kindle/layout.html.erb +27 -0
  20. data/guides/source/kindle/rails_guides.opf.erb +52 -0
  21. data/guides/source/kindle/toc.html.erb +24 -0
  22. data/guides/source/kindle/toc.ncx.erb +64 -0
  23. data/guides/source/kindle/welcome.html.erb +5 -0
  24. data/guides/source/layout.html.erb +11 -47
  25. data/guides/source/migrations.textile +1 -1
  26. data/lib/rails/application/bootstrap.rb +1 -1
  27. data/lib/rails/application/route_inspector.rb +10 -1
  28. data/lib/rails/generators/app_base.rb +3 -3
  29. data/lib/rails/generators/base.rb +3 -3
  30. data/lib/rails/generators/generated_attribute.rb +57 -3
  31. data/lib/rails/generators/named_base.rb +2 -3
  32. data/lib/rails/generators/rails/migration/migration_generator.rb +1 -1
  33. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  34. data/lib/rails/generators/rails/scaffold/USAGE +15 -9
  35. data/lib/rails/generators/test_case.rb +2 -2
  36. data/lib/rails/plugin.rb +1 -0
  37. data/lib/rails/tasks/documentation.rake +1 -1
  38. data/lib/rails/test_unit/sub_test_task.rb +36 -0
  39. data/lib/rails/test_unit/testing.rake +10 -50
  40. data/lib/rails/version.rb +1 -1
  41. metadata +132 -64
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="RailsGuides">
4
+ <metadata>
5
+ <meta name="cover" content="cover" />
6
+ <dc-metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
7
+
8
+ <dc:title>Ruby on Rails Guides (<%= @version %>)</dc:title>
9
+
10
+ <dc:language>en-us</dc:language>
11
+ <dc:creator>Ruby on Rails</dc:creator>
12
+ <dc:publisher>Ruby on Rails</dc:publisher>
13
+ <dc:subject>Reference</dc:subject>
14
+ <dc:date><%= Time.now.strftime('%Y-%m-%d') %></dc:date>
15
+
16
+ <dc:description>These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together.</dc:description>
17
+ </dc-metadata>
18
+ <x-metadata>
19
+ <output content-type="application/x-mobipocket-subscription-magazine" encoding="utf-8"/>
20
+ </x-metadata>
21
+ </metadata>
22
+
23
+ <manifest>
24
+ <!-- HTML content files [mandatory] -->
25
+ <% documents_flat.each do |document| %>
26
+ <item id="<%= document['url'] %>" media-type="text/html" href="<%= document['url'] %>" />
27
+ <% end %>
28
+
29
+ <% %w{toc.html credits.html welcome.html copyright.html}.each do |url| %>
30
+ <item id="<%= url %>" media-type="text/html" href="<%= url %>" />
31
+ <% end %>
32
+
33
+ <item id="toc" media-type="application/x-dtbncx+xml" href="toc.ncx" />
34
+
35
+ <item id="cover" media-type="image/jpeg" href="images/rails_guides_kindle_cover.jpg"/>
36
+ </manifest>
37
+
38
+ <spine toc="toc">
39
+ <itemref idref="toc.html" />
40
+ <itemref idref="welcome.html" />
41
+ <itemref idref="credits.html" />
42
+ <itemref idref="copyright.html" />
43
+ <% documents_flat.each do |document| %>
44
+ <itemref idref="<%= document['url'] %>" />
45
+ <% end %>
46
+ </spine>
47
+
48
+ <guide>
49
+ <reference type="toc" title="Table of Contents" href="toc.html"></reference>
50
+ </guide>
51
+
52
+ </package>
@@ -0,0 +1,24 @@
1
+ <% content_for :page_title do %>
2
+ Ruby on Rails Guides
3
+ <% end %>
4
+
5
+ <h1>Table of Contents</h1>
6
+ <div id="toc">
7
+ <ul><li><a href="welcome.html">Welcome</a></li></ul>
8
+ <% documents_by_section.each_with_index do |section, i| %>
9
+ <h3><%= "#{i + 1}." %> <%= section['name'] %></h3>
10
+ <ul>
11
+ <% section['documents'].each do |document| %>
12
+ <li>
13
+ <a href="<%= document['url'] %>"><%= document['name'] %></a>
14
+ <% if document['work_in_progress']%>(WIP)<% end %>
15
+ </li>
16
+ <% end %>
17
+ </ul>
18
+ <% end %>
19
+ <hr />
20
+ <ul>
21
+ <li><a href="credits.html">Credits</a></li>
22
+ <li><a href="copyright.html">Copyright &amp; License</a></li>
23
+ <ul>
24
+ </div>
@@ -0,0 +1,64 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
3
+ "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
4
+
5
+ <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en-US">
6
+ <head>
7
+ <meta name="dtb:uid" content="RailsGuides"/>
8
+ <meta name="dtb:depth" content="2"/>
9
+ <meta name="dtb:totalPageCount" content="0"/>
10
+ <meta name="dtb:maxPageNumber" content="0"/>
11
+ </head>
12
+ <docTitle><text>Ruby on Rails Guides</text></docTitle>
13
+ <docAuthor><text>docrails</text></docAuthor>
14
+ <navMap>
15
+ <navPoint playOrder="0" class="periodical" id="periodical">
16
+ <navLabel>
17
+ <text>Table of Contents</text>
18
+ </navLabel>
19
+ <content src="toc.html"/>
20
+
21
+ <navPoint class="section" id="welcome" playOrder="1">
22
+ <navLabel>
23
+ <text>Introduction</text>
24
+ </navLabel>
25
+ <content src="welcome.html"/>
26
+
27
+ <navPoint class="article" id="welcome" playOrder="2">
28
+ <navLabel>
29
+ <text>Welcome</text>
30
+ </navLabel>
31
+ <content src="welcome.html"/>
32
+ </navPoint>
33
+ <navPoint class="article" id="credits" playOrder="3">
34
+ <navLabel><text>Credits</text></navLabel>
35
+ <content src="credits.html">
36
+ </navPoint>
37
+ <navPoint class="article" id="copyright" playOrder="4">
38
+ <navLabel><text>Copyright &amp; License</text></navLabel>
39
+ <content src="copyright.html">
40
+ </navPoint>
41
+ </navPoint>
42
+
43
+ <% play_order = 4 %>
44
+ <% documents_by_section.each_with_index do |section, section_no| %>
45
+ <navPoint class="section" id="chapter_<%= section_no + 1 %>" playOrder="<% play_order +=1 %>">
46
+ <navLabel>
47
+ <text><%= section['name'] %></text>
48
+ </navLabel>
49
+ <content src="<%=section['documents'].first['url'] %>"/>
50
+
51
+ <% section['documents'].each_with_index do |document, document_no| %>
52
+ <navPoint class="article" id="_<%=section_no+1%>.<%=document_no+1%>" playOrder="<%=play_order +=1 %>">
53
+ <navLabel>
54
+ <text><%= document['name'] %></text>
55
+ </navLabel>
56
+ <content src="<%=document['url'] %>"/>
57
+ </navPoint>
58
+ <% end %>
59
+ </navPoint>
60
+ <% end %>
61
+
62
+ </navPoint>
63
+ </navMap>
64
+ </ncx>
@@ -0,0 +1,5 @@
1
+ <%= render 'welcome' %>
2
+
3
+ <h3>Kindle Edition</h3>
4
+
5
+ The Kindle Edition of the Rails Guides should be considered a work in progress. Feedback is really welcome, please see the "Feedback" section at the end of each guide for instructions.
@@ -44,51 +44,16 @@
44
44
  <li class="index"><a href="index.html" onclick="guideMenu(); return false;" id="guidesMenu">Guides Index</a>
45
45
  <div id="guides" class="clearfix" style="display: none;">
46
46
  <hr />
47
- <dl class="L">
48
- <dt>Start Here</dt>
49
- <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
50
- <dt>Models</dt>
51
- <dd><a href="migrations.html">Rails Database Migrations</a></dd>
52
- <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
53
- <dd><a href="association_basics.html">Active Record Associations</a></dd>
54
- <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
55
- <dt>Views</dt>
56
- <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
57
- <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
58
- <dt>Controllers</dt>
59
- <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
60
- <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
61
- </dl>
62
- <dl class="R">
63
- <dt>Digging Deeper</dt>
64
- <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
65
- <dd><a href="i18n.html">Rails Internationalization API</a></dd>
66
- <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
67
- <dd><a href="testing.html">Testing Rails Applications</a></dd>
68
- <dd><a href="security.html">Securing Rails Applications</a></dd>
69
- <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
70
- <dd><a href="performance_testing.html">Performance Testing Rails Applications</a></dd>
71
- <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
72
- <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
73
- <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
74
- <dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
75
-
76
- <dt>Extending Rails</dt>
77
- <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
78
- <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
79
- <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
80
-
81
- <dt>Contributing to Ruby on Rails</dt>
82
- <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
83
- <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
84
- <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
85
-
86
- <dt>Release Notes</dt>
87
- <dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
88
- <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
89
- <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
90
- <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
91
- </dl>
47
+ <% ['L', 'R'].each do |position| %>
48
+ <dl class="<%= position %>">
49
+ <% docs_for_menu(position).each do |section| %>
50
+ <dt><%= section['name'] %></dt>
51
+ <% finished_documents(section['documents']).each do |document| %>
52
+ <dd><a href="<%= document['url'] %>"><%= document['name'] %></a></dd>
53
+ <% end %>
54
+ <% end %>
55
+ </dl>
56
+ <% end %>
92
57
  </div>
93
58
  </li>
94
59
  <li><a href="contributing_to_ruby_on_rails.html">Contribute</a></li>
@@ -143,8 +108,7 @@
143
108
  <hr class="hide" />
144
109
  <div id="footer">
145
110
  <div class="wrapper">
146
- <p>This work is licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0</a> License</p>
147
- <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
111
+ <%= render 'license' %>
148
112
  </div>
149
113
  </div>
150
114
 
@@ -814,7 +814,7 @@ replaying the entire migration history. It is much simpler and faster to just
814
814
  load into the database a description of the current schema.
815
815
 
816
816
  For example, this is how the test database is created: the current development
817
- database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then
817
+ database is dumped (either to +db/schema.rb+ or +db/structure.sql+) and then
818
818
  loaded into the test database.
819
819
 
820
820
  Schema files are also useful if you want a quick look at what attributes an
@@ -28,7 +28,7 @@ module Rails
28
28
  FileUtils.mkdir_p File.dirname path
29
29
  end
30
30
 
31
- f = File.open path, 'w'
31
+ f = File.open path, 'a'
32
32
  f.binmode
33
33
  f.sync = !Rails.env.production? # make sure every write flushes
34
34
 
@@ -23,7 +23,7 @@ module Rails
23
23
  routes = routes.collect do |route|
24
24
  route_reqs = route.requirements
25
25
 
26
- rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
26
+ rack_app = discover_rack_app(route.app)
27
27
 
28
28
  controller = route_reqs[:controller] || ':controller'
29
29
  action = route_reqs[:action] || ':action'
@@ -70,6 +70,15 @@ module Rails
70
70
  "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
71
71
  end
72
72
  end
73
+
74
+ def discover_rack_app(app)
75
+ class_name = app.class.name.to_s
76
+ if class_name == "ActionDispatch::Routing::Mapper::Constraints"
77
+ discover_rack_app(app.app)
78
+ elsif class_name !~ /^ActionDispatch::Routing/
79
+ app
80
+ end
81
+ end
73
82
  end
74
83
  end
75
84
  end
@@ -200,8 +200,8 @@ module Rails
200
200
  # Gems used only for assets and not required
201
201
  # in production environments by default.
202
202
  group :assets do
203
- gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git'
204
- gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git'
203
+ gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git', :branch => '3-2-stable'
204
+ gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git', :branch => '3-2-stable'
205
205
  #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)}
206
206
  gem 'uglifier', '>= 1.0.3'
207
207
  end
@@ -211,7 +211,7 @@ module Rails
211
211
  # Gems used only for assets and not required
212
212
  # in production environments by default.
213
213
  group :assets do
214
- gem 'sass-rails', '~> 3.2.0'
214
+ gem 'sass-rails', '~> 3.2.3'
215
215
  gem 'coffee-rails', '~> 3.2.0'
216
216
  #{"gem 'therubyrhino'\n" if defined?(JRUBY_VERSION)}
217
217
  gem 'uglifier', '>= 1.0.3'
@@ -128,13 +128,13 @@ module Rails
128
128
  #
129
129
  # ==== Boolean hooks
130
130
  #
131
- # In some cases, you want to provide a boolean hook. For example, webrat
131
+ # In some cases, you may want to provide a boolean hook. For example, webrat
132
132
  # developers might want to have webrat available on controller generator.
133
133
  # This can be achieved as:
134
134
  #
135
135
  # Rails::Generators::ControllerGenerator.hook_for :webrat, :type => :boolean
136
136
  #
137
- # Then, if you want, webrat to be invoked, just supply:
137
+ # Then, if you want webrat to be invoked, just supply:
138
138
  #
139
139
  # rails generate controller Account --webrat
140
140
  #
@@ -146,7 +146,7 @@ module Rails
146
146
  #
147
147
  # You can also supply a block to hook_for to customize how the hook is
148
148
  # going to be invoked. The block receives two arguments, an instance
149
- # of the current class and the klass to be invoked.
149
+ # of the current class and the class to be invoked.
150
150
  #
151
151
  # For example, in the resource generator, the controller should be invoked
152
152
  # with a pluralized class name. But by default it is invoked with the same
@@ -1,14 +1,48 @@
1
1
  require 'active_support/time'
2
2
  require 'active_support/core_ext/object/inclusion'
3
+ require 'active_support/core_ext/object/blank'
3
4
 
4
5
  module Rails
5
6
  module Generators
6
7
  class GeneratedAttribute
7
8
  attr_accessor :name, :type
9
+ attr_reader :attr_options
8
10
 
9
- def initialize(name, type)
10
- type = :string if type.blank?
11
- @name, @type = name, type.to_sym
11
+ class << self
12
+ def parse(column_definition)
13
+ name, type, has_index = column_definition.split(':')
14
+
15
+ # if user provided "name:index" instead of "name:string:index"
16
+ # type should be set blank so GeneratedAttribute's constructor
17
+ # could set it to :string
18
+ has_index, type = type, nil if %w(index uniq).include?(type)
19
+
20
+ type, attr_options = *parse_type_and_options(type)
21
+ new(name, type, has_index, attr_options)
22
+ end
23
+
24
+ private
25
+
26
+ # parse possible attribute options like :limit for string/text/binary/integer or :precision/:scale for decimals
27
+ # when declaring options curly brackets should be used
28
+ def parse_type_and_options(type)
29
+ case type
30
+ when /(string|text|binary|integer)\{(\d+)\}/
31
+ return $1, :limit => $2.to_i
32
+ when /decimal\{(\d+),(\d+)\}/
33
+ return :decimal, :precision => $1.to_i, :scale => $2.to_i
34
+ else
35
+ return type, {}
36
+ end
37
+ end
38
+ end
39
+
40
+ def initialize(name, type=nil, index_type=false, attr_options={})
41
+ @name = name
42
+ @type = (type.presence || :string).to_sym
43
+ @has_index = %w(index uniq).include?(index_type)
44
+ @has_uniq_index = %w(uniq).include?(index_type)
45
+ @attr_options = attr_options
12
46
  end
13
47
 
14
48
  def field_type
@@ -45,9 +79,29 @@ module Rails
45
79
  name.to_s.humanize
46
80
  end
47
81
 
82
+ def index_name
83
+ reference? ? "#{name}_id" : name
84
+ end
85
+
48
86
  def reference?
49
87
  self.type.in?([:references, :belongs_to])
50
88
  end
89
+
90
+ def has_index?
91
+ @has_index
92
+ end
93
+
94
+ def has_uniq_index?
95
+ @has_uniq_index
96
+ end
97
+
98
+ def inject_options
99
+ "".tap { |s| @attr_options.each { |k,v| s << ", :#{k} => #{v.inspect}" } }
100
+ end
101
+
102
+ def inject_index_options
103
+ has_uniq_index? ? ", :unique => true" : ''
104
+ end
51
105
  end
52
106
  end
53
107
  end
@@ -153,9 +153,8 @@ module Rails
153
153
 
154
154
  # Convert attributes array into GeneratedAttribute objects.
155
155
  def parse_attributes! #:nodoc:
156
- self.attributes = (attributes || []).map do |key_value|
157
- name, type = key_value.split(':')
158
- Rails::Generators::GeneratedAttribute.new(name, type)
156
+ self.attributes = (attributes || []).map do |attr|
157
+ Rails::Generators::GeneratedAttribute.parse(attr)
159
158
  end
160
159
  end
161
160
 
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module Generators
3
3
  class MigrationGenerator < NamedBase #metagenerator
4
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
4
+ argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
5
5
  hook_for :orm, :required => true
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module Generators
3
3
  class ModelGenerator < NamedBase #metagenerator
4
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
4
+ argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
5
5
  hook_for :orm, :required => true
6
6
  end
7
7
  end
@@ -7,23 +7,29 @@ Description:
7
7
  under_scored, as the first argument, and an optional list of attribute
8
8
  pairs.
9
9
 
10
- Attribute pairs are field:type arguments specifying the
11
- model's attributes. Timestamps are added by default, so you don't have to
12
- specify them by hand as 'created_at:datetime updated_at:datetime'.
10
+ Attributes are field arguments specifying the model's attributes. You can
11
+ optionally pass the type and an index to each field. For instance:
12
+ "title body:text tracking_id:integer:uniq" will generate a title field of
13
+ string type, a body with text type and a tracking_id as an integer with an
14
+ unique index. "index" could also be given instead of "uniq" if one desires
15
+ a non unique index.
16
+
17
+ Timestamps are added by default, so you don't have to specify them by hand
18
+ as 'created_at:datetime updated_at:datetime'.
13
19
 
14
20
  You don't have to think up every attribute up front, but it helps to
15
21
  sketch out a few so you can start working with the resource immediately.
16
22
 
17
- For example, 'scaffold post title:string body:text published:boolean'
18
- gives you a model with those three attributes, a controller that handles
23
+ For example, 'scaffold post title body:text published:boolean' gives
24
+ you a model with those three attributes, a controller that handles
19
25
  the create/show/update/destroy, forms to create and edit your posts, and
20
- an index that lists them all, as well as a resources :posts
21
- declaration in config/routes.rb.
26
+ an index that lists them all, as well as a resources :posts declaration
27
+ in config/routes.rb.
22
28
 
23
29
  If you want to remove all the generated files, run
24
30
  'rails destroy scaffold ModelName'.
25
31
 
26
32
  Examples:
27
33
  `rails generate scaffold post`
28
- `rails generate scaffold post title:string body:text published:boolean`
29
- `rails generate scaffold purchase order_id:integer amount:decimal`
34
+ `rails generate scaffold post title body:text published:boolean`
35
+ `rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`