Version 1/10
-
Next » -
Current version
Mike Gunderloy, 09/25/2009 08:06 pm
BugMash Cheat Sheet¶
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.
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.
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 branch--track 2-3-stable origin/2-3-stableWorking 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):
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.diffEditing someone else's patch:
First, apply the existing patch:
git checkout stable git apply <patch file>
Then ... (we're waiting for advice from core on how they'd like this handled).