Install Ruby on Rails

December 1, 2011 Leave a comment

Installing native libraries:

sudo apt-get install curl git zlib1g zlib1g-dev openssl
sudo apt-get install libpq-dev

Installing ruby version manager(rvm):

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc

Close the terminal and reopen again (reload config) then install:

rvm pkg install zlib
rvm pkg install openssl

Installing Ruby version 1.9.2

rvm install 1.9.2

Make rvm to use Ruby version 1.9.2 as default

rvm use 1.9.2 --default
Advertisements
Categories: Ruby

How to install ruby v1.9.2 and upgrade rails 2.3.x to 3.x

download the ruby 1.9.2 package:
for ubuntu user:

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
tar -xvf ruby-1.9.2-p0.tar.gz
./configure
make
make install
gem install rails

for window user you can donwload installer package: Ruby Installer for Windows

Categories: Ruby

How to set up & run Jsspec

Step 1: download Jsspec lib http://jsspec.googlecode.com/files/JSSpec20080923.zip and store it on your pc
Step 2: Write test code

describe('Initialize Maplet', {
	before_each: function(){
		main = new Main();
		maplet = mock(Maplet);
	},
	'Given that org.instedd.ResourcesMap namespace is defined': function(){
		value_of(org.instedd.ResourcesMap).should_not_be_undefined();
	},
	'And Main object is defined': function(){
		value_of(main).should_not_be_undefined();
	},
	'When application initialize a maplet Then a map is being shown': function(){		
		main.initialize(maplet);
		value_of(verify(maplet.show()).called()).should_be_true();
	}
});

Step 3:

Categories: Javascript

How to set up & run rcov in the rails project

Step 1: install rcov package using gem

kakada@instedd-kakada:~$ sudo gem install rcov

Step 2: install subversion to your Linux(Ubuntu recommended)

kakada@instedd-kakada:~$ sudo apt-get install subversion

Step 3: install plugin rcov into your rails project
Go to root folder of rails project that locate and then run the following command line below:

kakada@instedd-kakada:~/work/my_rails_project$ ./script/plugin install http://svn.codahale.com/rails_rcov

Step 4: Run rcov
On the root folder of rails project that locate then run the following command line below:

# sort by coverage
kakada@instedd-kakada:~/work/my_rails_project$ rake test:units:rcov RCOV_PARAMS="--sort=coverage"
kakada@instedd-kakada:~/work/my_rails_project$ rake test:functionals:rcov RCOV_PARAMS="--sort=coverage"
# show callsites and hide fully covered files
kakada@instedd-kakada:~/work/my_rails_project$ rake test:units:rcov RRCOV_PARAMS="--callsites --only-uncovered"
kakada@instedd-kakada:~/work/my_rails_project$ rake test:functionals:rcov RCOV_PARAMS="--callsites --only-uncovered"
# only show files which begin with "app/models" or "app/controllers"
kakada@instedd-kakada:~/work/my_rails_project$ rake test:units:rcov SHOW_ONLY='app/models' 
kakada@instedd-kakada:~/work/my_rails_project$ rake test:functionals:rcov SHOW_ONLY='app/controllers'
Categories: Ruby

Get IP address from DHCP server in Ubuntu server

edit file 70-persistent-net.rules (/etc/udev/rules.d)
->nano /etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:7f:94:7a", ATTR{type}$

remove all content in it, then reboot system (-_-)

Categories: Ubuntu Server

TestCase with Authlogic in Ruby

/test/test_helper.rb

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require "authlogic/test_case"

class ActiveSupport::TestCase
  ...
  # Add more helper methods to be used by all tests here...
  include Authlogic::TestCase
  def setup
    activate_authlogic
  end
  ...
end

/test/functional/users_controller_test.rb

require 'test_helper'

class UsersControllerTest < ActionController::TestCase
  setup :activate_authlogic
  fixtures :users
  test "should get index" do
    UserSession.create(users(:admin))
    get :index
    assert_response :success
    assert_not_nil assigns(:users)
  end
  …
end
Categories: Ruby Tags: , ,