Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Friday, 6 May 2011

Rails 3 and lighttpd

This was performed on Archlinux with lighttpd 1.4.28 and rails 3.0.3

Prerequisites

Required packages:
  • lighttpd,
  • fcgi,
  • ruby,
  • and their dependencies...

Ruby Setup


Required gems:
  • fcgi,
  • bundler

(if you are behind a proxy, the magic gem command is :
# gem install GEM -r -p "http://[PROXY_URL]:[PROXY_PORT]"
)

Once you have that you need to create a "dispatch.fcgi" script to do all the rails magic. I found an example one at http://stackoverflow.com/questions/3296206/rails-3-and-fcgi .

#!/usr/bin/ruby

require 'rubygems'
require 'fcgi'

require_relative '../config/environment'

class Rack::PathInfoRewriter
  def initialize(app)
    @app = app
  end

  def call(env)
    env.delete('SCRIPT_NAME')
    parts = env['REQUEST_URI'].split('?')
    env['PATH_INFO'] = parts[0]
    env['QUERY_STRING'] = parts[1].to_s
    @app.call(env)
  end
end

Rack::Handler::FastCGI.run  Rack::PathInfoRewriter.new(YOUR_APP_NAME::Application)



Running a "bundle install" from your app root will make sure all the necessary gems are available for local use. Follow these instructions and run "ruby public/dispatch.fcgi", if you get no errors, voila!

Lighttpd Setup


Now, to set up lighttpd you need to merge this with your config:

server.modules   += ( "mod_fastcgi", "mod_rewrite" )


$HTTP["host"] == "localhost" {
        server.document-root = "/path/to/your/app/public/"

        server.dir-listing          = "disable"
        server.error-handler-404 = "/dispatch.fcgi"

        fastcgi.server      = ( ".fcgi" => ( "localhost" => (
                "min-procs"       => 1,
                "max-procs"       => 1,
                "socket" => "/tmp/ruby-beholder.socket",
                "bin-path" => "/path/to/your/app/public/dispatch.fcgi",
                "bin-environment" => ( "RAILS_ENV" => "development" )
        ) ) )

}

A quick "sudo /etc/rc.d/lighttpd restart" and a check of the error logs will tell you if it has worked

Monday, 5 January 2009

Ruby and Watir: Sending keyboard events to an element

Ok, so you need to send certain keyboard events to an element to properly test a webpage, but stuck how to do it?

Ive looked at some tutorials on the web, but there doesn't seem a simple solution.

However, I have been experimenting, and this method seems to work fine.

First off create your Watir::IE object

ie = Watir::IE.new

Then navigate to the page you are testing

ie.goto("mypage.myserver.com")

Grab the descriptor of the element you wish to send a keyboard command to (for example, a text field)

element = ie.textField(:id, "myText")

Now, I found that keyboard events only work if the Watir::IE window is on top and has focus, so for example if we wish to send a "Pageup" keyboard command to the element "myText" we would do so by

ie.bring_to_front
element.focus

element.container.focus
element.container.send_keys("{PGUP}")

This method does require Autoit(http://www.autoitscript.com/autoit3/) to be installed, and a full list of keyboard events can be found here: http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm