railties 3.0.3 → 3.0.4.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/guides/assets/stylesheets/main.css +1 -1
  2. data/guides/rails_guides/helpers.rb +2 -7
  3. data/guides/source/3_0_release_notes.textile +2 -2
  4. data/guides/source/action_controller_overview.textile +0 -4
  5. data/guides/source/action_mailer_basics.textile +9 -11
  6. data/guides/source/action_view_overview.textile +0 -2
  7. data/guides/source/active_record_querying.textile +9 -57
  8. data/guides/source/active_record_validations_callbacks.textile +4 -6
  9. data/guides/source/active_support_core_extensions.textile +49 -2
  10. data/guides/source/api_documentation_guidelines.textile +1 -1
  11. data/guides/source/association_basics.textile +0 -2
  12. data/guides/source/caching_with_rails.textile +0 -1
  13. data/guides/source/command_line.textile +2 -3
  14. data/guides/source/configuring.textile +332 -64
  15. data/guides/source/contribute.textile +1 -1
  16. data/guides/source/contributing_to_ruby_on_rails.textile +370 -0
  17. data/guides/source/debugging_rails_applications.textile +0 -2
  18. data/guides/source/form_helpers.textile +0 -2
  19. data/guides/source/generators.textile +262 -9
  20. data/guides/source/getting_started.textile +0 -2
  21. data/guides/source/i18n.textile +13 -18
  22. data/guides/source/index.html.erb +9 -9
  23. data/guides/source/initialization.textile +4 -4
  24. data/guides/source/layout.html.erb +27 -2
  25. data/guides/source/layouts_and_rendering.textile +10 -16
  26. data/guides/source/migrations.textile +0 -2
  27. data/guides/source/performance_testing.textile +1 -3
  28. data/guides/source/plugins.textile +0 -2
  29. data/guides/source/rails_application_templates.textile +0 -2
  30. data/guides/source/rails_on_rack.textile +0 -2
  31. data/guides/source/routing.textile +13 -15
  32. data/guides/source/security.textile +3 -5
  33. data/guides/source/testing.textile +16 -12
  34. data/lib/rails/generators.rb +1 -1
  35. data/lib/rails/generators/actions.rb +1 -1
  36. data/lib/rails/generators/base.rb +1 -1
  37. data/lib/rails/generators/rails/app/app_generator.rb +2 -8
  38. data/lib/rails/generators/rails/app/templates/Gemfile +1 -1
  39. data/lib/rails/generators/rails/app/templates/config/boot.rb +3 -10
  40. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
  41. data/lib/rails/generators/rails/app/templates/gitignore +1 -1
  42. data/lib/rails/rack/logger.rb +1 -1
  43. data/lib/rails/railtie.rb +2 -2
  44. data/lib/rails/test_help.rb +0 -11
  45. data/lib/rails/version.rb +4 -3
  46. metadata +22 -17
  47. data/guides/source/contributing_to_rails.textile +0 -308
@@ -166,7 +166,7 @@ end
166
166
  The section about session fixation introduced the problem of maintained sessions. An attacker maintaining a session every five minutes can keep the session alive forever, although you are expiring sessions. A simple solution for this would be to add a created_at column to the sessions table. Now you can delete sessions that were created a long time ago. Use this line in the sweep method above:
167
167
 
168
168
  <ruby>
169
- delete_all "updated_at < '#{time.to_s(:db)}' OR
169
+ delete_all "updated_at < '#{time.ago.to_s(:db)}' OR
170
170
  created_at < '#{2.days.ago.to_s(:db)}'"
171
171
  </ruby>
172
172
 
@@ -524,10 +524,10 @@ h4. Logging
524
524
 
525
525
  -- _Tell Rails not to put passwords in the log files._
526
526
 
527
- By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers et cetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can _(highlight)filter certain request parameters from your log files_ by the filter_parameter_logging method in a controller. These parameters will be marked [FILTERED] in the log.
527
+ By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers et cetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can _(highlight)filter certain request parameters from your log files_ by appending them to <tt>config.filter_parameters</tt> in the application configuration. These parameters will be marked [FILTERED] in the log.
528
528
 
529
529
  <ruby>
530
- filter_parameter_logging :password
530
+ config.filter_parameters << :password
531
531
  </ruby>
532
532
 
533
533
  h4. Good Passwords
@@ -979,6 +979,4 @@ The security landscape shifts and it is important to keep up to date, because mi
979
979
 
