21:32:17:~/clients/brep/td/trunk > rake stats
(in /Users/balaparanj/clients/brep/td/trunk)
/Users/balaparanj/clients/brep/td/trunk/config/boot.rb:38:Warning: require_gem is obsolete. Use gem instead.
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 1158 | 972 | 28 | 118 | 4 | 6 |
| Helpers | 329 | 283 | 0 | 42 | 0 | 4 |
| Models | 975 | 759 | 25 | 127 | 5 | 3 |
| Libraries | 733 | 552 | 9 | 82 | 9 | 4 |
| Components | 0 | 0 | 0 | 0 | 0 | 0 |
| Integration tests | 0 | 0 | 0 | 0 | 0 | 0 |
| Functional tests | 701 | 522 | 52 | 106 | 2 | 2 |
| Unit tests | 493 | 382 | 26 | 62 | 2 | 4 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total | 4389 | 3470 | 140 | 537 | 3 | 4 |
+----------------------+-------+-------+---------+---------+-----+-------+
Code LOC: 2566 Test LOC: 904 Code to Test Ratio: 1:0.4
Monday, April 30, 2007
ssh: somedomain.org: No address associated with nodename
This error message happened while remote login using ssh. ping command did not work. The problem was the domain was incorrect.
Saturday, April 28, 2007
Ruby: No such file to load -- ubygems (LoadError)
I deleted the contents of directory site_ruby and I was getting that error message. After some googling found Rich Kilmer's reply
"You have installed rubygems and set the RUBYOPT variable. This is the
downside to using the RUBYOPT :-(
Just unset that variable and then you should be good to go."
-rich
Thanks Rich, that fixed my problem.
"You have installed rubygems and set the RUBYOPT variable. This is the
downside to using the RUBYOPT :-(
Just unset that variable and then you should be good to go."
-rich
Thanks Rich, that fixed my problem.
rmagick headache on mac os
Finally resolved the rmagick installation problems. The actual problem was not rmagick itself but a custom script in my project.
I found the RMagick install script for Mac OS X - Version 0.2.0
on rmagick installation faq.
I found the RMagick install script for Mac OS X - Version 0.2.0
on rmagick installation faq.
/opt/local/bin/ruby: bad interpreter:
I was getting the weird ruby bad interpreter error message after I deleted everything under site_ruby directory. I was working on getting the rmagick working on my laptop. I resolved the problem by reinstalling the Ruby 1.8.6 and Rubygems 0.9.2.
Friday, April 27, 2007
warning: multiple values for a block parameter (0 for 1)
In the following irb session the error message indicates that the input parameter is missing.
>> hello = lambda { "hello" }
=> #
>> hello.call
=> "hello"
>> log = lambda { |str| puts "[LOG] #{str}" }
=> #
>> log.call
(irb):16: warning: multiple values for a block parameter (0 for 1)
from (irb):17
[LOG]
=> nil
>> log.call("A test log message")
[LOG] A test log message
=> nil
>> hello = lambda { "hello" }
=> #
>> hello.call
=> "hello"
>> log = lambda { |str| puts "[LOG] #{str}" }
=> #
>> log.call
(irb):16: warning: multiple values for a block parameter (0 for 1)
from (irb):17
[LOG]
=> nil
>> log.call("A test log message")
[LOG] A test log message
=> nil
Friday, April 20, 2007
Capistrano Concepts
Chris Selmer's Capistrano Presentation from the April 5, 2007 DCRUG
meeting is very good.
The Rails Edge conference had discussion on the material
covered in this presentation, but this presentation connected all the
dots for me.
meeting is very good.
The Rails Edge conference had discussion on the material
covered in this presentation, but this presentation connected all the
dots for me.
Copying to the clipboard in UNIX
You can send any output to the clipboard by using pbcopy. For example: history | pbcopy will send the output of history command to the clipboard. You can just paste it in email or other document. Very nice. pbpaste will paste the contents of the clip board.
Tuesday, March 20, 2007
How to create drop down boxes in Ruby on Rails
Migration file : 001_create_people.rb
class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people do |t|
t.column :first_name, :string
t.column :last_name, :string
t.column :email, :string
t.column :created_at, :datetime
end
end
def self.down
drop_table :people
end
end
person.rb
class Person < ActiveRecord::Base
has_many :tasks
end
task.rb
class Task < ActiveRecord::Base
belongs_to :user
def self.find_all_person
Person.find(:all, :order => "first_name").map {|u| [u.first_name, u.id] }
end
end
tasks/_form.rhtml
<h2> Create a Task for a Person</h2>
<% form_for ( :task, :url => path, :html => { :method => method } ) do |f| %>
<p>
Title: <br>
<%= f.text_field :title, :class => 'text_field' %><br>
</p>
<p>
Content:
<br>
<%= f.text_field :content, :class => 'text_field' %><br>
</p>
<br>
<p>Select a priority:
<%= f.select ( :priority, %w { 1 2 3 4 5 6 7 8 9 10 } ) %>
</p>
</p>
Person:
<br>
<%=
f.select ( :people_id, @people )
%>
</p>
<p>
<%= submit_tag button_text %>
</p>
<% end %>
tasks/edit.rhtml
<h1>Editing task</h1>
<%= error_messages_for :task %>
<% form_for ( :task, :url => task_path ( @task ) , :html => { :method => :put } ) do |f| %>
<p>
<%= submit_tag "Update" %>
</p>
<% end %>
<%= link_to 'Show', task_path ( @task ) %> |
<%= link_to 'Back', tasks_path %>
tasks/index.rhtml
<h1>Listing tasks</h1>
<table>
<tr>
</tr>
<% for task in @tasks %>
<tr>
<td><%= link_to ( h task.title ) , task_path ( task ) %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New task', new_task_path %>
tasks/new.rhtml
<h1>New task</h1>
<%= error_messages_for :task %>
<%= render :partial => 'form', :locals => { :path => tasks_path,
:method => :post,
:button_text => 'Create' } %>
<%= link_to 'Back', tasks_path %>
tasks/show.rhtml
<h2>Task </h2>
<p> Title: <%= h @task.title %></p>
<p>Content: <%= h @task.content %></p>
<p>Priority: <%= h @task.priority %></p>
<p>Created At: <%= @task.created_at %></p>
<p>Person: <%= @person.first_name %></p> -->
<%= link_to 'Back', tasks_path %>
people/_form.rhtml
<% form_for ( :person, :url => path, :html => { :method => method } ) do |f| %>
<p>
<strong>First Name: </strong>
<br>
<%= f.text_field :first_name, :class => 'text_field' %><br>
</p>
<p>
<strong>Last Name: </strong>
<br>
<%= f.text_field :last_name, :class => 'text_field' %><br>
</p>
<strong>Email: </strong>
<br>
<%= f.text_field :email, :class => 'text_field' %><br>
</p>
<p>
<%= submit_tag button_text %>
</p>
<% end %>
people/edit.rhtml
<h1>Editing person</h1>
<%= error_messages_for :person %>
<%= render :partial => 'form', :locals => { :path => person_path ( @person ) ,
:method => :put,
:button_text => 'Update' }
%>
<%= link_to 'Show', person_path ( @person ) %> |
<%= link_to 'Back', people_path %>
people/index.rhtml
<h1>Listing people</h1>
* Create an application to track a person's tasks. The user should be able to
create people, create tasks, and assign a task to a person when the task is created.
<table>
<tr>
</tr>
<% for person in @people %>
<tr>
<td><%= link_to ( h person.first_name ) , person_path ( person ) %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New person', new_person_path %>
people/new.rhtml
<h1>New person</h1>
<%= error_messages_for :person %>
<%= render :partial => 'form', :locals => { :path => people_path,
:method => :post,
:button_text => 'Create' } %>
<%= link_to 'Back', people_path %>
people/show.rhtml
<h2>Person </h2>
<p>First Name: <%= h @person.first_name %></p>
<p>Last Name: <%= h @person.last_name %></p>
<p>Last Name: <%= h @person.email %></p>
<%= link_to 'Edit', edit_person_path ( @person ) %> |
<%= link_to 'Back', people_path %>
home/index.rhtml
<%= link_to "People", :controller => :people, :action => :index %><br>
<%= link_to "Tasks", :controller => :tasks, :action => :index %>
layouts/people.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>People: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>
layouts/tasks.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Tasks: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>
controllers/home_controller.rb
class HomeController < ApplicationController
def index
end
end
people_controller.rb
class PeopleController < ApplicationController
# GET /people
# GET /people.xml
def index
@people = Person.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @people.to_xml }
end
end
# GET /people/1
# GET /people/1.xml
def show
@person = Person.find(params[:id])
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @person.to_xml }
end
end
# GET /people/new
def new
@person = Person.new
end
# GET /people/1;edit
def edit
@person = Person.find(params[:id])
end
# POST /people
# POST /people.xml
def create
@person = Person.new(params[:person])
respond_to do |format|
if @person.save
flash[:notice] = 'Person was successfully created.'
format.html { redirect_to person_url(@person) }
format.xml { head :created, :location => person_url(@person) }
else
format.html { render :action => "new" }
format.xml { render :xml => @person.errors.to_xml }
end
end
end
# PUT /people/1
# PUT /people/1.xml
def update
@person = Person.find(params[:id])
respond_to do |format|
if @person.update_attributes(params[:person])
flash[:notice] = 'Person was successfully updated.'
format.html { redirect_to person_url(@person) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @person.errors.to_xml }
end
end
end
# DELETE /people/1
# DELETE /people/1.xml
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to people_url }
format.xml { head :ok }
end
end
end
controllers/tasks_controller.rb
class TasksController < ApplicationController
# GET /tasks
# GET /tasks.xml
def index
@tasks = Task.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @tasks.to_xml }
end
end
# GET /tasks/1
# GET /tasks/1.xml
def show
@task = Task.find(params[:id])
@person = Person.find(:first, :conditions => "id = #{@task.people_id}")
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @task.to_xml }
end
end
# GET /tasks/new
def new
@task = Task.new
@people = Task.find_all_person
end
# GET /tasks/1;edit
def edit
@task = Task.find(params[:id])
end
# POST /tasks
# POST /tasks.xml
def create
@task = Task.new(params[:task])
@person = Person.find(:first, :conditions => "id = #{@task.people_id}")
respond_to do |format|
if @task.save
flash[:notice] = 'Task was successfully created.'
format.html { redirect_to task_url(@task) }
format.xml { head :created, :location => task_url(@task) }
else
format.html { render :action => "new" }
format.xml { render :xml => @task.errors.to_xml }
end
end
end
# PUT /tasks/1
# PUT /tasks/1.xml
def update
@task = Task.find(params[:id])
respond_to do |format|
if @task.update_attributes(params[:task])
flash[:notice] = 'Task was successfully updated.'
format.html { redirect_to task_url(@task) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @task.errors.to_xml }
end
end
end
# DELETE /tasks/1
# DELETE /tasks/1.xml
def destroy
@task = Task.find(params[:id])
@task.destroy
respond_to do |format|
format.html { redirect_to tasks_url }
format.xml { head :ok }
end
end
end
class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people do |t|
t.column :first_name, :string
t.column :last_name, :string
t.column :email, :string
t.column :created_at, :datetime
end
end
def self.down
drop_table :people
end
end
person.rb
class Person < ActiveRecord::Base
has_many :tasks
end
task.rb
class Task < ActiveRecord::Base
belongs_to :user
def self.find_all_person
Person.find(:all, :order => "first_name").map {|u| [u.first_name, u.id] }
end
end
tasks/_form.rhtml
<h2> Create a Task for a Person</h2>
<% form_for ( :task, :url => path, :html => { :method => method } ) do |f| %>
<p>
Title: <br>
<%= f.text_field :title, :class => 'text_field' %><br>
</p>
<p>
Content:
<br>
<%= f.text_field :content, :class => 'text_field' %><br>
</p>
<br>
<p>Select a priority:
<%= f.select ( :priority, %w { 1 2 3 4 5 6 7 8 9 10 } ) %>
</p>
</p>
Person:
<br>
<%=
f.select ( :people_id, @people )
%>
</p>
<p>
<%= submit_tag button_text %>
</p>
<% end %>
tasks/edit.rhtml
<h1>Editing task</h1>
<%= error_messages_for :task %>
<% form_for ( :task, :url => task_path ( @task ) , :html => { :method => :put } ) do |f| %>
<p>
<%= submit_tag "Update" %>
</p>
<% end %>
<%= link_to 'Show', task_path ( @task ) %> |
<%= link_to 'Back', tasks_path %>
tasks/index.rhtml
<h1>Listing tasks</h1>
<table>
<tr>
</tr>
<% for task in @tasks %>
<tr>
<td><%= link_to ( h task.title ) , task_path ( task ) %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New task', new_task_path %>
tasks/new.rhtml
<h1>New task</h1>
<%= error_messages_for :task %>
<%= render :partial => 'form', :locals => { :path => tasks_path,
:method => :post,
:button_text => 'Create' } %>
<%= link_to 'Back', tasks_path %>
tasks/show.rhtml
<h2>Task </h2>
<p> Title: <%= h @task.title %></p>
<p>Content: <%= h @task.content %></p>
<p>Priority: <%= h @task.priority %></p>
<p>Created At: <%= @task.created_at %></p>
<p>Person: <%= @person.first_name %></p> -->
<%= link_to 'Back', tasks_path %>
people/_form.rhtml
<% form_for ( :person, :url => path, :html => { :method => method } ) do |f| %>
<p>
<strong>First Name: </strong>
<br>
<%= f.text_field :first_name, :class => 'text_field' %><br>
</p>
<p>
<strong>Last Name: </strong>
<br>
<%= f.text_field :last_name, :class => 'text_field' %><br>
</p>
<strong>Email: </strong>
<br>
<%= f.text_field :email, :class => 'text_field' %><br>
</p>
<p>
<%= submit_tag button_text %>
</p>
<% end %>
people/edit.rhtml
<h1>Editing person</h1>
<%= error_messages_for :person %>
<%= render :partial => 'form', :locals => { :path => person_path ( @person ) ,
:method => :put,
:button_text => 'Update' }
%>
<%= link_to 'Show', person_path ( @person ) %> |
<%= link_to 'Back', people_path %>
people/index.rhtml
<h1>Listing people</h1>
* Create an application to track a person's tasks. The user should be able to
create people, create tasks, and assign a task to a person when the task is created.
<table>
<tr>
</tr>
<% for person in @people %>
<tr>
<td><%= link_to ( h person.first_name ) , person_path ( person ) %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New person', new_person_path %>
people/new.rhtml
<h1>New person</h1>
<%= error_messages_for :person %>
<%= render :partial => 'form', :locals => { :path => people_path,
:method => :post,
:button_text => 'Create' } %>
<%= link_to 'Back', people_path %>
people/show.rhtml
<h2>Person </h2>
<p>First Name: <%= h @person.first_name %></p>
<p>Last Name: <%= h @person.last_name %></p>
<p>Last Name: <%= h @person.email %></p>
<%= link_to 'Edit', edit_person_path ( @person ) %> |
<%= link_to 'Back', people_path %>
home/index.rhtml
<%= link_to "People", :controller => :people, :action => :index %><br>
<%= link_to "Tasks", :controller => :tasks, :action => :index %>
layouts/people.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>People: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>
layouts/tasks.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Tasks: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>
controllers/home_controller.rb
class HomeController < ApplicationController
def index
end
end
people_controller.rb
class PeopleController < ApplicationController
# GET /people
# GET /people.xml
def index
@people = Person.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @people.to_xml }
end
end
# GET /people/1
# GET /people/1.xml
def show
@person = Person.find(params[:id])
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @person.to_xml }
end
end
# GET /people/new
def new
@person = Person.new
end
# GET /people/1;edit
def edit
@person = Person.find(params[:id])
end
# POST /people
# POST /people.xml
def create
@person = Person.new(params[:person])
respond_to do |format|
if @person.save
flash[:notice] = 'Person was successfully created.'
format.html { redirect_to person_url(@person) }
format.xml { head :created, :location => person_url(@person) }
else
format.html { render :action => "new" }
format.xml { render :xml => @person.errors.to_xml }
end
end
end
# PUT /people/1
# PUT /people/1.xml
def update
@person = Person.find(params[:id])
respond_to do |format|
if @person.update_attributes(params[:person])
flash[:notice] = 'Person was successfully updated.'
format.html { redirect_to person_url(@person) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @person.errors.to_xml }
end
end
end
# DELETE /people/1
# DELETE /people/1.xml
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to people_url }
format.xml { head :ok }
end
end
end
controllers/tasks_controller.rb
class TasksController < ApplicationController
# GET /tasks
# GET /tasks.xml
def index
@tasks = Task.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @tasks.to_xml }
end
end
# GET /tasks/1
# GET /tasks/1.xml
def show
@task = Task.find(params[:id])
@person = Person.find(:first, :conditions => "id = #{@task.people_id}")
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @task.to_xml }
end
end
# GET /tasks/new
def new
@task = Task.new
@people = Task.find_all_person
end
# GET /tasks/1;edit
def edit
@task = Task.find(params[:id])
end
# POST /tasks
# POST /tasks.xml
def create
@task = Task.new(params[:task])
@person = Person.find(:first, :conditions => "id = #{@task.people_id}")
respond_to do |format|
if @task.save
flash[:notice] = 'Task was successfully created.'
format.html { redirect_to task_url(@task) }
format.xml { head :created, :location => task_url(@task) }
else
format.html { render :action => "new" }
format.xml { render :xml => @task.errors.to_xml }
end
end
end
# PUT /tasks/1
# PUT /tasks/1.xml
def update
@task = Task.find(params[:id])
respond_to do |format|
if @task.update_attributes(params[:task])
flash[:notice] = 'Task was successfully updated.'
format.html { redirect_to task_url(@task) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @task.errors.to_xml }
end
end
end
# DELETE /tasks/1
# DELETE /tasks/1.xml
def destroy
@task = Task.find(params[:id])
@task.destroy
respond_to do |format|
format.html { redirect_to tasks_url }
format.xml { head :ok }
end
end
end
Monday, March 05, 2007
sudo: port: command not found
export PATH=$PATH:/opt/local/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info
Included the above lines in .bash_profile (my mac is using bash shell) and voila a nagging problem sudo: port: command not found is gone!!!
sudo port -d selfupdate
ran successfully. Now I was able to install FreeImage by running:
sudo port install freeimage
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info
Included the above lines in .bash_profile (my mac is using bash shell) and voila a nagging problem sudo: port: command not found is gone!!!
sudo port -d selfupdate
ran successfully. Now I was able to install FreeImage by running:
sudo port install freeimage
Thursday, March 01, 2007
LoadError: no such file to load — selenium
LoadError: no such file to load — selenium. This kind of error message can happen if you have installed anything as a gem but you have not specified require "rubygems" as the first statement in your program.
Wednesday, February 28, 2007
LoadError: no such file to load — flexmock
If you get this error, it means you need the statement: require 'rubygems' as the first line in your program.
Monday, February 05, 2007
Subversion 1.4.3 upgrade
Installed the latest version of Subversion. I had the older version 1.3, it looks like it installed successfully. svn --version shows the version as 1.4.3 and the files which were already in svn is still there.
Sunday, February 04, 2007
Spam Prevention using the Obfuscator Widget for Mac OS
This plugin obfuscates your email so that spambots cannot recognize the email that you post on your web page.
Testing... my email is : bparanj@gmail.com
Testing... my email is : bparanj@gmail.com
CSS Tweak - Nice Widget for Mac OS to optimize CSS
CSS Tweak! widget is very useful plugin to optimize your CSS files. Just select the file you want to optimize from the Finder, hit F12 and drop it into the widget, select the options and the rest is done by the widget! Very cool.
Code to HTML Mac OS widget test - Download Code2HTML
#!/bin/sh
pid=$ ( ps -o pid, command | grep '\<script/server\>' | awk ' { print $1 } ' )
kill -9 $pid
ruby script/server
Code2HTML is a nifty little plugin that helps to convert the code to html. It solved my problem of posting code to the blog without messing up the characters. It is very quick and easy to convert the code to html.
pid=$ ( ps -o pid, command | grep '\<script/server\>' | awk ' { print $1 } ' )
kill -9 $pid
ruby script/server
Code2HTML is a nifty little plugin that helps to convert the code to html. It solved my problem of posting code to the blog without messing up the characters. It is very quick and easy to convert the code to html.
Tuesday, January 23, 2007
Colorizing Autotest
1. install turn and facets
2. require 'turn' in environment.rb in the Rails project.
Step 2 must be done for each project that needs the colorizing of the autotest window. Another way to do this is shown in one of the topfunky's videos.
2. require 'turn' in environment.rb in the Rails project.
Step 2 must be done for each project that needs the colorizing of the autotest window. Another way to do this is shown in one of the topfunky's videos.
Friday, January 19, 2007
The new :& syntax in Ruby
The advantage of the new syntax is that it allows passing in a proc object, which is powerful.
I am surprised how the presenter in the No Fluff Just Stuff thought its main purpose was to make the code concise!
I am surprised how the presenter in the No Fluff Just Stuff thought its main purpose was to make the code concise!
Thursday, December 14, 2006
Functional Testing in Rails that Requires Login
For RESTful authentication, there is a
login_as(user) method in AuthenticatedTestHelper module that sets the
current user
in the session from the user fixtures. This is under the lib directory.
In my functional test, I have:
def test_should_show_billing_profile_for_valid_login
login_as (:aaron)
get :show, :id => :aaron.id
assert_response :success
assert_select "html:root>head>title", "BillingProfiles: show"
end
users.yml looks like this:
quentin:
id: 1
login: quentin
email: quentin@example.com
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
created_at: <%= 5.days.ago.to_s :db %>
aaron:
id: 2
login: aaron
email: aaron@example.com
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
created_at: <%= 1.days.ago.to_s :db %>
class BillingProfilesController < ApplicationController
before_filter :login_required
def show
@user = User.find(session[:user], :include => [:billing_profile])
@billing_profile = @user.billing_profile
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @billing_profile.to_xml }
end
end
The problem was that I was using session[:user_id] in my controller
whereas the RESTful authentication
module is using session[:user] as shown below:
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
....
So I changed my controller code to use session[:user] and my tests now
pass! The plugin itself has the API to help you do the functional
testing. Very nice indeed.
login_as(user) method in AuthenticatedTestHelper module that sets the
current user
in the session from the user fixtures. This is under the lib directory.
In my functional test, I have:
def test_should_show_billing_profile_for_valid_login
login_as (:aaron)
get :show, :id => :aaron.id
assert_response :success
assert_select "html:root>head>title", "BillingProfiles: show"
end
users.yml looks like this:
quentin:
id: 1
login: quentin
email: quentin@example.com
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
created_at: <%= 5.days.ago.to_s :db %>
aaron:
id: 2
login: aaron
email: aaron@example.com
salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
created_at: <%= 1.days.ago.to_s :db %>
class BillingProfilesController < ApplicationController
before_filter :login_required
def show
@user = User.find(session[:user], :include => [:billing_profile])
@billing_profile = @user.billing_profile
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @billing_profile.to_xml }
end
end
The problem was that I was using session[:user_id] in my controller
whereas the RESTful authentication
module is using session[:user] as shown below:
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
....
So I changed my controller code to use session[:user] and my tests now
pass! The plugin itself has the API to help you do the functional
testing. Very nice indeed.
Monday, December 04, 2006
Installing Sqlite3 on Mac OS 10.4
1. Install DarwinPorts, download DarwinPorts 1.3.2-archive.tar.gz, unzip it.
2. Copy unzipped folder to some location
3. cd to that location cd darwinports/base and run ./configure
4. make
5. sudo make install
6. Add export PATH=$PATH:/opt/local/bin to ~/.profile
7. Either logout of Mac or do source .profile
8. Run port sync
9. sudo port install rb-sqlite3
10.Run sqlite databasename in a shell. You will go to the sqlite command prompt.
You can now create tables and run sql queries. The advantage of this database is that it speeds up the testing during development. It is very fast.
2. Copy unzipped folder to some location
3. cd to that location cd darwinports/base and run ./configure
4. make
5. sudo make install
6. Add export PATH=$PATH:/opt/local/bin to ~/.profile
7. Either logout of Mac or do source .profile
8. Run port sync
9. sudo port install rb-sqlite3
10.Run sqlite databasename in a shell. You will go to the sqlite command prompt.
You can now create tables and run sql queries. The advantage of this database is that it speeds up the testing during development. It is very fast.
Subscribe to:
Posts (Atom)