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
# https://codility.com/demo/results/demoJ2Q7MX-R8M/
# 100% performance and correctness
def solution(a)
return 1 unless a && a.size > 0
length = a.length + 1
sum1 = 0
sum2 = 0
sum1 = a.inject(&:+)
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'