#113
Jun 09, 2008

Contributing to Rails with Git

If you want Rails to behave a certain way, try changing it and submitting a patch. This episode will show how to do exactly this using Git.
Download (45.5 MB, 11:36)
alternative download for iPod & Apple TV (21.5 MB, 11:36)

Resources

# run tests
rake test
cd activerecord
rake test_mysql
rake test_mysql TEST='test/cases/named_scope_test.rb

# make changes on branch
git checkout -b named_scope_with_bang
git commit -a -m "named_scope with bang"

# pull recent changes and apply to branch
git checkout master
git pull
git checkout named_scope_with_bang
git rebase master

# make patch
git format-patch master --stdout > ~/named_scope_with_bang.diff

# apply patch
curl ... | git am
create database activerecord_unittest;
create database activerecord_unittest2;
grant all on activerecord_unittest.* TO rails@localhost;
grant all on activerecord_unittest2.* TO rails@localhost;

RSS Feed for Episode Comments 25 comments

1. Russ Jones Jun 09, 2008 at 01:57

Awesome topic, thanks Ryan :)


2. Senthil Nayagam Jun 09, 2008 at 18:36

Now people wont one less excuse for not contributing back to rails :)


3. Tom Harrison Jun 10, 2008 at 12:05

Very cool, Ryan. You sure covered a lot of territory here ... kind of like one of those cooking shows where all the vegetables and ingredients are prepared in advance, and the food has already baked in advance :-)

So this gets to the core of the main steps of making a contribution. For the more timid amongst us, do you have any pointers on some of the "pre-show" work that should go into making a patch?

For example, you mentioned in passing that it was a good idea to make sure the functionality wasn't already implemented. Now being about 9 months into RoR I am still learning a lot of things I just didn't know existed. Any tips on knowing what a good candidate is for a patch?

Thanks for all you do.

Tom


4. Mike Jun 12, 2008 at 06:39

Nice walk through on contributing. With the patch you wrote couldn't you have re-written your method as:

def find_products
 returning Product.scoped({}) do |conditions|
  conditions! ...
  conditions! ...
  conditions! ...
  conditions! ...
 end
end


5. Ryan Bates Jun 14, 2008 at 14:01

@Tom, excellent questions. As mentioned at the end of the episode, I think subscribing to the Rails Core google group is the best way to get started. Keep up with the tickets coming in, try them out, and give feedback. Sometimes there will be tickets which don't have a patch, or just include a failing test. These you can try contributing a patch to.

As for coming up with patches from scratch, that's kind of hard to do on the spot. The best thing to do is to work on a Rails application and look for possible patches that will aid your app. This will lead to patches which have a real world use case and will more likely be useful to others.

As for your second question, I've ran into that a number of times, where I thought of making a patch for something and, after a little digging, realized it was already implemented in Rails.

Usually you can tell if it's already implemented by reading the Rails source code. If you don't see it, go ahead and submit a patch and others will point you to the existing functionality if it's already implemented. If it's a larger patch, it's probably best to ask in the google group before attempting to implement it, to see if others would find it useful and if they have any ideas on the implementation.

@Mike, you would still need to call "conditions!" on a scope object. In your code it's just being called on "self" which is the search model.


6. Rick DeNatale Jun 23, 2008 at 10:03

Ryan,

I always add a step right after the git pull followed by rebasing my branch, and that is to rerun the tests to make sure that they still work should any changes pulled down affect them.


7. Tim Haines Jul 01, 2008 at 15:04

Hey Ryan,

thanks for this screencast. I installed git and followed your screencast to submitted a patch - only to find later that my changes to files were in the patch, but the new file I had created wasn't included. I spent a bit of time this morning trying to figure out how to get that file included in the patch, but haven't had much luck yet. Is there a good resource for learning this stuff somewhere? A walk through for first timers?

cheers, Loving your work as always.

Tim.


8. jamir Jul 06, 2008 at 03:15

Thanks a lot for the patch!


9. Cassiano Sep 21, 2008 at 20:41

@Ryan,

You seem to have mispelled 'activerecord_unittest2' in the code that appears at the top of this page (just below 'Resources'), so:

create database activerecord_unittes2;

should actually read:

create database activerecord_unittest2;

Also, I believe you missed the -b flag in:

git checkout named_scope_with_bang

so it should read:

git checkout -b named_scope_with_bang


10. Ryan Bates Sep 27, 2008 at 13:30

@Cassiano, Thanks for pointing these problems out! Fixed.


11. Mike Perz Jul 26, 2009 at 17:43

Ryan, Thank you. I didn't have the mocha gem installed. Got a lot of "NoMethodError: undefined method `expects'/`stubs' for ...". But once I installed it, all the tests passed. - Mike


12. shoesghost.com Nov 11, 2009 at 04:16

welcome to
www.shoesghost.com
cheap boots and shoes


13. Viktora Dec 08, 2009 at 03:02

Как-то нелогично названы функции в коде


14. estetik Dec 15, 2009 at 23:54

Nice post good article to read.


15. Evdokiyushka Dec 26, 2009 at 14:39

As for your second question, I've ran into that a number of times, where I thought of making a patch for something and, after a little digging, realized it was already implemented in Rails.
[url=http://sevenportal.ru/]Evdokiyushka[/url]


16. kablo Jan 07, 2010 at 01:50

kablo üretiminde lider kuruluş


17. wholesale nike shoes Jan 13, 2010 at 23:28

A very good article, I will always come in.


18. fashion scarves Jan 13, 2010 at 23:28

Such a good article, caught my sympathy!
-


19. kurye Jan 18, 2010 at 06:25

Ryan, Thank you. I didn't have the mocha gem installed. Got a lot of "NoMethodError: undefined method `expects'/`stubs' for ...". But once I installed it, all the tests passed. - Mike
 my web page <a href="http://www.jwebtasarim.com" >web tasarım</a>


20. Svetuha Jan 19, 2010 at 23:59

The best thing to do is to work on a Rails application and look for possible patches that will aid your app.


21. hemoroid Jan 22, 2010 at 16:32

thank you very much


22. Web Tasarım Jan 26, 2010 at 00:45

A very good article, I will always come in.


23. Ksenyusha Jan 28, 2010 at 12:31

For example, you mentioned in passing that it was a good idea to make sure the functionality wasn't already implemented. Now being about 9 months into RoR I am still learning a lot of things I just didn't know existed.


24. Danusya Jan 30, 2010 at 23:43

Now being about 9 months into RoR I am still learning a lot of things I just didn't know existed.


25. cheap adidas shoes Jan 31, 2010 at 19:18

Adidas Shoes Online Shop-Hot Selling Adidas Shoes & Cheap Adidas Shoes

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player
Give Back to Open Source