Here's a list of handy shortcuts for BugMashers.
Required software
If you're having trouble getting the Rails source code set up on your computer, use our Pre-flight Checklist as a guide, or drop by #railsbridge on Freenode IRC to ask for help.
Generating a Rails app on master branch
You can generate a quick sample application from the Rails source code tree by
cd railties rake dev
This will create a new application named rails at the root of your Rails repository. (NOTE: As of Sept 26, rake dev appears to be busted. https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3261-rake-dev-not-working-on-master has a fix.)
Testing Active Record
If you wish to test patches on Active Record, you'll have to generate test databases for MySQL. Otherwise, most of the Active Record tests won't pass. You should run these tasks in the activerecord directory.
rake mysql:build_databases
There is also a PostgreSQL task for doing the same job given you have PostgreSQL installed on your system.
rake postgresql:build_databases
When you're done testing patches, you can delete the generated databases.
rake mysql:drop_databases rake postgresql:drop_databases
There are also useful tasks for deleting and regenerating databases if you need to refresh.
rake mysql:rebuild_databases rake postgresql:rebuild_databases
If you're writing new tests for ActiveRecord, please try to reuse the existing test models instead of adding new ones.
Testing specified frameworks only
Running the whole test suite takes a lot of time? You can run tests in the individual Rails frameworks also. Just cd into the library you wish to test and rake test.
cd activesupport rake test
Testing Active Record
Running rake test for Active Record will run tests for MySQL, SQLite3 and PostgreSQL. To run test individually based on different adapters:
rake test_mysql rake test_postgresql rake test_sqlite3
You should test all three of these widely-used database adapters if you're contributing to Active Record. See rake -T for all the adapters Rails supports, as this is only a fraction of them.
Testing Individual Files
Better yet, you can test a separate file for a speed boost.
rake test TEST=test/ordered_options_test.rb
If testing ActiveRecord and you've changed the schema, you have to initialize the database before running the test:
rake test_mysql TEST=test/cases/aaa_create_tables_test.rb # update the schema rake test_mysql TEST=test/cases/associations/has_many_through_associations_test.rb
Working with Rails and git
Getting the Rails source:
git clone git://github.com/rails/rails.git cd rails git checkout -b 2-3-stable origin/2-3-stable # this will leave you on the 2-3-stable branch (you can also do: git checkout -t origin/2-3-stable # this will also leave you on the 2-3-stable branch)Working on the master (3.0) branch:
git checkout masterWorking on the 2-3-stable branch:
git checkout 2-3-stableCreating your own feature branch:
git checkout -b my_feature_branchApply a patch:
git apply <patch file>Creating a patch:
git checkout master git checkout -b my_feature_branch (write and test code) git commit -a -m "This is my great patch" git checkout master git pull git checkout my_feature_branch git rebase master rake (to be sure tests still patch) git format-patch master --stdout > my_great_patch.diffPatching both master and 2-3-stable:
First, follow above to create a patch for master. If the same patch applies cleanly to 2-3-stable, just say so in the Lighthouse ticket and the committer will apply it to both. Otherwise, you'll need to generate a separate patch for 2-3-stable (assuming that this issue should be patched on both branches). The first thing to try is just cherry-picking your patch over to 2-3-stable:
git checkout -b my-feature-2-3 2-3-stable git cherry-pick <revision of change made to master> rake test git format-patch 2-3-stable --stdout > my_great_patch_for_rails23.diff
As a last resort, you can write a completely separate patch for 2.3:
git checkout 2-3-stable git checkout -b my_feature_branch (write and test code) git commit -a -m "This is my great patch" git checkout 2-3-stable git pull git checkout my_feature_branch git rebase 2-3-stable rake (to be sure tests still patch) git format-patch 2-3-stable --stdout > my_great_patch.diff
NOTE
Please keep in mind the core workflow here for Rails itself:
- All active development happens on master
- Changes targeting the stable release are made to master and flow back to 2.3
- Development on 2.3 with forward port to master causes log jams and is strongly discouraged
Editing someone else's patch:
First, apply the existing patch:
git checkout stable git apply <patch file>
Then if you need to make changes to the patch (perhaps because Rails has moved on), follow this advice from core:
For updating others' patches: preserving authorship is a common courtesy we encourage. The simplest is to assign authorship of the fixed commit to the original author and sign off on it. You can git commit --author "Foo Bar <foobar@example.com>" --signoff
to make a commit this way, or even git commit --amend --author ... --signoff
to change the author and add a signoff to the previous commit.
Another scenario is building on an incomplete patch. Rather than apply the patch and commit it as yourself, apply it as the original author. Then do subsequent commits as yourself. This preserves the full history and authorship.