Skip Validations
How many times have you felt like skipping validations on a particular model while writing rspec tests ? Last night, I was trying to write rspec tests for one of my models which tested transactions of money between two users. My user model has tens of validations and I totally wanted to skip them all. I just wanted to test the functionality that the money was transacted between the two users correctly. Thats when I used some of Ruby's metaprogramming capabilities to skip validations. Once I was done writing my tests (phew !!) , I decided to turn this into a Rails Plugin, enter SkipValidations ( http://github.com/balpreetspankaj/SkipValidations/tree/master).
This is a very simple plugin. Just install the plugin and then use the skip_validations on any ActiveRecord::Base class and give it the list of models fr which you want no validations. Simple ! for example,
User.skip_validations(:user, :person) {SellRequest.match_requests }
will skip validations for both User and Person model while running the SellRequest.match_requests function. This plugin made my testing a lot more smoother. Hopefully this is useful for you guys too.
