Skip to content

Instantly share code, notes, and snippets.

View rtacconi's full-sized avatar

Riccardo Tacconi rtacconi

View GitHub Profile
# render a file (image, video) inside the browser
def inline
@video = Video.find(params[:id])
send_file @video.filepath.path, :type => @video.filepath_content_type
end
# force the browser to show the download modal box and send the file to the browser
# you can use the :xsendfile => true option
# send_file @video.filepath.path, :type => @video.filepath_content_type
def download
require File.dirname(__FILE__) + '/../test_helper'
class PickaxeBookGooggleSearchTest < ActiveSupport::TestCase
include WatirOnRails
# Uncomment the following lines to specify a test server.
# WatirOnRails defaults to http://localhost:3000
#
# server "localhost"
# port 3001
#!/usr/local/bin/ruby -w
require "rubygems"
require "highline/import"
# The old way, using ask() and say()...
choices = %w{ruby python perl}
say("This is the old way using ask() and say()...")
say("Please choose your favorite programming language:")
say(choices.map { |c| " #{c}\n" }.join)
context "should destroy participation" do
setup do
@configuration = Factory.create :configuration, :status => 'LIVE'
@p = Factory.create :participation, :configuration => @configuration
@admin = Factory.create :participant, :admin => true
login_as @admin
end
should "delete :destroy participations" do
assert_difference('Participation.count', -1) do
<html><body>You are being <a href="http://test.host/configurations/46/edit">redirected</a>.</body></html>
begin
p = Participant.find params[:id]
render :nothing => true, :status => 200
rescue
render :nothing => true, :status => 404
end
With this code:
browser.link(:text, "Move questions to...").click
browser.alert do
browser.button(:id => "alert").click
end #=> "the alert message"
I get this error:
#!/bin/sh
echo "recursively removing .svn folders from"
pwd
rm -rf `find . -type d -name .svn`
@rtacconi
rtacconi / gist:708121
Created November 20, 2010 20:21
Test unique attributes with RSpec and accept_values_for, a custom matcher
class CourseItem < ActiveRecord::Base
validates_presence_of :course_id, :day, :url
validates_uniqueness_of :course_id, :scope => :day, :message => "- this day has been already created."
end
describe CourseItem do
# check uniqueness using this matcher https://github.com/bogdan/accept_values_for
context "should create one item per day and per course only" do
before do
CourseItem.create! :day => 1, :course_id => 1, :url => '/courses/index.html'
@rtacconi
rtacconi / package-ubuntu-server-rvm.txt
Created June 20, 2011 19:47
Ubuntu server dependencies for Ruby 1.9.2 (rvm)
sudo aptitude install curl git-core ruby build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline-dev libxml2-dev git-core subversion autoconf