diff options
Diffstat (limited to 'railties')
8 files changed, 469 insertions, 374 deletions
diff --git a/railties/Rakefile b/railties/Rakefile index 5137bee761..1b469543cc 100755 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -46,8 +46,8 @@ task :generate_guides do end task :update_ujs do - system "curl http://github.com/rails/prototype-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js" - system "curl http://github.com/rails/jquery-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/jquery_ujs.js" + system "curl https://github.com/rails/prototype-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js" + system "curl https://github.com/rails/jquery-ujs/raw/master/src/rails.js > lib/rails/generators/rails/app/templates/public/javascripts/jquery_ujs.js" end # Validate guides ------------------------------------------------------------------------- diff --git a/railties/guides/source/contributing_to_rails.textile b/railties/guides/source/contributing_to_rails.textile deleted file mode 100644 index 1a1f4e9858..0000000000 --- a/railties/guides/source/contributing_to_rails.textile +++ /dev/null @@ -1,311 +0,0 @@ -h2. Contributing to Rails - -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: - -* Using Lighthouse to report issues with Rails -* Cloning edge Rails and running the test suite -* Helping to resolve existing issues -* Contributing to the Rails documentation -* Contributing to the Rails code - -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. - -endprologue. - -h3. Reporting a Rails Issue - -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. - -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. - -h4. Creating a Bug Report - -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. - -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. - -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. - -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. - -h4. Special Treatment for Security Issues - -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. - -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. - -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. - -h4. What About Feature Requests? - -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. - -h3. Running the Rails Test Suite - -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. - -h4. Install git - -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: - -* "Everyday Git":http://www.kernel.org/pub/software/scm/git/docs/everyday.html will teach you just enough about git to get by. -* The "PeepCode screencast":https://peepcode.com/products/git on git ($9) is easier to follow. -* "GitHub":http://github.com/guides/home offers links to a variety of git resources. -* "Pro Git":http://progit.org/book/ is an entire book about git with a Creative Commons license. - -h4. Get the Rails Source Code - -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: - -<shell> -git clone git://github.com/rails/rails.git -cd rails -</shell> - -h4. Set up and Run the Tests - -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: - -NOTE: Ensure you install bundler v1.0 - -<shell> -gem install bundler -bundle install --without db -</shell> - -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: - -<shell> -rake test -</shell> - -You can also run tests for an specific framework, like Action Pack, by going into its directory and executing the same command: - -<shell> -cd actionpack -rake test -</shell> - -h4. Testing Active Record - -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: - -<shell> -cd activerecord -rake test_sqlite3 -rake test_sqlite3 TEST=test/cases/validations_test.rb -</shell> - -If you want to use another database, as MySQL, you need to create a user named +rails+ with privileges on the test databases. - -<shell> -mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.* - to 'rails'@'localhost'; -mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.* - to 'rails'@'localhost'; -</shell> - -Now you'll have to install Active Record dependencies. This step is a little tricky because just running +bundle install+ without the +--without db+ parameter won't get those dependencies installed. It turns out that bundler remembers the +--without db+ parameter between calls so you'll have to manually override this. (See the "+bundle_install+ man page":http://gembundler.com/man/bundle-install.1.html for details) - -The easiest way to do this is to remove bundler's config file and then run +install+ again: - -<shell> -rm .bundle/config -bundle install -</shell> - -INFO: If you don't feel comfortable deleting bundler's config file, you can achieve the same effect by manually removing the "+BUNDLE_WITHOUT: db+" line on +.bundle/config+. - -Finally, enter this from the +activerecord+ directory to create the test databases: - -<shell> -rake mysql:build_databases -</shell> - -NOTE: Using the rake task to create the test databases ensures they have the correct character set and collation. - -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. - -You can now run tests as you did for +sqlite3+: - -<shell> -rake test_mysql -</shell> - -You can also replace +mysql+ 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. - -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. - -h4. Older versions of Rails - -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: - -<shell> -git branch --track 2-3-stable origin/2-3-stable -git checkout 2-3-stable -</shell> - -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. - -h3. Helping to Resolve Existing Issues - -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: - -h4. Verifying Bug Reports - -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. - -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. - -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. - -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. - -h4. Testing Patches - -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: - -<shell> -git checkout -b testing_branch -</shell> - -Then you can apply their patch: - -<shell> -git apply their-patch-file.diff -</shell> - -After applying a patch, test it out! Here are some things to think about: - -* Does the patch actually work? -* Are you happy with the tests? Can you follow what they're testing? Are there any tests missing? -* Does the documentation still seem right to you? -* Do you like the implementation? Can you think of a nicer or faster way to implement a part of their change? - -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: - -<blockquote> -I like the way you've restructured that code in generate_finder_sql, much nicer. The tests look good too. -</blockquote> - -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. - -h3. Contributing to the Rails Documentation - -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. - -TIP: "docrails":http://github.com/lifo/docrails/tree/master is the documentation branch for Rails with an *open commit policy*, it has public write access. 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. - -h4. The Rails Guides - -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. - -h4. The Rails API Documentation - -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. - -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. - -h3. The Rails Wiki - -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. - -h3. Contributing to the Rails Code - -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. - -h4. Learn the Language and the Framework - -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. - -h4. Fork the Rails Source Code - -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 - -<shell> -git checkout -b my_new_branch -</shell> - -It doesn’t really matter what name you use, because this branch will only exist on your local computer. - -h4. Write Your Code - -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: - -* Get the code right -* Use Rails idioms and helpers -* Include tests that fail without your code, and pass with it -* Update the documentation - -h4. Follow the Coding Conventions - -Rails follows a simple set of coding style conventions. - -* Two spaces, no tabs -* Prefer +&&+/+||+ over +and+/+or+ -* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+ -* Follow the conventions you see used in the source already - -h4. Sanity Check - -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. - -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. - -h4. Commit Your Changes - -When you're happy with the code on your computer, you need to commit the changes to git: - -<shell> -git commit -a -m "Here is a commit message" -</shell> - -h4. Update Rails - -Update your copy of Rails. It’s pretty likely that other changes to core Rails have happened while you were working. Go get them: - -<shell> -git checkout master -git pull -</shell> - -Now reapply your patch on top of the latest changes: - -<shell> -git checkout my_new_branch -git rebase master -</shell> - -No conflicts? Tests still pass? Change still seems reasonable to you? Then move on. - -h4. Create a Patch - -Now you can create a patch file to share with other developers (and with the Rails core team). Still in your branch, run - -<shell> -git commit -a -git format-patch master --stdout > my_new_patch.diff -</shell> - -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. - -h4. Create a Lighthouse Ticket - -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. - -h4. Get Some Feedback - -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. - -h4. Iterate as Necessary - -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. - -And then...think about your next contribution! - -h3. Changelog - -* April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com -* August 1, 2009: Updates/amplifications by "Mike Gunderloy":credits.html#mgunderloy -* March 2, 2009: Initial draft by "Mike Gunderloy":credits.html#mgunderloy - diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile new file mode 100644 index 0000000000..484c36aeea --- /dev/null +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -0,0 +1,370 @@ +h2. Contributing to Ruby on Rails + +This guide covers ways in which _you_ can become a part of the ongoing development of Ruby on Rails. After reading it, you should be familiar with: + +* Using Lighthouse to report issues +* Cloning master and running the test suite +* Helping to resolve existing issues +* Contributing to the Ruby on Rails documentation +* Contributing to the Ruby on Rails code + +Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation. All with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches. + +endprologue. + +h3. Reporting an Issue + +Ruby on 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 Ruby on 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 patches. + +NOTE: Bugs in the most recent released version of Ruby on 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. + +h4. Creating a Bug Report + +If you've found a problem in Ruby on Rails which is not a security risk do a search in Lighthouse in case it was already reported. If you find no ticket addressing it you can "add a new one":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/new. (See the next section for reporting security issues.) + +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. + +You shouldn't assign the bug to a particular core developer unless you know for sure which developer will be handling that issue. The core team periodically reviews issues and assigns developers and milestones to them. + +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. + +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. + +h4. Special Treatment for Security Issues + +WARNING: Please do not report security vulnerabilities on public Lighthouse tickets. The "Rails security policy page":http://rubyonrails.org/security details the procedure to follow for security issues. + +h4. What About Feature Requests? + +Please don't put "feature request" tickets into Lighthouse. If there's a new feature that you want to see added to Ruby on 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 Ruby on 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. + +h3. Running the Test Suite + +To move on from submitting bugs to helping resolve existing issues or contributing your own code to Ruby on Rails, you _must_ be able to run its test suite. In this section of the guide you'll learn how to set up the tests on your own computer. + +h4. Install git + +Ruby on Rails uses git for source code control. The "git homepage":http://git-scm.com/ has installation instructions. There are a variety of resources on the net that will help you get familiar with git: + +* "Everyday Git":http://www.kernel.org/pub/software/scm/git/docs/everyday.html will teach you just enough about git to get by. +* The "PeepCode screencast":https://peepcode.com/products/git on git ($9) is easier to follow. +* "GitHub":http://github.com/guides/home offers links to a variety of git resources. +* "Pro Git":http://progit.org/book/ is an entire book about git with a Creative Commons license. + +h4. Clone the Ruby on Rails Repository + +Navigate to the folder where you want the Ruby on Rails source code (it will create its own +rails+ subdirectory) and run: + +<shell> +git clone git://github.com/rails/rails.git +cd rails +</shell> + +h4. Set up and Run the Tests + +The test suite must pass with any submitted code. No matter whether you are writing a new patch, or evaluating someone else's, you need to be able to run the tests. + +Install first libxml2 and libxslt together with their development files for Nokogiri. In Ubuntu that's + +<shell> +sudo aptitude install libxml2 libxml2-dev libxslt1-dev +</shell> + +Also, SQLite3 and its development files for the +sqlite3-ruby+ gem, in Ubuntu you're done with + +<shell> +sudo aptitude install sqlite3 libsqlite3-dev +</shell> + +Get a recent version of "Bundler":http://gembundler.com/: + +<shell> +gem install bundler +</shell> + +and run: + +<shell> +bundle install --without db +</shell> + +This command will install all dependencies except the MySQL and PostgreSQL Ruby drivers. We will come back at these soon. With dependencies installed, you can run the test suite with: + +<shell> +rake test +</shell> + +You can also run tests for an specific framework, like Action Pack, by going into its directory and executing the same command: + +<shell> +cd actionpack +rake test +</shell> + +h4. Warnings + +The test suite runs with warnings enabled. Ideally Ruby on Rails should issue no warning, but there may be a few, and also some from third-party libraries. Please ignore (or fix!) them if any, and submit patches that do not issue new warnings. + +As of this writing they are specially noisy with Ruby 1.9. If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag: + +<shell> +RUBYOPT=-W0 rake test +</shell> + +h4. Testing Active Record + +The test suite of Active Record attempts to run four times, once for SQLite3, once for each of the two MySQL gems (+mysql+ and +mysql2+), and once for PostgreSQL. We are going to see now how to setup the environment for them. + +WARNING: If you're working with Active Record code, you _must_ ensure that the tests pass for at least MySQL, PostgreSQL, and SQLite3. Subtle differences between the various adapters have been behind the rejection of many patches that looked OK when tested only against MySQL. + +h5. SQLite3 + +The gem +sqlite3-ruby+ does not belong to the "db" group indeed, if you followed the instructions above you're ready. This is how you run the Active Record test suite only for SQLite3: + +<shell> +cd activerecord +rake test_sqlite3 +</shell> + +h5. MySQL and PostgreSQL + +To be able to run the suite for MySQL and PostgreSQL we need their gems. Install first the servers, their client libraries, and their development files. In Ubuntu just run + +<shell> +sudo aptitude install mysql-server libmysqlclient15-dev +sudo aptitude install postgresql postgresql-client postgresql-contrib libpq-dev +</shell> + +After that run: + +<shell> +rm .bundle/config +bundle install +</shell> + +We need first to delete +.bundle/config+ because Bundler remembers in that file that we didn't want to install the "db" group (alternatively you can edit the file). + +In order to be able to run the test suite against MySQL you need to create a user named +rails+ with privileges on the test databases: + +<shell> +mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.* + to 'rails'@'localhost'; +mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.* + to 'rails'@'localhost'; +</shell> + +and create the test databases: + +<shell> +cd activerecord +rake mysql:build_databases +</shell> + +PostgreSQL's authentication works differently. A simple way to setup the development environment for example is to run with your development account + +<shell> +sudo -u postgres createuser --superuser $USER +</shell> + +and after that create the test databases with + +<shell> +cd activerecord +rake postgresql:build_databases +</shell> + +NOTE: Using the rake task to create the test databases ensures they have the correct character set and collation. + +If you’re using another database, check the files under +activerecord/test/connections+ 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. + +You can now run tests as you did for +sqlite3+, the tasks are + +<shell> +test_mysql +test_mysql2 +test_postgresql +</shell> + +respectively. As we mentioned before + +<shell> +rake test +</shell> + +will now run the four of them in turn. + +You can also invoke +test_jdbcmysql+, +test_jdbcsqlite3+ or +test_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 continuous integration server runs. + +h4. Older versions of Ruby on Rails + +If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 2-3-stable branch: + +<shell> +git branch --track 2-3-stable origin/2-3-stable +git checkout 2-3-stable +</shell> + +TIP: You may want to "put your git branch name in your shell prompt":http://qugstart.com/blog/git-and-svn/add-colored-git-branch-name-to-your-shell-prompt/ to make it easier to remember which version of the code you're working with. + +h3. Helping to Resolve Existing Issues + +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 lots of issues already requiring attention. What can you do for these? Quite a bit, actually: + +h4. Verifying Bug Reports + +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. + +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. + +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 source code: looking at the existing test files will teach you how to write more tests. New tests are best contributed in the form of a patch, as explained later on in the "Contributing to the Rails Code" section. + +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. + +h4. Testing Patches + +You can also help out by examining patches that have been submitted to Ruby on Rails via Lighthouse. To apply someone's changes you need to first create a dedicated branch: + +<shell> +git checkout -b testing_branch +</shell> + +Then you can apply their patch: + +<shell> +git apply their-patch-file.diff +</shell> + +After applying a patch, test it out! Here are some things to think about: + +* Does the patch actually work? +* Are you happy with the tests? Can you follow what they're testing? Are there any tests missing? +* Does it have proper documentation coverage? Should documentation elsewhere be updated? +* Do you like the implementation? Can you think of a nicer or faster way to implement a part of their change? + +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: + +<blockquote> +I like the way you've restructured that code in generate_finder_sql, much nicer. The tests look good too. +</blockquote> + +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. + +h3. Contributing to the Rails Documentation + +Ruby on Rails has two main sets of documentation: The guides help you to learn Ruby on Rails, and the API is a reference. + +You can create a ticket in Lighthouse to fix or expand documentation. However, if you're confident about your changes you can push them yourself directly via "docrails":http://github.com/lifo/docrails/tree/master. docrails is a branch with an *open commit policy* and public write access. Commits to docrails are still reviewed, but that happens after they are pushed. docrails is merged with master regularly, so you are effectively editing the Ruby on Rails documentation. + +When working with documentation, please take into account the "API Documentation Guidelines":api_documentation_guidelines.html and the "Ruby on Rails Guides Guidelines":ruby_on_rails_guides_guidelines.html. + +NOTE: As explained above, ordinary code patches should have proper documentation coverage. docrails is only used for isolated documentation improvements. + +WARNING: docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails. + +If you have an idea for a new guide you can refer to the "contribution page":contribute.html for instructions on getting involved. + +h3. Contributing to the Rails Code + +h4. Clone the Rails Repository + +The first thing you need to do to be able to contribute code is to clone the repository: + +<shell> +git clone git://github.com/rails/rails.git +</shell> + +and create a dedicated branch: + +<shell> +cd rails +git checkout -b my_new_branch +</shell> + +It doesn’t really matter what name you use, because this branch will only exist on your local computer. + +h4. Write Your Code + +Now get busy and add or edit 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: + +* Get the code right +* Use Rails idioms and helpers +* Include tests that fail without your code, and pass with it +* Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution + +h4. Follow the Coding Conventions + +Rails follows a simple set of coding style conventions. + +* Two spaces, no tabs +* Prefer +&&+/+||+ over +and+/+or+ +* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+ +* Follow the conventions you see used in the source already + +h4. Sanity Check + +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. + +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. + +h4. Commit Your Changes + +When you're happy with the code on your computer, you need to commit the changes to git: + +<shell> +git commit -a -m "Here is a commit message" +</shell> + +h4. Update master + +It’s pretty likely that other changes to master have happened while you were working. Go get them: + +<shell> +git checkout master +git pull +</shell> + +Now reapply your patch on top of the latest changes: + +<shell> +git checkout my_new_branch +git rebase master +</shell> + +No conflicts? Tests still pass? Change still seems reasonable to you? Then move on. + +h4. Create a Patch + +Now you can create a patch file to share with other developers (and with the core team). Still in your branch, run + +<shell> +git commit -a +git format-patch master --stdout > my_new_patch.diff +</shell> + +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. + +h4. Create a Lighthouse Ticket + +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. + +h4. Get Some Feedback + +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. + +h4. Iterate as Necessary + +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. + +And then...think about your next contribution! + +h3. Rails Contributors + +All contributions, either via master or docrails, get credit in "Rails Contributors":http://contributors.rubyonrails.org. + +h3. Changelog + +* December 28, 2010: Complete revision by "Xavier Noria":credits.html#fxn +* April 6, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com +* August 1, 2009: Updates/amplifications by "Mike Gunderloy":credits.html#mgunderloy +* March 2, 2009: Initial draft by "Mike Gunderloy":credits.html#mgunderloy + diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb index 825e042628..8c2f1ffeb6 100644 --- a/railties/guides/source/credits.html.erb +++ b/railties/guides/source/credits.html.erb @@ -20,7 +20,7 @@ Ruby on Rails Guides: Credits <% end %> <%= author('Xavier Noria', 'fxn', 'fxn.png') do %> - Xavier has been into Rails since 2005, he is currently a Rails consultant. Xavier is Rails committer and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as "fxn". + Xavier Noria has been into Ruby on Rails since 2005. He is a Rails committer and enjoys combining his passion for Rails and his past life as a proofreader of math textbooks. Xavier is currently a Ruby on Rails consultant. Oh, he also <a href="http://twitter.com/fxn">tweets</a> and can be found everywhere as "fxn". <% end %> <h3 class="section">Rails Guides Designers</h3> @@ -52,7 +52,7 @@ Ruby on Rails Guides: Credits <% end %> <%= author('James Miller', 'bensie') do %> - James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. Find me on GitHub, Gmail, Twitter, and Freenode as "bensie". + James Miller is a software developer for <a href="http://www.jk-tech.com">JK Tech</a> in San Diego, CA. You can find James on GitHub, Gmail, Twitter, and Freenode as "bensie". <% end %> <%= author('Emilio Tagua', 'miloops') do %> diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index 771cfbb794..933bf66b3f 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -151,10 +151,10 @@ Ruby on Rails Guides <% end %> </dl> -<h3>Contributing to Rails</h3> +<h3>Contributing to Ruby on Rails</h3> <dl> - <%= guide("Contributing to Rails", 'contributing_to_rails.html') do %> + <%= guide("Contributing to Ruby on Rails", 'contributing_to_ruby_on_rails.html') do %> <p>Rails is not "somebody else's framework." This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p> <% end %> diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb index dbb48124d0..91dab18b21 100644 --- a/railties/guides/source/layout.html.erb +++ b/railties/guides/source/layout.html.erb @@ -75,8 +75,8 @@ <dd><a href="rails_on_rack.html">Rails on Rack</a></dd> <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd> - <dt>Contributing to Rails</dt> - <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd> + <dt>Contributing to Ruby on Rails</dt> + <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd> <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd> <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd> diff --git a/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery_ujs.js b/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery_ujs.js index 43456a77f6..668cffa73a 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery_ujs.js +++ b/railties/lib/rails/generators/rails/app/templates/public/javascripts/jquery_ujs.js @@ -1,3 +1,12 @@ +/* + * jquery-ujs + * + * http://github.com/rails/jquery-ujs/blob/master/src/rails.js + * + * This rails.js file supports jQuery 1.4.3 and 1.4.4 . + * + */ + jQuery(function ($) { var csrf_token = $('meta[name=csrf-token]').attr('content'), csrf_param = $('meta[name=csrf-param]').attr('content'); @@ -7,9 +16,6 @@ jQuery(function ($) { * Triggers a custom event on an element and returns the event result * this is used to get around not being able to ensure callbacks are placed * at the end of the chain. - * - * TODO: deprecate with jQuery 1.4.2 release, in favor of subscribing to our - * own events and placing ourselves at the end of the chain. */ triggerAndReturn: function (name, data) { var event = new $.Event(name); @@ -19,26 +25,33 @@ jQuery(function ($) { }, /** - * Handles execution of remote calls firing overridable events along the way + * Handles execution of remote calls. Provides following callbacks: + * + * - ajax:beforeSend - is executed before firing ajax call + * - ajax:success - is executed when status is success + * - ajax:complete - is executed when the request finishes, whether in failure or success + * - ajax:error - is execute in case of error */ callRemote: function () { var el = this, method = el.attr('method') || el.attr('data-method') || 'GET', url = el.attr('action') || el.attr('href'), - dataType = el.attr('data-type') || 'script'; + dataType = el.attr('data-type') || ($.ajaxSettings && $.ajaxSettings.dataType); if (url === undefined) { - throw "No URL specified for remote call (action or href must be present)."; + throw "No URL specified for remote call (action or href must be present)."; } else { - if (el.triggerAndReturn('ajax:before')) { - var data = el.is('form') ? el.serializeArray() : []; + var $this = $(this), data = el.is('form') ? el.serializeArray() : []; + $.ajax({ url: url, data: data, dataType: dataType, type: method.toUpperCase(), beforeSend: function (xhr) { - el.trigger('ajax:loading', xhr); + if ($this.triggerHandler('ajax:beforeSend') === false) { + return false; + } }, success: function (data, status, xhr) { el.trigger('ajax:success', [data, status, xhr]); @@ -47,20 +60,17 @@ jQuery(function ($) { el.trigger('ajax:complete', xhr); }, error: function (xhr, status, error) { - el.trigger('ajax:failure', [xhr, status, error]); + el.trigger('ajax:error', [xhr, status, error]); } }); - } - - el.trigger('ajax:after'); } } }); /** - * confirmation handler + * confirmation handler */ - $('a[data-confirm],input[data-confirm]').live('click', function () { + $('body').delegate('a[data-confirm], button[data-confirm], input[data-confirm]', 'click.rails', function () { var el = $(this); if (el.triggerAndReturn('confirm')) { if (!confirm(el.attr('data-confirm'))) { @@ -70,28 +80,34 @@ jQuery(function ($) { }); + /** * remote handlers */ - $('form[data-remote]').live('submit', function (e) { + $('form[data-remote]').live('submit.rails', function (e) { $(this).callRemote(); e.preventDefault(); }); - $('a[data-remote],input[data-remote]').live('click', function (e) { + $('a[data-remote],input[data-remote]').live('click.rails', function (e) { $(this).callRemote(); e.preventDefault(); }); - $('a[data-method]:not([data-remote])').live('click', function (e){ + /** + * <%= link_to "Delete", user_path(@user), :method => :delete, :confirm => "Are you sure?" %> + * + * <a href="/users/5" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete</a> + */ + $('a[data-method]:not([data-remote])').live('click.rails', function (e){ var link = $(this), href = link.attr('href'), method = link.attr('data-method'), form = $('<form method="post" action="'+href+'"></form>'), metadata_input = '<input name="_method" value="'+method+'" type="hidden" />'; - if (csrf_param != null && csrf_token != null) { - metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />'; + if (csrf_param !== undefined && csrf_token !== undefined) { + metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />'; } form.hide() @@ -105,9 +121,9 @@ jQuery(function ($) { /** * disable-with handlers */ - var disable_with_input_selector = 'input[data-disable-with]'; - var disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')'; - var disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')'; + var disable_with_input_selector = 'input[data-disable-with]', + disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')', + disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')'; var disable_with_input_function = function () { $(this).find(disable_with_input_selector).each(function () { @@ -118,10 +134,10 @@ jQuery(function ($) { }); }; - $(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function); - $(disable_with_form_not_remote_selector).live('submit', disable_with_input_function); + $(disable_with_form_remote_selector).live('ajax:before.rails', disable_with_input_function); + $(disable_with_form_not_remote_selector).live('submit.rails', disable_with_input_function); - $(disable_with_form_remote_selector).live('ajax:complete', function () { + $(disable_with_form_remote_selector).live('ajax:complete.rails', function () { $(this).find(disable_with_input_selector).each(function () { var input = $(this); input.removeAttr('disabled') @@ -129,4 +145,10 @@ jQuery(function ($) { }); }); + var jqueryVersion = $().jquery; + + if (!( (jqueryVersion === '1.4.3') || (jqueryVersion === '1.4.4'))){ + alert('This rails.js does not support the jQuery version you are using. Please read documentation.'); + } + }); diff --git a/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js b/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js index fc69f93c58..4c18cb0c3e 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js +++ b/railties/lib/rails/generators/rails/app/templates/public/javascripts/prototype_ujs.js @@ -95,9 +95,10 @@ parameters: params, evalScripts: true, - onComplete: function(request) { element.fire("ajax:complete", request); }, - onSuccess: function(request) { element.fire("ajax:success", request); }, - onFailure: function(request) { element.fire("ajax:failure", request); } + onCreate: function(response) { element.fire("ajax:create", response); }, + onComplete: function(response) { element.fire("ajax:complete", response); }, + onSuccess: function(response) { element.fire("ajax:success", response); }, + onFailure: function(response) { element.fire("ajax:failure", response); } }); element.fire("ajax:after"); @@ -114,7 +115,7 @@ csrf_token = $$('meta[name=csrf-token]')[0]; var form = new Element('form', { method: "POST", action: url, style: "display: none;" }); - element.parentNode.insert(form); + $(element.parentNode).insert(form); if (method !== 'post') { insertHiddenField(form, '_method', method); @@ -127,52 +128,65 @@ form.submit(); } + function disableFormElements(form) { + form.select('input[type=submit][data-disable-with]').each(function(input) { + input.store('rails:original-value', input.getValue()); + input.setValue(input.readAttribute('data-disable-with')).disable(); + }); + } + + function enableFormElements(form) { + form.select('input[type=submit][data-disable-with]').each(function(input) { + input.setValue(input.retrieve('rails:original-value')).enable(); + }); + } - document.on("click", "*[data-confirm]", function(event, element) { + function allowAction(element) { var message = element.readAttribute('data-confirm'); - if (!confirm(message)) event.stop(); - }); + return !message || confirm(message); + } - document.on("click", "a[data-remote]", function(event, element) { - if (event.stopped) return; - handleRemote(element); - event.stop(); - }); + document.on('click', 'a[data-confirm], a[data-remote], a[data-method]', function(event, link) { + if (!allowAction(link)) { + event.stop(); + return false; + } - document.on("click", "a[data-method]", function(event, element) { - if (event.stopped) return; - handleMethod(element); - event.stop(); + if (link.readAttribute('data-remote')) { + handleRemote(link); + event.stop(); + } else if (link.readAttribute('data-method')) { + handleMethod(link); + event.stop(); + } }); - document.on("click", "form input[type=submit]", function(event, button) { + document.on("click", "form input[type=submit], form button[type=submit], form button:not([type])", function(event, button) { // register the pressed submit button event.findElement('form').store('rails:submit-button', button.name || false); }); document.on("submit", function(event) { - var form = event.findElement(), - message = form.readAttribute('data-confirm'); + var form = event.findElement(); - if (message && !confirm(message)) { + if (!allowAction(form)) { event.stop(); return false; } - form.select('input[type=submit][data-disable-with]').each(function(input) { - input.store('rails:original-value', input.getValue()); - input.disable().setValue(input.readAttribute('data-disable-with')); - }); - if (form.readAttribute('data-remote')) { handleRemote(form); event.stop(); + } else { + disableFormElements(form); } }); - document.on("ajax:after", "form", function(event, form) { - form.select('input[type=submit][data-disable-with]').each(function(input) { - input.setValue(input.retrieve('rails:original-value')).enable(); - }); + document.on('ajax:create', 'form', function(event, form) { + if (form == event.findElement()) disableFormElements(form); + }); + + document.on('ajax:complete', 'form', function(event, form) { + if (form == event.findElement()) enableFormElements(form); }); })(); |