980
980
  h3. Changelog
981
981
 
982
- "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/7
983
-
984
982
  * November 1, 2008: First approved version by Heiko Webers
@@ -182,21 +182,27 @@ class PostTest < ActiveSupport::TestCase
182
182
 
183
183
  The +PostTest+ class defines a _test case_ because it inherits from +ActiveSupport::TestCase+. +PostTest+ thus has all the methods available from +ActiveSupport::TestCase+. You'll see those methods a little later in this guide.
184
184
 
185
- <ruby>
186
- def test_truth
187
- </ruby>
188
-
189
185
  Any method defined within a +Test::Unit+ test case that begins with +test+ (case sensitive) is simply called a test. So, +test_password+, +test_valid_password+ and +testValidPassword+ all are legal test names and are run automatically when the test case is run.
190
186
 
191
- Rails adds a +test+ method that takes a test name and a block. It generates a normal +Test::Unit+ test with method names prefixed with +test_+.
187
+ Rails adds a +test+ method that takes a test name and a block. It generates a normal +Test::Unit+ test with method names prefixed with +test_+. So,
192
188
 
193
189
  <ruby>
194
190
  test "the truth" do
195
- # ...
191
+ assert true
192
+ end
193
+ </ruby>
194
+
195
+ acts as if you had written
196
+
197
+ <ruby>
198
+ def test_the_truth
199
+ assert true
196
200
  end
197
201
  </ruby>
198
202
 
199
- This makes test names more readable by replacing underscores with regular language.
203
+ only the +test+ macro allows a more readable test name. You can still use regular method definitions though.
204
+
205
+ NOTE: The method name is generated by replacing spaces with underscores. The result does not need to be a valid Ruby identifier though, the name may contain punctuation characters etc. That's because in Ruby technically any string may be a method name. Odd ones need +define_method+ and +send+ calls, but formally there's no restriction.
200
206
 
201
207
  <ruby>
202
208
  assert true
@@ -257,7 +263,7 @@ This will run all the test methods from the test case.
257
263
  You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+.
258
264
 
259
265
  <shell>
260
- $ ruby unit/post_test.rb -n test_truth
266
+ $ ruby -Itest test/unit/post_test.rb -n test_the_truth
261
267
 
262
268
  Loaded suite unit/post_test
263
269
  Started
@@ -381,7 +387,7 @@ There are a bunch of different types of assertions you can use. Here's the compl
381
387
  |+assert( boolean, [msg] )+ |Ensures that the object/expression is true.|
382
388
  |+assert_equal( obj1, obj2, [msg] )+ |Ensures that +obj1 == obj2+ is true.|
383
389
  |+assert_not_equal( obj1, obj2, [msg] )+ |Ensures that +obj1 == obj2+ is false.|
384
- |+assert_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is true.|
390
+ |+assert_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is true.|
385
391
  |+assert_not_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is false.|
386
392
  |+assert_nil( obj, [msg] )+ |Ensures that +obj.nil?+ is true.|
387
393
  |+assert_not_nil( obj, [msg] )+ |Ensures that +obj.nil?+ is false.|
@@ -389,7 +395,7 @@ There are a bunch of different types of assertions you can use. Here's the compl
389
395
  |+assert_no_match( regexp, string, [msg] )+ |Ensures that a string doesn't matches the regular expression.|
390
396
  |+assert_in_delta( expecting, actual, delta, [msg] )+ |Ensures that the numbers +expecting+ and +actual+ are within +delta+ of each other.|
391
397
  |+assert_throws( symbol, [msg] ) { block }+ |Ensures that the given block throws the symbol.|
