Monday, October 25, 2010

Rails 3 + Cucumber

Cucumber is a great gem to describe features.

To setup with Rails 3, we will need to use the README documentation on Github.

1) Include the necessary gems
2) $ bundle install
3) $ rails g cucumber:install --rspec --capybara

Generate a Feature
4) rails g cucumber:feature post title:string description:text published:boolean
5) rails g scaffold post title:string description:text published:boolean
6) rake db:migrate
7) Comment out the line require 'cucumber/rails/capybara_javascript_emulation' in /features/support/env.rb
8) rake cucumber

Sunday, October 17, 2010

Creating a Gem with Bundler

Bundler is really cool in that it helps manage gem dependencies and its a default in Rails 3.


Using those information, i am going to run through steps to start making a gem.

Step 1
$ bundle gem awesome-stuff

Step 2
Make some changes to .gemspec

Step 3
Put the logic in /lib/awesome-stuff

Step 4
require the rb files in /lib/awesome-stuff.rb

Step 5
$ git add .
$ git commit -m "My first gem commit"

Step 6
$ gem build awesome-stuff.gemspec
$ gem install awesome-stuff-0.0.1.gem

Now fire up Interactive Ruby (irb)
> require 'rubygems'
> require 'awesome-stuff'
> Awesome::Pop.makeSomeNoise
> Hello Gem!
> => nil

It works!

The github documentation has some information on using Rspec and Gem Dependencies stuff that you might be interested.
And share the gem with the rest of the world.

Tuesday, July 20, 2010

NoSql on Rails with MongoDB

It is possible to implement non-relational database (without SQL) to store data on Rails.

The definition of NoSql

Heroku's cloud support for NoSql and why it matters?

Article that apparently got Rubyists notice about NoSql

And get started to implementing NoSql
1) Install MongoDB

2) Setup MongoDB for Rails 3

3) Examples and explanations by Ryan Bates
Railscasts MongoDB and MongoMapper

4) More info about MongoMapper

5) Thinking of using Heroku as your host?

There is also a cloud host for MongoDb, MongoHQ

Livereload

A great tool to prevent frequent reloads every time changes to Javascript, CSS, or HTML is made.

Friday, July 9, 2010

Feedzirra on Rails 3

Feedzirra is a gem that helps to easily parse RSS feed.

To get Feedzirra to work with Rails 3, we will need to do a few stuff.

We will include the required gem in the gemfile. Add,
gem 'nokogiri', '1.4.1'
group :after_initialize do
gem "feedzirra"
end
then run bundle install to make sure we have the gem good

At the config/boot.rb
Add Bundler.require :after_initialize below Bundler setup

Then we should be able to kick start using Feedzirra, refer to the links below for more info.


Monday, June 28, 2010

Rspec with Rails 3

First of all, we will need to setup Rspec on Rails 3,
sudo gem install rspec
sudo gem install rspec-rails --pre

Then we include them in our gemfile,
gem 'rspec'
gem 'rspec-rails'

Then we will run the generator:install,
rails g rspec:install
which will provide us with all the files/directory that we need to use Rspec

For a more robust TDD/BDD, we could install autotest. This would assure that each time we edit the test file, the Rspec test will be conducted automatically without the need of us typing the command out.
gem install autotest
gem install autotest-fsevent
gem install autotest-growl (For some reason i still couldn't set it up to work with Growl for OSX)

Open the autotest file,
mate ~/.autotest

Add these 2 lines to the file
require "autotest/fsevent"
require "autotest/growl"

Kick it off with
autotest

If we are testing model, be sure to do
rake db:test:prepare
or Rspec will complain.

Friday, June 18, 2010

Upgrading a Rails 2 App to Rails 3

Most of us have Rails 2 Application in our stash and it would be nice to support the latest Rails 3 since some day the Rails 2 methods and architecture will be deprecated.

Some of the useful reads are Simon Carletti's Blog, Rails Dispatch, and omgbloglol.

So what you can do to upgrade an existing app is by running a (rails generate new app) on an existing Rails 2 application.

Say your previous Rails 2 app is in a folder titled "blogApp", then run
rails blogApp


It doesn't exactly forcefully overwrite the entire folder, but it prompts you if you wanna keep this particular file or if you wanna update it, and it also adds all the files that Rails 3 need like gemfile bundler, new rails.rb in the script folder, and so on.

Based on omgbloglol, it would probably be a save bet to overwrite these files:-
  • Rakefile
  • README
  • config/boot.rb
  • public/404.html (unless you’ve customized it)
  • public/500.html (unless you’ve customized it)
  • public/javascripts/* (if you don’t have a lot of version dependent custom JavaScript)
  • script/* (they probably wouldn’t work with the new Rails 3 stuff in their old form anyhow)
And depending on our needs, we might or might not wanna overwrite these :-
  • .gitignore (unless you don’t really care; the new standard one is pretty good)
  • app/helpers/application_helper.rb
  • config/routes.rb
  • config/environment.rb
  • config/environments/* (unless you haven’t touched these as many people don’t)
  • config/database.yml
  • doc/README_FOR_APP (you do write this, don’t you?)
  • test/test_helper.rb
By doing that, we pretty much have the boilerplate of a Rails 3 application and all we have to do is tweak the codes to conform to Rails 3.
  1. Moving gem to gemfile Bundler
  2. Moving the configurations from config/environment.rb to config/application.rb
  3. Routers new syntax
  4. etc..
And you can find the steps for the upgrade at omgbloglol, which to me is pretty comprehensive.

Let the Rails 3 Migration begin.