BugMashCheatSheet
Version 9 (Mike Gunderloy, 01/10/2010 07:14 pm)
| 1 | 1 | h1. BugMash Cheat Sheet |
|
|---|---|---|---|
| 2 | 1 | ||
| 3 | 1 | Here's a list of handy shortcuts for BugMashers. |
|
| 4 | 1 | ||
| 5 | 1 | h2. Required software |
|
| 6 | 1 | ||
| 7 | 1 | 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. |
|
| 8 | 1 | ||
| 9 | 9 | Mike Gunderloy | h2. Generating a new Rails application |
| 10 | 1 | ||
| 11 | 9 | Mike Gunderloy | You can generate a quick sample application from the Rails 2.3.5 source code tree by |
| 12 | 1 | ||
| 13 | 1 | <pre> |
|
| 14 | 1 | cd railties |
|
| 15 | 1 | rake dev |
|
| 16 | 1 | </pre> |
|
| 17 | 1 | ||
| 18 | 9 | Mike Gunderloy | This will create a new application named rails at the root of your Rails repository. (*NOTE*: This functionality is not available on the master branch.) |
| 19 | 9 | Mike Gunderloy | |
| 20 | 9 | Mike Gunderloy | You can also generate a sample application to use by calling the rails command directly out of your source tree: |
| 21 | 9 | Mike Gunderloy | |
| 22 | 9 | Mike Gunderloy | <pre> |
| 23 | 9 | Mike Gunderloy | cd /parent/of/new/app |
| 24 | 9 | Mike Gunderloy | ruby /path/to/rails/railties/bin/rails appname |
| 25 | 9 | Mike Gunderloy | cd appname/vendor |
| 26 | 9 | Mike Gunderloy | ln -s /path/to/rails/ ./rails |
| 27 | 9 | Mike Gunderloy | </pre> |
| 28 | 9 | Mike Gunderloy | |
| 29 | 9 | Mike Gunderloy | This will build a new application and then symlink your checked-out rails tree into the vendor/rails folder. |
| 30 | 9 | Mike Gunderloy | If you’re working with the master branch (Rails 3.0), you also need to bundle the necessary gems into your new application. Edit the Gemfile at the root of your new application, and add these lines at the top (*without changing what’s already there*): |
| 31 | 9 | Mike Gunderloy | |
| 32 | 9 | Mike Gunderloy | <pre> |
| 33 | 9 | Mike Gunderloy | directory "vendor/rails", :glob => "{*/,}*.gemspec" |
| 34 | 9 | Mike Gunderloy | git "git://github.com/rails/arel.git" |
| 35 | 9 | Mike Gunderloy | git "git://github.com/rails/rack.git" |
| 36 | 9 | Mike Gunderloy | </pre> |
| 37 | 9 | Mike Gunderloy | |
| 38 | 9 | Mike Gunderloy | Save the file and run the bundler in the root of your new application: |
| 39 | 9 | Mike Gunderloy | |
| 40 | 9 | Mike Gunderloy | <pre> |
| 41 | 9 | Mike Gunderloy | gem bundle |
| 42 | 9 | Mike Gunderloy | </pre> |
| 43 | 9 | Mike Gunderloy | |
| 44 | 9 | Mike Gunderloy | Now you should be able to run @script/server@ or @script/console@ and be working with a Rails 3.0 application. |
| 45 | 9 | Mike Gunderloy | |
| 46 | 9 | Mike Gunderloy | h2. Testing Rails |
| 47 | 9 | Mike Gunderloy | |
| 48 | 9 | Mike Gunderloy | Just go to the folder where you’ve cloned Rails and run rake: |
| 49 | 9 | Mike Gunderloy | |
| 50 | 9 | Mike Gunderloy | <pre> |
| 51 | 9 | Mike Gunderloy | cd rails |
| 52 | 9 | Mike Gunderloy | rake |
| 53 | 9 | Mike Gunderloy | </pre> |
| 54 | 9 | Mike Gunderloy | |
| 55 | 9 | Mike Gunderloy | Tests not passing? Don’t panic! If you’re on the cutting-edge master branch, the problem may be the code, not you. Check http://ci.rubyonrails.org to see how the official continuous integration server for Rails is seeing things. |
| 56 | 1 | ||
| 57 | 1 | h2. Testing Active Record |
|
| 58 | 1 | ||
| 59 | 7 | Jonathan Roes | 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. |
| 60 | 1 | ||
| 61 | 1 | <pre> |
|
| 62 | 1 | rake mysql:build_databases |
|
| 63 | 1 | </pre> |
|
| 64 | 1 | ||
| 65 | 1 | There is also a PostgreSQL task for doing the same job given you have PostgreSQL installed on your system. |
|
| 66 | 1 | ||
| 67 | 1 | <pre> |
|
| 68 | 1 | rake postgresql:build_databases |
|
| 69 | 1 | </pre> |
|
| 70 | 1 | ||
| 71 | 1 | When you're done testing patches, you can delete the generated databases. |
|
| 72 | 1 | ||
| 73 | 1 | <pre> |
|
| 74 | 1 | rake mysql:drop_databases |
|
| 75 | 1 | rake postgresql:drop_databases |
|
| 76 | 1 | </pre> |
|
| 77 | 1 | ||
| 78 | 1 | There are also useful tasks for deleting and regenerating databases if you need to refresh. |
|
| 79 | 1 | ||
| 80 | 1 | <pre> |
|
| 81 | 1 | rake mysql:rebuild_databases |
|
| 82 | 1 | rake postgresql:rebuild_databases |
|
| 83 | 1 | </pre> |
|
| 84 | 1 | ||
| 85 | 1 | If you're writing new tests for ActiveRecord, please try to reuse the existing test models instead of adding new ones. |
|
| 86 | 1 | ||
| 87 | 1 | h2. Testing specified frameworks only |
|
| 88 | 1 | ||
| 89 | 1 | 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. |
|
| 90 | 1 | ||
| 91 | 1 | <pre> |
|
| 92 | 1 | cd activesupport |
|
| 93 | 1 | rake test |
|
| 94 | 1 | </pre> |
|
| 95 | 1 | ||
| 96 | 1 | h3. Testing Active Record |
|
| 97 | 1 | ||
| 98 | 1 | Running rake test for Active Record will run tests for MySQL, SQLite3 and PostgreSQL. To run test individually based on different adapters: |
|
| 99 | 1 | ||
| 100 | 1 | <pre> |
|
| 101 | 1 | rake test_mysql |
|
| 102 | 1 | rake test_postgresql |
|
| 103 | 1 | rake test_sqlite3 |
|
| 104 | 1 | </pre> |
|
| 105 | 1 | ||
| 106 | 1 | 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. |
|
| 107 | 1 | ||
| 108 | 1 | h3. Testing Individual Files |
|
| 109 | 1 | ||
| 110 | 1 | Better yet, you can test a separate file for a speed boost. |
|
| 111 | 1 | ||
| 112 | 1 | <pre> |
|
| 113 | 1 | rake test TEST=test/ordered_options_test.rb |
|
| 114 | 1 | </pre> |
|
| 115 | 1 | ||
| 116 | 1 | If testing ActiveRecord and you've changed the schema, you have to initialize the database before running the test: |
|
| 117 | 1 | ||
| 118 | 1 | <pre> |
|
| 119 | 1 | rake test_mysql TEST=test/cases/aaa_create_tables_test.rb # update the schema |
|
| 120 | 1 | rake test_mysql |
|
| 121 | 1 | TEST=test/cases/associations/has_many_through_associations_test.rb |
|
| 122 | 1 | </pre> |
|
| 123 | 1 | ||
| 124 | 1 | h2. Working with Rails and git |
|
| 125 | 1 | ||
| 126 | 1 | Getting the Rails source: |
|
| 127 | 1 | ||
| 128 | 1 | <pre> |
|
| 129 | 1 | git clone git://github.com/rails/rails.git |
|
| 130 | 1 | cd rails |
|
| 131 | 3 | Redmine Admin | git checkout -b 2-3-stable origin/2-3-stable # this will leave you on the 2-3-stable branch |
| 132 | 4 | Mike Breen | (you can also do: git checkout -t origin/2-3-stable # this will also leave you on the 2-3-stable branch) |
| 133 | 1 | </pre> |
|
| 134 | 1 | ||
| 135 | 1 | Working on the master (3.0) branch: |
|
| 136 | 1 | ||
| 137 | 1 | <pre> |
|
| 138 | 1 | git checkout master |
|
| 139 | 1 | </pre> |
|
| 140 | 1 | ||
| 141 | 1 | Working on the 2-3-stable branch: |
|
| 142 | 1 | ||
| 143 | 1 | <pre> |
|
| 144 | 1 | git checkout 2-3-stable |
|
| 145 | 1 | </pre> |
|
| 146 | 1 | ||
| 147 | 1 | Creating your own feature branch: |
|
| 148 | 1 | ||
| 149 | 1 | <pre> |
|
| 150 | 1 | git checkout -b my_feature_branch |
|
| 151 | 1 | </pre> |
|
| 152 | 1 | ||
| 153 | 1 | Apply a patch: |
|
| 154 | 1 | ||
| 155 | 1 | <pre> |
|
| 156 | 1 | git apply <patch file> |
|
| 157 | 1 | </pre> |
|
| 158 | 1 | ||
| 159 | 1 | Creating a patch: |
|
| 160 | 1 | ||
| 161 | 1 | <pre> |
|
| 162 | 1 | git checkout master |
|
| 163 | 1 | git checkout -b my_feature_branch |
|
| 164 | 1 | (write and test code) |
|
| 165 | 1 | git commit -a -m "This is my great patch" |
|
| 166 | 1 | git checkout master |
|
| 167 | 1 | git pull |
|
| 168 | 1 | git checkout my_feature_branch |
|
| 169 | 1 | git rebase master |
|
| 170 | 1 | rake (to be sure tests still patch) |
|
| 171 | 1 | git format-patch master --stdout > my_great_patch.diff |
|
| 172 | 1 | </pre> |
|
| 173 | 1 | ||
| 174 | 1 | Patching both master and 2-3-stable: |
|
| 175 | 1 | ||
| 176 | 3 | Redmine Admin | 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: |
| 177 | 1 | ||
| 178 | 1 | <pre> |
|
| 179 | 3 | Redmine Admin | git checkout -b my-feature-2-3 2-3-stable |
| 180 | 3 | Redmine Admin | git cherry-pick <revision of change made to master> |
| 181 | 3 | Redmine Admin | rake test |
| 182 | 3 | Redmine Admin | git format-patch 2-3-stable --stdout > my_great_patch_for_rails23.diff |
| 183 | 3 | Redmine Admin | </pre> |
| 184 | 3 | Redmine Admin | |
| 185 | 3 | Redmine Admin | As a last resort, you can write a completely separate patch for 2.3: |
| 186 | 3 | Redmine Admin | |
| 187 | 3 | Redmine Admin | <pre> |
| 188 | 1 | git checkout 2-3-stable |
|
| 189 | 1 | git checkout -b my_feature_branch |
|
| 190 | 1 | (write and test code) |
|
| 191 | 1 | git commit -a -m "This is my great patch" |
|
| 192 | 1 | git checkout 2-3-stable |
|
| 193 | 1 | git pull |
|
| 194 | 1 | git checkout my_feature_branch |
|
| 195 | 1 | git rebase 2-3-stable |
|
| 196 | 1 | rake (to be sure tests still patch) |
|
| 197 | 1 | git format-patch 2-3-stable --stdout > my_great_patch.diff |
|
| 198 | 1 | </pre> |
|
| 199 | 1 | ||
| 200 | 3 | Redmine Admin | |
| 201 | 3 | Redmine Admin | *NOTE* |
| 202 | 3 | Redmine Admin | |
| 203 | 3 | Redmine Admin | Please keep in mind the core workflow here for Rails itself: |
| 204 | 3 | Redmine Admin | |
| 205 | 3 | Redmine Admin | * All active development happens on master |
| 206 | 3 | Redmine Admin | * Changes targeting the stable release are made to master and flow *back* to 2.3 |
| 207 | 3 | Redmine Admin | * Development on 2.3 with forward port to master causes log jams and is strongly discouraged |
| 208 | 3 | Redmine Admin | |
| 209 | 1 | Editing someone else's patch: |
|
| 210 | 1 | ||
| 211 | 1 | First, apply the existing patch: |
|
| 212 | 1 | ||
| 213 | 1 | <pre> |
|
| 214 | 1 | git checkout stable |
|
| 215 | 1 | git apply <patch file> |
|
| 216 | 1 | </pre> |
|
| 217 | 1 | ||
| 218 | 3 | Redmine Admin | Then if you need to make changes to the patch (perhaps because Rails has moved on), follow this advice from core: |
| 219 | 3 | Redmine Admin | |
| 220 | 3 | Redmine Admin | 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. |
| 221 | 3 | Redmine Admin | |
| 222 | 3 | Redmine Admin | 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. |
| 223 | 2 | Ryan Bigg | |
| 224 | 2 | Ryan Bigg | h2. Bot commands |
| 225 | 2 | Ryan Bigg | |
| 226 | 2 | Ryan Bigg | *!work <num> or !working <num>* - You start working on a ticket with this ID. Will return an error if ticket does not exist, or is not bugmashable. |
| 227 | 2 | Ryan Bigg | *!stop <num> or !stopworking <num>* - You stop working on a ticket with this ID. Will return an error if you're not working on it, ticket does not exist or is not bugmashable. |
| 228 | 2 | Ryan Bigg | *!gimme* - Tells you about a random ticket from lighthouse that nobody is (yet) working on. To start work on it, use the *!work* command. |
| 229 | 2 | Ryan Bigg | *!review <num>* - Marks the ticket for bugmash-review in Lighthouse. |
| 230 | 2 | Ryan Bigg | *!unreview <num>* - Removes the bugmash-review tag on the ticket in Lighthouse. |
| 231 | 2 | Ryan Bigg | *!me* - Private messages you telling you the number of tickets you're working on and lists them off. |
| 232 | 5 | Mike Gunderloy | |
| 233 | 5 | Mike Gunderloy | h2. Bugmash.com |
| 234 | 5 | Mike Gunderloy | |
| 235 | 5 | Mike Gunderloy | Some information from the [[BugMashFlowChart]] about the special strings in Lighthouse messages that Bugmash.com is looking for: |
| 236 | 5 | Mike Gunderloy | |
| 237 | 5 | Mike Gunderloy | # To up or down vote a ticket use "+1" and "-1". Your comment should also include a brief explanation of your vote. |
| 238 | 5 | Mike Gunderloy | # When verifying a patch or bug use "verified" or "not reproducible". |
| 239 | 5 | Mike Gunderloy | # If you've included a patch make sure your comment includes the phrase "I've attached a patch." |
| 240 | 5 | Mike Gunderloy | # Changeset points will be awarded when the patch is committed to the Rails core. |
| 241 | 5 | Mike Gunderloy | # You can check your score at the "official scoreboard":http://bugmash.com and if we've botched your score please "let us know":http://bugmash.com/issues/new |