Last weekend I took part in Rails BugMash – a ‘bug squashing’ event organized by RailsBridge.
From the beginning I found some ActiveRecord issues that seemed very interesting. What I learned is that digging through ActiveRecord is a lot easier in concept than through source code. Therefore, I managed to produce only a partial patch. The bright side is that it was a lot easier with tests, so I was more productive on this side.
Even if it didn’t add many points on my scorecard, the “ActiveRecord adventure” was indeed very interesting. Here are some useful tips for ActiveRecord testing:
recreate the tables after changing the schema: you have to do it yourself if running a single ActiveRecord test
# update the schema rake test_mysql TEST=test/cases/aaa_create_tables_test.rb # run a specific test rake test_mysql TEST=test/cases/associations/has_many_through_associations_test.rb # this will create the tables rake test_mysql
looking for the SQL generated during a test?
verify if an associated object is loaded? The way to do it depends on the realation type:
# Cat has_many Toys. Are they loaded? cat.toys.loaded? # false cat.toys cat.toys.loaded? # true # Cat belongs_to Human. Is it loaded? cat.instance_variable_get('@human').present? # false cat.human cat.instance_variable_get('@human').present? # true
adding an ActiveRecord test? it’s preferred to reuse the existing models rather than create new ones. Even if some models look a bit abused after so much use :), I guess it’s better than having a couple of new models for every patch
I was impressed by the energy and collaboration in the (virtual) room: issue creation, verification, testing & patching seemed to flow from person to person. This meant that I got feedback fast on my contributions, which was great.
Big Kudos to RailsBridge for organizing the event and easing the ‘contributing to Rails learning curve’. It allowed me to use my Ruby & Rails skills to the max, even if it was the first time I contributed.