Sunday, January 11, 2009

Test rails with Mocha

Rails is a framework that came up with facilities for testing using fixtures. Testing using  fixture is a nice feature to have for a small project. But as the project grows some problems might be seen. Like,

  1. Difficult to manage fixture
  2. Takes long time to run the test

Difficult to manage fixture:

As it becomes hard to manage fixtures, people tends to add and do not intend to reuse existing, as that might break current test codes.

So the number of the entry in fixtures increase day by day. Eventually it becomes unmanageable.

Takes long time to run the test:

As fixture driven testing takes a lot time to run the test. People don't feel comfortable to run test for a large project. Even running one test file sometime takes 2/3 minutes. We use Continuous Integration(CI) to run test for the whole project in different server, while we do our regular tasks. But even that is not working out for us right now. Because, It takes about 30 minutes to test the whole project. CI looks up in repository and check for changes and if found any, it starts to build and run test. So If any code is checked in with in with in 30 minutes while the build is not completed, then that build goes into queue. And eventually we get the email notification from CI after 1/2 hours. Which is not satisfying the purpose of CI.

Solution:

I read about Mocha and really got interested. It is a solution to fixtures. You can use mock object to replace fixtures. At first I was confused about how should I mock my model objects. As it contains the business logic as well as the logic to save in database. Mocha gives you a solution as it gives facility to overwrite methods for an object without writing a real class. So you can mock save or find method of ActiveRecord and replace it with mock method with out creating a class. You can even mock a private method. Here is an example.

Wednesday, January 7, 2009

Replacing Prototype with jQuery in Rails

jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.

For people who like to use jQuery in rails there is a  good news. There is a plugin jRails, which overwrites remote tags provided by rails and uses jQuery ajax call. You can find the project here.

jRails covers all of the functionality in the built in Rails prototype_helper as well as some of the functionality in scriptaculous_helper. Current release includes support for basic AJAX calls (form_to_remote, link_to_remote), RJS, observers (observe_form, observe_field) as well as a limited set of functionality for draggables, droppables, sortables and visual effects.

 

Resources:

jQuery home page

jRails plugin

jRails project page

http://justtalkaboutweb.com/2008/01/14/replace-prototype-with-jquery-on-rails/

Era of Multiprotocol Instant Messenger

Now a days people have at least 2 email accounts and most of the accounts are from different provider. When I am in my office I use gtalk for office account and yahoo messenger for my personal account. Open emails in gmail and yahoo. And might open facebook or any social networking sites. But now digsby has reduced much of these work. In one login to digsby I can login to messenger for gmail, yahoo or even facebook and more. See mail titles of various accounts and facebook feeds. And it is very intuitive and customizable.

Tuesday, November 25, 2008

Amazon Flexible Payments Service

Key features include

  • Send and receive money using credit card, bank account or Amazon Payments balance transfer as payment methods.
  • Create “Payment Instructions” to define conditions and constraints desired for a given transaction, and programmatically obtain payment authorizations or “tokens” that represent these Payment Instructions from customers.
  • Execute one-time, multiple, or recurring payments on behalf of customers.
  • Aggregate micro-transactions into a single larger transaction using Prepaid and Postpaid capabilities.
  • Integrate Amazon FPS into your website in minutes with Amazon Simple Pay, a set of copy-and-paste HTML buttons.
  • Build payment applications where you are neither the sender nor the recipient of funds. You can build marketplace applications that enable the movement of money between two third parties. Try Amazon Simple Pay Marketplace.
  • View account balances, transaction histories, and transaction details on the Amazon Payments web site.
  • Utilize the Amazon FPS sandbox to build and test applications without using real money or incurring any transaction charges.

References

General Process

  1. Generate a caller token(Needed once for each application)
  2. Generate a recipient token
  3. Generate a co-branded UI url with caller and recipient token
  4. Redirect to Amazon with a generated co-branded UI url
  5. Amazon will redirect to your web site with a sender token
  6. Execute Payment using caller, recipient and sender token

Sample Source Code and API can be found here

Plugins

There are 2 plugins amazon_fps_foo and remit. I could not find much documentation for amazon_fps_foo.

Remit

Remit uses a REST implementation of Amazon Flexible Payments Service (FPS).

There is an example for a "simple" implementation of a "marketplace" charge (one in which you are charging a client for a
product on behalf of another party): http://gist.github.com/46941

Testing

You can check your code with out flowing real money. Sandbox is the test server for checking your code regarding FPS.

Developer Resources

Additional Product Information

Friday, November 21, 2008

Collection of some useful jquery plugins

Some of useful jquery plugins I found. I have tested these plugins in IE6 and FireFox.

Datagrids

http://trirand.com/jqgrid/jqgrid.html

http://webplicity.net/flexigrid/

Animations

To animate your web page content flying from left and right Easy Slide demo

You want to flip your content? There you go

Chain your animation. Home Page demo

jTypeWriter gives a type writer effect with your text.

Effects

Gradient effect without images demo

Highlights text within the html

Charts and bars can be drawn with sparkline (need to test in ie)

A gradient effect on text (need to test in ie)

Menu

Fisheye

Picture Gallery

jquery-Fancyzoom

jqgalscroll-photo-gallery

image-slider-player-in-jquery and here is a demo

Rounded Corners

A nice api Home Demo

Really nice to have effect, liquid-canvas demo

jquery-roundcorners-canvas demo

jcorners

jquerycurvycorners

Local scroll

serialScroll nice scroller

jquerylocalscroll demos

jq-liscroll, automatically scrolls text horizontally.

The Silky Smooth Marquee demo, it is like list scroller

jscroller scrolls and show html. used for advertisement.

wslide (need to test in ie)