Submitting a patch to the Open Source project: composite_primary_keys

Posted by Dmytro Shteflyuk on under Ruby & Rails (33,457 views)

composite_primary_keys

Not so far ago I have found a weird bug in the Open Source Ruby gem called composite_primary_keys, occurred when you specify :primary_key option for has_one or has_many association. There are two ways to get it fixed: submit an issue and wait till someone will work out this problem or fix it by yourself and then pull request to get the patch merged into the core. This is a great library and I use it in almost all my project, so I decided to help the author and fix this bug by myself. Here I will show you how to do that.

Read the rest of entry »

My top 7 RSpec best practices

Posted by Dmytro Shteflyuk on under Ruby & Rails (181,767 views)

BDD kinkier than TDD

I use RSpec in all my projects. It’s really hard to overemphasize how helpful it is and how much easier becomes your life if you have good specs coverage. But its outstanding flexibility enables many ways to make your specs awful: horribly slow, over-bloated, even non-readable sometimes. I do not want to teach you BDD and RSpec here, but instead I will give you some ideas how to improve your specs quality and increase efficiency of your BDD workflow.

Read the rest of entry »

In reply to latest articles in Thoughtbot blog

Posted by Dmytro Shteflyuk on under Ссылки (24,021 views)

Last few weeks Thoughtbot publish lots of really stupid (gsub syntax manual; are you serious?) articles (WTF is Best practice: index every boolean column) in their blog. And yesterdays article about tailing your Rails log is the absolute leader, it’s freaking awesome. Hey guys, I’m waiting for other articles in this series: “@ in attribute names, what does it mean?”, “if-then-else statement usage best practices for Ruby on Rails senior developers”, “how to install a gem”.

Hey robots, we have a reply to your outstanding articles: A wonderful way to list your project files. Please read it carefully, you definitely will find something useful for you! Thanks to @labria for his great exploration.

Memo #5: Use ary.uniq method carefully in Ruby

Posted by Dmytro Shteflyuk on under Ruby & Rails (23,896 views)

Today my friend asked me to help him with an unexpected behavior of Ruby’s Hash.uniq method. Here is an example:

1
2
3
4
5
6
[{"id"=>667824693}, {"id"=>667824693}].uniq
# => [{"id"=>667824693}, {"id"=>667824693}]
[{"id"=>66782469}, {"id"=>66782469}].uniq
# => [{"id"=>66782469}]
[{"id"=>6678246931}, {"id"=>6678246931}].uniq
# => [{"id"=>6678246931}]

Read the rest of entry »