Selenium On Rails

December 12, 2008

Getting Started

Selenium on Rails is the name of the Selenium product crafted specifically for Rails
developers and is distributed as a Rails plugin. It has been designed to work seamlessly
with the Rails testing environment and fixtures.

It’s easy to install Selenium on Rails and get started.

1. Install the core Selenium files needed by the plugin:

SAMPLE>gem install selenium

2. Install the Selenium on Rails plugin for a given project:

SAMPLE>ruby  script/plugin install http://svn.openqa.org/svn/selenium-on-rails/selenium-on-rails/

3. Generate the test directory and a test script:

SAMPLE>ruby script/generate selenium first.rsel

4. Start your Rails server in its test environment:

SAMPLE>ruby script/server -e test

5. Open the Selenium Test Runner in your browser:

http://localhost:3000/selenium

If your installation and setup succeeded, you see the Selenium Test Runner in your browser. You should also know that Selenium tests can be run from the command line and integrated into an automated suite of tests, but for demonstration purposes we will use the built-in web interface to execute our tests.

SAMPLE/test/selenium/first.rsel

setup
open ‘/’
assert_title ‘Ruby on Rails: Welcome aboard’
Run test in –> http://localhost:3000/selenium

For more reference –> http://seleniumhq.org/

Regards,

P.Raveendran

Will Paginate — Plugin

September 29, 2008

Will Paginate:

1. Installation:

cmd>git clone git://github.com/mislav/will_paginate.git

2. Git Installation

You don’t have git installed already then install it

Install git from here.

3. Try with this Basic Code:

a. Product model(products Table) contains these fields

id
name
price
description

b. DB has 100 records

c. controller:

def productlist
@products = Product.paginate :page => params[:page]
end

d. productlist.hml.erb

<%= will_paginate @products %>

<ul>
<% @products.each do |c| %>
<li><%= c.id %> – <%= c.name %> – <%= c.price %> – <%=
c.description %></li>
<% end %>
</ul>

Output looks Like:

Links for more help –> http://agilewebdevelopment.com/plugins/will_paginate

Active Scaffold

Active scaffold is rails plugin used for,

Create,Edit,Update,delete,Search and sorting records in Ajax.

If you want to install it in your rails application then,

1. Please follow this url –> Active Scaffold

2. Install git in your computer –> Git

Ferret in rails

December 15, 2007

View

<%= start_form_tag :action => ’search_number’ %>

<div align=”center”>
<h3>Search Phonenumber By</h3>
<table>
<tr>

<td><select name=”searchfield” prompt=”select”>
<option selected>select</option>
<option value=”phonenumber” >Phonenumber</option>
<option value=”name” >Name</option>
<option value=”city” >City</option>
</select>
</td>
<td>
<%= text_field_tag ’searchkey’ %>
<%= submit_tag “Search” %>

</tr>
</table>
</div>

<%= end_form_tag %>

Controller:

def search_number
if params[:searchfield]
session[:field]= params[:searchfield]
end
field = session[:field]

if params[:searchkey]
session[:query] = params[:searchkey]
end
query= session[:query]
@total, @phones = User.full_text_search(field,query, :page => (params[:page]||1))
@pages = pages_for(@total)
if @phones.length > 0
render :action=>’search_number’
else
render :text=>’No Result’
end

end

MainURl : http://weblog.techno-weenie.net/articles/acts_as_attachment

Reference : http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment –> Tutorial

d:>rails attach

d:\attach>ruby script/plugin source http://svn.techno-weenie.net/projects/plugins

d:\attach>ruby script/plugin install acts_as_attachment

d:\attach>ruby script/generate attachment_model dvd_cover

d:\attach>ruby script/generate controller dvd_covers index new show

OPEn the rb File d:\attach\db02_create_dvd_covers.rb

create_table :dvd_covers do |t|
t.column “dvd_id”, :integer
t.column “content_type”, :string
t.column “filename”, :string
t.column “size”, :integer
t.column “parent_id”, :integer
t.column “thumbnail”, :string
t.column “width”, :integer
t.column “height”, :integer
end

Open the rb File d:\attach\app\model\dvd_cover.rb

class DvdCover < ActiveRecord::Base
belongs_to :dvd
acts_as_attachment :storage => :file_system, :max_size => 300.kilobytes, :content_type => :image
validates_as_attachment
end


Open the rb File d:\attach\app\dvd_covers_controller.rb

class DvdCoversController < ApplicationController
def index
@dvd_covers = DvdCover.find(:all)
end

def new
@dvd_cover = DvdCover.new
end

def show
@dvd_cover = DvdCover.find params[:id]
end

def create
@dvd_cover = DvdCover.create! params[:dvd_cover]
redirect_to :action => ’show’, :id => @dvd_cover
rescue ActiveRecord::RecordInvalid
render :action => ‘new’
end
end

Open the rhtml File d:\attach\app\views\dvd_covers\index.rhtml

<h1>DVD Covers</h1>

<ul>
<% @dvd_covers.each do |dvd_cover| -%>
<li><%= link_to dvd_cover.filename, :action => ’show’, :id => dvd_cover %></li>
<% end -%>
</ul>

<p><%= link_to ‘New’, :action => ‘new’ %></p>

Open the rhtml File d:\attach\app\views\dvd_covers\new.rhtml

<h1>New DVD Cover</h1>

<% form_for :dvd_cover, :url => { :action => ‘create’ }, :html => { :multipart => true } do |f| -%>
<p><%= f.file_field :uploaded_data %></p>
<p><%= submit_tag :Create %></p>
<% end -%>

Open the rhtml File d:\attach\app\views\dvd_covers\show.rhtml

<p><%= @dvd_cover.filename %></p>
<%= image_tag @dvd_cover.public_filename, :size => @dvd_cover.image_size %>
<%= link_to ‘Back’, :action => ‘new’ %>

d:\attach>rake db:migrate

now goto this url http://localhost:3000/dvd_covers in ur browser

THUMBNAIL:

main URL: http://weblog.techno-weenie.net/articles/acts_as_attachment/thumbnailing

MODEl :

acts_as_attachment :storage => :file_system, :thumbnails => { :normal => ‘300>’, :thumb => ‘75′ }


SHOW PAGE:

<p>Original: <%= link_to @dvd_cover.filename, @dvd_cover.public_filename %></p>
<% @dvd_cover.thumbnails.each do |thumb| -%>
<p><%= thumb.thumbnail.to_s.humanize %>: <%= link_to thumb.filename, thumb.public_filename %></p>
<% end -%>

<% DvdCover.attachment_options[:thumbnails].keys.each do |key| -%>
<p><%= key.to_s.humanize %>: <%= link_to key, @dvd_cover.public_filename(key) %></p>
<% end -%>

Controller :

def index
@dvd_covers = DvdCover.find(:all, :conditions => ‘parent_id is null’)
end