Simple Captcha Released
Hey guys, finally i have released the captcha plugin for public usage.
Check it out here
Sample Rails Application – A demo for the ajax based drag drop tree in rubyonrails
I have provided the source code of the ajax based drag drop tree in rubyonrails in one of my previous posts.
I found some of the people are getting problems to incorporate the code into their running applications so i am providing a sample rails application in which all the code for tree is already been placed well.
However the code written seems to be lagged behind the current trends followed in rails development coz of the fire growth of rails itself, but its simply that when i wrote this tree i was very new to rails so you may find the code looks like an old wine but still tastes good to go with.
CHECK THIS OUT…
Four simple steps to make the tree working…
- DOWNLOAD the sample application. (let me know if you are getting any error in downloading the application.)
- Create a test database in mysql or modify the file /config/database.yml according to the database and user u need.
- Run the command
ajaxtree> rake db:migrate
from the application root.
- Run the application server by running
ajaxtree> ruby script/server
and watch the working tree at http://localhost:3000
Integration Testing in Ruby on Rails — How to maintain sessions while testing in Rails
Well, its a natural feel to get amazed out of every other delighted feature provided by RubyonRails and so appreciating it before actually talking about the feature in every second post. This line is for those people who have published that the worst thing about rails is that every rails programmer always just focus on the appreciation of rails and not on the framework per se. As i think the reason behind his(let say) perception is that he might not have tried rails and probably in all posts he have been through yet is that he would have got jealous out of gaining popularity of ruby on rails over jsp and asp and else, and therefore he might not be reading the whole post due to which he just remained untouched with the real appreciable features.
Anyhow, here is my post on a fantastic rails feature - Integration Testing…
RoR is the only web application framework which provides an inbuilt high level of testing. Out of the whole testing the most interesting real time testing is Integrations Testing where you can synchronize with the sessions too unlike in the Functional Testing.
Where exactly we should use Integration Testing ?
Whenever we need to test a series of functionalities which belongs to more than one controller , we should go for Integration Testing and not the Functional one.
Since the functional and unit testing are controller and model centric respectively, rails automatically creates the related functional and unit tests files. But as integrations testing is not confined in any criteria of a specific controller or model, we have to create the integrations file manually… Well, nothing is headache in rails. Its a simple pre-written script, all you need is to call that script with a name you like for whole story you wish to test in the integration test.
Here is a real example of Integration Test in Ruby on Rails
Considerations for test…
We will simply test
- signing in
- posting a new article
- deleting an article with xml_http_request (ajax post request)
Create the test file by running
ruby script/generate integration_test initial_features
Make sure that now you have the file /test/integration/initial_features_test.rb. Rails automatically appends _test at the end of the file name.
For god sake Lets start the testing now
Code for the file /test/integration/initial_features_test.rb
require "#{File.dirname(__FILE__)}/../test_helper"
class InitialFeaturesTest < ActionController::IntegrationTest
fixtures :users, :articles
def test_initial_features
user = user_for_test
user.try_to_signin
user.signin
user.post_an_article
user.delete_an_article_with_xhr
end
def user_for_test
open_session do |user|
def user.try_to_signin
assert_nil session[:user] # assert_session_has & _has_no have been deprecated
get "user/signin"
assert_response :success
post "user/signin", :email=>"test failure string", :password=>"test failure string"
assert_nil session[:user]
end
def user.signin
assert_nil session[:user]
user = users(:first)
post "user/signin", :email=>user.email, :password=>user.password
assert_not_nil session[:user]
assert_response :redirect
assert_redirected_to "articles/show"
# now as the session is set once, we need not to signin again
end
def user.post_an_article
get "articles/show"
assert_response :success
assert_template "articles/show"
user = session[:user]
articles_count = user.articles.length
post_via_redirect "article/new", :title=>"Integration Tetsing in Rails", :description=>"another relishing rails feature"
assert_template "articles/show"
assert_equal articles_count.next, user.reload.articles.length
end
def user.delete_an_article_with_xhr
user = session[:user]
articles_count = user.articles.length
xml_http_request "articles/delete", :id=>articles(:first).id
assert_equal articles_count-1,user.reload.articles.length
end
end
end
end
Although these are not that high level integration tests that rails can provide but its just an overview on the integration tests. I will explain them soon.
RoR(Ruby on Rails) in India – Ruby on Rails based Indian Company
Ruby on Rails is creating the storms in the web development all over the world. RoR is even capable to challenge Big Caps like Microsoft’s Asp.NET and so everything else in the specific area. World is continuously changing… The current WEB not solely depends on the old,encoded,paid,stressful technologies but the fresh,open-source,free,joyful technologies like Ruby on Rails are now creating the new highways to connect the WEB… What else ?.. Providing a beautiful atmosphere to web-developers. At the moment the whole world of web-development is cherishing the fresh breeze of RoR.
How much of INDIA is delighted by Ruby on Rails ?
Currently, the INDIAN side of Rails is a small community…but growing at a rapid rate. I am proudly working at VINSOL(New Delhi,India), a company full fledged working on rails.
VINSOL is currently holding some good clients for web-development and providing efficient services in Ruby on Rails.
Captcha in Ruby on Rails – Customize the use of captcha in the plugin validates_captcha
Hello Everyone !!
I have released a captcha plugin Simple Captcha. It is really simple to implement, and provides a cool feature of multiple styles of images.
Previous Post for validates_captcha
To implement captcha in RubyonRails, validates_captcha plugin can be a good option but a small customization i need with this plugin was to use it on some specific action and not to be validated the captcha field every time an instance of the model is saved or updated.
Here is a small work-around for its customization…
How to use customized captcha in RoR ?
Install the plugin validates_captcha in your rails application by running this command from the root of your application
ruby script/plugin install http://svn.2750flesk.com/validates_captcha
Make sure that you can now see the directory vedor/plugins/validates_captcha.
Now run these commands from your application root to make the image and data directories
ruby script/generate captcha store_directory ruby script/generate captcha image_directory
Here is the complete API for the usage of this plugin. I am describing the same idea as given in this API but in a bit more specific means.
Lets consider a model User in which we will implement the captcha.
Add the following code in the file app/models/user.rb
class User < ActiveRecord::Base
validates_captcha :if => :request_captcha_validation?
attr_accessor :request_captcha_validation
def request_captcha_validation?
(self.request_captcha_validation==true)? true : false
end
end
Handle View and Controller
Add the code in the view inside your existing form.
<% c = prepare_captcha :type => :image -%> <%= captcha_hidden_field c, 'user' %> <%= captcha_image_tag c %> <%= captcha_label 'user', 'Type in the text from the image above' %> <%= captcha_text_field 'user' %>
Your controller will look like
def save
# the line in bold represents that you need captcha validation.
# if captcha validation is not required then remove this line from your controller.
@user = User.new(params[:user])
@user.request_captcha_validation = true
@user.save
end
However image is too noisy and it contains repeated strings.
To improve the quality of images generated by the plugin validates_captcha visit Here.
