Monday, June 17

Jasmine - Behavior Driven Development for JavaScript


Jasmine - is the new tool implemented based on BDD for JavaScript


Although BDD is principally an idea about how software development should be managed by both business interests and technical insight, the practice of BDD does assume the use of specialized software tools to support the development process.

Although these tools are often developed specifically for use in BDD projects, they can be seen as specialized forms of the tooling that supports test-driven development. The tools serve to add automation to the ubiquitous language that is a central theme of BDD.



Friday, October 26

Kaminari - Pagination gem for Rails3


Going down the line of Rails history, I was one of those people who admired the in-built pagination feature of Rails. Then later on as we progressed to Rails2 this was plugged out and that's when will_paginate got popularized as both gem and plug-in. It became part of every application that I had built of course varying with different CSS, styles. With advent of Rails3 and unsupported will_paginate had pushed us to move on with alternatives... here come Kaminari

So straight away, jumping on to the point it's pagination gem supporting Rails3. Kaminari is based on Scope & Engine (like rails engine!). It is simple, powerful


  1. Scope based API
  2. I18n customizable helper
  3. ORM & Template engine supported
  4. Supports HTML5
  5. Flavored with themes


There are quite number of themes, recipes available for Kaminari. For users coming from will_paginate there are two striking difference to be noted in implementation

Considering we are paginating over the list of posts....

will_paginate
@posts = Post.paginate(:page => params[:page], :per_page => 10)
kaminari
@posts = Post.page(params[:page]).per(10)

On to the views...

will_paginate
will_paginate @posts
kaminari 
paginate @posts

Kaminari - https://github.com/amatsuda/kaminari
Recipes - https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes


Monday, November 28

Configuring databases in case of integer type password

Though I have been working from past 6 years with Ruby on Rails in one of the recent bootstrap session to a small and enthusiastic groups I had noticed one another fine point in the way we use yml files.

Any newbie who is aware of Rails can pretty much recollect that we configure databases, test data and many other information required for application through YAML files.

Like in many of the previous sessions & trainings conducted I had moved on by creating simple rails application. Since it was a bootstrap session and the attendees were doing on their personal laptops couple of them had difficulty in configuring the database. I had zeroed down to database.yml after I got confirmed that they are all running on the right versions of mysql. This was the yml that they have in their applications


development:
  adapter: mysql2
  encoding: utf8
  database: blog_development
  pool: 5
  username: root
  password: 000000
  socket: /tmp/mysql.sock


As I found it normal I gave another try by myself and landed into same issue so did dig into the logs over there...


** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env** Execute db:load_config** Execute db:create
rake aborted!
can't convert Fixnum into String
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/client.rb:36:in `connect'


So here it is evident that there was a data type mis-match and keeping fingers crossed looked over again at the database.yml and this time zeroed down to the mistake




development:
  adapter: mysql2
  encoding: utf8
  database: blog_development
  pool: 5
  username: root
  password: 000000
  socket: /tmp/mysql.sock




The password was  000000 an integer type as per the yaml and password was expected as string. Once it was identified the fix was pretty simple




development:
  adapter: mysql2
  encoding: utf8
  database: blog_development
  pool: 5
  username: root
  password: "000000"
  socket: /tmp/mysql.sock



As always... every bootstrap session will keep on helping me to pick some tricky and interesting points otherwise which could not be easily noticed or observed in our day to day projects.