Technical
How To Mock Model In Development Mode

I had a case where my screens were taking really long time to load to the collection of data from database, which was expected by business. It was really unbearable for UI development, so I decided to mock out this model for development so I could concentrate on development and not loose time for getting data, since I knew it was correct.

A while ago I shamble upon this post by errtheblog who explained how to use Struct

So here we go:

I have a model called region_agreement which has a method find_report_generation_progress_by_date which I wanted to mock out.

  1. Create in test/mock/development file region_agreement.rb with the same model name and the method to overwright.
  2. Add Struct defenition right on top before defining the class.
    
    RegionAgreementFirst = Struct.new(:region_name,:end_time,:start_time,:num_expected,:num_ready,:region_id)
    class RegionAgreement < ActiveRecord::Base
    ...
    
  3. Now method returns our struct
    
    def self.find_report_generation_progress_by_date(date=nil)
    
    RegionAgreementFirst.new("BLACKROCK",'Wed Jun 27 09:03:28 -0400 2007',
                'Wed Jun 27 08:56:29 -0400 2007',118.0,119.0,1)
    

Also, you may check out How To Get Data From Console And Splat It in To Struct

Enjoy your speedy development