392
- |+assert_raise( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions.|
398
+ |+assert_raise( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions.|
393
399
  |+assert_nothing_raised( exception1, exception2, ... ) { block }+ |Ensures that the given block doesn't raise one of the given exceptions.|
394
400
  |+assert_instance_of( class, obj, [msg] )+ |Ensures that +obj+ is of the +class+ type.|
395
401
  |+assert_kind_of( class, obj, [msg] )+ |Ensures that +obj+ is or descends from +class+.|
@@ -941,8 +947,6 @@ The built-in +test/unit+ based testing is not the only way to test Rails applica
941
947
 
942
948
  h3. Changelog
943
949
 
944
- "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/8
945
-
946
950
  * April 4, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
947
951
  * November 13, 2008: Revised based on feedback from Pratik Naik by "Akshay Surve":credits.html#asurve (not yet approved for publication)
948
952
  * October 14, 2008: Edit and formatting pass by "Mike Gunderloy":credits.html#mgunderloy (not yet approved for publication)
@@ -158,7 +158,7 @@ module Rails
158
158
  # commands.
159
159
  def self.invoke(namespace, args=ARGV, config={})
160
160
  names = namespace.to_s.split(':')
161
- if klass = find_by_namespace(names.pop, names.shift)
161
+ if klass = find_by_namespace(names.pop, names.any? && names.join(':'))
162
162
  args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
163
163
  klass.start(args, config)
164
164
  else
@@ -45,7 +45,7 @@ module Rails
45
45
  #
46
46
  # ==== Example
47
47
  #
48
- # gem "rspec", :env => :test
48
+ # gem "rspec", :group => :test
49
49
  # gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
50
50
  # gem "rails", "3.0", :git => "git://github.com/rails/rails"
51
51
  #
@@ -274,7 +274,7 @@ module Rails
274
274
  # Use Rails default banner.
275
275
  #
276
276
  def self.banner
277
- "rails generate #{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
277
+ "rails generate #{namespace.sub(/^rails:/,'')} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]".gsub(/\s+/, ' ')
278
278
  end
279
279
 
280
280
  # Sets the base_name taking into account the current class namespace.
@@ -338,7 +338,7 @@ module Rails
338
338
 
339
339
  def set_default_accessors!
340
340
  self.rails_template = case options[:template]
341
- when /^http:\/\//
341
+ when /^https?:\/\//
342
342
  options[:template]
343
343
  when String
344
344
  File.expand_path(options[:template], Dir.pwd)
@@ -398,19 +398,13 @@ module Rails
398
398
  case options[:database]
399
399
  when "oracle" then "ruby-oci8"
400
400
  when "postgresql" then "pg"
401
- when "sqlite3" then "sqlite3-ruby"
401
+ when "sqlite3" then "sqlite3"
402
402
  when "frontbase" then "ruby-frontbase"
403
403
  when "mysql" then "mysql2"
404
404
  else options[:database]
405
405
  end
406
406
  end
407
407
 
408
- def require_for_database
409
- case options[:database]
410
- when "sqlite3" then "sqlite3"
411
- end
412
- end
413
-
414
408
  def mysql_socket
415
409
  @mysql_socket ||= [
416
410
  "/tmp/mysql.sock", # default
@@ -12,7 +12,7 @@ gem 'rails', '<%= Rails::VERSION::STRING %>'
12
12
  <%- end -%>
13
13
 
14
14
  <% unless options[:skip_active_record] -%>
15
- gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= require_for_database %>'<% end %>
15
+ gem '<%= gem_for_database %>'
16
16
  <% end -%>
17
17
 
18
18
  # Use unicorn as the web server
@@ -1,13 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
3
  # Set up gems listed in the Gemfile.
4
- gemfile = File.expand_path('../../Gemfile', __FILE__)
5
- begin
6
- ENV['BUNDLE_GEMFILE'] = gemfile
7
- require 'bundler'
8
- Bundler.setup
9
- rescue Bundler::GemNotFound => e
10
- STDERR.puts e.message
11
- STDERR.puts "Try running `bundle install`."
12
- exit!
13
- end if File.exist?(gemfile)
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -1,5 +1,5 @@
1
1
  # SQLite version 3.x
2
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
2
+ # gem install sqlite3
3
3
  development:
4
4
  adapter: sqlite3
5
5
  database: db/development.sqlite3
@@ -1,4 +1,4 @@
1
1
  .bundle
2
2
  db/*.sqlite3
3
3
  log/*.log
4
- tmp/**/*
4
+ tmp/
@@ -21,7 +21,7 @@ module Rails
21
21
  request = ActionDispatch::Request.new(env)
22
22
  path = request.fullpath
23
23
 
24
- info "\n\nStarted #{env["REQUEST_METHOD"]} \"#{path}\" " \
24
+ info "\n\nStarted #{request.request_method} \"#{path}\" " \
25
25
  "for #{request.ip} at #{Time.now.to_default_s}"
26
26
  end
27
27
 
@@ -98,7 +98,7 @@ module Rails
98
98
  # If your railtie has rake tasks, you can tell Rails to load them through the method
99
99
  # rake tasks:
100
100
  #
101
- # class MyRailtie < Railtie
101
+ # class MyRailtie < Rails::Railtie
102
102
  # rake_tasks do
103
103
  # load "path/to/my_railtie.tasks"
104
104
  # end
@@ -108,7 +108,7 @@ module Rails
108
108
  # your generators at a different location, you can specify in your Railtie a block which
109
109
  # will load them during normal generators lookup:
110
110
  #
111
- # class MyRailtie < Railtie
111
+ # class MyRailtie < Rails::Railtie
112
112
  # generators do
113
113
  # require "path/to/my_railtie_generator"
114
114
  # end
@@ -39,14 +39,3 @@ class ActionDispatch::IntegrationTest
39
39
  @routes = Rails.application.routes
40
40
  end
41
41
  end
42
-
43
- begin
44
- require_library_or_gem 'ruby-debug'
45
- Debugger.start
46
- if Debugger.respond_to?(:settings)
47
- Debugger.settings[:autoeval] = true
48
- Debugger.settings[:autolist] = 1
49
- end
50
- rescue LoadError
51
- # ruby-debug wasn't available so neither can the debugging be
52
- end
@@ -2,8 +2,9 @@ module Rails
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 3
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
5
+ TINY = 4
6
+ PRE = "rc1"
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
8
9
  end
9
10
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railties
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 977940590
5
+ prerelease: true
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 3
10
- version: 3.0.3
9
+ - 4
10
+ - rc1
11
+ version: 3.0.4.rc1
11
12
  platform: ruby
12
13
  authors:
13
14
  - David Heinemeier Hansson
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-16 00:00:00 -06:00
19
+ date: 2011-01-31 00:00:00 +13:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -58,12 +59,13 @@ dependencies:
58
59
  requirements:
59
60
  - - "="
60
61
  - !ruby/object:Gem::Version
61
- hash: 1
62
+ hash: 977940590
62
63
  segments:
63
64
  - 3
64
65
  - 0
65
- - 3
66
- version: 3.0.3
66
+ - 4
67
+ - rc1
68
+ version: 3.0.4.rc1
67
69
  type: :runtime
68
70
  version_requirements: *id003
69
71
  - !ruby/object:Gem::Dependency
@@ -74,12 +76,13 @@ dependencies:
74
76
  requirements:
75
77
  - - "="
76
78
  - !ruby/object:Gem::Version
77
- hash: 1
79
+ hash: 977940590
78
80
  segments:
79
81
  - 3
80
82
  - 0
81
- - 3
82
- version: 3.0.3
83
+ - 4
84
+ - rc1
85
+ version: 3.0.4.rc1
83
86
  type: :runtime
84
87
  version_requirements: *id004
85
88
  description: "Rails internals: application bootup, plugins, generators, and rake tasks."
@@ -233,7 +236,7 @@ files:
233
236
  - guides/source/command_line.textile
234
237
  - guides/source/configuring.textile
235
238
  - guides/source/contribute.textile
236
- - guides/source/contributing_to_rails.textile
239
+ - guides/source/contributing_to_ruby_on_rails.textile
237
240
  - guides/source/credits.html.erb
238
241
  - guides/source/debugging_rails_applications.textile
239
242
  - guides/source/form_helpers.textile
@@ -457,7 +460,7 @@ files:
457
460
  - lib/rails/generators/rails/app/templates/test/integration/.empty_directory
458
461
  - lib/rails/generators/rails/app/templates/test/unit/.empty_directory
459
462
  - lib/rails/generators/rails/generator/templates/templates/.empty_directory
460
- has_rdoc: true
463
+ has_rdoc: false
461
464
  homepage: http://www.rubyonrails.org
462
465
  licenses: []
463
466
 
@@ -481,12 +484,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
481
484
  required_rubygems_version: !ruby/object:Gem::Requirement
482
485
  none: false
483
486
  requirements:
484
- - - ">="
487
+ - - ">"
485
488
  - !ruby/object:Gem::Version
486
- hash: 3
489
+ hash: 25
487
490
  segments:
488
- - 0
489
- version: "0"
491
+ - 1
492
+ - 3
493
+ - 1
494
+ version: 1.3.1
490
495
  requirements: []
491
496
 
492
497
  rubyforge_project: rails
@@ -1,308 +0,0 @@
1
- h2. Contributing to Rails
2
-
3
- This guide covers ways in which _you_ can become a part of the ongoing development of Rails. After reading it, you should be familiar with:
4
-
5
- * Using Lighthouse to report issues with Rails
6
- * Cloning edge Rails and running the test suite
7
- * Helping to resolve existing issues
8
- * Contributing to the Rails documentation
9
- * Contributing to the Rails code
10
-
11
- Rails is not "someone else's framework." Over the years, hundreds of people have contributed code ranging from a single character to massive architectural changes, all with the goal of making Rails better for everyone. Even if you don't feel up to writing code yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches to contributing documentation.
12
-
13
- endprologue.
14
-
15
- h3. Reporting a Rails Issue
16
-
17
- Rails uses a "Lighthouse project":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/ to track issues (primarily bugs and contributions of new code). If you've found a bug in Rails, this is the place to start. You'll need to create a (free) Lighthouse account in order to comment on issues or to upload tests or patches.
18
-
19
- NOTE: Bugs in the most recent released version of Rails are likely to get the most attention. Also, the Rails core team is always interested in feedback from those who can take the time to test _edge Rails_ (the code for the version of Rails that is currently under development). Later in this Guide you'll find out how to get edge Rails for testing.
20
-
21
- h4. Creating a Bug Report
22
-
23
- If you've found a problem in Rails, you can start by "adding a new ticket":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/new to the Rails Lighthouse. At the minimum, your ticket needs a title and descriptive text. But that's only a minimum. You should include as much relevant information as possible. You need to at least post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix.
24
-
25
- You shouldn't assign the bug to a particular core developer (through the *Who's Responsible* select list) unless you know for sure which developer will be handling any patch. The core team periodically reviews issues and assigns developers and milestones to them.
26
-
27
- You should set tags for your issue. Use the "bug" tag for a bug report, and add the "patch" tag if you are attaching a patch. Try to find some relevant tags from the existing tag list (which will appear as soon as you start typing in the *Choose some tags* textbox), rather than creating new tags.
28
-
29
- Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kind of bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with a "I'm having this problem too" comment.
30
-
31
- h4. Special Treatment for Security Issues
32
-
33
- If you've found a security vulnerability in Rails, please do *not* report it via a Lighthouse ticket. Lighthouse tickets are public as soon as they are entered. Instead, you should use the dedicated email address "security@rubyonrails.org":mailto:security@rubyonrails.org to report any vulnerabilities. This alias is monitored and the core team will work with you to quickly and completely address any such vulnerabilities.
34
-
35
- WARNING: Just to emphasize the point, _please do not report security vulnerabilities on public Lighthouse tickets_. This will only expose your fellow Rails developers to needless risks.
36
-
37
- You should receive an acknowledgement and detailed response to any reported security issue within 48 hours. If you don't think you're getting adequate response from the security alias, refer to the "Rails security policy page":http://rubyonrails.org/security for direct emails for the current Rails security coordinators.
38
-
39
- h4. What About Feature Requests?
40
-
41
- Please don't put "feature request" tickets into Lighthouse. If there's a new feature that you want to see added to Rails, you'll need to write the code yourself - or convince someone else to partner with you to write the code. Later in this guide you'll find detailed instructions for proposing a patch to Rails. If you enter a wishlist item in Lighthouse with no code, you can expect it to be marked "invalid" as soon as it's reviewed.
42
-
43
- h3. Running the Rails Test Suite
44
-
45
- To move on from submitting bugs to helping resolve existing issues or contributing your own code to Rails, you _must_ be able to run the Rails test suite. In this section of the guide you'll learn how to set up the tests on your own computer.
46
-
47
- h4. Install git
48
-
49
- Rails uses git for source code control. You won’t be able to do anything without the Rails source code, and this is a prerequisite. The "git homepage":http://git-scm.com/ has installation instructions. If you’re on OS X, use the "Git for OS X":http://code.google.com/p/git-osx-installer/ installer. If you're unfamiliar with git, there are a variety of resources on the net that will help you learn more:
50
-
51
- * "Everyday Git":http://www.kernel.org/pub/software/scm/git/docs/everyday.html will teach you just enough about git to get by.
52
- * The "PeepCode screencast":https://peepcode.com/products/git on git ($9) is easier to follow.
53
- * "GitHub":http://github.com/guides/home offers links to a variety of git resources.
54
- * "Pro Git":http://progit.org/book/ is an entire book about git with a Creative Commons license.
55
-
56
- h4. Get the Rails Source Code
57
-
58
- Don’t fork the main Rails repository. Instead, you want to clone it to your own computer. Navigate to the folder where you want the source code (it will create its own /rails subdirectory) and run:
59
-
60
- <shell>
61
- git clone git://github.com/rails/rails.git
62
- cd rails
63
- </shell>
64
-
65
- h4. Set up and Run the Tests
66
-
67
- All of the Rails tests must pass with any code you submit, otherwise you have no chance of getting code accepted. This means you need to be able to run the tests. First, you need to install all Rails dependencies with bundler:
68
-
69
- NOTE: Ensure you install bundler v1.0
70
-
71
- <shell>
72
- gem install bundler
73
- bundle install --without db
74
- </shell>
75
-
76
- The second command will install all dependencies, except MySQL and PostgreSQL. We will come back at these soon. With dependencies installed, you can run the whole Rails test suite with:
77
-
78
- <shell>
79
- rake test
80
- </shell>
81
-
82
- You can also run tests for an specific framework, like Action Pack, by going into its directory and executing the same command:
83
-
84
- <shell>
85
- cd actionpack
86
- rake test
87
- </shell>
88
-
89
- h4. Testing Active Record
90
-
91
- By default, when you run Active Record tests, it will execute the test suite three times, one for each of the main databases: SQLite3, MySQL and PostgreSQL. If you are adding a feature that is not specific to the database, you can run the test suite (or just one file) for just one of them. Here is an example for SQLite3:
92
-
93
- <shell>
94
- cd activerecord
95
- rake test_sqlite3
96
- rake test_sqlite3 TEST=test/cases/validations_test.rb
97
- </shell>
98
-
99
- If you want to use another database, as MySQL, you need to create a user named +rails+ with privileges on the test databases.
100
-
101
- <shell>
102
- mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.*
103
- to 'rails'@'localhost';
104
- mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.*
105
- to 'rails'@'localhost';
106
- </shell>
107
-
108
- Then ensure you run bundle install without the +--without db+ option:
109
-
110
- <shell>
111
- bundle install
112
- </shell>
113
-
114
- Finally, enter this from the +activerecord+ directory to create the test databases:
115
-
116
- <shell>
117
- rake mysql:build_databases
118
- </shell>
119
-
120
- NOTE: Using the rake task to create the test databases ensures they have the correct character set and collation.
121
-
122
- If you’re using another database, check the files under +activerecord/test/connections+ in the Rails source code for default connection information. You can edit these files if you _must_ on your machine to provide different credentials, but obviously you should not push any such changes back to Rails.
123
-
124
- You can now run tests as you did for +sqlite3+:
125
-
126
- <shell>
127
- rake test_mysql
128
- </shell>
129
-
130
- You can also +myqsl+ with +postgresql+, +jdbcmysql+, +jdbcsqlite3+ or +jdbcpostgresql+. Check out the file +activerecord/RUNNING_UNIT_TESTS+ for information on running more targeted database tests, or the file +ci/ci_build.rb+ to see the test suite that the Rails continuous integration server runs.
131
-
132
- NOTE: If you're working with Active Record code, you _must_ ensure that the tests pass for at least MySQL, PostgreSQL, and SQLite 3. Subtle differences between the various Active Record database adapters have been behind the rejection of many patches that looked OK when tested only against MySQL.
133
-
134
- h4. Older versions of Rails
135
-
136
- If you want to work add a fix to older versions of Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to Rails 2.3 branch:
137
-
138
- <shell>
139
- git branch --track 2-3-stable origin/2-3-stable
140
- git checkout 2-3-stable
141
- </shell>
142
-
143
- TIP: You may want to "put your git branch name in your shell prompt":http://github.com/guides/put-your-git-branch-name-in-your-shell-prompt to make it easier to remember which version of the code you're working with.
144
-
145
- h3. Helping to Resolve Existing Issues
146
-
147
- As a next step beyond reporting issues, you can help the core team resolve existing issues. If you check the "open tickets":https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets?q=state%3Aopen list in Lighthouse, you'll find hundreds of issues already requiring attention. What can you do for these? Quite a bit, actually:
148
-
149
- h4. Verifying Bug Reports
150
-
151
- For starters, it helps to just verify bug reports. Can you reproduce the reported issue on your own computer? If so, you can add a comment to the ticket saying that you're seeing the same thing.
152
-
153
- If something is very vague, can you help squish it down into something specific? Maybe you can provide additional information to help reproduce a bug, or eliminate needless steps that aren't required to help demonstrate the problem.
154
-
155
- If you find a bug report without a test, it's very useful to contribute a failing test. This is also a great way to get started exploring the Rails source: looking at the existing test files will teach you how to write more tests for Rails. New tests are best contributed in the form of a patch, as explained later on in the "Contributing to the Rails Code" section.
156
-
157
- Anything you can do to make bug reports more succinct or easier to reproduce is a help to folks trying to write code to fix those bugs - whether you end up writing the code yourself or not.
158
-
159
- h4. Testing Patches
160
-
161
- You can also help out by examining patches that have been submitted to Rails via Lighthouse. To apply someone's changes you need to first create a branch of the Rails source code:
162
-
163
- <shell>
164
- git checkout -b testing_branch
165
- </shell>
166
-
167
- Then you can apply their patch:
168
-
169
- <shell>
170
- git apply their-patch-file.diff
171
- </shell>
172
-
173
- After applying a patch, test it out! Here are some things to think about:
174
-
175
- * Does the patch actually work?
176
- * Are you happy with the tests? Can you follow what they're testing? Are there any tests missing?
177
- * Does the documentation still seem right to you?
178
- * Do you like the implementation? Can you think of a nicer or faster way to implement a part of their change?
179
-
180
- Once you're happy that the patch contains a good change, comment on the Lighthouse ticket indicating your approval. Your comment should indicate that you like the change and what you like about it. Something like:
181
-
182
- <blockquote>
183
- I like the way you've restructured that code in generate_finder_sql, much nicer. The tests look good too.
184
- </blockquote>
185
-
186
- If your comment simply says "+1", then odds are that other reviewers aren't going to take it too seriously. Show that you took the time to review the patch. Once three people have approved it, add the "verified" tag. This will bring it to the attention of a core team member who will review the changes looking for the same kinds of things.
187
-
188
- h3. Contributing to the Rails Documentation
189
-
190
- Another area where you can help out if you're not yet ready to take the plunge to writing Rails core code is with Rails documentation. You can help with the Rails Guides or the Rails API documentation.
191
-
192
- TIP: "docrails":http://github.com/lifo/docrails/tree/master is the documentation branch for Rails with an *open commit policy*. You can simply PM "lifo":http://github.com/lifo on Github and ask for the commit rights. Documentation changes made as part of the "docrails":http://github.com/lifo/docrails/tree/master project are merged back to the Rails master code from time to time. Check out the "original announcement":http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch for more details.
193
-
194
- h4. The Rails Guides
195
-
196
- The "Rails Guides":http://guides.rubyonrails.org/ are a set of online resources that are designed to make people productive with Rails and to understand how all of the pieces fit together. These guides (including this one!) are written as part of the "docrails":http://github.com/lifo/docrails/tree/master project. If you have an idea for a new guide, or improvements for an existing guide, you can refer to the "contribution page":contribute.html for instructions on getting involved.
197
-
198
- h4. The Rails API Documentation
199
-
200
- The "Rails API documentation":http://api.rubyonrails.org/ is automatically generated from the Rails source code via "RDoc":http://rdoc.rubyforge.org/. If you find some part of the documentation to be incomplete, confusing, or just plain wrong, you can step in and fix it.
201
-
202
- To contribute an update to the API documentation, you can contact "lifo":http://github.com/lifo on GitHub and ask for commit rights to the docrails repository and push your changes to the docrails repository. Please follow the "docrails RDoc conventions":http://wiki.github.com/lifo/docrails/rails-api-documentation-conventions when contributing the changes.
203
-
204
- h3. The Rails Wiki
205
-
206
- The "Rails wiki":http://wiki.rubyonrails.org/ is a collection of user-generated and freely-editable information about Rails. It covers everything from getting started to FAQs to how-tos and popular plugins. To contribute to the wiki, just find some useful information that isn't there already and add it. There are style guidelines to help keep the wiki a coherent resources; see the section on "contributing to the wiki":http://wiki.rubyonrails.org/#contributing_to_the_wiki for more details.
207
-
208
- h3. Contributing to the Rails Code
209
-
210
- When you're ready to take the plunge, one of the most helpful ways to contribute to Rails is to actually submit source code. Here's a step-by-step listing of the things you need to do to make this a successful experience.
211
-
212
- h4. Learn the Language and the Framework
213
-
214
- Learn at least _something_ about Ruby and Rails. If you don’t understand the syntax of the language, common Ruby idioms, and the code that already exists in Rails, you’re unlikely to be able to build a good patch (that is, one that will get accepted). You don’t have to know every in-and-out of the language and the framework; some of the Rails code is fiendishly complex. But Rails is probably not appropriate as the first place that you ever write Ruby code. You should at least understand (though not necessarily memorize) "The Ruby Programming Language":http://www.amazon.com/gp/product/0596516177?ie=UTF8&linkCode=as2&camp=1789&creative=390957&creativeASIN=0596516177 and have browsed the Rails source code.
215
-
216
- h4. Fork the Rails Source Code
217
-
218
- Fork Rails. You’re not going to put your patches right into the master branch, OK? This is where you need that copy of Rails that you cloned earlier. Think of a name for your new branch and run
219
-
220
- <shell>
221
- git checkout -b my_new_branch
222
- </shell>
223
-
224
- It doesn’t really matter what name you use, because this branch will only exist on your local computer.
225
-
226
- h4. Write Your Code
227
-
228
- Now get busy and add your code to Rails (or edit the existing code). You’re on your branch now, so you can write whatever you want (you can check to make sure you’re on the right branch with +git branch -a+). But if you’re planning to submit your change back for inclusion in Rails, keep a few things in mind:
229
-
230
- * Get the code right
231
- * Use Rails idioms and helpers
232
- * Include tests that fail without your code, and pass with it
233
- * Update the documentation
234
-
235
- h4. Follow the Coding Conventions
236
-
237
- Rails follows a simple set of coding style conventions.
238
-
239
- * Two spaces, no tabs
240
- * Prefer +&amp;&amp;+/+||+ over +and+/+or+
241
- * +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+
242
- * Follow the conventions you see used in the source already
243
-
244
- h4. Sanity Check
245
-
246
- You should not be the only person who looks at the code before you submit it. You know at least one other Rails developer, right? Show them what you’re doing and ask for feedback. Doing this in private before you push a patch out publicly is the “smoke test” for a patch: if you can’t convince one other developer of the beauty of your code, you’re unlikely to convince the core team either.
247
-
248
- You might also want to check out the "RailsBridge BugMash":http://wiki.railsbridge.org/projects/railsbridge/wiki/BugMash as a way to get involved in a group effort to improve Rails. This can help you get started and help check your code when you're writing your first patches.
249
-
250
- h4. Commit Your Changes
251
-
252
- When you're happy with the code on your computer, you need to commit the changes to git:
253
-
254
- <shell>
255
- git commit -a -m "Here is a commit message"
256
- </shell>
257
-
258
- h4. Update Rails
259
-
260
- Update your copy of Rails. It’s pretty likely that other changes to core Rails have happened while you were working. Go get them:
261
-
262
- <shell>
263
- git checkout master
264
- git pull
265
- </shell>
266
-
267
- Now reapply your patch on top of the latest changes:
268
-
269
- <shell>
270
- git checkout my_new_branch
271
- git rebase master
272
- </shell>
273
-
274
- No conflicts? Tests still pass? Change still seems reasonable to you? Then move on.
275
-
276
- h4. Create a Patch
277
-
278
- Now you can create a patch file to share with other developers (and with the Rails core team). Still in your branch, run
279
-
280
- <shell>
281
- git commit -a
282
- git format-patch master --stdout > my_new_patch.diff
283
- </shell>
284
-
285
- Sanity check the results of this operation: open the diff file in your text editor of choice and make sure that no unintended changes crept in.
286
-
287
- h4. Create a Lighthouse Ticket
288
-
289
- Now create a ticket with your patch. Go to the "new ticket":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/new page at Lighthouse. Fill in a reasonable title and description, remember to attach your patch file, and tag the ticket with the ‘patch’ tag and whatever other subject area tags make sense.
290
-
291
- h4. Get Some Feedback
292
-
293
- Now you need to get other people to look at your patch, just as you've looked at other people's patches. You can use the rubyonrails-core mailing list or the #rails-contrib channel on IRC freenode for this. You might also try just talking to Rails developers that you know.
294
-
295
- h4. Iterate as Necessary
296
-
297
- It’s entirely possible that the feedback you get will suggest changes. Don’t get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then it’s worth making the tweaks and resubmitting. If the feedback is that your code doesn’t belong in the core, you might still think about releasing it as a plugin.
298
-
299
- And then...think about your next contribution!
300
-
301
- h3. Changelog
302
-
303
- "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/64
304
-
305
- * April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com
306
- * August 1, 2009: Updates/amplifications by "Mike Gunderloy":credits.html#mgunderloy
307
- * March 2, 2009: Initial draft by "Mike Gunderloy":credits.html#mgunderloy
308
-