Posts
Forget Me Not! Object Oriented Design in Custom Exception
When designing custom exceptions, you may forget about old school OO fundamentals. As a reminder, lets take a look into the following custom exception classes.
StorySaveError
StoryDescopeNotAllowedError
StoryCompleteError
StoryNotFoundError
StoryDeleteError
StoryDeleteNotAllowedErrorThese exceptions are really useful in my application. But the bad thing is, they all derive from StandardError class, whereas there should be a base class, may be StoryError, which is more meaningful and useful. So, we can have the following-
Posts
Unit Test eager loading in Rails ActiveRecord association
To avoid the n+1 problem, you need to use eager loading in ActiveRecord object associations. An easy implementation of eager loading can be done using named scope in the following way.
class User < ActiveRecord::Base
has_many :friends
named_scope :eager_load_friends, :include => :fiends
end
User.find(user_id).eager_load_friendsTo unit test the named scope, you can use this following helper method (keep it in test_helper.rb, if you like) that I wrote for ScrumPad
def test_eager_loaded(model, association)
Posts
Implementing Template Method in Rails Controllers Using Module and Mixin
All rails controllers are subclasses of the ApplicationController class. A typical controller class declaration will look like the following-
class LoginController < ApplicationController
#the actions go here
endWith this basic information, I would like to state the problem first.
The Problem/Job in Hand
Add an action switch_project to all the controllers (> 20) of the ScrumPad code base. The implementations of the switch_project method will be same for all the controllers only other than the fact that, the switching destination will be different.
Posts
Testing the SyntaxHighlighter Scripts
For the last few months, I am on the lookout for a really good syntax highlighter that helps me to post blogs on all the programming languages in a pretty html with syntax coloring/highlighting. This one is taken from http://alexgorbatchev.com/wiki/SyntaxHighlighter
Ruby/Rails class TestHighlighter
def my_highlighter
return "SyntaxHighlighter"
end
end
CSharp
public class TestHighlighter
{
public string MyHighlighter
{
get {return "SyntaxHighlighter";}
}
}
What did I add to my blog?
Posts
Pair Programming: How am I feeling?
For an explanation of Pair Programming, please visit this wiki entry.
Good
I am pair programming on the ScrumPad project now and the feeling in general is good. I have this perception is the work quality is better than doing alone. Also, the amount of time wasted to find small issues are now much reduced. Overall, its good.
Productivity Increased
I definitely found the productivity boosted by a factor of 1.
Posts
assert_equal_float : assert_equal between two float objects with precision
In doing rails unit testing, sometime you need to assert the equality between two float objects in the following fashion
assert_equal 32.8, object_under_test.method_returning_float
The internal storage of float objects sometimes will contain 32.8 with additional lower precision decimal points and hence the assert may fail although the significant digits may be same. For example, the value of object_under_test.method_returning_float may be stored as 32.80000001 in memory and the above call may fail.
Posts
Looking at ASP.NET MVC
Being over-burdened by all the blog posts on MVC from the ASP.Net for the last few months, I am now looking to ASP.Net MVC. Still seeing the tutorials on asp.net/mvc site.
I have worked on a few rails projects and the ASP.Net MVC implementation is very much like Rails. Anyway, still early for me to comment!
Comments Sohan @Tanvir,Yes, I read the first chapter. My finding is ASP.Net MVC is still far from being real!
Posts
named_scope : Real life examples from ScrumPad
I am working on ScrumPad chat refactoring now. In rails 2, the named_scope feature works really great for ActiveRecord models. Lets start with the code first-
The Source Code:
class ChatUser < ActiveRecord::Base belongs_to :chat belongs_to :user belongs_to :chat_status, :foreign_key => "status_id" named_scope :closed, lambda {|chat_id| {:conditions => ["status_id = #{ChatStatus::CLOSED} AND chat_id = ? ", chat_id]}} do def invite() each { |chat_user| chat_user.update_attribute(:status_id, ChatStatus::INVITED) } end end named_scope :active_chats, lambda {|user_id| {:conditions => ["
Posts
Design/Code Review: Now, It's time to realize!
Are you doing code reviews?
Thank God, you are. Not?
Well, you are not alone. You know, most of your bugs could be killed by reviews. Most of your technical debts could be paid by reviews. Your team could collectively learn more by reviews...
Now, It's time to realize!
Start now! It's simple. I have found the following approach to be useful-
Pair up with one developer. Make it explicit to the team.
Posts
Comet and Server Push (Reverse Ajax) technology
I am re-implementing an ajax based chat system. Presently an ajax request is polled continuously to look for any updates/messages from the user’s browser. However, the plan is to use the server to push the messages to the clients to off-load the server from a huge number of useless ajax calls.
I learned about Comet and found it interesting. You may read about comet here at WIKI.
Juggernaut is a rails plug-in that uses Flash to implement the server push technology.